Skip to content

Commit cf45cfb

Browse files
author
Alexander Obuhovich
committed
Merge pull request #20 from aik099/read-the-docs
Migrating documentation to ReadTheDocs.Org
2 parents 0c1367b + 5f13482 commit cf45cfb

17 files changed

Lines changed: 731 additions & 244 deletions

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ addons:
1717

1818
before_script:
1919
- composer require satooshi/php-coveralls:dev-master --dev --prefer-source
20+
- sudo easy_install -U Sphinx
21+
- sudo pip install sphinx_rtd_theme
2022

2123
script:
2224
- mkdir -p build/logs
2325
- phpunit -v --coverage-clover build/logs/clover.xml
26+
- sphinx-build -nW -b html -d docs/build/doctrees docs docs/build/html
2427

2528
after_script:
2629
- php vendor/bin/coveralls -v

README.md

Lines changed: 6 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# PHPUnit-Mink
22
[![Build Status](https://travis-ci.org/aik099/phpunit-mink.svg?branch=master)](https://travis-ci.org/aik099/phpunit-mink)
33
[![HHVM Status](http://hhvm.h4cc.de/badge/aik099/phpunit-mink.svg)](http://hhvm.h4cc.de/package/aik099/phpunit-mink)
4+
[![Documentation Status](https://readthedocs.org/projects/phpunit-mink/badge/?version=latest)](https://readthedocs.org/projects/phpunit-mink/?badge=latest)
45

56
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/aik099/phpunit-mink/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/aik099/phpunit-mink/?branch=master)
67
[![Coverage Status](https://img.shields.io/coveralls/aik099/phpunit-mink.svg)](https://coveralls.io/r/aik099/phpunit-mink?branch=master)
@@ -10,252 +11,13 @@
1011

1112
This library is an extension for [PHPUnit](sebastianbergmann/phpunit), that allows to write tests with help of [Mink](Behat/Mink).
1213

13-
## Overview
14-
This library allows to perform following things:
14+
## Documentation
1515

16-
* use [Mink](Behat/Mink) for browser session control
17-
* each test in a test case can use independent browser session
18-
* all tests in a test case can share session between them
19-
* Selenium server connection details are decoupled from tests using them
20-
* perform individual browser configuration for each test in a test case
21-
* support for "[Sauce Labs](https://saucelabs.com/)"
22-
* remote code coverage collection
16+
* http://phpunit-mink.readthedocs.org
2317

24-
Each mentioned above features is described in more detail below.
18+
## Installation using Composer
2519

26-
## Basic Usage
27-
1. create subclass from `\aik099\PHPUnit\BrowserTestCase` class
28-
2. define used browser configurations in static `$browsers` property of that class
29-
3. use `$this->getSession()` method in your tests to access [Mink](Behat/Mink) session
30-
31-
## Using Mink
32-
Call `$this->getSession()` from a test to get running `\Behat\Mink\Session` object, which is already configured from test configuration.
33-
34-
```php
35-
<?php
36-
37-
use aik099\PHPUnit\BrowserTestCase;
38-
39-
class SessionTest extends BrowserTestCase
40-
{
41-
42-
public function testSession()
43-
{
44-
$session = $this->getSession();
45-
46-
$session->visit('http://www.google.com');
47-
48-
$this->assertTrue($session->getPage()->hasContent('Google'));
49-
}
50-
51-
}
52-
```
53-
54-
55-
## Per-test Browser Configuration
56-
It is possible to set individual browser configuration for each test in a test case by creating a `\aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration` class instance in `setUp` method of the test case.
57-
58-
```php
59-
<?php
60-
61-
use aik099\PHPUnit\BrowserTestCase;
62-
use aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration;
63-
64-
class PerBrowserConfigTest extends BrowserTestCase
65-
{
66-
67-
protected function setUp()
68-
{
69-
// to create regular browser configuration via BrowserConfigurationFactory
70-
$browser = $this->createBrowserConfiguration(array(
71-
// options goes here (optional)
72-
));
73-
74-
// to create "Sauce Labs" browser configuration via BrowserConfigurationFactory
75-
$browser = $this->createBrowserConfiguration(array(
76-
// required
77-
'type' => 'saucelabs',
78-
'api_username' => 'sauce_username',
79-
'api_key' => 'sauce_api_key',
80-
// options (optional) goes here
81-
));
82-
83-
// options can be changed later (optional)
84-
$browser->setHost('selenium_host')->setPort('selenium_port')->setTimeout(30);
85-
$browser->setBrowserName('browser name')->setDesiredCapabilities(array('version' => '6.5'));
86-
$browser->setBaseUrl('http://www.test-host.com');
87-
88-
// set browser configuration to test case
89-
$this->setBrowser($browser);
90-
91-
parent::setUp();
92-
}
93-
94-
}
95-
```
96-
97-
## Sharing Browser Configuration Between Tests
98-
It is possible to define a single browser configuration to be used for each test in test case. This can be done by defining static `$browsers` class variable as an array, where each item represents a single browser configuration. In that case each of the tests in a test case would be executed using each of defined browser configurations.
99-
100-
```php
101-
<?php
102-
103-
use aik099\PHPUnit\BrowserTestCase;
104-
105-
class CommonBrowserConfigTest extends BrowserTestCase
106-
{
107-
108-
public static $browsers = array(
109-
array(
110-
'host' => 'localhost',
111-
'port' => 4444,
112-
'browserName' => 'firefox',
113-
'baseUrl' => 'http://www.google.com',
114-
),
115-
array(
116-
'host' => 'localhost',
117-
'port' => 4444,
118-
'browserName' => 'chrome',
119-
'baseUrl' => 'http://www.google.com',
120-
),
121-
);
122-
123-
public function testUsingBrowsersArray()
124-
{
125-
echo sprintf("I'm executed using '%s' browser", $this->getBrowser()->getBrowserName());
126-
}
127-
128-
}
129-
```
130-
131-
## Sharing Session Between Tests
132-
As a benefit of shared browser configuration, that was described above is an ability to not only share browser configuration, that is used to create [Mink](Behat/Mink) session, but to actually share created sessions between all tests in a test case. This can be done by adding `sessionStrategy` option to browser configuration.
133-
134-
```php
135-
<?php
136-
137-
use aik099\PHPUnit\BrowserTestCase;
138-
139-
class CommonBrowserConfigTest extends BrowserTestCase
140-
{
141-
142-
public static $browsers = array(
143-
array(
144-
'host' => 'localhost',
145-
'port' => 4444,
146-
'browserName' => 'firefox',
147-
'baseUrl' => 'http://www.google.com',
148-
'sessionStrategy' => 'shared',
149-
),
150-
);
151-
152-
}
153-
```
154-
155-
## Using Browser Aliases
156-
All previous examples demonstrate various ways how browser configuration can be defined, but they all have same downside - server connection details stay hard-coded in test case classes. This could become very problematic if:
157-
158-
* same test cases needs to be executed on different servers (e.g. each developer runs them on his own machine)
159-
* due change of server connection details each test case class needs to be changed
160-
161-
To solve this problem a browser aliases were introduced. Basically a browser alias is predefined browser configuration, that is available in the test case by it's alias. How it can be used:
162-
163-
1. create base test case class, by extending BrowserTestCase class in the project with `getBrowserAliases` method in it. That method will return an associative array of a browser configurations (array key acts as alias name)
164-
2. in any place, where browser configuration is defined use `'alias' => 'alias_name_here'` instead of actual browser configuration
165-
3. feel free to override any part of configuration defined in alias
166-
4. nested aliases are also supported
167-
168-
```php
169-
<?php
170-
171-
use aik099\PHPUnit\BrowserTestCase;
172-
173-
abstract class BrowserAliasTest extends BrowserTestCase
174-
{
175-
176-
public function getBrowserAliases()
177-
{
178-
return array(
179-
'example_alias' => array(
180-
'host' => 'localhost',
181-
'port' => 4444,
182-
'browserName' => 'firefox',
183-
'baseUrl' => 'http://www.google.com',
184-
),
185-
);
186-
}
187-
188-
}
189-
190-
191-
class ConcreteTest extends BrowserAliasTest
192-
{
193-
194-
public static $browsers = array(
195-
array(
196-
'alias' => 'example_alias',
197-
198-
),
199-
array(
200-
'alias' => 'example_alias',
201-
'browserName' => 'chrome',
202-
),
203-
);
204-
}
205-
206-
```
207-
208-
## Using "Sauce Labs"
209-
When using "Sauce Labs" account to perform Selenium server-based testing you need to specify `'type' => 'saucelabs', 'api_username' => '...', 'api_key' => '...'` instead of `host` or `port` settings. In all other aspects all will work the same as if all tests are running locally.
210-
211-
## Remote Code Coverage
212-
Browser tests are executed on different machine, then one, where code coverage information is collected (and tests are executed). To solve that problem this library uses remote coverage collection. Following steps needs to be performed before using this feature:
213-
214-
### On Remote Server
215-
Remote server is web-server, where website used in tests is located.
216-
217-
1. Install [Xdebug](http://xdebug.org/) PHP extension on web-server
218-
2. Copy `library/aik099/PHPUnit/RemoteCoverage/RemoteCoverageTool.php` into web-server's DocumentRoot directory.
219-
3. Include following code before your application bootstraps:
220-
221-
```php
222-
require_once 'RemoteCoverageTool.php';
223-
\aik099\PHPUnit\RemoteCoverage\RemoteCoverageTool::init();
224-
```
225-
226-
### On Test Machine
227-
This is machine, where PHPUnit tests are being executed.
228-
229-
By default the `baseUrl` setting from browser configuration is used as the `remote code coverage information url`. However if a need exists to set alternative url on per-test basis, then place following code in the `setUp` method of the test case class, that extends `BrowserTestCase` class:
230-
231-
```php
232-
$this->setRemoteCoverageScriptUrl('http://host/'); // `host` should be replaced with web server's url
233-
```
234-
235-
### How This Works
236-
1. each test sets a special cookie on website under test
237-
2. when cookie is present, then `RemoteCoverageTool.php` script collects coverage information and stores it on disk
238-
3. once test finishes, then `http://host/?rct_mode=output` url is accessed on remote server, which in turn returns collected coverage information
239-
4. remote coverage information is then joined with coverage information collected locally on test machine
240-
241-
## Browser Configuration in Details
242-
Each browser configuration consists of the following settings:
243-
244-
| Name | Description |
245-
|---|---|
246-
| `host` | host, where Selenium Server is located (defaults to `localhost`) |
247-
| `port` | port, on which Selenium Server is listening for incoming connections (defaults to `4444`) |
248-
| `timeout` | connection timeout of the server in seconds (defaults to `60`) |
249-
| `browserName` | name of browser to use (e.g. `firefox`, `chrome`, etc., defaults to `firefox`) |
250-
| `desiredCapabilities` | parameters, that specify additional browser configuration (e.g. browser version, platform, etc.) |
251-
| `baseUrl` | base url of website, that is tested |
252-
| `sauce` | Sauce Labs connection configuration (e.g. `array('username' => 'username_here', 'api_key' => 'api_key_here')`) |
253-
254-
There are also corresponding `set` and `get` methods for each of mentioned above settings, that allow to individually change them before test has started (from `setUp` method).
255-
256-
## Using Composer
257-
258-
1. Define the dependencies in your ```composer.json```:
20+
Define the dependencies in your ```composer.json```:
25921
```json
26022
{
26123
"require": {
@@ -264,7 +26,7 @@ There are also corresponding `set` and `get` methods for each of mentioned above
26426
}
26527
```
26628

267-
2. Install/update your vendors:
29+
Install/update your vendors:
26830
```bash
26931
$ curl http://getcomposer.org/installer | php
27032
$ php composer.phar install

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

0 commit comments

Comments
 (0)