Skip to content

Commit

Permalink
Improved tests for routes macros x2.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulin-evgeny committed May 17, 2024
1 parent 19ff088 commit 721f3fb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 15 deletions.
81 changes: 67 additions & 14 deletions tests/VersionRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function setUp(): void
public function getTestVersionRangeData(): array
{
return [
// Range
[
'version' => '1',
'is_correct_version' => true,
Expand Down Expand Up @@ -101,8 +100,26 @@ public function getTestVersionRangeData(): array
'is_correct_version' => false,
'route' => static::ROUTE_FACADE_RANGE,
],
];
}

/**
* @dataProvider getTestVersionRangeData
*/
public function testVersionRange(string $version, bool $isCorrectVersion, string $route): void
{
$this->mockRoutes();

$response = $this->get("/v{$version}{$route}");

$status = ($isCorrectVersion) ? 200 : 404;

$response->assertStatus($status);
}

// From
public function getTestVersionFromData(): array
{
return [
[
'version' => '1',
'is_correct_version' => false,
Expand Down Expand Up @@ -154,8 +171,26 @@ public function getTestVersionRangeData(): array
'is_correct_version' => false,
'route' => static::ROUTE_FACADE_FROM,
],
];
}

/**
* @dataProvider getTestVersionFromData
*/
public function testVersionFrom(string $version, bool $isCorrectVersion, string $route): void
{
$this->mockRoutes();

$response = $this->get("/v{$version}{$route}");

$status = ($isCorrectVersion) ? 200 : 404;

$response->assertStatus($status);
}

// To
public function getTestVersionToData(): array
{
return [
[
'version' => '1',
'is_correct_version' => true,
Expand Down Expand Up @@ -184,31 +219,49 @@ public function getTestVersionRangeData(): array

[
'version' => '1',
'is_correct_version' => false,
'route' => static::ROUTE_FACADE_FROM,
'is_correct_version' => true,
'route' => static::ROUTE_FACADE_TO,
],
[
'version' => '2.0',
'is_correct_version' => false,
'route' => static::ROUTE_FACADE_FROM,
'route' => static::ROUTE_FACADE_TO,
],
[
'version' => '2',
'is_correct_version' => true,
'route' => static::ROUTE_FACADE_FROM,
'route' => static::ROUTE_FACADE_TO,
],
[
'version' => '3',
'is_correct_version' => true,
'route' => static::ROUTE_FACADE_FROM,
'is_correct_version' => false,
'route' => static::ROUTE_FACADE_TO,
],
[
'version' => '3.5',
'version' => '1.5',
'is_correct_version' => false,
'route' => static::ROUTE_FACADE_FROM,
'route' => static::ROUTE_FACADE_TO,
],
];
}

// Version
/**
* @dataProvider getTestVersionToData
*/
public function testVersionTo(string $version, bool $isCorrectVersion, string $route): void
{
$this->mockRoutes();

$response = $this->get("/v{$version}{$route}");

$status = ($isCorrectVersion) ? 200 : 404;

$response->assertStatus($status);
}

public function getTestVersionData(): array
{
return [
[
'version' => '2',
'is_correct_version' => true,
Expand All @@ -233,9 +286,9 @@ public function getTestVersionRangeData(): array
}

/**
* @dataProvider getTestVersionRangeData
* @dataProvider getTestVersionData
*/
public function testVersionRange(string $version, bool $isCorrectVersion, string $route): void
public function testVersion(string $version, bool $isCorrectVersion, string $route): void
{
$this->mockRoutes();

Expand Down
1 change: 0 additions & 1 deletion tests/support/Traits/ModelTestStateMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace RonasIT\Support\Tests\Support\Traits;

use Illuminate\Database\Connection;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
Expand Down

0 comments on commit 721f3fb

Please sign in to comment.