diff --git a/example/phpunit.all.xml b/example/phpunit.all.xml
index 02a047d51..9df3e7b43 100644
--- a/example/phpunit.all.xml
+++ b/example/phpunit.all.xml
@@ -36,5 +36,6 @@
+
diff --git a/example/phpunit.consumer.xml b/example/phpunit.consumer.xml
index 0e521db3e..4c076cf92 100644
--- a/example/phpunit.consumer.xml
+++ b/example/phpunit.consumer.xml
@@ -25,5 +25,6 @@
+
diff --git a/example/phpunit.core.xml b/example/phpunit.core.xml
index 57e6e2e40..5e9ed2010 100644
--- a/example/phpunit.core.xml
+++ b/example/phpunit.core.xml
@@ -24,5 +24,6 @@
+
diff --git a/src/PhpPact/Consumer/Listener/PactTestListener.php b/src/PhpPact/Consumer/Listener/PactTestListener.php
index 6e25ccbf2..edb39aa16 100644
--- a/src/PhpPact/Consumer/Listener/PactTestListener.php
+++ b/src/PhpPact/Consumer/Listener/PactTestListener.php
@@ -7,6 +7,7 @@
use PhpPact\Standalone\Broker\Broker;
use PhpPact\Standalone\Broker\BrokerConfig;
use PhpPact\Standalone\MockService\MockServerEnvConfig;
+use PhpPact\Standalone\PactConfigInterface;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
@@ -49,6 +50,25 @@ public function __construct(array $testSuiteNames)
$this->mockServerConfig = new MockServerEnvConfig();
}
+ /**
+ * @param TestSuite $suite
+ *
+ * @throws \Exception
+ */
+ public function startTestSuite(TestSuite $suite): void
+ {
+ if (
+ \in_array($suite->getName(), $this->testSuiteNames) &&
+ $this->mockServerConfig->getPactFileWriteMode() === PactConfigInterface::MODE_MERGE
+ ) {
+ file_put_contents('/home/tien/Downloads/test.txt', 'deleted');
+ $consumer = $this->mockServerConfig->getConsumer();
+ $provider = $this->mockServerConfig->getProvider();
+ $pactDir = $this->mockServerConfig->getPactDir();
+ unlink($pactDir . \DIRECTORY_SEPARATOR . "{$consumer}-{$provider}.json");
+ }
+ }
+
public function addError(Test $test, \Throwable $t, float $time): void
{
$this->failed = true;
diff --git a/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php b/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
index 1f11a8a84..4621f33a8 100644
--- a/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
+++ b/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
@@ -39,6 +39,10 @@ public function __construct()
}
$this->setPactSpecificationVersion($version);
+
+ if ($writeMode = $this->parseEnv('PACT_FILE_WRITE_MODE', false)) {
+ $this->setPactFileWriteMode($writeMode);
+ }
}
/**
diff --git a/src/PhpPact/Standalone/PactConfig.php b/src/PhpPact/Standalone/PactConfig.php
index e5a526f9b..dd195b128 100644
--- a/src/PhpPact/Standalone/PactConfig.php
+++ b/src/PhpPact/Standalone/PactConfig.php
@@ -57,7 +57,7 @@ class PactConfig implements PactConfigInterface
*
* @var string
*/
- private string $pactFileWriteMode = self::MODE_OVERWRITE;
+ private string $pactFileWriteMode = self::MODE_MERGE;
/**
* {@inheritdoc}