/** @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'); }
/** @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 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'); }
/** @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')); }
protected function reset() { $this->name = $this->faker->name; $this->email = $this->faker->email; $this->amount = Money::MXN($this->faker->numberBetween(0, 10000)); $this->id = $this->faker->uuid; }
/** @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())); }
function it_should_not_allow_withdrawing_more_than_the_current_balance() { $this->beConstructedThrough('withBalance', [Money::MXN(3000)]); $this->shouldThrow(InsufficientFunds::class)->duringWithdraw(Money::MXN(3500)); }
/** @test */ function it_should_format_a_money_object_information() { $this->assertEquals('$5,987.29 MXN', $this->formatter->formatMoney(Money::MXN(598729))); }
/** * @return TransferWasMade */ public function build() { $event = new TransferWasMade(Identifier::fromString($this->fromId), Money::MXN($this->amount), Identifier::fromString($this->toId)); $this->reset(); return $event; }
function it_should_record_that_a_transfer_was_made() { $this->transfer(Money::MXN(500), A::member()->build()); $this->events()->count()->shouldBe(1); }
/** * @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)); }
/** * @param integer $lowerLimit * @return AmountLowerThanConstraint */ public static function isBalanceAmountGreaterThan($lowerLimit) { return new AmountGreaterThanConstraint(Money::MXN((int) $lowerLimit)); }
/** @test */ function it_should_delegate_formatting_a_money_object() { $this->extension->formatMoney($amount = Money::MXN(300000)); $this->formatter->shouldHaveReceived('formatMoney')->once()->with($amount); }
/** * @Transform :amount */ public function transformStringToMoney($amount) { return Money::MXN((int) $amount * 100); }