PHP code example of webino / nette-tester

1. Go to this page and download the library: Download webino/nette-tester 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/ */

    

webino / nette-tester example snippets


class Greeting
{
	function say($name)
	{
		if (!$name) {
			throw new InvalidArgumentException('Invalid name.');
		}
		return "Hello $name";
	}
}



use Tester\Assert;

$h = new Greeting;

// use an assertion function to test say()
Assert::same( 'Hello John', $h->say('John') );

Assert::exception(function() {
	$h = new Greeting;
	$h->say(NULL);
}, 'InvalidArgumentException', 'Invalid name.');

Assert::error(function() {
	$h = new Greeting;
	echo $h->abc;
}, E_NOTICE, 'Undefined property: Greeting::$abc');



Tester\Environment::setup();

$dom = Tester\DomQuery::fromHtml($html);

Assert::true( $dom->has('input[name="username"]') );
Assert::true( $dom->has('input[name="password"]') );

> tester
 _____ ___  ___ _____ ___  ___
|_   _/ __)( __/_   _/ __)| _ )
  |_| \___ /___) |_| \___ |_|_\  v1.7.2

PHP 5.3.16 | "php-cgi" -n | 8 threads
.
OK (1 tests, 0 skipped, 0.0 seconds)