diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7697056b..330251ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,7 +70,6 @@ jobs: uses: ramsey/composer-install@v2 with: dependency-versions: ${{ matrix.dependencies }} - composer-options: ${{ matrix.composer-options }} - name: Composer test run: composer test diff --git a/src/PhpPact/Standalone/Broker/Broker.php b/src/PhpPact/Standalone/Broker/Broker.php index 75742c28..eda58eb1 100644 --- a/src/PhpPact/Standalone/Broker/Broker.php +++ b/src/PhpPact/Standalone/Broker/Broker.php @@ -44,10 +44,6 @@ public function canIDeploy() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } @@ -92,10 +88,6 @@ public function createOrUpdatePacticipant() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } @@ -121,10 +113,6 @@ public function createOrUpdateWebhook() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } @@ -144,10 +132,6 @@ public function createVersionTag() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } @@ -172,10 +156,6 @@ public function createWebhook() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } @@ -194,10 +174,6 @@ public function describeVersion() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } @@ -215,10 +191,6 @@ public function listLatestPactVersions() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } @@ -246,12 +218,7 @@ public function publish(): void ) ); - try { $runner->runBlocking(); - } finally { - $this->logger->info('out > ' . $runner->getOutput()); - $this->logger->error('err > ' . $runner->getStderr()); - } } public function testWebhook() @@ -268,10 +235,6 @@ public function testWebhook() ); $runner->runBlocking(); - if ($runner->getExitCode() !== 0) { - throw new \Exception($runner->getStderr()); - } - return \json_decode($runner->getOutput(), true); } diff --git a/src/PhpPact/Standalone/ProviderVerifier/VerifierProcess.php b/src/PhpPact/Standalone/ProviderVerifier/VerifierProcess.php index 447b5189..f3b316c4 100644 --- a/src/PhpPact/Standalone/ProviderVerifier/VerifierProcess.php +++ b/src/PhpPact/Standalone/ProviderVerifier/VerifierProcess.php @@ -59,12 +59,7 @@ public function run(array $arguments, $processTimeout, $processIdleTimeout) $logger->info("Verifying PACT with script:\n{$processRunner->getCommand()}\n\n"); - try { - $processRunner->runBlocking(); - } finally { - $logger->info('out > ' . $processRunner->getOutput()); - $logger->error('err > ' . $processRunner->getStderr()); - } + $processRunner->runBlocking(); } /** diff --git a/src/PhpPact/Standalone/Runner/ProcessRunner.php b/src/PhpPact/Standalone/Runner/ProcessRunner.php index bcd8325f..a90e6e7b 100644 --- a/src/PhpPact/Standalone/Runner/ProcessRunner.php +++ b/src/PhpPact/Standalone/Runner/ProcessRunner.php @@ -129,7 +129,9 @@ public function runBlocking(): int $logger->debug("Exit code: {$this->getExitCode()}"); if ($this->getExitCode() !== 0) { - throw new \Exception("PactPHP Process returned non-zero exit code: {$this->getExitCode()}"); + $this->logger->info('out > ' . $this->getOutput()); + $this->logger->error('err > ' . $this->getStderr()); + throw new \Exception("PactPHP Process returned non-zero exit code: {$this->getExitCode()}", $this->getExitCode()); } Loop::stop(); diff --git a/tests/PhpPact/Standalone/Broker/BrokerTest.php b/tests/PhpPact/Standalone/Broker/BrokerTest.php index 292c9b7f..ea1ee6e5 100644 --- a/tests/PhpPact/Standalone/Broker/BrokerTest.php +++ b/tests/PhpPact/Standalone/Broker/BrokerTest.php @@ -78,4 +78,22 @@ public function listLatestPactVersions(): void $result = $broker->listLatestPactVersions(); $this->assertArrayHasKey('pacts', $result); } + + /** + * @test + * + * @throws \Exception + */ + public function publishLogsStdError(): void + { + $config = new BrokerConfig(); + $config->setPactLocations('not a directory'); + $broker = new Broker($config); + try { + $broker->publish(); + } catch(\Exception $e){ + $this->assertEquals(1, $e->getCode()); + $this->assertStringContainsString("PactPHP Process returned non-zero exit code: 1", $e->getMessage()); + } + } } diff --git a/tests/PhpPact/Standalone/Runner/ProcessRunnerTest.php b/tests/PhpPact/Standalone/Runner/ProcessRunnerTest.php index 7d7c50ca..6e52fab9 100644 --- a/tests/PhpPact/Standalone/Runner/ProcessRunnerTest.php +++ b/tests/PhpPact/Standalone/Runner/ProcessRunnerTest.php @@ -39,13 +39,13 @@ public function testBlockingProcess() try { $p->runBlocking(); } catch (\Exception $e) { + $exitCode = $p->getExitCode(); + $this->assertEquals($exitCode, $e->getCode()); + $this->assertStringContainsString("PactPHP Process returned non-zero exit code: $exitCode", $e->getMessage()); + $this->assertNotEquals($exitCode, 0, 'Expect the exit code to be non-zero: ' . $exitCode); + $this->assertStringContainsString($expectedErr, $p->getStderr(), "Expect '{$expectedErr}' to be in the stderr"); + $this->assertEquals(null, $p->getOutput(), 'Expect a null stdout'); } - - $exitCode = $p->getExitCode(); - - $this->assertNotEquals($exitCode, 0, 'Expect the exit code to be non-zero: ' . $exitCode); - $this->assertStringContainsString($expectedErr, $p->getStderr(), "Expect '{$expectedErr}' to be in the stderr"); - $this->assertEquals(null, $p->getOutput(), 'Expect a null stdout'); } /** @@ -62,12 +62,12 @@ public function testProcessRunnerShouldReturnCompleteOutput() $p = new ProcessRunner($cmd, []); $expectedOutput = 'third line'; $expectedErr = 'fourth line'; - try { $p->runBlocking(); } catch (\Exception $e) { - } - + $this->assertEquals(42, $e->getCode()); + $this->assertStringContainsString("PactPHP Process returned non-zero exit code: 42", $e->getMessage()); + } $this->assertTrue((\stripos($p->getOutput(), $expectedOutput) !== false), "Expect '{$expectedOutput}' to be in the output:"); $this->assertTrue((\stripos($p->getStderr(), $expectedErr) !== false), "Expect '{$expectedErr}' to be in the stderr"); }