Тестирование phpUnit заглушка

volnistii11

Пытаюсь реализовать заглушку метода ReadOffices внутри метода SearchOffices, но у меня не выходит, в консоле пишет :

Код (Text):
  1. 1) TestStub::testSearch
  2. Failed asserting that null is identical to Array &0 (
  3. ‘offices’ => Array &1 (
  4.     0 => Array &2 (
  5.         ‘id’ => 3
  6.         ‘address’ => ‘Moscow 21 Snezhnaya Street’
  7.         ‘workingHours’ => ‘8:00-20:00’
  8.         ‘rentalPrice($)’ => 4300
  9.     )
  10. )
  11. ).

Что я делаю не так? index.php

PHP:
  1.        <?php
  2.    
  3.     class Offices
  4.     {
  5.    
  6.         public function ReadOffices()
  7.         {
  8.             $Offices = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . ‘office.json’);
  9.             return json_decode($Offices, true);
  10.         }
  11.    
  12.    
  13.         public function SearchOffices()
  14.         {
  15.             $jsonOffices = $this->ReadOffices();
  16.    
  17.             return $jsonOffices;
  18.         }
  19.    
  20.     }

test.class.php

PHP:
  1. <?php
  2.     require ‘index.php’;
  3.    
  4.    
  5.    
  6.     class TestStub extends PHPUnitFrameworkTestCase
  7.     {
  8.    
  9.    
  10.         public function testSearch()
  11.         {
  12.    
  13.             //Создаем заглушку
  14.             $stub = $this->createMock(Offices::class);
  15.    
  16.             //Настраиваем заглушку ReadOffices
  17.             $stub->method(‘ReadOffices’)
  18.                 ->willReturn([
  19.                     ‘offices’ => [
  20.                         0 => [
  21.                             ‘id’ => 3,
  22.                             ‘address’ => ‘Moscow 21 Snezhnaya Street’,
  23.                             ‘workingHours’ => ‘8:00-20:00’,
  24.                             ‘rentalPrice($)’ => 4300
  25.                         ]
  26.                     ]
  27.                 ]);
  28.    
  29.             //Тестируем метод SearchOffices
  30.             $this->assertSame([
  31.                 ‘offices’ => [
  32.                     0 => [
  33.                         ‘id’ => 3,
  34.                         ‘address’ => ‘Moscow 21 Snezhnaya Street’,
  35.                         ‘workingHours’ => ‘8:00-20:00’,
  36.                         ‘rentalPrice($)’ => 4300
  37.                     ]
  38.                 ]
  39.             ],$stub->SearchOffices());
  40.    
  41.         }
  42.    
  43.    
  44.     }
 

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *