From a6c4c28108890e551ff239fb8977e850646a2c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 30 Jun 2024 12:08:50 +0000 Subject: [PATCH] Fix tests --- tests/Client.php | 2 +- tests/ExecutorTest.php | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/Client.php b/tests/Client.php index f1b27ba..d279a4e 100644 --- a/tests/Client.php +++ b/tests/Client.php @@ -153,7 +153,7 @@ public function call(string $method, string $path = '', array $headers = [], arr if ($decode) { $strpos = strpos($responseType, ';'); - $strpos = \is_bool($strpos) ? 0 : $strpos; + $strpos = \is_bool($strpos) ? \strlen($responseType) : $strpos; switch (substr($responseType, 0, $strpos)) { case 'multipart/form-data': $boundary = \explode('boundary=', $responseHeaders['content-type'] ?? '')[1] ?? ''; diff --git a/tests/ExecutorTest.php b/tests/ExecutorTest.php index 988543d..180cf21 100644 --- a/tests/ExecutorTest.php +++ b/tests/ExecutorTest.php @@ -342,7 +342,7 @@ public function provideScenarios(): array $this->assertEmpty($response['body']['errors']); }, 'body' => function () { - return 1; + return '1'; }, ], [ @@ -359,7 +359,7 @@ public function provideScenarios(): array $this->assertEmpty($response['body']['errors']); }, 'body' => function () { - return 5; + return '5'; }, ], [ @@ -374,11 +374,11 @@ public function provideScenarios(): array $this->assertEquals("OK", $response['body']['body']); $this->assertGreaterThan(5 * 1024 * 1024, strlen($response['body']['logs'])); $this->assertLessThan(6 * 1024 * 1024, strlen($response['body']['logs'])); - $this->assertStringContainsString('Log file has been truncated to 5 MBs', $response['body']['logs']); + $this->assertStringContainsString('truncated', $response['body']['logs']); $this->assertEmpty($response['body']['errors']); }, 'body' => function () { - return 15; + return '15'; }, ], [ @@ -418,6 +418,7 @@ public function provideScenarios(): array $this->assertEmpty($response['body']['logs']); $this->assertEmpty($response['body']['errors']); }, + null, // body 'mimeType' => 'multipart/form-data' ], [ @@ -431,6 +432,7 @@ public function provideScenarios(): array $this->assertEquals(400, $response['headers']['status-code']); \var_dump($response); }, + null, // body 'mimeType' => 'application/json' ], [ @@ -473,7 +475,7 @@ public function provideScenarios(): array * * @dataProvider provideScenarios */ - public function testScenarios(string $image, string $entrypoint, string $folder, string $version, string $startCommand, string $buildCommand, callable $assertions, callable $bodyCallable = null, string $mimeType = "application/json"): void + public function testScenarios(string $image, string $entrypoint, string $folder, string $version, string $startCommand, string $buildCommand, callable $assertions, callable $body = null, string $mimeType = "application/json"): void { /** Prepare deployment */ $output = ''; @@ -497,11 +499,6 @@ public function testScenarios(string $image, string $entrypoint, string $folder, $path = $response['body']['path']; - $body = ""; - if (isset($bodyCallable)) { - $body = \strval($bodyCallable()); - } - $params = [ 'source' => $path, 'entrypoint' => $entrypoint, @@ -512,8 +509,8 @@ public function testScenarios(string $image, string $entrypoint, string $folder, 'logging' => true, ]; - if (!empty($body)) { - $params['body'] = $body; + if (isset($body)) { + $params['body'] = $body(); } /** Execute function */