<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stevegrunwell / phpunit-markup-assertions example snippets
use PHPUnit\Framework\TestCase;
use SteveGrunwell\PHPUnit_Markup_Assertions\MarkupAssertionsTrait;
class MyUnitTest extends TestCase
{
use MarkupAssertionsTrait;
/**
* Ensure the #first-name and #last-name selectors are present in the form.
*/
public function testRenderFormContainsInputs()
{
$markup = render_form();
$this->assertContainsSelector('#first-name', $markup);
$this->assertContainsSelector('#last-name', $markup);
}
}
use PHPUnit\Framework\TestCase;
use SteveGrunwell\PHPUnit_Markup_Assertions\MarkupAssertionsTrait;
class MyTestCase extends TestCase
{
use MarkupAssertionsTrait;
}
# tests/TestCase.php
namespace Tests;
use PHPUnit\Framework\TestCase as BaseTestCase;
use SteveGrunwell\PHPUnit_Markup_Assertions\MarkupAssertionsTrait;
class TestCase extends BaseTestCase
{
use MarkupAssertionsTrait;
}
# tests/Unit/ExampleTest.php
namespace Tests/Unit;
use Tests\TestCase;
class MyUnitTest extends TestCase
{
// This class now automatically has markup assertions.
}
public function testBodyContainsImage()
{
$body = getPageBody();
$this->assertContainsSelector('img', $body, 'Did not find an image in the page body.');
}
public function testPostList()
{
factory(Post::class, 10)->create();
$response = $this->get('/posts');
$this->assertSelectorCount(10, 'li.post-item', $response->getBody());
}
public function testExpectedInputsArePresent()
{
$user = getUser();
$form = getFormMarkup();
$this->assertHasElementWithAttributes(
[
'name' => 'first-name',
'value' => $user->first_name,
],
$form,
'Did not find the expected input for the user first name.'
);
}
public function testColumnShowsUserEmail()
{
$user = getUser();
$table = getTableMarkup();
$this->assertElementContains(
$user->email,
'td.email',
$table,
'The <td class="email"> should contain the user\'s email address.'
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.