PHP code example of oscarotero / psr7-unitesting

1. Go to this page and download the library: Download oscarotero/psr7-unitesting 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/ */

    

oscarotero / psr7-unitesting example snippets


use Psr7Unitesting\Assert;

class AppTest extends PHPUnit_Framework_TestCase
{
	public function testRemote()
	{
		//Execute a GET request and assert the response:

		Assert::get('http://example.com')
			->statusCode(200)
			->header('Content-Type', 'text/html')
			->hasHeader('Cache-Control')
			->hasNotHeader('Expires')

			->assertBody()
				->isReadable()
				->isSeekable()
				->end() //back to Response

			->assertHtml()
				->isValid() //use w3c vnu validator
				->has('meta[property="og:title"]')
				->hasNot('blink')
				->contains('a.home-link', 'Go to home')
				->notContains('p', '') //empty paragraphs

				//Execute more tests for each element individually
				->map('img', function ($img) {
					$this->assertNotEmpty($img->attr('alt'));
				});
	}

	public function testLocal()
	{
		//Assert local psr-7 instances
		$app = new App();
		$response = $app->dispatch('/post/34');

		Assert::create($response)
			->statusCode(200);
	}
}