コード例 #1
0
 /** @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");
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
 /** @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');
 }
コード例 #4
0
 /**
  * @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));
 }
コード例 #5
0
 /** @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());
 }
コード例 #6
0
 /** @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);
 }
コード例 #7
0
 /** @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'));
 }
コード例 #8
0
 /** @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);
 }
コード例 #9
0
ファイル: UuidType.php プロジェクト: zoek1/php-testing-tools
 /**
  * @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;
 }
コード例 #10
0
 /** @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());
 }
コード例 #11
0
 /**
  * @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');
 }
コード例 #12
0
 /**
  * @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));
 }
コード例 #13
0
 /**
  * @return Member
  */
 public function build()
 {
     $member = Member::withAccountBalance(Identifier::fromString($this->id), $this->name, new Email($this->email), $this->amount);
     $this->reset();
     return $member;
 }
コード例 #14
0
 /** @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()));
 }
コード例 #15
0
 /**
  * @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));
 }
コード例 #16
0
 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();
 }
コード例 #17
0
 /**
  * @return TransferWasMade
  */
 public function build()
 {
     $event = new TransferWasMade(Identifier::fromString($this->fromId), Money::MXN($this->amount), Identifier::fromString($this->toId));
     $this->reset();
     return $event;
 }
コード例 #18
0
ファイル: Member.php プロジェクト: zoek1/php-testing-tools
 /**
  * @param Member $member
  * @return bool
  */
 public function equals(Member $member)
 {
     return $this->memberId->equals($member->memberId);
 }
コード例 #19
0
 function it_should_know_when_it_is_equal_to_another_id()
 {
     $this->beConstructedThrough('fromString', ['abcd']);
     $this->equals(Identifier::fromString('abcd'))->shouldBe(true);
 }
コード例 #20
0
 /**
  * @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);
 }