PHPackages                             openbuildings/phpunit-spiderling - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. openbuildings/phpunit-spiderling

ActiveLibrary[Testing &amp; Quality](/categories/testing)

openbuildings/phpunit-spiderling
================================

Use openbuildings/spiderling in phpunit tests

0.5.1(5y ago)15133.0k42BSD-3-ClausePHPPHP ^7.3 || ^7.4CI failing

Since Jul 24Pushed 5y ago13 watchersCompare

[ Source](https://github.com/OpenBuildings/phpunit-spiderling)[ Packagist](https://packagist.org/packages/openbuildings/phpunit-spiderling)[ RSS](/packages/openbuildings-phpunit-spiderling/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (26)Used By (2)

PHPUnit Spiderling
==================

[](#phpunit-spiderling)

[![Build Status](https://camo.githubusercontent.com/ad6dbaf1f9f2b6cece2a4f79b314973fc3f9a53b1f9e3eac98ef30080eb1ab62/68747470733a2f2f7472617669732d63692e6f72672f4f70656e4275696c64696e67732f706870756e69742d7370696465726c696e672e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/OpenBuildings/phpunit-spiderling)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/2663c0d06cbf1c1fd8af457cca7f466915e87e0701a20a935157aa2ed68887e0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f70656e4275696c64696e67732f706870756e69742d7370696465726c696e672f6261646765732f7175616c6974792d73636f72652e706e673f733d39613139383661653834646639646464303239613361643431643930333064346634323633343533)](https://scrutinizer-ci.com/g/OpenBuildings/phpunit-spiderling/)[![Code Coverage](https://camo.githubusercontent.com/277ddc964d2f913113d6fc64d4dcd3f1bf06003b4cb6fed880a7f6e95146d2a4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f70656e4275696c64696e67732f706870756e69742d7370696465726c696e672f6261646765732f636f7665726167652e706e673f733d33376434343764333164336463336234313239653665376337396133336331393266373163333232)](https://scrutinizer-ci.com/g/OpenBuildings/phpunit-spiderling/)[![Latest Stable Version](https://camo.githubusercontent.com/950ed6b8d7f7a8c95f579a6b26ef91fe3bd85bdc50107ca508606a7d79b4c072/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e6275696c64696e67732f706870756e69742d7370696465726c696e672f762f737461626c652e706e67)](https://packagist.org/packages/openbuildings/phpunit-spiderling)

Heavily inspired by capybara [capybara](https://github.com/jnicklas/capybara). Using the [spiderling](https://github.com/OpenBuildings/spiderling) package to the fullest. It gives you the ability to quickly write integration test with powerful DSL and choose between different drivers with different combinations of features and performance - e.g. phanomjs or raw php with curl.

Example Test:

```
use Openbuildings\PHPUnitSpiderling\TestCase;

class SpiderlingTest extends TestCase {

	/**
	 * @driver phantomjs
	 */
	public function test_sample()
	{
		$this
			->visit('http://example.com/index.html')
			->assertHasCss('#navlink-1', array('text' => 'Subpage 1'), 'Should have a navigation link')
			->click_button('Edit')
			->assertHasCss('h1', array('text' => 'Edit Record'), 'Should be on the edit page of a record')
			->fill_in('Name', 'New name')
			->click_button('Save')
			->assertHasCss('.notification', array('text' => 'Successfull edit'), 'Should have successfully performed the edit');
	}
}
```

Spiderling
----------

[](#spiderling)

[Spiderling](https://github.com/OpenBuildings/spiderling) has a fluid DSL that its best you get familiar with. The testcase has all the methods of Openbuildings\\Spiderling\\Page so you can use them directly along with some additional assertions.

The Testcase
------------

[](#the-testcase)

To use phpunit spiderling you need to write your test as `extends \Openbuildings\PHPUnitSpiderlingTestCase` - it will give you all of the feature as methods of the class.

### Assertions

[](#assertions)

The custom assertions are:

- `assertHasCss($selector, array $filters = array(), $message = NULL)`
- `assertHasNoCss($selector, array $filters = array(), $message = NULL)`
- `assertHasField($selector, array $filters = array(), $message = NULL)`
- `assertHasNoField($selector, array $filters = array(), $message = NULL)`
- `assertHasXPath($selector, array $filters = array(), $message = NULL)`
- `assertHasNoXPath($selector, array $filters = array(), $message = NULL)`
- `assertHasLink($selector, array $filters = array(), $message = NULL)`
- `assertHasNoLink($selector, array $filters = array(), $message = NULL)`
- `assertHasButton($selector, array $filters = array(), $message = NULL)`
- `assertHasNoButton($selector, array $filters = array(), $message = NULL)`

All of them assert that an element is on the page (or is not) by using a specific locator type and filters. Also they are actually an extension of Openbuildings\\Spiderling\\Page so they are available to all the nested nodes (and are asserting only in the context of the node)

For example:

```
use Openbuildings\PHPUnitSpiderling\TestCase;

class SpiderlingTest extends TestCase {

	public function test_sample()
	{
		$this
			->visit('http://example.com/index.html')
			->find('form#big')
				// This assertion checks only the form
				->assertHasField('Name')
			->end();
	}
}
```

### Environment

[](#environment)

You can modify the environment only for a specific test by using the `->environment()` method. It returns a [Environment Backup](https://github.com/OpenBuildings/environment-backup) object, and whatever you set it to will be restored at the end of the test.

Here's an example usage:

```
use Openbuildings\PHPUnitSpiderling\TestCase;

class SpiderlingTest extends TestCase {

	public function test_sample()
	{
		$this
			->environment()
				->backup_and_set(array(
					'SomeClass::$variable' => 'new value',
					'REMOTE_HOST' => 'example.com',
				));

		$this
			->visit('http://example.com/index.html')
			->assertHasField('Name');
	}
}
```

### Switching drivers

[](#switching-drivers)

PHPUnit Spiderling uses the PHP Annotations to set up which driver to use fore each test. Heres how you do that:

```
use Openbuildings\PHPUnitSpiderling\TestCase;

class SpiderlingTest extends TestCase {

	/**
	 * @driver simple
	 */
	public function test_sample()
	{
		// ...
	}

	/**
	 * @driver phantomjs
	 */
	public function test_sample_2()
	{
		// ...
	}
}
```

You can have different drivers for each test, the available ones are: `simple`, `kohana` and `phantomjs` - where the default driver is `simple`. Each driver is loaded with the default configuration, but you can change it by modifying the appropriate method that loads the driver

- driver\_simple() - will return Driver\_Simple object
- driver\_kohana() - will return Driver\_Kohana object
- driver\_phantomjs() - will return Driver\_Phantomjs object

Save on failure
---------------

[](#save-on-failure)

There is a special testcase listener class included that saves the state of the test when there is a failure, and saves it as an html page for ease referance later. This is the `Saveonfailure` class. In order to use it, you'll need to modify your phpunit.xml like this:

```

				application/logs/functest

				http://test.clippings.dev

```

License
-------

[](#license)

Copyright (c) 2012-2013, OpenBuildings Ltd. Developed by Ivan Kerin as part of [clippings.com](http://clippings.com)

Under BSD-3-Clause license, read LICENSE file.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 64.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~129 days

Recently: every ~163 days

Total

22

Last Release

2002d ago

PHP version history (2 changes)0.3.0PHP ^7.1

0.5.0PHP ^7.3 || ^7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/506129?v=4)[Harry Dobrev](/maintainers/hkdobrev)[@hkdobrev](https://github.com/hkdobrev)

![](https://avatars.githubusercontent.com/u/4113307?v=4)[Danail Kyosev](/maintainers/dkyosev)[@dkyosev](https://github.com/dkyosev)

![](https://avatars.githubusercontent.com/u/7592650?v=4)[Evstati Zarkov](/maintainers/EZarkov)[@EZarkov](https://github.com/EZarkov)

![](https://avatars.githubusercontent.com/u/745771?v=4)[Filip Georgiev](/maintainers/phgeorgiev)[@phgeorgiev](https://github.com/phgeorgiev)

![](https://avatars.githubusercontent.com/u/490439?v=4)[Zdravko Evstatiev](/maintainers/zedevs)[@zedevs](https://github.com/zedevs)

---

Top Contributors

[![hkdobrev](https://avatars.githubusercontent.com/u/506129?v=4)](https://github.com/hkdobrev "hkdobrev (53 commits)")[![stanstst](https://avatars.githubusercontent.com/u/9391542?v=4)](https://github.com/stanstst "stanstst (11 commits)")[![ivank](https://avatars.githubusercontent.com/u/4976?v=4)](https://github.com/ivank "ivank (7 commits)")[![EZarkov](https://avatars.githubusercontent.com/u/7592650?v=4)](https://github.com/EZarkov "EZarkov (6 commits)")[![george-clippings](https://avatars.githubusercontent.com/u/67631863?v=4)](https://github.com/george-clippings "george-clippings (2 commits)")[![halfer](https://avatars.githubusercontent.com/u/480975?v=4)](https://github.com/halfer "halfer (2 commits)")[![tumbalev](https://avatars.githubusercontent.com/u/28398671?v=4)](https://github.com/tumbalev "tumbalev (1 commits)")

### Embed Badge

![Health badge](/badges/openbuildings-phpunit-spiderling/health.svg)

```
[![Health](https://phpackages.com/badges/openbuildings-phpunit-spiderling/health.svg)](https://phpackages.com/packages/openbuildings-phpunit-spiderling)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k129.9M913](/packages/brianium-paratest)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k41.3M38.9k](/packages/orchestra-testbench)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.0M321](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

30300.1k6](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
