/** @test */ function it_should_update_the_information_of_a_registered_member() { $member = $this->members->with(Identifier::fromString('wxyz')); $member->transfer(Money::MXN(500), $this->existingMember); $this->members->update($this->existingMember); $this->assertBalanceAmounts(3500, $this->existingMember, "Current member balance should be 3500"); }
/** * @param string $fromMemberId * @param string $amount * @param string $toMemberId * @param string $occurredOn */ public function __construct($fromMemberId, $amount, $toMemberId, $occurredOn) { $this->occurredOn = DateTime::createFromFormat('Y-m-d H:i:s', $occurredOn); $this->fromMemberId = Identifier::fromString($fromMemberId); $this->amount = Money::MXN($amount); $this->toMemberId = Identifier::fromString($toMemberId); }
/** @test */ function it_should_serialize_a_domain_event_to_json() { $serializer = new JsonSerializer(); $anEvent = new InstantaneousEvent(Identifier::fromString('abc'), Money::MXN(10000), new DateTime('2015-10-24 12:39:51')); $json = $serializer->serialize($anEvent); $this->assertEquals('{"occurred_on":"2015-10-24 12:39:51","member_id":"abc","amount":10000}', $json, 'JSON format for serialized event is incorrect'); }
/** * @param string $fromMemberId * @return array */ public function getMembersWhiteList($fromMemberId) { $memberId = Identifier::any(); if (!is_null($fromMemberId)) { $memberId = Identifier::fromString($fromMemberId); } return array_keys($this->getMembersChoicesExcluding($memberId)); }
/** @test */ function it_should_show_transfer_funds_form() { $responder = Mockery::mock(TransferFundsWebResponder::class); $responder->shouldReceive('respondEnterTransferInformation')->once(); $responder->shouldReceive('response')->once()->andReturn(new Response()); $controller = new TransferFundsAction($responder); $response = $controller->showForm(Identifier::any()); $this->assertEquals(200, $response->getStatusCode()); }
/** @test */ function it_should_generate_options_excluding_the_member_transferring_funds() { Fixtures::load(__DIR__ . '/../../../../_data/fixtures/members.yml', $this->entityManager); /** @var MembersRepository $members */ $members = $this->entityManager->getRepository(Member::class); $configuration = new MembersConfiguration($members); $options = $configuration->getMembersChoicesExcluding(Identifier::fromString('ABC')); $this->assertCount(2, $options); $this->assertArrayNotHasKey('ABC', $options); }
/** @test */ function it_should_create_an_stored_event_from_a_given_domain_event() { $event = new InstantaneousEvent(Identifier::fromString('abc'), Money::MXN(500000), new DateTime('2015-10-25 19:59:00')); $factory = new StoredEventFactory(new JsonSerializer()); $storedEvent = $factory->from($event); // Stored events get an ID after being persisted $this->assertEquals(null, $storedEvent->id()); $this->assertEquals('{"occurred_on":"2015-10-25 19:59:00","member_id":"abc","amount":500000}', $storedEvent->body()); $this->assertEquals(InstantaneousEvent::class, $storedEvent->type()); $this->assertEquals('2015-10-25 19:59:00', $storedEvent->occurredOn()->format('Y-m-d H:i:s')); }
/** @test */ function it_should_exclude_from_choices_the_member_making_the_transfer() { $form = new TransferFundsForm(); $fromMemberId = Identifier::fromString('abc'); $configuration = Mockery::mock(MembersConfiguration::class); $configuration->shouldReceive('getMembersChoicesExcluding')->once()->with($fromMemberId)->andReturn(['lmn' => null, 'xyz' => null]); $form->configure($configuration, $fromMemberId); $view = $form->buildView(); $this->assertCount(2, $view->toMemberId->choices); $this->assertArrayNotHasKey('abc', $view->toMemberId->choices); }
/** * @param string|null $value * @param AbstractPlatform $platform * @throws ConversionException * @return Identifier|null */ public function convertToPHPValue($value, AbstractPlatform $platform) { if (empty($value)) { return null; } try { $uuid = Identifier::fromString($value); } catch (InvalidArgumentException $e) { throw ConversionException::conversionFailed($value, self::NAME); } return $uuid; }
/** @test */ function it_should_build_a_response_to_show_the_transfer_form() { $configuration = Mockery::mock(MembersConfiguration::class); $form = Mockery::mock(TransferFundsForm::class); $form->shouldReceive('buildView')->once(); $form->shouldReceive('configure')->once()->with($configuration, Mockery::type(Identifier::class)); $view = Mockery::mock(TemplateEngine::class); $view->shouldReceive('render')->once()->with(Mockery::type('string'), Mockery::type('array'))->andReturn(''); $responder = new TransferFundsFormResponder($view, new DiactorosResponseFactory(), $form, $configuration); $responder->respondEnterTransferInformation(Identifier::fromString('abc')); $this->assertEquals(200, $responder->response()->getStatusCode()); }
/** * @param Slim $app * @param Resolver $resolver */ public function register(Slim $app, Resolver $resolver) { $app->get('/', function () use($app) { $app->redirectTo('transfer_form'); }); $app->get('/transfer-form', $resolver->resolve($app, 'ewallet.transfer_form_controller:showForm', function () { return [Identifier::fromString('ABC')]; }))->name('transfer_form'); $app->post('/transfer-funds', $resolver->resolve($app, 'ewallet.transfer_funds_controller:transfer', function () use($app) { /** @var \EwalletModule\Bridges\Zf2\InputFilter\TransferFundsInputFilterRequest $request */ $request = $app->container->get('ewallet.transfer_filter_request'); $request->populate($app->request->post()); return [$request]; }))->name('transfer_funds'); }
/** * @param array $filteredInput */ private function __construct(array $filteredInput) { $this->fromMemberId = Identifier::fromString($filteredInput['fromMemberId']); $this->toMemberId = Identifier::fromString($filteredInput['toMemberId']); $this->amount = Money::MXN((int) ($filteredInput['amount'] * 100)); }
/** * @return Member */ public function build() { $member = Member::withAccountBalance(Identifier::fromString($this->id), $this->name, new Email($this->email), $this->amount); $this->reset(); return $member; }
/** @test */ function it_should_subscribe_to_all_event_types() { $subscriber = new PersistEventsSubscriber(Mockery::mock(EventStore::class), Mockery::mock(StoredEventFactory::class)); $this->assertTrue($subscriber->isSubscribedTo(new InstantaneousEvent(Identifier::any(), Money::MXN(100000), new DateTime('now')))); $this->assertTrue($subscriber->isSubscribedTo(A::transferWasMadeEvent()->build())); }
/** * @param array $messages * @param array $values * @param string $fromMemberId * @return \Psr\Http\Message\ResponseInterface */ public function respondInvalidTransferInput(array $messages, array $values, $fromMemberId) { $this->form->submit($values); $this->form->setErrorMessages($messages); $this->respondEnterTransferInformation(Identifier::fromString($fromMemberId)); }
function it_should_not_allow_an_empty_name() { $this->beConstructedThrough('withAccountBalance', [Identifier::fromString(self::A_VALID_ID), '', new Email(self::A_VALID_EMAIL), Money::MXN(self::A_VALID_AMOUNT)]); $this->shouldThrow(InvalidArgumentException::class)->duringInstantiation(); }
/** * @return TransferWasMade */ public function build() { $event = new TransferWasMade(Identifier::fromString($this->fromId), Money::MXN($this->amount), Identifier::fromString($this->toId)); $this->reset(); return $event; }
/** * @param Member $member * @return bool */ public function equals(Member $member) { return $this->memberId->equals($member->memberId); }
function it_should_know_when_it_is_equal_to_another_id() { $this->beConstructedThrough('fromString', ['abcd']); $this->equals(Identifier::fromString('abcd'))->shouldBe(true); }
/** * @Then my friend's balance should be :amount MXN */ public function myFriendSBalanceShouldBeMxn($amount) { $forMyFriend = $this->members->with(Identifier::fromString('xyz')); $this->membersHelper->assertBalanceIs($amount, $forMyFriend); }