3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-03-01 13:59:07 +00:00
Files
snipe-it/tests/Support/InteractsWithResponses.php
2023-06-21 16:18:09 -07:00

34 lines
1.0 KiB
PHP

<?php
namespace Tests\Support;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Testing\TestResponse;
use RuntimeException;
trait InteractsWithResponses
{
protected function assertResponseContainsInRows(TestResponse $response, Model $model, string $property = 'name')
{
$this->guardAgainstNullProperty($model, $property);
$this->assertTrue(collect($response['rows'])->pluck($property)->contains($model->{$property}));
}
protected function assertResponseDoesNotContainInRows(TestResponse $response, Model $model, string $property = 'name')
{
$this->guardAgainstNullProperty($model, $property);
$this->assertFalse(collect($response['rows'])->pluck($property)->contains($model->{$property}));
}
private function guardAgainstNullProperty(Model $model, string $property): void
{
if (is_null($model->{$property})) {
throw new RuntimeException(
"The property ({$property}) is null on the model which isn't helpful for comparison."
);
}
}
}