mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
added new assert function for tests
This commit is contained in:
parent
f6dc3399a3
commit
2d9cdac14c
@ -410,10 +410,6 @@ class AnimeSearchEndpointTest extends TestCase
|
||||
"order_by" => $paramName
|
||||
]);
|
||||
|
||||
$this->seeStatusCode(200);
|
||||
$this->assertPaginationData($expectedCount);
|
||||
$this->assertIsArray($content["data"]);
|
||||
$this->assertCount($expectedCount, $content["data"]);
|
||||
$expectedItems = $items->map(fn($elem) => data_get($elem, $orderByField));
|
||||
$actualItems = collect($content["data"])->map(fn($elem) => data_get($elem, $orderByField));
|
||||
|
||||
@ -422,8 +418,11 @@ class AnimeSearchEndpointTest extends TestCase
|
||||
$actualItems = $actualItems->map(fn(Carbon $elem) => $elem->getTimestamp());
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $expectedItems->diff($actualItems)->count());
|
||||
$this->assertTrue($expectedItems->toArray() === $actualItems->toArray());
|
||||
$this->seeStatusCode(200);
|
||||
$this->assertPaginationData($expectedCount);
|
||||
$this->assertIsArray($content["data"]);
|
||||
$this->assertCount($expectedCount, $content["data"]);
|
||||
$this->assertCollectionsStrictlyEqual($expectedItems, $actualItems);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ use App\Testing\ScoutFlush;
|
||||
use App\Testing\SyntheticMongoDbTransaction;
|
||||
use Faker\Factory as FakerFactory;
|
||||
use Faker\Generator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Laravel\Lumen\Testing\TestCase as LumenTestCase;
|
||||
|
||||
@ -69,4 +70,10 @@ abstract class TestCase extends LumenTestCase
|
||||
$this->response->assertJsonPath("pagination.items.total", $expectedTotal);
|
||||
return $this->response->assertJsonPath("pagination.items.per_page", $perPage);
|
||||
}
|
||||
|
||||
public function assertCollectionsStrictlyEqual(Collection $expectedItems, Collection $actualItems): void
|
||||
{
|
||||
$this->assertEquals(0, $expectedItems->diff($actualItems)->count());
|
||||
$this->assertEquals($expectedItems->toArray(), $actualItems->toArray());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user