Exemplo n.º 1
0
 /**
  * @param string $aggregateClassName
  *
  * @return string
  */
 protected function streamName($aggregateClassName)
 {
     return NameResolver::resolve($aggregateClassName);
 }
Exemplo n.º 2
0
 /**
  * Test Resolve method.
  */
 public function testResolve()
 {
     $this->given($className = PostEventSourced::class)->when($result = NameResolver::resolve($className))->then()->string($result)->isEqualTo('post_event_sourced');
     $this->given($className = 'FooDocument')->when($result = NameResolver::resolve($className))->then()->string($result)->isEqualTo('foo_document');
 }
 /**
  * Test Get method.
  */
 public function testGet()
 {
     $this->given($store = new InMemorySnapshotStore())->and($repository = $this->createRepository($store))->and($post = PostEventSourcedFactory::create($this->faker->sentence, $this->faker->paragraph))->and($version = new Version(0, 0, 231))->and($post->setVersion($version))->and($post->changeTitle($this->faker->sentence))->and($snapshot = new Snapshot(NameResolver::resolve(get_class($post)), $post, new \DateTime()))->and($applicationVersion = Version::fromString('0.0.0'))->when($repository->persist($post))->and($store->persist($snapshot, $applicationVersion))->then()->object($repository->get($post->id()))->isEqualTo($post);
 }
 /**
  * Test ShouldCreateSnapshot method.
  */
 public function testShouldCreateSnapshot()
 {
     $this->given($snapshotStore = new InMemorySnapshotStore())->and($policy = new TimeBasedSnapshottingPolicy($snapshotStore, PostEventSourced::class, '1 hour'))->and($post = PostEventSourcedFactory::create($this->faker->sentence, $this->faker->paragraph))->and($createdAt = date_create()->modify('-2 hours'))->and($snapshot = new Snapshot(NameResolver::resolve(get_class($post)), $post, $createdAt))->and($applicationVersion = Version::fromString('0.0.0'))->and($snapshotStore->persist($snapshot, $applicationVersion))->then()->boolean($policy->shouldCreateSnapshot($post))->isTrue()->and()->when($post->clearEvents())->then()->boolean($policy->shouldCreateSnapshot($post))->isFalse();
     $this->given($snapshotStore = new InMemorySnapshotStore())->and($policy = new TimeBasedSnapshottingPolicy($snapshotStore, PostEventSourced::class, '1 hour'))->and($post = PostEventSourcedFactory::create($this->faker->sentence, $this->faker->paragraph))->and($createdAt = new \DateTime())->and($snapshot = new Snapshot(NameResolver::resolve(get_class($post)), $post, $createdAt))->and($applicationVersion = Version::fromString('0.1.0'))->and($snapshotStore->persist($snapshot, $applicationVersion))->then()->boolean($policy->shouldCreateSnapshot($post))->isFalse();
 }