-
Notifications
You must be signed in to change notification settings - Fork 92
/
ExampleMessageConsumerTest.php
65 lines (52 loc) · 1.83 KB
/
ExampleMessageConsumerTest.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace MessageConsumer\Tests;
use Exception;
use MessageConsumer\ExampleMessageConsumer;
use PhpPact\Consumer\MessageBuilder;
use PhpPact\Config\PactConfigInterface;
use PhpPact\Consumer\Matcher\Matcher;
use PhpPact\Standalone\PactMessage\PactMessageConfig;
use PHPUnit\Framework\TestCase;
use stdClass;
class ExampleMessageConsumerTest extends TestCase
{
private static PactConfigInterface $config;
private Matcher $matcher;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::$config = (new PactMessageConfig())
->setConsumer('messageConsumer')
->setProvider('messageProvider')
->setPactDir(__DIR__.'/../../pacts');
if ($logLevel = \getenv('PACT_LOGLEVEL')) {
self::$config->setLogLevel($logLevel);
}
}
public function setUp(): void
{
$this->matcher = new Matcher();
}
/**
* @throws Exception
*/
public function testProcessText()
{
$builder = new MessageBuilder(self::$config);
$contents = new stdClass();
$contents->text = 'Hello Mary';
$contents->number = $this->matcher->integerV3();
$metadata = ['queue' => 'wind cries', 'routing_key' => $this->matcher->string()];
$builder
->given('a message', ['foo' => 'bar'])
->expectsToReceive('an alligator named Mary exists')
->withMetadata($metadata)
->withContent($contents);
// established mechanism to this via callbacks
$consumerMessage = new ExampleMessageConsumer();
$callback = [$consumerMessage, 'processMessage'];
$builder->setCallback($callback);
$verifyResult = $builder->verify();
$this->assertTrue($verifyResult);
}
}