PHP code example of kodzila / data-assertions
1. Go to this page and download the library: Download kodzila/data-assertions 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/ */
kodzila / data-assertions example snippets
use Kodzila\DataAssertions\EntityAssertion;
$noteData = $webService->getNote();
$assertions = EntityAssertion::build($noteData);
$assertions->field('@id')->iri();
$assertions->field('title')->string();
$assertions->field('description')->string();
$assertions->field('location')->entity();
$assertions->field('startDate')->string();
$assertions->field('endDate')->string();
$assertions->field('personal')->bool();
$assertions->field('content')->iri();
$assertions->field('author')->iri();
$assertions->field('createdAt')->string();
$noteData = [
'@id' => '/api/note/dd85948e-6573-4d66-b743-cca4835448e9',
'title' => 'Note title',
'description' => 'Note title',
'location' => [
'lat' => 1,
'lng' => 2,
'name' => 'Kodzila note',
],
'startDate' => '2020-04-06T00:00:00+02:00',
'endDate' => '2020-04-10T00:00:00+02:00',
'personal' => true,
'content' => '/api/projects/dd85948e-6573-4d66-b743-cca4835448e9',
'author' => '/api/people/b1a93fec-45f1-461f-a93b-b7d2497e9eeb',
'createdAt' => '2020-09-14T12:55:17+02:00',
];
use Kodzila\DataAssertions\EntityAssertion;
$notesData = $webService->getNotes();
EntityCollectionAssertion::build($notesData)
->each(function (EntityAssertion $entityAssertion): void {
$entityAssertion->field('@id')->iri();
$entityAssertion->field('title')->string();
$entityAssertion->field('description')->string();
});
$notesData = [
[
'@id' => '/api/note/dd85948e-6573-4d66-b743-cca4835448e9',
'title' => 'Note title',
'description' => 'Note title',
],
[
'@id' => '/api/note/b1a93fec-45f1-461f-a93b-b7d2497e9eeb',
'title' => 'Note title 2',
'description' => 'Note title 2',
],
];