-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Create classes for matchers and generators
- Loading branch information
Showing
96 changed files
with
2,426 additions
and
1,178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/PhpPact/Consumer/Matcher/Exception/GeneratorRequiredException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Exception; | ||
|
||
use Exception; | ||
|
||
class GeneratorRequiredException extends Exception | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
src/PhpPact/Consumer/Matcher/Exception/InvalidHttpStatusException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Exception; | ||
|
||
use Exception; | ||
|
||
class InvalidHttpStatusException extends Exception | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
src/PhpPact/Consumer/Matcher/Exception/InvalidRegexException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Exception; | ||
|
||
use Exception; | ||
|
||
class InvalidRegexException extends Exception | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
src/PhpPact/Consumer/Matcher/Exception/InvalidUuidFormatException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Exception; | ||
|
||
use Exception; | ||
|
||
class InvalidUuidFormatException extends Exception | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
src/PhpPact/Consumer/Matcher/Exception/MatcherNotSupportedException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Exception; | ||
|
||
use Exception; | ||
|
||
class MatcherNotSupportedException extends Exception | ||
{ | ||
} |
32 changes: 32 additions & 0 deletions
32
src/PhpPact/Consumer/Matcher/Generators/AbstractDateTime.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
use PhpPact\Consumer\Matcher\Model\GeneratorInterface; | ||
|
||
abstract class AbstractDateTime implements GeneratorInterface | ||
{ | ||
public function __construct(private ?string $format = null, private ?string $expression = null) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
$data = ['pact:generator:type' => $this->getType()]; | ||
|
||
if ($this->format !== null) { | ||
$data['format'] = $this->format; | ||
} | ||
|
||
if ($this->expression !== null) { | ||
$data['expression'] = $this->expression; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
abstract protected function getType(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
/** | ||
* Generates a date value for the provided format. | ||
* If no format is provided, ISO date format is used. | ||
* If an expression is given, it will be evaluated to generate the date, otherwise 'today' will be used | ||
* | ||
* Example format: yyyy-MM-dd | ||
* Example expression: +1 day | ||
*/ | ||
class Date extends AbstractDateTime | ||
{ | ||
protected function getType(): string | ||
{ | ||
return 'Date'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
/** | ||
* Generates a datetime value for the provided format. | ||
* If no format is provided, ISO format is used. | ||
* If an expression is given, it will be evaluated to generate the datetime, otherwise 'now' will be used | ||
* | ||
* Example format: YYYY-mm-DD'T'HH:mm:ss | ||
* Example expression: +1 day | ||
*/ | ||
class DateTime extends AbstractDateTime | ||
{ | ||
protected function getType(): string | ||
{ | ||
return 'DateTime'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
use PhpPact\Consumer\Matcher\Model\GeneratorInterface; | ||
|
||
/** | ||
* Generates a URL with the mock server as the base URL. | ||
* | ||
* Example regex: .*(/path)$ | ||
* Example example: http://localhost:1234/path | ||
*/ | ||
class MockServerURL implements GeneratorInterface | ||
{ | ||
public function __construct(private string $regex, private string $example) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'regex' => $this->regex, | ||
'example' => $this->example, | ||
'pact:generator:type' => 'MockServerURL', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
use PhpPact\Consumer\Matcher\Model\GeneratorInterface; | ||
|
||
/** | ||
* Generates a value that is looked up from the provider state context using the given expression | ||
* | ||
* Example expression: /products/${id} | ||
*/ | ||
class ProviderState implements GeneratorInterface | ||
{ | ||
public function __construct(private string $expression) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'expression' => $this->expression, | ||
'pact:generator:type' => 'ProviderState', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
use PhpPact\Consumer\Matcher\Model\GeneratorInterface; | ||
|
||
/** | ||
* Generates a random boolean value | ||
*/ | ||
class RandomBoolean implements GeneratorInterface | ||
{ | ||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'pact:generator:type' => 'RandomBoolean', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
use PhpPact\Consumer\Matcher\Model\GeneratorInterface; | ||
|
||
/** | ||
* Generates a random big decimal value with the provided number of digits | ||
*/ | ||
class RandomDecimal implements GeneratorInterface | ||
{ | ||
public function __construct(private int $digits = 10) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, string|int> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'digits' => $this->digits, | ||
'pact:generator:type' => 'RandomDecimal', | ||
]; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/PhpPact/Consumer/Matcher/Generators/RandomHexadecimal.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
use PhpPact\Consumer\Matcher\Model\GeneratorInterface; | ||
|
||
/** | ||
* Generates a random hexadecimal value of the given number of digits | ||
*/ | ||
class RandomHexadecimal implements GeneratorInterface | ||
{ | ||
public function __construct(private int $digits = 10) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, string|int> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'digits' => $this->digits, | ||
'pact:generator:type' => 'RandomHexadecimal', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Generators; | ||
|
||
use PhpPact\Consumer\Matcher\Model\GeneratorInterface; | ||
|
||
/** | ||
* Generates a random integer between the min and max values (inclusive) | ||
*/ | ||
class RandomInt implements GeneratorInterface | ||
{ | ||
public function __construct(private int $min = 0, private int $max = 10) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, string|int> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'min' => $this->min, | ||
'max' => $this->max, | ||
'pact:generator:type' => 'RandomInt', | ||
]; | ||
} | ||
} |
Oops, something went wrong.