mingk 发表于 2015-8-26 15:36:54

[PHP]windows下手动安装phpunit

    Whenever you are tempted to type something into a       print statement or a debugger expression, write it       as a test instead.   




--Martin Fowler

  
  1、到http://pear.phpunit.de/get/   去下载最新版本

2、 解压(推荐放在WAMP包下),将PHPUnit的路径加入php.ini 的include_path
3、修改phpunit.bat中 @phpbin@ 为php解析器位置(php.exe位置,如d:\wamp\php5\php.exe)
4、将phpunit.bat最后一行的路径修改为你的phpunit.php的路径(跟phpunit.bat在同一位置,如修改为:%PHPBIN% "D:\Wamp\PHPUnit\phpunit.php" %*),注意,是phpunit.php而不是phpunit
5、修改PHPUnit/Util/PHP.php,其中@php_bin@改为php.exe位置

OK,我们来验证是否正确安装:
写一个测试脚本,用官方的arraytest.php

1<?php
2require_once 'PHPUnit/Framework.php';
3
4class StackTest extends PHPUnit_Framework_TestCase
5{
6    public function testPushAndPop()
7    {
8      $stack = array();
9      $this->assertEquals(0, count($stack));
10
11      array_push($stack, 'foo');
12      $this->assertEquals('foo', $stack);
13      $this->assertEquals(1, count($stack));
14
15      $this->assertEquals('foo', array_pop($stack));
16      $this->assertEquals(0, count($stack));
17    }
18}
19?>
命名为ArrayTest.php,放到d:\wamp\PHPUnit
进入命令行phpunit目录,执行 phpunit ArrayTest.php
输出: OK(1 test, 5 assertions)
对每个测试,PHPUnit命令行测试工具打印一个字符表示进程:
测试成功打印“.”。
运行测试方法发生了断言失败打印“F”。
运行测试方法发生了错误打印“E”。
页: [1]
查看完整版本: [PHP]windows下手动安装phpunit