我尝试在我的laravel项目中开始使用phpunit。
我打电话给“phpunit”并收到此错误:
$ phpunit
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /home/bee/www/postaler/phpunit.xml
EPHP Fatal error: Cannot redeclare Helper\isMenuActive() (previously declared in /home/bee/www/postaler/app/helpers.php:4) in /home/bee/www/postaler/app/helpers.php on line 6
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:130
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:192
PHP 5. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/TextUI/TestRunner.php:325
PHP 6. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:705
PHP 7. PHPUnit_Framework_TestSuite->runTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:745
PHP 8. PHPUnit_Framework_TestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:772
PHP 9. PHPUnit_Framework_TestResult->run() /usr/share/php/PHPUnit/Framework/TestCase.php:751
PHP 10. PHPUnit_Framework_TestCase->runBare() /usr/share/php/PHPUnit/Framework/TestResult.php:649
PHP 11. Illuminate\Foundation\Testing\TestCase->setUp() /usr/share/php/PHPUnit/Framework/TestCase.php:801
PHP 12. Illuminate\Foundation\Testing\TestCase->refreshApplication() /home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:31
PHP 13. Illuminate\Foundation\Application->boot() /home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:48
PHP 14. Illuminate\Foundation\Application->bootApplication() /home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:552
PHP 15. Illuminate\Foundation\Application->fireAppCallbacks() /home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:569
PHP 16. call_user_func:{/home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:792}() /home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:792
PHP 17. TestCase->{closure:/home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/start.php:223-271}() /home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:792
PHP 18. require() /home/bee/www/postaler/vendor/laravel/framework/src/Illuminate/Foundation/start.php:239
我的帮助代码
<?php namespace Helper;
//app/helpers.php
function isMenuActive($url_segment) {
if (\Request::segment(1) == $url_segment) { return " active"; }
}
我在app / start / global.php
中包含了帮助文件require app_path().'/helpers.php'
我的测试脚本
<?php
// app/tests/FromTest.php
class FromTest extends TestCase {
public function testFrom()
{
$response = $this->call('GET', 'user/profile');
$this->assertTrue(true);
}
}
答案 0 :(得分:0)
app/start/global.php
执行一次,不应该用于类/函数/常量定义。而是在您的composer.json中添加files
自动加载规则。
"files": ["src/functions.php"],