1. Go to this page and download the library: Download soyhuce/laravel-embuscade 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/ */
use Soyhuce\LaravelEmbuscade\ViewExpect;
new ViewExpect($html);
// From a TestResponse
$expect = $this->get('/')->expectView();
// From a TestView
$expect = $this->view('home', ['links' => $links])->expectView();
// From a TestComponent
$expect = $this->component(Home::class, ['links' => $links])->expectView();
// Selects all elements matching the CSS selector
$expect->in($cssSeclector);
// Selects the nth element matching the CSS selector, index starts at 0 !
$expect->at($cssSelector, $index);
// Selects the first element matching the CSS selector
$expect->first($cssSelector);
// Selects the last element matching the CSS selector
$expect->last($cssSeclector);
// Selects the only element matching the CSS selector
$expect->sole($cssSelector);
use Soyhuce\LaravelEmbuscade\Embuscade;
Embuscade::selectorHtmlAttribute('data-test'); // or 'dusk' if you use Dusk and want to leverage existing Dusk selectors.
// Expects the view to contain at least an element matching the CSS selector
$expect->toHave('.links a');
// Expects the view to contain exactly n elements matching the CSS selector
$expect->toHave('.links a', 2);
// Expects the view to contain at least one element pointing to $link
$expect->toHaveLink('https://laravel.com/docs');
// Expect the view contains a meta tag with the given attributes in head section
$expect->toHaveMeta(['property' => 'og:title', 'content' => 'Laravel']);
// Expect the view text equals given text
$expect->toHaveText('Laravel');
// Expect the view text contains given text
$expect->toContainText('Documentation');
// Expect the view text is empty
$expect->toBeEmpty();
// Expect the view html contains given content
$expect->toContain('<a href="https://laravel.com/docs">Documentation</a>');
// Expect the element to have the given attribute
$expect->toHaveAttribute('disabled');
// Expect the element to have the given attribute with the given value
$expect->toHaveAttribute('href', 'https://laravel.com/docs');
// Expect the element to have the given attribute containing the given value
$expect->toHaveAttributeContaining('class', 'btn');
$expect->toAccept($value); // same as toHaveAttribute('accept', $value)
$expect->toBeDisabled(); // same as toHaveAttribute('disabled')
$expect->toHaveAlt($value); // same as toHaveAttribute('alt', $value)
$expect->toHaveClass($value); // same as toHaveAttributeContaining('class', $value)
$expect->toHaveHref($value); // same as toHaveAttribute('href', $value)
$expect->toHaveSrc($value); // same as toHaveAttribute('src', $value)
$expect->toHaveValue($value); // same as toHaveAttribute('value', $value)