在简单测试中使用assertTrue方法错误进行Laravel测试

时间:2013-12-10 13:47:22

标签: laravel phpunit laravel-4

我试图用Laravel 4做一个真正简单的测试但是会出错。

这是我的超级简单测试。

class SignupTest extends TestCase {
    public function testIndex()
    {
        $this->call('GET', '/');
        $this->assertResponseOk();
    }
}

错误堆栈跟踪

PHP Fatal error:  Call to undefined method SignupTest::assertTrue() in /home/domain/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php on line 135
PHP Stack trace:
PHP   1. {main}() /home/domain/vendor/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/domain/vendor/bin/phpunit:63
PHP   3. PHPUnit_TextUI_Command->run() /home/domain/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/domain/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /home/domain/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->runTest() /home/domain/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745
PHP   7. PHPUnit_Framework_TestCase->run() /home/domain/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775
PHP   8. PHPUnit_Framework_TestResult->run() /home/domain/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:783
PHP   9. PHPUnit_Framework_TestCase->runBare() /home/domain/vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648
PHP  10. PHPUnit_Framework_TestCase->runTest() /home/domain/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:838
PHP  11. ReflectionMethod->invokeArgs() /home/domain/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:983
PHP  12. SignupTest->testIndex() /home/domain/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:983
PHP  13. Illuminate\Foundation\Testing\TestCase->assertResponseOk() /home/domain/app/tests/Unit/Controllers/SignupTest.php:9

您可以看到我正在扩展TestCase,因此我应该可以访问assertTrue方法。

Composer Part Incase it help.s

"require-dev": {
    "phpunit/phpunit": "3.7.*",
    "way/laravel-test-helpers": "dev-master",
    "fzaninotto/faker": "dev-master",
    "mockery/mockery": "dev-master@dev"
},

我已经转储了自动加载并清除了编译。

希望你能提出建议。

1 个答案:

答案 0 :(得分:0)

事实证明,phpunit是旧版本,我不得不重新安装所有供应商文件。