【发布时间】:2013-12-28 01:47:27
【问题描述】:
我正在尝试使用 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"
},
我已经转储自动加载并清除编译。
希望你能给点建议。
【问题讨论】:
-
SignupTest 的第 9 行是什么?
-
assertTrue 方法:$this->assertResponseOk();
-
您能否显示您的
app/tests文件夹、完整的SignupTest类和composer.json自动加载部分的内容? -
app/tests 文件夹仅包含您在上面看到的类和 Laravel 创建的 TestCase 文件。而SignupTest就是上面的一切,我在上面添加了require-dev composer部分。