|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* This file is part of the Aggrego. |
|
5
|
|
|
* (c) Tomasz Kunicki <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types = 1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Aggrego\DomainEventProducer\EventConsumer; |
|
15
|
|
|
|
|
16
|
|
|
use Aggrego\DomainEventProducer\Domain\Repository; |
|
17
|
|
|
use Aggrego\DomainEventProducer\EventConsumer\Producer; |
|
18
|
|
|
use Aggrego\EventConsumer\Client; |
|
19
|
|
|
use Aggrego\EventConsumer\Event\CreatedAt; |
|
20
|
|
|
use Aggrego\EventConsumer\Event\Domain; |
|
21
|
|
|
use Aggrego\EventConsumer\Event\Name; |
|
22
|
|
|
use Aggrego\EventConsumer\Event\Version; |
|
23
|
|
|
use Aggrego\EventConsumer\Shared\Event; |
|
24
|
|
|
use Aggrego\EventConsumer\Shared\Events; |
|
25
|
|
|
use DateTimeImmutable; |
|
26
|
|
|
use PhpSpec\ObjectBehavior; |
|
27
|
|
|
use Prophecy\Argument; |
|
28
|
|
|
|
|
29
|
|
|
class ProducerSpec extends ObjectBehavior |
|
30
|
|
|
{ |
|
31
|
|
|
function let(Repository $repository, Client $client) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$this->beConstructedWith($repository, $client); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_is_initializable() |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldHaveType(Producer::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_should_publish_events(Repository $repository, Client $client) |
|
42
|
|
|
{ |
|
43
|
|
|
$events = new Events(); |
|
44
|
|
|
$events->add( |
|
45
|
|
|
new Event( |
|
46
|
|
|
Domain::fromString('Test:7835a2f1-65c4-4e05-aacf-2e9ed950f5f2'), |
|
47
|
|
|
new Name('test'), |
|
48
|
|
|
new CreatedAt(new DateTimeImmutable()), |
|
49
|
|
|
new Version('1.0.0.0'), |
|
50
|
|
|
[] |
|
51
|
|
|
) |
|
52
|
|
|
); |
|
53
|
|
|
$repository->pullEvents()->willReturn($events); |
|
|
|
|
|
|
54
|
|
|
$client->consume(Argument::type(Event::class))->shouldBeCalled(); |
|
|
|
|
|
|
55
|
|
|
$this->beConstructedWith($repository, $client); |
|
56
|
|
|
|
|
57
|
|
|
$this->publish()->shouldReturn(null); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.