-
Notifications
You must be signed in to change notification settings - Fork 92
/
PactWriter.php
39 lines (34 loc) · 1.39 KB
/
PactWriter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace PhpPactTest\CompatibilitySuite\Service;
use PhpPact\Config\PactConfigInterface;
use PhpPact\Consumer\Driver\Pact\PactDriver;
use PhpPact\Consumer\Registry\Interaction\InteractionRegistry;
use PhpPact\FFI\Client;
use PhpPact\Standalone\MockService\MockServerConfig;
use PhpPactTest\CompatibilitySuite\Constant\Path;
use PhpPactTest\CompatibilitySuite\Model\PactPath;
class PactWriter implements PactWriterInterface
{
public function __construct(
private InteractionsStorageInterface $storage,
private string $specificationVersion,
) {
}
public function write(int $id, PactPath $pactPath, string $mode = PactConfigInterface::MODE_OVERWRITE): void
{
$config = new MockServerConfig();
$config
->setConsumer($pactPath->getConsumer())
->setProvider(PactPath::PROVIDER)
->setPactDir(Path::PACTS_PATH)
->setPactSpecificationVersion($this->specificationVersion)
->setPactFileWriteMode($mode);
$client = new Client();
$pactDriver = new PactDriver($client, $config);
$interactionRegistry = new InteractionRegistry($client, $pactDriver);
$interaction = $this->storage->get(InteractionsStorageInterface::PACT_WRITER_DOMAIN, $id);
$interactionRegistry->registerInteraction($interaction);
$pactDriver->writePact();
$pactDriver->cleanUp();
}
}