Php Mockry在测试Laravel facade时抛出NoMatchingExpectationException异常

Php Mockry在测试Laravel facade时抛出NoMatchingExpectationException异常,php,laravel,laravel-4,phpunit,mockery,Php,Laravel,Laravel 4,Phpunit,Mockery,我正在尝试测试我的一个服务类,但无法通过PHPUnit测试 未通过测试的相关部分: File::shouldReceive('put')->with('app/storage/logs/laravel.log', 'New content.')->once()->andReturn(12); 我尝试测试的代码(简化版): 我得到的例外情况是: Time: 1.72 seconds, Memory: 17.50Mb There was 1 error: 1) Unit\Se

我正在尝试测试我的一个服务类,但无法通过PHPUnit测试

未通过测试的相关部分:

File::shouldReceive('put')->with('app/storage/logs/laravel.log', 'New content.')->once()->andReturn(12);
我尝试测试的代码(简化版):

我得到的例外情况是:

Time: 1.72 seconds, Memory: 17.50Mb

There was 1 error:

1) Unit\Services\Maintenance\LogCleanerTest::testLogsAreClearedAndUpdated
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_0_Illuminate_Filesystem_Filesystem::put("app/storage/logs/laravel.log", "Last maintenance check performed at Tue, Jul 15, 2014 12:16 PM. The old logs have been deleted.
"). Either the method was unexpected or its arguments matched no expected argument list for this method


/home/vagrant/Code/MyApp/vendor/mockery/mockery/library/Mockery/ExpectationDirector.php:93
/home/vagrant/Code/MyApp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:211
/home/vagrant/Code/MyApp/app/Code/Services/Maintenance/LogCleaner.php:19
/home/vagrant/Code/MyApp/app/Code/Services/Maintenance/LogCleaner.php:19
/home/vagrant/Code/MyApp/app/tests/Unit/Services/Maintenance/LogCleanerTest.php:30
/home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:179
/home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:132
有人能解释一下我做错了什么吗?任何帮助都将不胜感激。

如:

File::shouldReceive('put')->with('app/storage/logs/laravel.log', 'Last maintenance check performed at')->once()->andReturn(12);

应该有用。您告诉Mockry将“新内容”作为第二个参数,但您的代码正在发送“上次维护检查…”。我相信Mockry会在默认情况下尝试正则表达式匹配,如果它不能匹配精确的字符串。

谢谢。我现在能够通过测试,但是只有当两个字符串完全匹配时才会发生。还有其他方法可以让模拟识别部分文本匹配吗(或者如果可能的话)?@kajetons关键是测试应该给你一个与你期望的完全匹配的结果,否则这可能是有bug的迹象。还有其他方法可以编写期望,这样你就不需要完全匹配。看精彩的节目。但是,正如@TheShift Exchange notes所述,关键是您的输出与您的预期相符,因此请小心使用这些方法。
File::shouldReceive('put')->with('app/storage/logs/laravel.log', 'Last maintenance check performed at')->once()->andReturn(12);