From 4d98388cc43109c025bd52c1a1e92b8b6bb6ea90 Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Mon, 21 Oct 2024 02:21:31 +0700 Subject: [PATCH] fix(compatibility-suite): Clean up mock server --- compatibility-suite/tests/Service/Server.php | 6 ++++++ src/PhpPact/Consumer/Driver/Pact/PactDriver.php | 3 +++ tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php | 2 +- .../Plugin/Driver/Pact/AbstractPluginPactDriverTestCase.php | 3 +-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compatibility-suite/tests/Service/Server.php b/compatibility-suite/tests/Service/Server.php index c4580f8b..36f58740 100644 --- a/compatibility-suite/tests/Service/Server.php +++ b/compatibility-suite/tests/Service/Server.php @@ -77,4 +77,10 @@ public function getPort(): int { return $this->config->getPort(); } + + public function __destruct() + { + // Clean up mock server + $this->getVerifyResult(); + } } diff --git a/src/PhpPact/Consumer/Driver/Pact/PactDriver.php b/src/PhpPact/Consumer/Driver/Pact/PactDriver.php index e2de57df..b19c28ef 100644 --- a/src/PhpPact/Consumer/Driver/Pact/PactDriver.php +++ b/src/PhpPact/Consumer/Driver/Pact/PactDriver.php @@ -23,6 +23,9 @@ public function __construct( public function cleanUp(): void { + if (!$this->pact) { + return; + } $success = $this->client->freePactHandle($this->getPact()->handle) === 0; if (!$success) { trigger_error('Can not free pact handle. The handle is not valid or does not refer to a valid Pact. Could be that it was previously deleted.', E_USER_WARNING); diff --git a/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php b/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php index 9e3e81cd..b754c662 100644 --- a/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php +++ b/tests/PhpPact/Consumer/Driver/Pact/PactDriverTest.php @@ -81,7 +81,7 @@ public function testCleanUp(): void public function testCleanUpWithoutPact(): void { - $this->expectException(MissingPactException::class); + $this->expectNotToPerformAssertions(); $this->driver->cleanUp(); } diff --git a/tests/PhpPact/Plugin/Driver/Pact/AbstractPluginPactDriverTestCase.php b/tests/PhpPact/Plugin/Driver/Pact/AbstractPluginPactDriverTestCase.php index 3d0b7d78..6a6a05cf 100644 --- a/tests/PhpPact/Plugin/Driver/Pact/AbstractPluginPactDriverTestCase.php +++ b/tests/PhpPact/Plugin/Driver/Pact/AbstractPluginPactDriverTestCase.php @@ -2,7 +2,6 @@ namespace PhpPactTest\Plugin\Driver\Pact; -use PhpPact\Consumer\Driver\Exception\MissingPactException; use PhpPact\Plugin\Driver\Pact\AbstractPluginPactDriver; use PhpPact\Plugin\Exception\PluginNotSupportedBySpecificationException; use PhpPactTest\Consumer\Driver\Pact\PactDriverTest; @@ -51,7 +50,7 @@ public function testCleanUpPlugin(): void public function testCleanUpPluginWithoutPact(): void { - $this->expectException(MissingPactException::class); + $this->expectNotToPerformAssertions(); $this->driver->cleanUp(); }