/**
  * Test Remove method.
  */
 public function testRemove()
 {
     $this->given($repository = $this->createRepository())->and($post = PostEventSourcedFactory::create($this->faker->sentence, $this->faker->paragraph))->and($post->changeTitle($this->faker->sentence))->when($repository->persist($post))->then()->object($repository->get($post->id()))->isEqualTo($post)->and()->when($repository->remove($post))->then()->exception(function () use($repository, $post) {
         $repository->get($post->id());
     })->isInstanceOf(\RuntimeException::class);
     $this->given($repository = $this->createRepository())->and($post = new Post(PostId::fromNative(md5(rand())), $this->faker->sentence, $this->faker->paragraph))->then()->exception(function () use($repository, $post) {
         $repository->remove($post);
     })->isInstanceOf(\InvalidArgumentException::class);
     $this->given($repository = $this->createRepository())->and($post = PostEventSourcedFactory::create($this->faker->sentence, $this->faker->paragraph))->and($repository->persist($post))->and($preRemoveSubscriber = new PreRemoveSubscriber(42))->and($postRemoveSubscriber = new PostRemoveSubscriber())->and(DomainEventPublisher::subscribe($preRemoveSubscriber))->and(DomainEventPublisher::subscribe($postRemoveSubscriber))->when($repository->remove($post))->then()->integer($post->version()->patch())->isEqualTo(21);
 }
 /**
  * Test set method.
  */
 public function testSet()
 {
     $this->given($incrementEvent = new IncrementCounterEvent(5))->and($decrementEvent = new DecrementCounterEvent(3))->and($counterSubscriber = new CounterEventSubscriber())->and(DomainEventPublisher::set(EventBus::create()))->and(DomainEventPublisher::subscribe($counterSubscriber))->when(DomainEventPublisher::publish($incrementEvent))->then()->integer($counterSubscriber->counter())->isEqualTo(5)->when(DomainEventPublisher::publish($incrementEvent))->then()->integer($counterSubscriber->counter())->isEqualTo(10)->when(DomainEventPublisher::publish($decrementEvent))->then()->integer($counterSubscriber->counter())->isEqualTo(7);
 }