单元测试 – 找不到“Mockery”类

前端之家收集整理的这篇文章主要介绍了单元测试 – 找不到“Mockery”类前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用laravel(4.1)框架,我读了“Laravel-testing-decoding”,这是Jeffrey Wey的电子书.

我想测试我的模态用户和我的方法setPasswordAttribute($password)

我的单元测试:

  1. <?PHP
  2.  
  3. class UserTest extends TestCase {
  4.  
  5. public function testHashesPasswordWhenSet(){
  6.  
  7. Hash::shouldReceive('make')->once()->andReturn('hashed');
  8.  
  9. $user = new User;
  10. $user->password = 'food';
  11.  
  12. $this->assertEquals('hashed',$user->password);
  13. }
  14. }

但是当我启动CLI:PHPunit时它会返回一个错误:致命错误:找不到类’Mockery’

完全错误

  1. Fatal error: Class 'Mockery' not found in /Applications/MAMP/htdocs/ptf/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.PHP on line 84
  2.  
  3. Call Stack:
  4. 0.0021 236384 1. {main}() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/composer/bin/PHPunit:0
  5. 0.0294 1425104 2. PHPUnit_TextUI_Command::main() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/composer/bin/PHPunit:63
  6. 0.0294 1425336 3. PHPUnit_TextUI_Command->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/TextUI/Command.PHP:129
  7. 0.0692 3626416 4. PHPUnit_TextUI_TestRunner->doRun() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/TextUI/Command.PHP:176
  8. 0.0741 3944720 5. PHPUnit_Framework_TestSuite->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/TextUI/TestRunner.PHP:349
  9. 0.0741 3946368 6. PHPUnit_Framework_TestSuite->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestSuite.PHP:705
  10. 0.0742 3946968 7. PHPUnit_Framework_TestSuite->runTest() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestSuite.PHP:745
  11. 0.0742 3947000 8. PHPUnit_Framework_TestCase->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestSuite.PHP:775
  12. 0.0743 3948232 9. PHPUnit_Framework_TestResult->run() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:783
  13. 0.0754 4005504 10. PHPUnit_Framework_TestCase->runBare() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestResult.PHP:648
  14. 0.2926 15417592 11. PHPUnit_Framework_TestCase->runTest() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:838
  15. 0.2926 15418872 12. ReflectionMethod->invokeArgs() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:983
  16. 0.2926 15418904 13. UserTest->testHashesPasswordWhenSet() /Applications/MAMP/htdocs/ptf/vendor/PHPunit/PHPunit/PHPUnit/Framework/TestCase.PHP:983
  17. 0.2928 15426728 14. Illuminate\Support\Facades\Facade::shouldReceive() /Applications/MAMP/htdocs/ptf/app/tests/models/UserTest.PHP:7
  18. 0.2928 15426944 15. Illuminate\Support\Facades\Facade::createFreshMockInstance() /Applications/MAMP/htdocs/ptf/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.PHP:50
  19. 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:
  1. "require-dev": {
  2. "mockery/mockery": "dev-master@dev"
  3. }

然后运行:

  1. composer update

猜你在找的PHP相关文章