創建 composer.json 檔案
vim composer.json
{
"require-dev": {
"phpunit/phpunit": "4.6.*",
"phpunit/php-invoker": "*",
"phpunit/dbunit": ">=1.2",
"phpunit/phpunit-selenium": ">=1.2"
}
}
安裝phpunit
# php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing sebastian/global-state (1.0.0)
Downloading: 100%
- Installing sebastian/recursion-context (1.0.0)
Downloading: 100%
- Installing phpunit/php-timer (1.0.5)
Downloading: 100%
- Installing phpunit/php-invoker (1.1.3)
Downloading: 100%
- Installing symfony/yaml (v2.6.7)
Downloading: 100%
- Installing sebastian/version (1.0.5)
Downloading: 100%
- Installing sebastian/exporter (1.2.0)
Downloading: 100%
- Installing sebastian/environment (1.2.2)
Downloading: 100%
- Installing sebastian/diff (1.3.0)
Downloading: 100%
- Installing sebastian/comparator (1.1.1)
Downloading: 100%
- Installing doctrine/instantiator (1.0.4)
Downloading: 100%
- Installing phpdocumentor/reflection-docblock (2.0.4)
Downloading: 100%
- Installing phpspec/prophecy (v1.4.1)
Downloading: 100%
- Installing phpunit/php-text-template (1.2.0)
Downloading: 100%
- Installing phpunit/phpunit-mock-objects (2.3.1)
Downloading: 100%
- Installing phpunit/php-token-stream (1.4.1)
Downloading: 100%
- Installing phpunit/php-file-iterator (1.4.0)
Downloading: 100%
- Installing phpunit/php-code-coverage (2.0.16)
Downloading: 100%
- Installing phpunit/phpunit (4.6.6)
Downloading: 100%
- Installing phpunit/dbunit (1.3.2)
Downloading: 100%
- Installing phpunit/phpunit-selenium (1.4.2)
Downloading: 100%
sebastian/global-state suggests installing ext-uopz (*)
phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0)
phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
Writing lock file
Generating autoload files
例 6.6. Phpunit Selenium
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
public static $browsers = array(
array(
'name' => 'Firefox on Linux',
'browser' => '*firefox',
'host' => '172.30.5.73',
'port' => 4444,
'timeout' => 30000,
),
/*
array(
'name' => 'Safari on MacOS X',
'browser' => '*safari',
'host' => 'my.macosx.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Safari on Windows XP',
'browser' => '*custom C:\Program Files\Safari\Safari.exe -url',
'host' => 'my.windowsxp.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Internet Explorer on Windows XP',
'browser' => '*iexplore',
'host' => 'my.windowsxp.box',
'port' => 4444,
'timeout' => 30000,
)
*/
);
protected function setUp()
{
$this->setBrowserUrl('http://www.google.com/');
}
public function testTitle()
{
$this->open('http://www.google.com/');
$this->assertTitle('Google');
}
public function tearDown()
{
$this->close();
}
}
?>
# vendor/bin/phpunit test.php