将PHPUnit添加到现有的Cakephp 2.0 [英] Adding PHPUnit to an existing Cakephp 2.0

查看:98
本文介绍了将PHPUnit添加到现有的Cakephp 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何将PHPUnit添加到不是使用composer创建的现有CakePHP 2.0项目中吗?

Does anyone know how to add PHPUnit to an existing CakePHP 2.0 project that wasn't created using composer?

我正在尝试将PHPUnit添加到不是使用composer创建的现有CakePHP 2.0项目中,并且我无法让CakePHP看到已安装PHPUnit.我正在使用Windows计算机.

I am trying to add PHPUnit to an existing CakePHP 2.0 project that wasn't created with composer and I cannot get CakePHP to see that PHPUnit is installed. I am using a Windows machine.

这是我到目前为止所采取的步骤:

Here are the steps I have taken so far:

  1. 通过composer全局安装了PHPUnit 3.7.32
  2. 将PHPUnit添加到我的路径
  3. 通过命令行phpunit --version验证了安装
  4. 将位置添加到php.ini中的PHP include_path
  5. 重新启动服务器
  6. 使用Composer安装了一个新的CakePHP项目(以测试CakePHP可以看到PHPUnit)
  7. 成功测试了新项目中是否安装了PHPUnit

提前谢谢.

推荐答案

我终于能够将PHPUnit添加到不是使用composer创建的现有CakePHP项目中.

I finally was able to add PHPUnit to an existing CakePHP project that wasn't created with composer.

我浏览了CakeTestSuiteDispatcher.php文件,以查看它在哪里寻找PHPUnit.它会在供应商,应用程序/供应商以及名为AutoUnit.php的名为PHPUnit的文件夹的include_path中查找(感谢Nick Zinger的帮助).复制完此文件夹后,CakePHP将看到已安装PHPUnit,但在包含依赖项(代码覆盖率,计时器等)时将引发错误.这是我为使一切正常运行而采取的步骤.

I had a look inside the CakeTestSuiteDispatcher.php file to see where it was trying to find PHPUnit. It looks in the vendors, app/Vendor, and the include_path for a folder called PHPUnit that has the Autoload.php file (thanks to Nick Zinger for his help with this). Once this folder has been copied across, CakePHP will see that PHPUnit is installed but will throw errors when including dependencies (code coverage, timer, etc.). Here are the steps I took to get everything working.

  1. 确保在app/config/Database.php中具有测试数据库设置,否则您的主数据库可能会被覆盖或损坏
  2. 通过Composer使用PHPUnit(我使用的版本3.7.38)将新的CakePHP(版本2.6.2)项目安装到新位置
  3. 将新项目中具有Autoload.php文件(phpunit/phpunit/PHPUnit)的内部PHPUnit文件夹复制到旧项目的cakephp供应商文件夹(应用程序外部的文件夹)
  4. 将以下文件夹从phpunit文件夹(在步骤1中使用composer创建的项目中)复制到您现有的供应商文件夹(应用外部的文件夹):
    • php-code-coverage
    • php-file-iterator
    • php-text-template
    • php-timer
    • php-token-stream
    • phpunit-mock-objects
  1. Ensure you have the test database setup in app/config/Database.php otherwise your main database may be overwritten or corrupted
  2. Install a fresh CakePHP (version 2.6.2) project to a new location with PHPUnit (I used version 3.7.38) via Composer
  3. Copy the inner PHPUnit folder with the Autoload.php file (phpunit/phpunit/PHPUnit ) in the new project to the cakephp vendors folder (the folder outside app) of the old project
  4. Copy the following folders from the phpunit folder (from the project created with composer in step 1) to you existing vendors folder (the one outside of app):
    • php-code-coverage
    • php-file-iterator
    • php-text-template
    • php-timer
    • php-token-stream
    • phpunit-mock-objects
  • PHPUnit/Autoload.php
  • php-code-coverage/PHP/CodeCoverage/Autoload.php

一旦进行了这些更改,CakePHP测试套件就可以使用了,并且我能够运行我的测试用例.这适用于我的CakePHP项目(v2.0.6)和我的同事CakePHP项目(v2.0.6).

Once these changes were made the CakePHP Test Suite was available and I was able to run my test cases. This worked for my CakePHP Project(v2.0.6) and my colleagues CakePHP project(v2.0.6).

我希望这可以帮助其他遇到相同问题的人.

I hope this helps anyone else having the same problem.

这篇关于将PHPUnit添加到现有的Cakephp 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆