LoginSignup
4
3

More than 5 years have passed since last update.

PHP5.2の開発環境のPHPUnit3.4を3.6にしてみる

Last updated at Posted at 2017-02-06

一応動くみたい

ヾ(・ω<)ノ" 三三三● ⅱⅲ コロコロ♪


------------------- ↓ 余談はここから ↓-------------------

前回記事「PHP5.2の開発環境にPHPUnitをいれる」にて、
古いPHP環境に古いPHPUnitをインストールを試した。
一応動くところまではいけたので、
いったん記事にしたのだが、
できれば、古い中でも最新のものを使いたい。
そこで今回はPHPUnit3.6をインストールしてみる。

前回発生したエラーを考察してみると

$ ./phpunit.sh ../test.php
Warning: require_once(File/Iterator/Autoload.php): 
failed to open stream: No such file or directory in
 /home/dozo/phpunit/phpunit/PHPUnit/Autoload.php on line 45

Fatal error: require_once(): 
Failed opening required 'File/Iterator/Autoload.php'
 (include_path='.:./phpunit/:・・・:/usr/local/lib/php') 
in /home/dozo/phpunit/phpunit/PHPUnit/Autoload.php on line 45

php-file-iteratorのAutoload.phpが見つからないということだそうだが、
要するにPathを通せばいいだけのこと。

時代の変遷を得てファイル構造が変化して、
マニュアルを書いた当時はmasterブランチだったのが、
別のところに埋もれているということのようだ。

ならば、各リポジトリに対して当時の状態を作ってあげればPathが通って動作までこぎ着けるだろう。

ヾ(・ω<)ノ" 三三三● ⅱⅲ コロコロ♪


------------------- ↓ 本題はここから ↓-------------------

PHPUnitのインストール

インストール先をphpunitというディレクトリとしている

必要なモジュールをGitHubからダウンロード

gitclone.sh
mkdir phpunit && cd phpunit
git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git
cd ..

ダウンロードはこちらから
https://gist.githubusercontent.com/dohzoh/2d1da015471585a4f59993fc9b79e8e6/raw/344163719cef4cf1fcde445bf15ba5c4b200e0df/gitclone.sh

各ブランチを変更

checkout.sh
cd phpunit
cd phpunit && git checkout 3.6 && cd ..
cd dbunit && git checkout 1.1 && cd ..
cd php-file-iterator && git checkout tags/1.3.2 && cd ..
cd php-code-coverage && git checkout 1.1 && cd ..
cd php-token-stream && git checkout tags/1.1.4 && cd ..
cd php-text-template && git checkout tags/1.1.1 && cd ..
cd php-timer && git checkout tags/1.0.3 && cd ..
cd phpunit-mock-objects && git checkout 1.1 && cd ..
cd phpunit-selenium && git checkout 1.1 && cd ..

ダウンロードはこちらから
https://gist.githubusercontent.com/dohzoh/2d1da015471585a4f59993fc9b79e8e6/raw/344163719cef4cf1fcde445bf15ba5c4b200e0df/checkout.sh

実行用のシェルを作成

phpunit.sh
#!/bin/sh

php -d include_path='.:./phpunit/:./dbunit/:./php-code-coverage/:./php-file-iterator/:./php-invoker/:./php-text-template/:./php-timer:./php-token-stream:./phpunit-mock-objects/:./phpunit-selenium/:./phpunit-story/:/usr/local/lib/php' ./phpunit/phpunit.php $*

テスト実行

unittest.php
<?php

/**
 * Test class for Hello.
 * Generated by PHPUnit on 2010-03-29 at 03:14:15.
 */
class HelloTest extends PHPUnit_Framework_TestCase
{
    protected function setUp(){
    }

   /**
     * @dataProvider abcProvider
     */
    public function testAbc($actual, $expected){
        $this->assertEquals($actual, $expected);
    }

    public function abcProvider(){
         return array(
             array(1,0),
         );
    }

}

実行

$ chmod +x phpunit.sh
$ ./phpunit.sh unittest.php
PHPUnit @package_version@ by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 2.50Mb

There was 1 failure:

1) HelloTest::testAbc with data set #0 (1, 0)
Failed asserting that 0 matches expected 1.

/home/dozo/tmp/unittest.php:16
/home/dozo/local/php/phpunit/phpunit/phpunit.php:46

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

ふむふむ。
動作も問題なさそうだ。


ヾ(・ω<)ノ" 三三三● ⅱⅲ コロコロ♪

------------------- ↓ 後書はここから ↓-------------------

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3