Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkaOnLine committed Sep 3, 2024
1 parent d9531ef commit 4cc0c79
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions tests/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use L5Swagger\Http\Controllers\SwaggerController;
use L5Swagger\Http\Middleware\Config;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;

/**
* @covers \L5Swagger\Http\Controllers\SwaggerController
Expand Down Expand Up @@ -179,12 +181,15 @@ public function testUserCanAccessDocumentationInterface(): void
/**
* @throws L5SwaggerException
*/
public function testUserCanAccessDocumentationInterfaceAndConfigureProxy(): void
{
#[DataProvider('provideProxies')]
public function testUserCanAccessDocumentationInterfaceAndConfigureProxy(
mixed $proxy,
array $expectedProxies
): void {
config(['l5-swagger' => [
'default' => 'default',
'documentations' => config('l5-swagger.documentations'),
'defaults' => array_merge(config('l5-swagger.defaults'), ['proxy' => ['foo', 'bar']]),
'defaults' => array_merge(config('l5-swagger.defaults'), ['proxy' => $proxy]),
]]);

$config = $this->configFactory->documentationConfig();
Expand All @@ -195,18 +200,14 @@ public function testUserCanAccessDocumentationInterfaceAndConfigureProxy(): void
->assertSee(route('l5-swagger.default.oauth2_callback'))
->isOk();

$this->assertSame(['foo', 'bar'], Request::getTrustedProxies());

config(['l5-swagger' => [
'default' => 'default',
'documentations' => config('l5-swagger.documentations'),
'defaults' => array_merge(config('l5-swagger.defaults'), ['proxy' => 'baz']),
]]);

$this->get($config['routes']['api'])
->isOk();
$this->assertSame($expectedProxies, Request::getTrustedProxies());

Check notice on line 203 in tests/RoutesTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/RoutesTest.php#L203

Avoid using static access to class '\Illuminate\Http\Request' in method 'testUserCanAccessDocumentationInterfaceAndConfigureProxy'.
}

$this->assertSame(['baz'], Request::getTrustedProxies());
public static function provideProxies(): \Generator
{
yield 'proxies array' => ['proxy' => ['foo', 'bar'], 'expectedProxies' => ['foo', 'bar']];
yield 'proxy as string' => ['proxy' => 'baz', 'expectedProxies' => ['baz']];
yield 'proxy is null' => ['proxy' => null, 'expectedProxies' => []];
}

/**
Expand Down Expand Up @@ -273,13 +274,15 @@ public function testItWillReturn404WhenDocGenerationFails(): void
]]);

$mockGenerator = $this->mockGenerator();
$mockGenerator->expects($this->once())->method('generateDocs')->willThrowException(new \Exception);
$mockGenerator->expects($this->once())->method('generateDocs')->willThrowException(new L5SwaggerException());

$this->get($jsonUrl)->assertNotFound();
}

/**
* @throws Exception
*
* @return Generator&MockObject
*/
private function mockGenerator(): Generator
{
Expand Down

0 comments on commit 4cc0c79

Please sign in to comment.