1. Go to this page and download the library: Download juampi92/test-seo 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/ */
juampi92 / test-seo example snippets
// Create TestSEO instance using the response:
$seo = new TestSEO($htmlResponse);
// Perform assertions:
$seo->assertTitleEndsWith(' - My Website');
// Assert the data yourself:
$this->assertEquals(
'My title - My Website',
$seo->data->title()
);
public function testLandingPageSEO()
{
// Arrange
// ...
// Act
$response = $client->get('/')->send();
// Assert
$this->assertEquals(200, $response->getStatusCode());
$html = json_decode($response->getBody(true), true);
$seo = new TestSEO($html);
// Assert
$seo
->assertTitleEndsWith(' - My Website')
->assertCanonicalIs('https://www.mywebsite.com/');
}
public function test_landing_page_SEO()
{
// Arrange
// ...
// Act
$response = $this->get('/');
// Assert
$response->assertStatus(200);
$seo = new TestSEO($response->getContent());
$seo
->assertTitleEndsWith(' - My Website')
->assertCanonicalIs('https://www.mywebsite.com/');
}
test('landing page SEO tags', function () {
// Arrange
// ...
// Act
$response = get('/')->assertStatus(200);
$seo = new TestSEO($response->getContent());
// Assert
expect($seo->data)
->title()->toEndWith(' - My Website')
->description()->toBe('This is my description')
->canonical()->not()->toBeNull()
->robots()->index()->toBeTrue()
->robots()->nofollow()->toBeTrue();
});
$seo = new TestSEO($response->getContent(), snapshotSerializer: null);
$json = json_encode($seo);
$seo = new TestSEO($response->getContent(), new MyCustomSerializer());
$json = json_encode($seo);
use function Spatie\Snapshots\{assertMatchesSnapshot, assertMatchesJsonSnapshot};
use Juampi92\TestSEO\TestSEO;
test('landing page SEO', function () {
$response = $this->get('/');
$response->assertStatus(200);
$seo = new TestSEO($response->getContent());
assertMatchesJsonSnapshot(json_encode($seo));
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.