PHP code example of openbuildings / phpunit-spiderling

1. Go to this page and download the library: Download openbuildings/phpunit-spiderling library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

openbuildings / phpunit-spiderling example snippets


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');
	}
}

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();
	}
}

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');
	}
}

use Openbuildings\PHPUnitSpiderling\TestCase;

class SpiderlingTest extends TestCase {

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


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