Skip to content

Commit

Permalink
Default write mode merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Mar 2, 2023
1 parent ca46297 commit 4149902
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/phpunit.all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
<env name="PACT_CONSUMER_TAG" value="master"/>
<env name="PACT_PROVIDER_NAME" value="someProvider"/>
<env name="PACT_OUTPUT_DIR" value=".\example\output\\"/>
<env name="PACT_FILE_WRITE_MODE" value="merge"/>
</php>
</phpunit>
1 change: 1 addition & 0 deletions example/phpunit.consumer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<env name="PACT_PROVIDER_NAME" value="someProvider"/>
<env name="PACT_OUTPUT_DIR" value=".\example\output"/>
<!-- <env name="PACT_BROKER_URI" value="http://localhost"/> -->
<env name="PACT_FILE_WRITE_MODE" value="merge"/>
</php>
</phpunit>
1 change: 1 addition & 0 deletions example/phpunit.core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<env name="PACT_CONSUMER_TAG" value="master"/>
<env name="PACT_PROVIDER_NAME" value="someProvider"/>
<env name="PACT_OUTPUT_DIR" value=".\example\output\\"/>
<env name="PACT_FILE_WRITE_MODE" value="merge"/>
</php>
</phpunit>
20 changes: 20 additions & 0 deletions src/PhpPact/Consumer/Listener/PactTestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function __construct()
}

$this->setPactSpecificationVersion($version);

if ($writeMode = $this->parseEnv('PACT_FILE_WRITE_MODE', false)) {
$this->setPactFileWriteMode($writeMode);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPact/Standalone/PactConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PactConfig implements PactConfigInterface
*
* @var string
*/
private string $pactFileWriteMode = self::MODE_OVERWRITE;
private string $pactFileWriteMode = self::MODE_MERGE;

/**
* {@inheritdoc}
Expand Down

0 comments on commit 4149902

Please sign in to comment.