From e2a63c10a1e50d0318cf8f0c755e9779618ed0d7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 25 Oct 2022 12:37:19 +1300 Subject: [PATCH 1/2] Fix spec tests --- tests/e2e/General/HTTPTest.php | 61 ++++++++++++---------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/tests/e2e/General/HTTPTest.php b/tests/e2e/General/HTTPTest.php index 06ceada976..debef37e97 100644 --- a/tests/e2e/General/HTTPTest.php +++ b/tests/e2e/General/HTTPTest.php @@ -124,56 +124,33 @@ class HTTPTest extends Scope $this->client->setEndpoint($previousEndpoint); } - // public function testSpecSwagger2() - // { - // $response = $this->client->call(Client::METHOD_GET, '/specs/swagger2?platform=client', [ - // 'content-type' => 'application/json', - // ], []); - - // if(!file_put_contents(__DIR__ . '/../../resources/swagger2.json', json_encode($response['body']))) { - // throw new Exception('Failed to save spec file'); - // } - - // $client = new Client(); - // $client->setEndpoint('https://validator.swagger.io'); - - // /** - // * Test for SUCCESS - // */ - // $response = $client->call(Client::METHOD_POST, '/validator/debug', [ - // 'content-type' => 'application/json', - // ], json_decode(file_get_contents(realpath(__DIR__ . '/../../resources/swagger2.json')), true)); - - // $response['body'] = json_decode($response['body'], true); - - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertTrue(empty($response['body'])); - - // unlink(realpath(__DIR__ . '/../../resources/swagger2.json')); - // } - - public function testSpecOpenAPI3() + public function testSpecs() { - $response = $this->client->call(Client::METHOD_GET, '/specs/open-api3?platform=console', [ - 'content-type' => 'application/json', - ], []); - $directory = __DIR__ . '/../../../app/config/specs/'; $files = scandir($directory); $client = new Client(); $client->setEndpoint('https://validator.swagger.io'); + $versions = [ + 'latest', + '0.15.x', + '0.14.x', + ]; + foreach ($files as $file) { if (in_array($file, ['.', '..'])) { continue; } - if ( - (strpos($file, 'latest') === false) && - (strpos($file, '0.12.x') === false) && - (strpos($file, '0.13.x') === false) - ) { + $allowed = false; + foreach ($versions as $version) { + if (\str_contains($file, $version)) { + $allowed = true; + break; + } + } + if (!$allowed) { continue; } @@ -186,7 +163,13 @@ class HTTPTest extends Scope $response['body'] = json_decode($response['body'], true); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertTrue(empty($response['body'])); + + if (!empty($response['body']['schemaValidationMessages'])) { + \var_dump($file); + \var_dump($response['body']); + } + + $this->assertEmpty($response['body']['schemaValidationMessages']); } } From 1f49985d26b743768e4a0117c5da24f94f4dfef7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 25 Oct 2022 19:38:31 +1300 Subject: [PATCH 2/2] Remove var dumps --- tests/e2e/General/HTTPTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/e2e/General/HTTPTest.php b/tests/e2e/General/HTTPTest.php index debef37e97..14e6ada761 100644 --- a/tests/e2e/General/HTTPTest.php +++ b/tests/e2e/General/HTTPTest.php @@ -163,12 +163,6 @@ class HTTPTest extends Scope $response['body'] = json_decode($response['body'], true); $this->assertEquals(200, $response['headers']['status-code']); - - if (!empty($response['body']['schemaValidationMessages'])) { - \var_dump($file); - \var_dump($response['body']); - } - $this->assertEmpty($response['body']['schemaValidationMessages']); } }