Skip to content

Commit

Permalink
Merge branch 'master' into rust-ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
cfmack authored Nov 18, 2021
2 parents 01c5ff4 + be7c9a6 commit ce65785
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
35 changes: 33 additions & 2 deletions src/PhpPact/Standalone/ProviderVerifier/Model/VerifierConfig.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
(): array(): array(): array<?php

namespace PhpPact\Standalone\ProviderVerifier\Model;

Expand Down Expand Up @@ -43,6 +43,13 @@ class VerifierConfig implements VerifierConfigInterface
private bool $stateChangeAsQuery = false;
private bool $stateChangeTeardown = false;

/** @var null|string */
private $logDirectory;

/** @var string */
private $format;


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -463,6 +470,11 @@ public function getFiles(): array
return $this->files;
}

public function getFilterConsumerNames(): array
{
return $this->$this->filterConsumerNames;
}

/**
* {@inheritdoc}
*/
Expand All @@ -476,7 +488,26 @@ public function setFilterConsumerNames(string ...$filterConsumerNames): Verifier
/**
* {@inheritdoc}
*/
public function getFilterConsumerNames(): array
public function getLogDirectory()
{
return $this->logDirectory;
}

/**
* {@inheritdoc}
*/
public function setLogDirectory(string $log): VerifierConfigInterface
{
$this->logDirectory = $log;

return $this;
}

/**
* {@inheritdoc}
*/
public function getFormat()

{
return $this->filterConsumerNames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ public function setStateChangeTeardown(bool $stateChangeTeardown): self;

/**
* @return bool
* @return null|string set the directory for the pact.log file
*/
public function getLogDirectory();

/**
* @param string $log set the directory for the pact.log file
*
* @return VerifierConfigInterface
*/
public function setLogDirectory(string $log): self;

/**
* @return null|string RSpec formatter. Defaults to custom Pact formatter. json and RspecJunitFormatter may also be used
*/
public function isStateChangeTeardown(): bool;

Expand Down
20 changes: 20 additions & 0 deletions src/PhpPact/Standalone/ProviderVerifier/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ public function getArguments(): array

if ($this->config->getBrokerPassword() !== null) {
$parameters[] = "--password={$this->config->getBrokerPassword()}";
$parameters[] = "--broker-password={$this->config->getBrokerPassword()}";
}

if ($this->config->getCustomProviderHeaders() !== null) {
foreach ($this->config->getCustomProviderHeaders() as $customProviderHeader) {
$parameters[] = "--custom-provider-header=\"{$customProviderHeader}\"";
}
}

if ($this->config->isVerbose() === true) {
$parameters[] = '--verbose';
}

if ($this->config->getLogDirectory() !== null) {
$parameters[] = "--log={$this->config->getLogDirectory()}";
}

if ($this->config->getFormat() !== null) {
$parameters[] = "--format={$this->config->getFormat()}";
}

if ($this->config->isEnablePending() === true) {
Expand Down Expand Up @@ -174,3 +193,4 @@ public function verify(): bool
return !$this->ffi->pactffi_verify(\implode(PHP_EOL, $this->getArguments()));
}
}
(): array
38 changes: 37 additions & 1 deletion tests/PhpPact/Standalone/ProviderVerifier/VerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,23 @@ public function testGetArguments(): void
->setEnablePending(true)
->setStateChangeAsQuery(true)
->setStateChangeTeardown(true);
->addCustomProviderHeader('key1', 'value1')
->addCustomProviderHeader('key2', 'value2')
->setVerbose(true)
->setLogDirectory('my/log/directory')
->setFormat('someformat')
->setProcessTimeout(30)
->setProcessIdleTimeout(5)
->setEnablePending(true)
->setIncludeWipPactSince('2020-01-30')
->setRequestFilter(
function (RequestInterface $r) {
return $r->withHeader('MY_SPECIAL_HEADER', 'my special value');
}
)
->setConsumerVersionSelectors($consumerVersionSelectors);


$verifier = new Verifier($config);
$arguments = $verifier->getArguments();

Expand All @@ -73,6 +89,27 @@ public function testGetArguments(): void
$this->assertContains('--token=someToken', $arguments);
$this->assertContains('--user=someusername', $arguments);
$this->assertContains('--password=somepassword', $arguments);

/** @var BrokerHttpClientInterface $brokerHttpService */
$server = new Verifier($config);
$arguments = $server->getArguments();

$this->assertContains('--provider-base-url=http://myprovider:1234', $arguments);
$this->assertContains('--provider-states-setup-url=http://someurl:1234', $arguments);
$this->assertContains('--publish-verification-results', $arguments);
$this->assertContains('--broker-token=someToken', $arguments);
$this->assertContains('--broker-username=someusername', $arguments);
$this->assertContains('--broker-password=somepassword', $arguments);
$this->assertContains('--custom-provider-header="key1: value1"', $arguments);
$this->assertContains('--custom-provider-header="key2: value2"', $arguments);
$this->assertContains('--verbose', $arguments);
$this->assertContains('--log=my/log/directory', $arguments);
$this->assertContains('--format=someformat', $arguments);
$this->assertContains('--provider-version-tag=prod', $arguments);
$this->assertContains('--provider-version-tag=dev', $arguments);
$this->assertContains('--consumer-version-tag=dev', $arguments);
$this->assertSame(['process_timeout' => 30, 'process_idle_timeout' => 5], $server->getTimeoutValues());
$this->assertContains('--enable-pending', $arguments);
$this->assertContains('--include-wip-pacts-since=2020-01-30', $arguments);
$this->assertContains('--build-url=http://build.domain.com', $arguments);
$this->assertContains('--consumer-version-selectors=\'[{"tag":"new-feature","latest":true,"fallbackTag":"master"},{"tag":"test","latest":true},{"tag":"production","latest":true},{"tag":"production","consumer":"my-mobile-consumer"}]\'', $arguments);
Expand Down Expand Up @@ -123,7 +160,6 @@ public function testVerify(): void
->setPort(8000)
->setProviderName('someProvider')
->setProviderVersion('1.0.0');

$verifier = new Verifier($config);

$this->assertTrue($verifier->verify());
Expand Down

0 comments on commit ce65785

Please sign in to comment.