unit testing - phpunit error with app helper in laravel 4 -


i try start using phpunit on laravel project.

i call "phpunit" , got error:

$ phpunit  phpunit 3.6.10 sebastian bergmann.  configuration read /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 

my helper code

<?php namespace helper; //app/helpers.php  function ismenuactive($url_segment) {     if (\request::segment(1) == $url_segment) { return " active"; } } 

i included helper file in app/start/global.php

require app_path().'/helpers.php' 

my test script

<?php // app/tests/fromtest.php class fromtest extends testcase {      public function testfrom()     {         $response = $this->call('get', 'user/profile');          $this->asserttrue(true);     }  } 

app/start/global.php executed once each request , should not used class/function/constant definitions. instead, add files autoload rule composer.json.

"files": ["src/functions.php"], 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -