我使用laravel(4.1)框架,我读了“Laravel-testing-decoding”,这是Jeffrey Wey的电子书.
我想测试我的模态用户和我的方法setPasswordAttribute($password)
我的单元测试:
<?PHP class UserTest extends TestCase { public function testHashesPasswordWhenSet(){ Hash::shouldReceive('make')->once()->andReturn('hashed'); $user = new User; $user->password = 'food'; $this->assertEquals('hashed',$user->password); } }
但是当我启动CLI:PHPunit时它会返回一个错误:致命错误:找不到类’Mockery’
完全错误:
Fatal error: Class 'Mockery' not found in /Applications/MAMP/htdocs/ptf/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.PHP on line 84 Call Stack: 0.0021 236384 1. {main}() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/composer/bin/PHPunit:0 0.0294 1425104 2. PHPUnit_TextUI_Command::main() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/composer/bin/PHPunit:63 0.0294 1425336 3. PHPUnit_TextUI_Command->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/TextUI/Command.PHP:129 0.0692 3626416 4. PHPUnit_TextUI_TestRunner->doRun() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/TextUI/Command.PHP:176 0.0741 3944720 5. PHPUnit_Framework_TestSuite->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/TextUI/TestRunner.PHP:349 0.0741 3946368 6. PHPUnit_Framework_TestSuite->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestSuite.PHP:705 0.0742 3946968 7. PHPUnit_Framework_TestSuite->runTest() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestSuite.PHP:745 0.0742 3947000 8. PHPUnit_Framework_TestCase->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestSuite.PHP:775 0.0743 3948232 9. PHPUnit_Framework_TestResult->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:783 0.0754 4005504 10. PHPUnit_Framework_TestCase->runBare() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestResult.PHP:648 0.2926 15417592 11. PHPUnit_Framework_TestCase->runTest() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:838 0.2926 15418872 12. ReflectionMethod->invokeArgs() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:983 0.2926 15418904 13. UserTest->testHashesPasswordWhenSet() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:983 0.2928 15426728 14. Illuminate\Support\Facades\Facade::shouldReceive() /Applications/MAMP/htdocs/ptf/app/tests/models/UserTest.PHP:7 0.2928 15426944 15. Illuminate\Support\Facades\Facade::createFreshMockInstance() /Applications/MAMP/htdocs/ptf/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.PHP:50 0.2928 15427040 16. Illuminate\Support\Facades\Facade::createMockByName() /Applications/MAMP/htdocs/ptf/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.PHP:64
我不明白,为什么我有这个错误.
你有Mockery安装?
如果没有,请更新您的composer.json:
原文链接:https://www.f2er.com/php/136067.html如果没有,请更新您的composer.json:
"require-dev": { "mockery/mockery": "dev-master@dev" }
然后运行:
composer update