diff --git a/.gitignore b/.gitignore index 5965d92..8886f97 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock .idea .php-cs-fixer.cache +.phpunit.cache diff --git a/composer.json b/composer.json index 8628af7..1172189 100644 --- a/composer.json +++ b/composer.json @@ -8,10 +8,11 @@ "php": "^8.2" }, "require-dev": { - "phpunit/phpunit": "^8.0 || ^9.0", + "phpunit/phpunit": "^11.5", "broadway/coding-standard": "^1.2", "phpstan/phpstan": "^2.0", - "phpspec/prophecy": "^1.15" + "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.2" }, "authors": [ { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c5804e5..f32fa41 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,18 @@ - - - - - ./test/ - - - - - ./src/ - - - - - functional - - + + + + ./test/ + + + + + functional + + + + + ./src/ + + diff --git a/test/EventSourcing/SnapshottingEventSourcingRepositoryTest.php b/test/EventSourcing/SnapshottingEventSourcingRepositoryTest.php index b60e73a..0b40e6d 100644 --- a/test/EventSourcing/SnapshottingEventSourcingRepositoryTest.php +++ b/test/EventSourcing/SnapshottingEventSourcingRepositoryTest.php @@ -24,10 +24,14 @@ use Broadway\Snapshotting\Snapshot\SnapshotRepository; use Broadway\Snapshotting\Snapshot\Snapshotter; use Broadway\Snapshotting\Snapshot\Trigger\EventCountTrigger; +use PHPUnit\Framework\Attributes\Test; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; class SnapshottingEventSourcingRepositoryTest extends \PHPUnit\Framework\TestCase { + use ProphecyTrait; + private $eventStore; private $eventSourcingRepository; private $snapshotRepository; @@ -50,9 +54,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function it_reconstitutes_aggregate_when_no_snapshot_found() { $this->snapshotRepository @@ -70,9 +72,7 @@ public function it_reconstitutes_aggregate_when_no_snapshot_found() $this->snapshottingEventSourcingRepository->load(42); } - /** - * @test - */ + #[Test] public function it_queries_the_event_store_for_events_recorded_after_playhead_of_snapshot() { // create a snapshot of an aggregate root with 5 committed events @@ -106,9 +106,7 @@ public function it_queries_the_event_store_for_events_recorded_after_playhead_of $this->assertEquals(6, $aggregateRoot->getPlayhead()); } - /** - * @test - */ + #[Test] public function it_does_not_take_a_snapshot_when_threshold_not_reached() { $aggregateRoot = $this->createAggregateRootWithEvents(99); @@ -121,9 +119,7 @@ public function it_does_not_take_a_snapshot_when_threshold_not_reached() $this->snapshottingEventSourcingRepository->save($aggregateRoot); } - /** - * @test - */ + #[Test] public function it_takes_a_snapshot_when_threshold_reached() { $aggregateRoot = $this->createAggregateRootWithEvents(100); diff --git a/test/Snapshot/InMemorySnapshotRepositoryTest.php b/test/Snapshot/InMemorySnapshotRepositoryTest.php index 54f9618..3ca9778 100644 --- a/test/Snapshot/InMemorySnapshotRepositoryTest.php +++ b/test/Snapshot/InMemorySnapshotRepositoryTest.php @@ -12,7 +12,7 @@ namespace Broadway\Snapshotting\Snapshot; -class InMemorySnapshotRepositoryTest extends SnapshotRepositoryTest +class InMemorySnapshotRepositoryTest extends SnapshotRepositoryTestCase { /** * @return SnapshotRepository diff --git a/test/Snapshot/SnapshotRepositoryTest.php b/test/Snapshot/SnapshotRepositoryTestCase.php similarity index 93% rename from test/Snapshot/SnapshotRepositoryTest.php rename to test/Snapshot/SnapshotRepositoryTestCase.php index 368c510..6e8fe43 100644 --- a/test/Snapshot/SnapshotRepositoryTest.php +++ b/test/Snapshot/SnapshotRepositoryTestCase.php @@ -13,33 +13,28 @@ namespace Broadway\Snapshotting\Snapshot; use Broadway\EventSourcing\EventSourcedAggregateRoot; +use PHPUnit\Framework\Attributes\Test; -abstract class SnapshotRepositoryTest extends \PHPUnit\Framework\TestCase +abstract class SnapshotRepositoryTestCase extends \PHPUnit\Framework\TestCase { /** * @var SnapshotRepository */ protected $repository; - /** - * @test - */ + #[Test] public function it_implements__snapshot_repository() { $this->assertInstanceOf(SnapshotRepository::class, $this->repository); } - /** - * @test - */ + #[Test] public function it_returns_null_when_no_snapshot_available() { $this->assertNull($this->repository->load(42)); } - /** - * @test - */ + #[Test] public function it_returns_snapshot_when_available() { $aggregate = $this->createAggregateWithHistory(5); @@ -51,9 +46,7 @@ public function it_returns_snapshot_when_available() ); } - /** - * @test - */ + #[Test] public function it_does_not_mutate_state_of__snapshot__aggregate_after_persisting() { $aggregate = $this->createAggregateWithHistory(5); @@ -67,9 +60,7 @@ public function it_does_not_mutate_state_of__snapshot__aggregate_after_persistin $this->assertEquals(new Snapshot($this->createAggregateWithHistory(5)), $snapshot); } - /** - * @test - */ + #[Test] public function it_does_not_mutate_state_of__snapshot__aggregate_after_loading() { $aggregate = $this->createAggregateWithHistory(5); diff --git a/test/Snapshot/Snapshotter/CommandDispatchingSnapshotterTest.php b/test/Snapshot/Snapshotter/CommandDispatchingSnapshotterTest.php index 6248205..c986d7f 100644 --- a/test/Snapshot/Snapshotter/CommandDispatchingSnapshotterTest.php +++ b/test/Snapshot/Snapshotter/CommandDispatchingSnapshotterTest.php @@ -15,9 +15,13 @@ use Broadway\CommandHandling\CommandBus; use Broadway\EventSourcing\EventSourcedAggregateRoot; use Broadway\Snapshotting\Snapshot\Command\ScheduleSnapshot; +use PHPUnit\Framework\Attributes\Test; +use Prophecy\PhpUnit\ProphecyTrait; class CommandDispatchingSnapshotterTest extends \PHPUnit\Framework\TestCase { + use ProphecyTrait; + /** * @var CommandBus */ @@ -28,9 +32,7 @@ class CommandDispatchingSnapshotterTest extends \PHPUnit\Framework\TestCase */ private $snapshotter; - /** - * @test - */ + #[Test] public function it_dispatches__schedule_snapshot_command() { $this->commandBus diff --git a/test/Snapshot/Snapshotter/SynchronousSnapshotterTest.php b/test/Snapshot/Snapshotter/SynchronousSnapshotterTest.php index 58d5a97..613da00 100644 --- a/test/Snapshot/Snapshotter/SynchronousSnapshotterTest.php +++ b/test/Snapshot/Snapshotter/SynchronousSnapshotterTest.php @@ -15,9 +15,13 @@ use Broadway\EventSourcing\EventSourcedAggregateRoot; use Broadway\Snapshotting\Snapshot\Snapshot; use Broadway\Snapshotting\Snapshot\SnapshotRepository; +use PHPUnit\Framework\Attributes\Test; +use Prophecy\PhpUnit\ProphecyTrait; class SynchronousSnapshotterTest extends \PHPUnit\Framework\TestCase { + use ProphecyTrait; + /** * @var SnapshotRepository */ @@ -28,9 +32,7 @@ class SynchronousSnapshotterTest extends \PHPUnit\Framework\TestCase */ private $snapshotter; - /** - * @test - */ + #[Test] public function it_persists_directly_to__snapshot_repository() { $aggregate = new MyAggregate(); diff --git a/test/Snapshot/Trigger/EventCountTriggerTest.php b/test/Snapshot/Trigger/EventCountTriggerTest.php index 8309e0b..4f0c42e 100644 --- a/test/Snapshot/Trigger/EventCountTriggerTest.php +++ b/test/Snapshot/Trigger/EventCountTriggerTest.php @@ -14,12 +14,11 @@ namespace Broadway\Snapshotting\Snapshot\Trigger; use Broadway\Snapshotting\EventSourcing\Testing\TestEventSourcedAggregateRoot; +use PHPUnit\Framework\Attributes\Test; class EventCountTriggerTest extends \PHPUnit\Framework\TestCase { - /** - * @test - */ + #[Test] public function it_should_snapshot_when_number_of_uncommitted_events_exceeds_given_event_count() { $trigger = new EventCountTrigger(1);