如何升级PHPunit

渐行I渐远 2017-01-06 06:09:45
自动化接口测试的php工程文件,安装了xampp、php5.6.21、phpunit3.7.21
想要升级成最新版本的phpunit但是网上通过pear方式升级根本行不通求教新的方法。

自己尝试的方法:
根据官网的手册https://phpunit.de/manual/current/zh_cn/installation.html
****************
Windows
整体上说,在 Windows 下安装 PHAR 和手工在 Windows 下安装 Composer 是一样的过程:
为 PHP 的二进制可执行文件建立一个目录,例如 C:\bin
将 ;C:\bin 附加到 PATH 环境变量中(相关帮助)
下载 https://phar.phpunit.de/phpunit.phar 并将文件保存到 C:\bin\phpunit.phar
打开命令行(例如,按 Windows+R » 输入 cmd » ENTER)
建立外包覆批处理脚本(最后得到 C:\bin\phpunit.cmd):

C:\Users\username> cd C:\bin
C:\bin> echo @php "%~dp0phpunit.phar" %* > phpunit.cmd
C:\bin> exit

新开一个命令行窗口,确认一下可以在任意路径下执行 PHPUnit:
C:\Users\username> phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

对于 Cygwin 或 MingW32 (例如 TortoiseGit) shell 环境,可以跳过第五步。 取而代之的是,把文件保存为 phpunit (没有 .phar 扩展名),然后用 chmod 775 phpunit 将其设为可执行。
Composer
如果用 Composer 来管理项目的依赖关系,只要在项目的 composer.json 文件中简单地加上对 phpunit/phpunit 的依赖关系即可。下面是一个最小化的 composer.json 文件的例子,只定义了一个对 PHPUnit 5.7 的开发时(development-time)依赖:


{
"require-dev": {
"phpunit/phpunit": "5.5.*"
}
}

要通过 Composer 完成系统级的安装,可以运行:

composer global require "phpunit/phpunit=5.5.*"

请确保 path 变量中包含有 ~/.composer/vendor/bin/。
*******************************
按照上述进行操作
但是:(dos显示)
C:\Users\Administrator>composer global require "phpunit/phpunit=5.7.*"
Changed current directory to C:/Users/Administrator/AppData/Roaming/Composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 25 installs, 0 updates, 0 removals
- Installing symfony/yaml (v3.2.1) Downloading: 100%
- Installing sebastian/version (2.0.1) Downloading: 100%
- Installing sebastian/resource-operations (1.0.0) Downloading: 100%
- Installing sebastian/recursion-context (2.0.0) Downloading: 100%
- Installing sebastian/object-enumerator (2.0.0) Downloading: 100%
- Installing sebastian/global-state (1.1.1) Downloading: 100%
- Installing sebastian/exporter (2.0.0) Downloading: 100%
- Installing sebastian/environment (2.0.0) Downloading: 100%
- Installing sebastian/diff (1.4.1) Downloading: 100%
- Installing sebastian/comparator (1.2.2) Downloading: 100%
- Installing doctrine/instantiator (1.0.5) Downloading: 100%
- Installing phpunit/php-text-template (1.2.1) Downloading: 100%
- Installing phpunit/phpunit-mock-objects (3.4.3) Downloading: 100%
- Installing phpunit/php-timer (1.0.8) Downloading: 100%
- Installing phpunit/php-file-iterator (1.4.2) Downloading: 100%
- Installing sebastian/code-unit-reverse-lookup (1.0.0) Downloading: Connectin
Downloading: 100%
- Installing phpunit/php-token-stream (1.4.9) Downloading: 100%
- Installing phpunit/php-code-coverage (4.0.4) Downloading: 100%
- Installing webmozart/assert (1.2.0) Downloading: 100%
- Installing phpdocumentor/reflection-common (1.0) Downloading: 100%
- Installing phpdocumentor/type-resolver (0.2.1) Downloading: 100%
- Installing phpdocumentor/reflection-docblock (3.1.1) Downloading: Connecting
Downloading: 100%
- Installing phpspec/prophecy (v1.6.2) Downloading: 100%
- Installing myclabs/deep-copy (1.5.5) Downloading: 100%
- Installing phpunit/phpunit (5.7.5) Downloading: 100%
symfony/yaml suggests installing symfony/console (For validating YAML files usin
g the lint command)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.4.0)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
phpunit/phpunit suggests installing ext-xdebug (*)
Writing lock file
Generating autoload files

C:\Users\Administrator>phpunit --version
PHPUnit 3.7.21 by Sebastian Bergmann.

phpunit已经下载了最新版本,却没安装?最后的版本还是3.7.21
而且我通过pear卸载phpunit但是还是能查到版本3.7.21
菜鸟不懂原理,求教
...全文
737 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2017-01-07
  • 打赏
  • 举报
回复
下载新版覆盖安装就可以了。
xuzuning 2017-01-06
  • 打赏
  • 举报
回复
虽然我从来就不用什么 phpunit 但我知道,他不过是 php 代码书写的类库 你只需下载最新代码,覆盖掉原有的旧代码就可以了
[php] view plain copy <?php       class StackTest extends PHPUnit_Framework_TestCase       {           public function testEmpty()           {               $stack = array();               $this->assertEmpty($stack);               return $stack;           }           /**            * @depends testEmpty            */           public function testPush(array $stack)           {               array_push($stack, 'foo');               $this->assertEquals('foo', $stack[count($stack)-1]);               $this->assertNotEmpty($stack);               return $stack;           }           /**            * @depends testPush            */           public function testPop(array $stack)           {               $this->assertEquals('foo', array_pop($stack));               $this->assertEmpty($stack);           }       }                              ?>1. 什么是单元测试?【百度百科】单元测试是对软件中的最小可测单元进行检查和验证。是开发者编写的一小段代码,用于检验被测代码的一个很小的、很明确的功能是否正确。2. 作用是什么?【废话】检查软件、程序的可行性,稳定性。通过单元测试能够避免在迭代、升级等过程中,引起重复的、多余的问题。避免在别人修改代码的时候,影响到你的逻辑3. 哪些程序需要写单元测试(PHP)?【理想】理想的单元测试应当覆盖程序中所有可能的路径,包括正确的和错误的路径,个单元测试通常覆盖一个函数或方法中的一个特定路径。【现实】model、helper、controller中的函数必须测试、路径覆盖到所有可能性

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧