我仍然无法进入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
我该如何解决这个问题?当然,我可以尝试手动修复依赖项。但我更喜欢Composer和Zend使用的方法。
答案 0 :(得分:1)
ZF1和Composer不能一起使用。
ZF1不会知道您通过Composer安装的其他类/文件。
Composer Autoloading和ZF1
您始终需要将Composer Autoloader添加到ZF1。
" bin脚本的一次"和一次网络" public / index.php"。
脚本
请在zendframework1/bin/zf.php
文件的顶部添加以下行:
require '../vendor/autoload.php';
这将设置Composer Autoloader,以便PHPUnit类可以自动加载。
Sven的评论:
这不会永远存在。修补生成的bin / zf.php文件将在下次安装较新的ZF1版本时被覆盖 - 并且在新安装项目的另一台机器上完全无法开箱即用。
使用composer.json的脚本部分。您可以在那里添加PHP脚本,每次更新依赖项时都会自动修改zf.php文件(通过插入require语句)。
网络
您需要将上面的行添加到public/index.php
。
PHPUnit版本
请注意,您可能需要将phpUnit版本降低到" 3.4"。
PHPUnit for Zend Framework v1支持的分支是v3.4.x. 没有计划将ZFv1更新为任何较新版本的PHPUnit。
对于老朋友,你需要老朋友的部分:) 至少" Zend_Test_PHPUnit_ControllerTestCase"需要一些调整才能使它与phpUnit v4完全兼容。另见:https://stackoverflow.com/a/27092238/1163786
无论如何,......我的日食仍然不知道:...类名...
您可以将供应商文件夹添加到项目的包含路径中,以便扫描文件中的类名称和" Intellisense"开始工作了。
答案 1 :(得分:1)
我可以在它之后做一些更新命令吗?因为似乎命令" zf.sh创建项目。"已经流产了。或者它是否经历过任何错误?
无论如何,......我的日食仍然不知道这个: class IndexController扩展了Zend_Controller_Action .. Eclipse不知道Zend_Controller_Action是什么。 与测试文件夹相同... class IndexControllerTest扩展了Zend_Test_PHPUnit_ControllerTestCase Eclipse无法解析Zend_Test_PHPUnit_ControllerTestCase