Php 模拟函数未被调用
在模拟接口方法时,我得到以下错误 注- 我正在使用服务存储库模式,并基于此创建了一个服务,并从中调用一个存储库,在其中执行数据库操作Php 模拟函数未被调用,php,phpunit,lumen,mockery,Php,Phpunit,Lumen,Mockery,在模拟接口方法时,我得到以下错误 注- 我正在使用服务存储库模式,并基于此创建了一个服务,并从中调用一个存储库,在其中执行数据库操作 流明版本-5.4 PhpUnit版本-4.8.35 错误- 代码- 我解决了这个问题。我在服务中使用toArray()函数将集合对象转换为数组。模拟存储库需要集合,但我提供了数组。所以我也嘲笑了这个系列,现在一切都正常了。我解决了这个问题。我在服务中使用toArray()函数将集合对象转换为数组。模拟存储库需要集合,但我提供了数组。所以我也嘲笑了这个系列,现在
- 流明版本-5.4
- PhpUnit版本-4.8.35
我解决了这个问题。我在服务中使用toArray()函数将集合对象转换为数组。模拟存储库需要集合,但我提供了数组。所以我也嘲笑了这个系列,现在一切都正常了。我解决了这个问题。我在服务中使用toArray()函数将集合对象转换为数组。模拟存储库需要集合,但我提供了数组。所以我也嘲笑了这个系列,现在一切都正常了。有了这个错误,你的问题是?我为什么会犯这个错误?有了这个错误,你的问题是?我为什么会犯这个错误?
E:\event>phpunit
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.
..E
Time: 4.63 seconds, Memory: 7.25MB
There was 1 error:
1) EventServiceTest::testEventListing
Mockery\Exception\InvalidCountException: Method getEventList() from Mockery_0_App_Repositories_Event_EventInterface should be called exactly 1 times but called 0 times.
E:\event\vendor\mockery\mockery\library\Mockery\CountValidator\Exact.php:37
E:\event\vendor\mockery\mockery\library\Mockery\Expectation.php:298
E:\event\vendor\mockery\mockery\library\Mockery\ExpectationDirector.php:120
E:\event\vendor\mockery\mockery\library\Mockery\Container.php:297
E:\event\vendor\mockery\mockery\library\Mockery\Container.php:282
E:\event\vendor\mockery\mockery\library\Mockery.php:152
E:\event\vendor\laravel\lumen-framework\src\Testing\TestCase.php:107
E:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
E:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
FAILURES!
Tests: 3, Assertions: 2, Errors: 1.
public function testEventListing()
{
$data = [
'startDate' => '2017-06-14 00:00:00',
'endDate' => '2017-06-14 23:59:59'
];
$reposneData = array(
array(
'eventDate' => "2017-06-14 08:00:00"
),
'status' => 1
);
//Mocking the event Repository
$eventRepoMock = \Mockery::mock ( App\Repositories\Event\EventInterface::class );
$eventRepoMock->shouldReceive ( 'getEventList' )
->once ()
->with ( $eventData )
->andReturn ( $reposneData );
$eventService = new EventService($eventRepoMock);
//Fetching mocked data
$eventObj = $eventService->geteventList( $eventData );
//Asserting based on success result.
$this->assertEquals(1, $eventObj['status']);
}