phpvms/tests/ApiTestTrait.php
Arthur Parienté 110e6b584b
Upgrade to PHPUnit 10 (#1764)
* Remove sempro/phpunit-pretty-print

* Bump PHPUnit dependencies

* Bump nunomaduro/collision and filp/whoops

* Update phpunit.xml

* Change setUp to protected

* Remove --verbose option

* Update phpunit.xml

* Remove Bootstrap

* Add types in tests

* Make tests class final

* Remove unused variables

* Add .phpunit.cache to .gitignore

* Apply fixes from StyleCI

* Update phpunit.xml

* Break tests (to test CI/CD)

* Revert "Break tests (to test CI/CD)"

This reverts commit 928b199bc4ee09238f83f33cc7c12304992368ab.

* Update composer.lock

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
2024-02-21 13:43:35 -06:00

29 lines
733 B
PHP

<?php
trait ApiTestTrait
{
public function assertApiResponse(array $actualData): void
{
$this->assertApiSuccess();
$response = json_decode($this->response->getContent(), true);
$responseData = $response['data'];
$this->assertNotEmpty($responseData['id']);
$this->assertModelData($actualData, $responseData);
}
public function assertApiSuccess(): void
{
$this->assertResponseOk();
$this->seeJson(['success' => true]);
}
public function assertModelData(array $actualData, array $expectedData): void
{
foreach ($actualData as $key => $value) {
$this->assertEquals($actualData[$key], $expectedData[$key]);
}
}
}