From 8ff736eb0bbffd90aa2b911dd28b78bff7c9304f Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 29 Jan 2021 12:01:01 +0100 Subject: [PATCH 1/2] add more assertions, add a mock for email sending instead of var_dumping wild stuff --- .../BasicIntegrationTest.php | 5 ++++ .../Processor/SendEmailProcessor.php | 5 ++-- .../BasicImplementation/SendEmailMock.php | 25 +++++++++++++++++++ tests/Unit/Aggregate/AggregateRootTest.php | 19 +++++++++++--- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 tests/Integration/BasicImplementation/SendEmailMock.php diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index c8282c76..f6a70eec 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -45,6 +45,7 @@ public function setUp(): void public function tearDown(): void { $this->connection->close(); + SendEmailMock::reset(); unlink(self::DB_PATH); } @@ -85,6 +86,7 @@ public function testSuccessful(): void self::assertEquals('1', $profile->aggregateRootId()); self::assertEquals(0, $profile->playhead()); + self::assertEquals(1, SendEmailMock::count()); } public function testWithSymfonySuccessful(): void @@ -123,6 +125,7 @@ public function testWithSymfonySuccessful(): void self::assertEquals('1', $profile->aggregateRootId()); self::assertEquals(0, $profile->playhead()); + self::assertEquals(1, SendEmailMock::count()); } public function testMultiTableSuccessful(): void @@ -159,6 +162,7 @@ public function testMultiTableSuccessful(): void self::assertEquals('1', $profile->aggregateRootId()); self::assertEquals(0, $profile->playhead()); + self::assertEquals(1, SendEmailMock::count()); } public function testSnapshot(): void @@ -198,5 +202,6 @@ public function testSnapshot(): void self::assertEquals('1', $profile->aggregateRootId()); self::assertEquals(0, $profile->playhead()); + self::assertEquals(1, SendEmailMock::count()); } } diff --git a/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php b/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php index 0cafbbf5..800a5045 100644 --- a/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php +++ b/tests/Integration/BasicImplementation/Processor/SendEmailProcessor.php @@ -7,8 +7,7 @@ use Patchlevel\EventSourcing\Aggregate\AggregateChanged; use Patchlevel\EventSourcing\EventBus\Listener; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Events\ProfileCreated; - -use function var_dump; +use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\SendEmailMock; final class SendEmailProcessor implements Listener { @@ -18,6 +17,6 @@ public function __invoke(AggregateChanged $event): void return; } - var_dump('send email yo'); + SendEmailMock::send(); } } diff --git a/tests/Integration/BasicImplementation/SendEmailMock.php b/tests/Integration/BasicImplementation/SendEmailMock.php new file mode 100644 index 00000000..a78dc27f --- /dev/null +++ b/tests/Integration/BasicImplementation/SendEmailMock.php @@ -0,0 +1,25 @@ +releaseEvents(); self::assertCount(1, $events); + $event = $events[0]; + self::assertEquals(0, $event->playhead()); } public function testExecuteMethod(): void @@ -45,6 +47,8 @@ public function testExecuteMethod(): void self::assertCount(1, $events); self::assertEquals(0, $profile->playhead()); + $event = $events[0]; + self::assertEquals(0, $event->playhead()); $profile->publishMessage( Message::create( @@ -61,6 +65,8 @@ public function testExecuteMethod(): void $events = $profile->releaseEvents(); self::assertCount(1, $events); + $event = $events[0]; + self::assertEquals(1, $event->playhead()); } public function testEventWithoutApplyMethod(): void @@ -70,20 +76,27 @@ public function testEventWithoutApplyMethod(): void Email::fromString('visitor@test.com') ); - self::assertCount(1, $visitorProfile->releaseEvents()); + $events = $visitorProfile->releaseEvents(); + self::assertCount(1, $events); self::assertEquals(0, $visitorProfile->playhead()); + $event = $events[0]; + self::assertEquals(0, $event->playhead()); $visitedProfile = Profile::createProfile( ProfileId::fromString('2'), Email::fromString('visited@test.com') ); - self::assertCount(1, $visitedProfile->releaseEvents()); + $events = $visitedProfile->releaseEvents(); + self::assertCount(1, $events); self::assertEquals(0, $visitedProfile->playhead()); + $event = $events[0]; + self::assertEquals(0, $event->playhead()); $visitorProfile->visitProfile($visitedProfile->id()); - self::assertCount(0, $visitedProfile->releaseEvents()); + $events = $visitedProfile->releaseEvents(); + self::assertCount(0, $events); self::assertEquals(0, $visitedProfile->playhead()); } From 4c14d26708367a173f94f327673cdbd521002eef Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 29 Jan 2021 12:20:20 +0100 Subject: [PATCH 2/2] increase msi, add log into file --- .gitignore | 1 + infection.json.dist | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7983535e..6e280077 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ phpunit.xml .phpunit.result.cache .phpcs-cache phpstan.neon +infection.log diff --git a/infection.json.dist b/infection.json.dist index b3d93d93..90b01582 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -5,7 +5,7 @@ ] }, "logs": { - "text": "php:\/\/stderr", + "text": "infection.log", "badge": { "branch": "master" } @@ -13,6 +13,6 @@ "mutators": { "@default": true }, - "minMsi": 40, - "minCoveredMsi": 40 + "minMsi": 52, + "minCoveredMsi": 76 }