Mockery和Laravel测试:在非对象上调用成员函数__call()

时间:2014-01-16 23:41:16

标签: php unit-testing laravel-4 phpunit

我正在尝试使用https://github.com/JeffreyWay/Laravel-4-Generators

生成的laravel中运行测试

我的测试用例文件是这样的:http://pastebin.com/U9zfmyM6

控制器文件:http://pastebin.com/aiYZa6dA

控制器生成的测试文件如下:http://pastebin.com/nh9Bv9ht

我用vendor/bin/phpunit运行phpunit,我得到了这个:

tom@debian:~/public_html/madserver-laravel$ vendor/bin/phpunit 
PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from /home/tom/public_html/madserver-laravel/phpunit.xml

...PHP Fatal error:  Call to a member function __call() on a non-object in /home/tom/public_html/madserver-laravel/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(16) : eval()'d code on line 350
PHP Stack trace:
PHP   1. {main}() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/composer/bin/phpunit:63
PHP   3. PHPUnit_TextUI_Command->run() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->run() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705
PHP   7. PHPUnit_Framework_TestSuite->runTest() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
PHP   8. PHPUnit_Framework_TestCase->run() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
PHP   9. PHPUnit_Framework_TestResult->run() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:783
PHP  10. PHPUnit_Framework_TestCase->runBare() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648
PHP  11. PHPUnit_Framework_TestCase->runTest() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:838
PHP  12. ReflectionMethod->invokeArgs() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:983
PHP  13. BannersTest->testStore() /home/tom/public_html/madserver-laravel/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:983
PHP  14. Illuminate\Foundation\Testing\TestCase->call() /home/tom/public_html/madserver-laravel/app/tests/controllers/BannersTest.php:47
PHP  15. call_user_func_array() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:74
PHP  16. Symfony\Component\BrowserKit\Client->request() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:74
PHP  17. Symfony\Component\HttpKernel\Client->doRequest() /home/tom/public_html/madserver-laravel/vendor/symfony/browser-kit/Symfony/Component/BrowserKit/Client.php:319
PHP  18. Illuminate\Foundation\Application->handle() /home/tom/public_html/madserver-laravel/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Client.php:81
PHP  19. Illuminate\Foundation\Application->dispatch() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:691
PHP  20. Illuminate\Routing\Router->dispatch() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:716
PHP  21. Illuminate\Routing\Router->dispatchToRoute() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php:939
PHP  22. Illuminate\Routing\Route->run() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php:969
PHP  23. call_user_func_array() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php:105
PHP  24. Illuminate\Routing\Router->Illuminate\Routing\{closure}() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php:105
PHP  25. Illuminate\Routing\ControllerDispatcher->dispatch() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php:905
PHP  26. Illuminate\Routing\ControllerDispatcher->call() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:62
PHP  27. Illuminate\Routing\Controller->callAction() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:93
PHP  28. call_user_func_array() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:194
PHP  29. BannersController->store() /home/tom/public_html/madserver-laravel/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:194
PHP  30. Mockery_0_Banner::create() /home/tom/public_html/madserver-laravel/app/controllers/BannersController.php:65
PHP  31. Mockery_0_Banner::__callStatic() /home/tom/public_html/madserver-laravel/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(16) : eval()'d code:946
tom@debian:~/public_html/madserver-laravel$ 

我已经进行了大量的测试并测试了很多东西以使其工作,但同样的结果:(

我做错了什么?

提前致谢!

2 个答案:

答案 0 :(得分:1)

对我而言,移动

解决了这个问题
    $this->mock = m::mock('Eloquent', 'Models\Broadcasts\Voice\VoiceBroadcast')->shouldDeferMissing();
    $this->collection = m::mock('Illuminate\Database\Eloquent\Collection')->shouldDeferMissing();

__construct()setUp()

答案 1 :(得分:0)

我遇到了同样的问题。我通过将$this->mock = m::mock('Eloquent', 'Banner');更改为$this->mock = m::mock('Banner');来完成测试。

但是我不确定这个问题或者我错过了Eloquent param。