/** @test */ function it_should_persist_an_event() { $store = Mockery::mock(EventStore::class); $subscriber = new PersistEventsSubscriber($store, new StoredEventFactory(new JsonSerializer())); $store->shouldReceive('append')->once()->with(Mockery::type(StoredEvent::class)); $subscriber->handle(A::transferWasMadeEvent()->build()); }
/** @before */ function generateFixtures() { $this->members = $this->membersInstance(); $this->existingMember = A::member()->withId('abcd')->withBalance(3000)->build(); $this->members->add(A::member()->withId('wxyz')->withBalance(1000)->build()); $this->members->add($this->existingMember); $this->members->add(A::member()->withId('hijk')->build()); }
/** @test */ function beneficiary_balance_should_increase_after_funds_have_been_transferred() { $this->forAll(Generator\int(1, 10000))->then(function ($amount) { $fromMember = A::member()->withBalance(10000)->build(); $toMember = A::member()->withBalance(5000)->build(); $fromMember->transfer(Money::MXN($amount), $toMember); $this->assertBalanceIsGreaterThan(5000, $toMember, "Transferring {$amount} increased balance of receiver member"); }); }
/** @test */ function it_should_send_deposit_received_email() { $template = Mockery::mock(TemplateEngine::class); $template->shouldReceive('render')->once()->with(Mockery::type('string'), Mockery::type('array')); $transport = new InMemory(); $sender = new TransferFundsZendMailSender($template, $transport); $sender->sendDepositReceivedEmail(A::member()->build()->information(), A::member()->withEmail('*****@*****.**')->build()->information(), Money::MXN(500), new DateTime()); $this->assertEquals('*****@*****.**', $transport->getLastMessage()->getTo()->current()->getEmail(), 'Address doesn\'t belong to the member receiving the deposit'); $this->assertRegExp('/received.*deposit/', $transport->getLastMessage()->getSubject(), 'Email\'s subject is wrong'); }
function it_should_transfer_funds_between_accounts(Members $members, TransferFundsNotifier $notifier) { $fromMember = A::member()->withBalance(2000)->build(); $toMember = A::member()->withBalance(1000)->build(); $members->with($fromMember->information()->id())->willReturn($fromMember); $members->with($toMember->information()->id())->willReturn($toMember); $members->update($fromMember)->shouldBeCalled(); $members->update($toMember)->shouldBeCalled(); $this->beConstructedWith($members); $this->attach($notifier); $this->transfer(TransferFundsRequest::from(['fromMemberId' => (string) $fromMember->information()->id(), 'toMemberId' => (string) $toMember->information()->id(), 'amount' => 5])); $notifier->transferCompleted(Argument::type(TransferFundsResponse::class))->shouldHaveBeenCalled(); }
/** @before */ function generateFixtures() { $this->store = $this->storeInstance(); $factory = new StoredEventFactory(new JsonSerializer()); $event1 = $factory->from(A::transferWasMadeEvent()->build()); $this->event2 = $factory->from(A::transferWasMadeEvent()->build()); $event3 = $factory->from(A::transferWasMadeEvent()->build()); $this->event4 = $factory->from(A::transferWasMadeEvent()->build()); $this->store->append($event1); $this->store->append($this->event2); $this->store->append($event3); $this->store->append($this->event4); }
/** @test */ function it_should_build_a_response_to_show_that_a_transfer_was_successful() { $configuration = Mockery::mock(MembersConfiguration::class); $form = Mockery::mock(TransferFundsForm::class); $form->shouldReceive('configure')->once()->with($configuration, Mockery::type(Identifier::class)); $form->shouldReceive('buildView')->once(); $view = Mockery::mock(TemplateEngine::class); $view->shouldReceive('render')->once()->with(Mockery::type('string'), Mockery::type('array'))->andReturn(''); $result = new TransferFundsResponse(A::member()->build(), A::member()->build()); $responder = new TransferFundsFormResponder($view, new DiactorosResponseFactory(), $form, $configuration); $responder->respondTransferCompleted($result); $this->assertEquals(200, $responder->response()->getStatusCode()); }
/** @test */ function it_should_update_last_published_message_when_publisher_fails_before_last_one() { $nonEmptyExchangeName = 'non_empty_exchange_name'; $severalMessages = [A::storedEvent()->withId(12000)->build(), A::storedEvent()->withId(11000)->build(), A::storedEvent()->build()]; $store = $this->givenAStoreWith($severalMessages); $tracker = $this->givenANonEmptyExchange($nonEmptyExchangeName); $message = A::publishedMessage()->withExchangeName($nonEmptyExchangeName)->build(); $this->givenMostRecentPublishedMessageIs($tracker, $message, $nonEmptyExchangeName); $this->expectToTrackUpdatedMessage($tracker, $message); $producer = new MessageProducerThatThrowsException(); $publisher = new MessagePublisher($store, $tracker, $producer); $messages = $publisher->publishTo($nonEmptyExchangeName); $this->assertEquals(1, $messages, 'Should have processed only 1 message'); $this->assertEquals(12000, $message->mostRecentMessageId(), 'Most recent message ID should be 12000'); }
/** @test */ function it_should_transfer_funds_from_one_member_to_another() { $responder = Mockery::mock(TransferFundsWebResponder::class); $responder->shouldReceive('respondTransferCompleted')->once()->with(Mockery::type(TransferFundsResponse::class)); $responder->shouldReceive('response')->once()->andReturn(new Response()); $members = new InMemoryMembers(); $members->add(A::member()->withId('abc')->withBalance(20000)->build()); $members->add(A::member()->withId('xyz')->build()); $useCase = new TransferFunds($members); $request = Mockery::mock(FilteredRequest::class); $request->shouldReceive('isValid')->once()->andReturn(true); $request->shouldReceive('values')->once()->andReturn(['fromMemberId' => 'abc', 'toMemberId' => 'xyz', 'amount' => 100]); $controller = new TransferFundsAction($responder, $useCase); $response = $controller->transfer($request); $this->assertEquals(200, $response->getStatusCode()); }
/** @test */ function it_should_persist_an_event_published_inside_an_slim_route() { /** @var \Hexagonal\Bridges\Doctrine2\DomainEvents\EventStoreRepository $store */ $store = $this->entityManager->getRepository(StoredEvent::class); $publisher = new EventPublisher(); $middleware = new StoreEventsMiddleware(new PersistEventsSubscriber($store, new StoredEventFactory(new JsonSerializer())), $publisher); $app = new Slim(); $app->get('/', function () use($publisher) { $events = new SplObjectStorage(); $events->attach(A::transferWasMadeEvent()->build()); $publisher->publish($events); }); $app->add($middleware); Environment::mock(['REQUEST_METHOD' => 'GET']); $app->run(); $this->assertCount(1, $store->allEvents()); }
/** * @Given my friend has an account balance of :amount MXN */ public function myFriendHasAnAccountBalanceOfMxn($amount) { $myFriend = A::member()->withId('xyz')->withBalance($amount)->build(); $this->members->add($myFriend); }
/** @test */ function it_should_format_a_member_information() { $aMember = A::member()->withName('Mario Montealegre')->withBalance(1500025)->build(); $this->assertEquals('Mario Montealegre $15,000.25 MXN', $this->formatter->formatMember($aMember->information())); }
function it_should_know_when_another_member_is_not_equal_to_it() { $aDifferentMember = A::member()->withId('xyz')->build(); $this->equals($aDifferentMember)->shouldBe(false); }
function it_should_delegate_formatting_a_member() { $member = A::member()->build()->information(); $this->extension->formatMember($member); $this->formatter->shouldHaveReceived('formatMember')->once()->with($member); }