phpunit错误和include_path

时间:2016-09-12 13:32:01

标签: php phpunit

我遇到了require_once函数和phpunit测试的问题。

我有一个文件Login_test.php调用模型,Prodotto.php,它在第2行有这个功能:

require_once('Oggetto.php');

Fist time,我试图从我的application / tests目录运行以下命令:

/opt/lampp/htdocs/my-project/application/tests$ php phpunit.phar controllers/api/Login_test.php 

输出显示如下错误:

Fatal error: main(): Failed opening required '/opt/lampp/htdocs/my-project/application/models/Oggetto.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/my-project/application/models/Prodotto.php on line 2

(在Prodotto.php中有require_once(' Oggetto.php'),两个文件都在/ opt / lampp / htdocs / my-project / application / models /目录中)

随后我尝试将错误显示的include_path中的Oggetto.php文件移到/ opt / lampp / lib / php中,并且使用phpunit进行测试运行正常!

之后我尝试了这个命令: php phpunit.phar --include-path / opt / lampp / htdocs / my-project / application / model / controller / api / Login_test.php,但输出再次给我错误:

遇到PHP错误

Severity:    Compile Error
Message:     main(): Failed opening required 'Oggetto.php' (include_path='/opt/lampp/htdocs/my-project/application/models/:.:/opt/lampp/lib/php')
Filename:    /opt/lampp/htdocs/my-project/application/models/Prodotto.php
Line Number: 2

我希望有人已经遇到并解决了这个错误。提前谢谢!

发布整个输出可能很有用:

Warning: Uncaught exception 'LogicException' with message 'Replacement data still remain' in /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/patcher/Patcher/MethodPatcher.php:75
Stack trace:
#0 /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/patcher/Patcher/AbstractPatcher.php(45): Kenjis\MonkeyPatch\Patcher\MethodPatcher::generateNewSource('<?php\n\n/**\n * T...')
#1 /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/patcher/MonkeyPatchManager.php(313): Kenjis\MonkeyPatch\Patcher\AbstractPatcher->patch('<?php\n\n/**\n * T...')
#2 /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/patcher/MonkeyPatchManager.php(276): Kenjis\MonkeyPatch\MonkeyPatchManager::execPatchers('<?php\n\n/**\n * T...')
#3 /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/patcher/IncludeStream.php(57): Kenjis\MonkeyPatch\MonkeyPatchManager::patch('/opt/lampp/htdo...')
#4 /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test in /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/patcher/Patcher/MethodPatcher.php on line 75

Call Stack:
    0.0149     694848   1. {main}() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:0
    0.1474   13330248   2. PHPUnit_TextUI_Command::main() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:569
    0.1475   13330872   3. PHPUnit_TextUI_Command->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:113
    0.2428   18638128   4. PHPUnit_TextUI_TestRunner->doRun() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:162
    0.2826   18798536   5. PHPUnit_Framework_TestSuite->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/TestRunner.php:465
    0.3158   19502704   6. PHPUnit_Framework_TestCase->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestSuite.php:753
    0.3158   19504672   7. PHPUnit_Framework_TestResult->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:888
    0.3784   19508752   8. PHPUnit_Framework_TestCase->runBare() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestResult.php:701
    0.3996   19710432   9. PHPUnit_Framework_TestCase->runTest() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:932
    0.4001   19711328  10. ReflectionMethod->invokeArgs() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4001   19711496  11. Login_test->test_prodotto_post_ok() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4169   19877616  12. CIPHPUnitTestCase->request() /opt/lampp/htdocs/my-project/application/tests/controllers/api/Login_test.php:39
    0.4171   19877976  13. CIPHPUnitTestRequest->request() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php:114
    0.4183   19878520  14. CIPHPUnitTestRequest->requestUri() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:141
    0.7082   20513064  15. CIPHPUnitTestRequest->createAndCallController() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:265
    1.0317   20935488  16. call_user_func_array:{/opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331}() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0317   20937424  17. REST_Controller->_remap() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0389   20941408  18. call_user_func_array:{/opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654}() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.0389   20942360  19. Login->prodotto_post() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.4195   23147264  20. CI_Loader->model() /opt/lampp/htdocs/my-project/application/controllers/api/Login.php:88
    1.4399   23591064  21. MY_Model->__construct() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:355
    1.4535   23599144  22. Pagamento->__after_construct() /opt/lampp/htdocs/my-project/application/core/MY_Model.php:98
    1.4596   23602568  23. CI_Loader->model() /opt/lampp/htdocs/my-project/application/models/Pagamento.php:63
   50.0535   29854528  24. require_once('/opt/lampp/htdocs/my-project/application/models/Prodotto.php') /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:335


Fatal error: main(): Failed opening required 'Oggetto.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/my-project/application/models/Prodotto.php on line 2

Call Stack:
    0.0149     694848   1. {main}() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:0
    0.1474   13330248   2. PHPUnit_TextUI_Command::main() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:569
    0.1475   13330872   3. PHPUnit_TextUI_Command->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:113
    0.2428   18638128   4. PHPUnit_TextUI_TestRunner->doRun() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:162
    0.2826   18798536   5. PHPUnit_Framework_TestSuite->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/TestRunner.php:465
    0.3158   19502704   6. PHPUnit_Framework_TestCase->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestSuite.php:753
    0.3158   19504672   7. PHPUnit_Framework_TestResult->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:888
    0.3784   19508752   8. PHPUnit_Framework_TestCase->runBare() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestResult.php:701
    0.3996   19710432   9. PHPUnit_Framework_TestCase->runTest() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:932
    0.4001   19711328  10. ReflectionMethod->invokeArgs() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4001   19711496  11. Login_test->test_prodotto_post_ok() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4169   19877616  12. CIPHPUnitTestCase->request() /opt/lampp/htdocs/my-project/application/tests/controllers/api/Login_test.php:39
    0.4171   19877976  13. CIPHPUnitTestRequest->request() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php:114
    0.4183   19878520  14. CIPHPUnitTestRequest->requestUri() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:141
    0.7082   20513064  15. CIPHPUnitTestRequest->createAndCallController() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:265
    1.0317   20935488  16. call_user_func_array:{/opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331}() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0317   20937424  17. REST_Controller->_remap() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0389   20941408  18. call_user_func_array:{/opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654}() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.0389   20942360  19. Login->prodotto_post() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.4195   23147264  20. CI_Loader->model() /opt/lampp/htdocs/my-project/application/controllers/api/Login.php:88
    1.4399   23591064  21. MY_Model->__construct() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:355
    1.4535   23599144  22. Pagamento->__after_construct() /opt/lampp/htdocs/my-project/application/core/MY_Model.php:98
    1.4596   23602568  23. CI_Loader->model() /opt/lampp/htdocs/my-project/application/models/Pagamento.php:63
   50.0535   29854528  24. require_once('/opt/lampp/htdocs/my-project/application/models/Prodotto.php') /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:335


A PHP Error was encountered

Severity:    Compile Error
Message:     main(): Failed opening required 'Oggetto.php' (include_path='.:/opt/lampp/lib/php')
Filename:    /opt/lampp/htdocs/my-project/application/models/Prodotto.php
Line Number: 2

Backtrace:


Fatal error: Uncaught exception 'CIPHPUnitTestExitException' with message 'exit() called in _error_handler() function' in /opt/lampp/htdocs/my-project/system/core/Common.php on line 635

Call Stack:
    0.0149     694848   1. {main}() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:0
    0.1474   13330248   2. PHPUnit_TextUI_Command::main() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:569
    0.1475   13330872   3. PHPUnit_TextUI_Command->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:113
    0.2428   18638128   4. PHPUnit_TextUI_TestRunner->doRun() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:162
    0.2826   18798536   5. PHPUnit_Framework_TestSuite->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/TestRunner.php:465
    0.3158   19502704   6. PHPUnit_Framework_TestCase->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestSuite.php:753
    0.3158   19504672   7. PHPUnit_Framework_TestResult->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:888
    0.3784   19508752   8. PHPUnit_Framework_TestCase->runBare() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestResult.php:701
    0.3996   19710432   9. PHPUnit_Framework_TestCase->runTest() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:932
    0.4001   19711328  10. ReflectionMethod->invokeArgs() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4001   19711496  11. Login_test->test_prodotto_post_ok() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4169   19877616  12. CIPHPUnitTestCase->request() /opt/lampp/htdocs/my-project/application/tests/controllers/api/Login_test.php:39
    0.4171   19877976  13. CIPHPUnitTestRequest->request() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php:114
    0.4183   19878520  14. CIPHPUnitTestRequest->requestUri() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:141
    0.7082   20513064  15. CIPHPUnitTestRequest->createAndCallController() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:265
    1.0317   20935488  16. call_user_func_array:{/opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331}() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0317   20937424  17. REST_Controller->_remap() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0389   20941408  18. call_user_func_array:{/opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654}() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.0389   20942360  19. Login->prodotto_post() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.4195   23147264  20. CI_Loader->model() /opt/lampp/htdocs/my-project/application/controllers/api/Login.php:88
    1.4399   23591064  21. MY_Model->__construct() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:355
    1.4535   23599144  22. Pagamento->__after_construct() /opt/lampp/htdocs/my-project/application/core/MY_Model.php:98
    1.4596   23602568  23. CI_Loader->model() /opt/lampp/htdocs/my-project/application/models/Pagamento.php:63
   50.0535   29854528  24. require_once('/opt/lampp/htdocs/my-project/application/models/Prodotto.php') /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:335

CIPHPUnitTestExitException: exit() called in _error_handler() function in /opt/lampp/htdocs/my-project/system/core/Common.php on line 635

Call Stack:
    0.0149     694848   1. {main}() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:0
    0.1474   13330248   2. PHPUnit_TextUI_Command::main() /opt/lampp/htdocs/my-project/application/tests/phpunit.phar:569
    0.1475   13330872   3. PHPUnit_TextUI_Command->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:113
    0.2428   18638128   4. PHPUnit_TextUI_TestRunner->doRun() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/Command.php:162
    0.2826   18798536   5. PHPUnit_Framework_TestSuite->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/TextUI/TestRunner.php:465
    0.3158   19502704   6. PHPUnit_Framework_TestCase->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestSuite.php:753
    0.3158   19504672   7. PHPUnit_Framework_TestResult->run() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:888
    0.3784   19508752   8. PHPUnit_Framework_TestCase->runBare() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestResult.php:701
    0.3996   19710432   9. PHPUnit_Framework_TestCase->runTest() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:932
    0.4001   19711328  10. ReflectionMethod->invokeArgs() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4001   19711496  11. Login_test->test_prodotto_post_ok() phar:///opt/lampp/htdocs/my-project/application/tests/phpunit.phar/phpunit/Framework/TestCase.php:1081
    0.4169   19877616  12. CIPHPUnitTestCase->request() /opt/lampp/htdocs/my-project/application/tests/controllers/api/Login_test.php:39
    0.4171   19877976  13. CIPHPUnitTestRequest->request() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php:114
    0.4183   19878520  14. CIPHPUnitTestRequest->requestUri() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:141
    0.7082   20513064  15. CIPHPUnitTestRequest->createAndCallController() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:265
    1.0317   20935488  16. call_user_func_array:{/opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331}() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0317   20937424  17. REST_Controller->_remap() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:331
    1.0389   20941408  18. call_user_func_array:{/opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654}() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.0389   20942360  19. Login->prodotto_post() /opt/lampp/htdocs/my-project/application/libraries/REST_Controller.php:654
    1.4195   23147264  20. CI_Loader->model() /opt/lampp/htdocs/my-project/application/controllers/api/Login.php:88
    1.4399   23591064  21. MY_Model->__construct() /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:355
    1.4535   23599144  22. Pagamento->__after_construct() /opt/lampp/htdocs/my-project/application/core/MY_Model.php:98
    1.4596   23602568  23. CI_Loader->model() /opt/lampp/htdocs/my-project/application/models/Pagamento.php:63
   50.0535   29854528  24. require_once('/opt/lampp/htdocs/my-project/application/models/Prodotto.php') /opt/lampp/htdocs/my-project/application/tests/_ci_phpunit_test/replacing/core/Loader.php:335
   55.7306   29946560  25. _shutdown_handler() /opt/lampp/htdocs/my-project/system/core/Common.php:0
   55.7377   29947544  26. _error_handler() /opt/lampp/htdocs/my-project/system/core/Common.php:692
   55.7654   29990544  27. exit__() /opt/lampp/htdocs/my-project/system/core/Common.php:635

0 个答案:

没有答案