如何创建一个包含PHPUnit的Zend1.12项目



我仍然很难进入Zend Framework。

我使用的是这个Composer配置:

{
"name": "MyProjectsName/zf1-test",
"description": "som description",
"type": "project",
"keywords": [
"framework",
"zf1"
],
"require": {
"zendframework/zendframework1": "1.12.11"
},
"require-dev": {
"phpunit/phpunit": "4.1.0",
"phpunit/dbunit": "1.3.0"
}
}

这些是我的命令:

sudo mkdir /var/www/projects/MyProjectsName/
# and put that composer file in the folder
# /var/www/projects/MyProjectsName/composer.json
sudo chown www-data:www-data -R /var/www/projects/MyProjectsName/
sudo chmod 775 -R /var/www/projects/MyProjectsName/
cd /var/www/projects/MyProjectsName/
sudo composer update
sudo ./vendor/zendframework/zendframework1/bin/zf.sh create project .
cd /var/www/projects/

但这行不通。它抛出一个错误:

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Test/PHPUnit/ControllerTestCase.php on line 48

这是完整的堆栈跟踪:

n00n@lubuntu-dev:/var/www/projects/MyProjectsName$ sudo composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing zendframework/zendframework1 (1.12.11)
Loading from cache
- Installing symfony/yaml (v2.6.6)
Loading from cache
- Installing sebastian/version (1.0.5)
Loading from cache
- Installing sebastian/recursion-context (1.0.0)
Loading from cache
- Installing sebastian/exporter (1.2.0)
Loading from cache
- Installing sebastian/environment (1.2.2)
Loading from cache
- Installing sebastian/diff (1.3.0)
Loading from cache
- Installing sebastian/comparator (1.1.1)
Loading from cache
- Installing doctrine/instantiator (1.0.4)
Loading from cache
- Installing phpunit/php-text-template (1.2.0)
Loading from cache
- Installing phpunit/phpunit-mock-objects (2.3.1)
Loading from cache
- Installing phpunit/php-timer (1.0.5)
Loading from cache
- Installing phpunit/php-file-iterator (1.3.4)
Loading from cache
- Installing phpunit/php-token-stream (1.4.1)
Loading from cache
- Installing phpunit/php-code-coverage (2.0.16)
Loading from cache
- Installing phpunit/phpunit (4.1.0)
Loading from cache
- Installing phpunit/dbunit (1.3.0)
Loading from cache
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files
n00n@lubuntu-dev:/var/www/projects/MyProjectsName$ 

一切都很顺利。。。但现在,创建zend项目的下一个命令失败了。。。。

n00n@lubuntu-dev:/var/www/projects/MyProjectsName$ sudo ./vendor/zendframework/zendframework1/bin/zf.sh create project .
Creating project at /var/www/projects/MyProjectsName
Note: This command created a web project, for more information setting up your VHOST, please see docs/README
PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found in /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Test/PHPUnit/ControllerTestCase.php on line 48
PHP Stack trace:
PHP   1. {main}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:0
PHP   2. ZF::main() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:623
PHP   3. ZF->run() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:74
PHP   4. ZF->_runTool() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:117
PHP   5. Zend_Tool_Framework_Client_Abstract->dispatch() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:600
PHP   6. Zend_Tool_Framework_Client_Abstract->_handleDispatch() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:241
PHP   7. Zend_Tool_Framework_Client_Abstract->_handleDispatchExecution() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:318
PHP   8. call_user_func_array:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:324}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:324
PHP   9. Zend_Tool_Project_Provider_Project->create() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:324
PHP  10. Zend_Tool_Project_Profile_Resource->create() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Provider/Project.php:107
PHP  11. Zend_Tool_Project_Profile_Resource->__call() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Provider/Project.php:107
PHP  12. call_user_func_array:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Profile/Resource.php:256}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Profile/Resource.php:256
PHP  13. Zend_Tool_Project_Context_Zf_TestApplicationActionMethod->create() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Profile/Resource.php:256
PHP  14. Zend_CodeGenerator_Php_File::fromReflectedFileName() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Context/Zf/TestApplicationActionMethod.php:176
PHP  15. include() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/CodeGenerator/Php/File.php:124
PHP  16. spl_autoload_call() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/CodeGenerator/Php/File.php:4
PHP  17. Zend_Loader_Autoloader::autoload() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/CodeGenerator/Php/File.php:0
PHP  18. call_user_func:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:124}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:124
PHP  19. Zend_Loader_Autoloader->_autoload() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:124
PHP  20. call_user_func:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:479}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:479
PHP  21. Zend_Loader::loadClass() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:479
PHP  22. Zend_Loader::loadFile() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader.php:82
PHP  23. include_once() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader.php:134
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Test/PHPUnit/ControllerTestCase.php on line 48
Call Stack:
0.0014     308896   1. {main}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:0
0.0016     308944   2. ZF::main() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:623
0.0065     559080   3. ZF->run() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:74
0.0065     559216   4. ZF->_runTool() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:117
0.0082     629864   5. Zend_Tool_Framework_Client_Abstract->dispatch() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/bin/zf.php:600
0.1806    4532200   6. Zend_Tool_Framework_Client_Abstract->_handleDispatch() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:241
0.1807    4532952   7. Zend_Tool_Framework_Client_Abstract->_handleDispatchExecution() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:318
0.1808    4533392   8. call_user_func_array:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:324}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:324
0.1808    4534304   9. Zend_Tool_Project_Provider_Project->create() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Framework/Client/Abstract.php:324
0.2263    4724520  10. Zend_Tool_Project_Profile_Resource->create() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Provider/Project.php:107
0.2263    4724704  11. Zend_Tool_Project_Profile_Resource->__call() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Provider/Project.php:107
0.2263    4725144  12. call_user_func_array:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Profile/Resource.php:256}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Profile/Resource.php:256
0.2263    4725632  13. Zend_Tool_Project_Context_Zf_TestApplicationActionMethod->create() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Profile/Resource.php:256
0.2265    4725904  14. Zend_CodeGenerator_Php_File::fromReflectedFileName() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Tool/Project/Context/Zf/TestApplicationActionMethod.php:176
0.2269    4730368  15. include('/var/www/projects/MyProjectsName/tests/application/controllers/IndexControllerTest.php') /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/CodeGenerator/Php/File.php:124
0.2269    4730640  16. spl_autoload_call() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/CodeGenerator/Php/File.php:4
0.2269    4730696  17. Zend_Loader_Autoloader::autoload() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/CodeGenerator/Php/File.php:0
0.2270    4731048  18. call_user_func:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:124}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:124
0.2270    4731080  19. Zend_Loader_Autoloader->_autoload() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:124
0.2270    4731128  20. call_user_func:{/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:479}() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:479
0.2270    4731160  21. Zend_Loader::loadClass() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader/Autoloader.php:479
0.2271    4731416  22. Zend_Loader::loadFile() /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader.php:82
0.2306    4959256  23. include_once('/var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Test/PHPUnit/ControllerTestCase.php') /var/www/projects/MyProjectsName/vendor/zendframework/zendframework1/library/Zend/Loader.php:134

我该如何解决这个问题?当然,我可以尝试手动修复依赖关系。但我更喜欢作曲家和曾德使用的方式。

我可以在它之后发出某种更新命令吗?因为命令"zf.sh创建项目"似乎已中止。还是出现了任何错误?

无论如何,。。。我的eclipse仍然不知道这一点:类IndexController扩展Zend_Controller_Action。。Eclipse不知道Zend_Controller_Action是什么。与测试文件夹相同。。。类IndexControllerTest扩展Zend_Test_PHPUnit_ControllerTestCaseEclipse无法解析Zend_Test_PHPUnit_ControllerTestCase

ZF1和Composer不能开箱即用地协同工作。

ZF1将不知道您通过Composer安装的其他类/文件。

Composer自动加载和ZF1

您总是需要将Composer Autoloader添加到ZF1中。

一次用于";bin脚本";并且一次用于web";public/index.php";。

  • 脚本

    请在zendframework1/bin/zf.php文件的顶部添加以下行:

    require '../vendor/autoload.php';

    这将设置Composer Autoloader,以便PHPUnit类自动加载。

    Sven评论:

    这不会永远持续下去。下一次安装新的ZF1版本时,对生成的bin/zf.php文件进行修补将被覆盖,而且在新安装项目的另一台机器上,它将完全无法开箱即用。

    使用composer.json的脚本部分。您可以在那里添加一个PHP脚本,它在每次更新依赖项时自动修改zf.PHP文件(通过插入require语句)。

  • Web

    您还需要将上面的行添加到public/index.php中。

PHPUnit版本

请注意,您可能需要将phpUnit版本降低到";3.4〃;。

引用Adam Lundrigan:

Zend Framework v1支持的PHPUnit分支是v3.4.x。目前还没有计划将ZFv1更新到任何新版本的PHPUnit。

对于旧计时器,您需要旧计时器部件:)至少;Zend_Test_PHPUnit_ControllerTestCase";需要进行一些调整,使其与phpUnitv4完全兼容。另请参阅:https://stackoverflow.com/a/27092238/1163786


无论如何,。。。我的日食仍然不知道:。。。类名。。。

您可以将供应商文件夹添加到项目的include路径中,以便扫描文件中的类名和"Intellisense";开始工作。

相关内容

  • 没有找到相关文章

最新更新