PEARのインストール

既にシステムにPEARが入ってる場合。

% sudo pear uninstall pear

PEAR公式ドキュメントの通りにやる。

% curl -O http://pear.php.net/go-pear.phar
% php -d detect_unicode=0 go-pear.phar

(debianの場合)

% wget http://pear.php.net/go-pear.phar
% php -d suhosin.executor.include.whitelist="phar" go-pear.phar

PHPUnitのインストール

公式ドキュメントの通りにやる。

% pear config-set auto_discover 1
% pear install pear.phpunit.de/PHPUnit

include_pathは自動で追加してくれるけどPATHは通してくれないので自分で通す。

export PATH=~/pear/bin:$PATH
% phpunit --version
PHPUnit 3.6.12 by Sebastian Bergmann.

せばすちゃああああん

Selenium RCをインストール

PHPUnitをインストール

PHPUnit_Seleniumをインストール。

% pear install phpunit/PHPUnit_Selenium

testを書く(ファイル名はクラスと同じCamelCase)

test/integrations/LoginTest.php

<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class LoginTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser('*firefox');
        $this->setBrowserUrl('http://foo/');
    }

    public function testTitle()
    {
        $this->open('/sign_in');
        $this->assertTitle('Sign In');
        $this->type('account', 'foo');
        $this->type('password', 'password');
        $this->submitAndWait('user_form');
        $this->assertTitle('Dashboard');
    }
}
?>

実行。対象ディレクトリ以下のなんとかTest.phpを全部実行する。

$ phpunit test/integrations