예제 #1
0
 function it_emits_money_transfer_requested(EventDispatcherInterface $dispatcher)
 {
     $dispatcher->dispatch(MoneyTransferRequestedEnvelope::getEventName(), Argument::type(MoneyTransferRequestedEnvelope::class))->shouldBeCalled();
     $events = new EventCollection([new MoneyTransferRequestedEvent(AccountNumber::fromString('123ABC'), new Transfer(Transaction::fromString('000'), AccountNumber::fromString('456DEF'), 100))]);
     $this->beConstructedWith($dispatcher);
     $this->emit($events);
 }
예제 #2
0
 public function handle(TransferCommand $command)
 {
     $account = $this->accounting->getAccount(AccountNumber::fromString($command->getSourceAccountNumber()));
     $transfer = new Transfer(Transaction::generate(), AccountNumber::fromString($command->getTargetAccountNumber()), $command->getAmount());
     $account->transfer($transfer);
     $this->accounting->commit();
 }
예제 #3
0
 public function handle(TransferDepositCommand $command)
 {
     $account = $this->accounting->getAccount(AccountNumber::fromString($command->getAccountNumber()));
     $deposit = new Deposit(Transaction::fromString($command->getTransaction()), $command->getAmount());
     $account->deposit($deposit);
     $this->accounting->commit();
 }
예제 #4
0
 public function handle(WithdrawCommand $command)
 {
     $account = $this->accounting->getAccount(AccountNumber::fromString($command->getAccountNumber()));
     $withdraw = new Withdraw(Transaction::generate(), $command->getAmount());
     $account->withdraw($withdraw);
     $this->accounting->commit();
 }
예제 #5
0
 function it_will_store_transfer_requested_event()
 {
     $deposit = new Deposit(Transaction::fromString('000'), 100);
     $transfer = new Transfer(Transaction::fromString('000'), AccountNumber::fromString('456DEF'), 100);
     $this->deposit($deposit);
     $this->transfer($transfer);
     $this->getRecordedEvents()[2]->shouldBeAnInstanceOf(MoneyTransferRequestedEvent::class);
 }
예제 #6
0
 public function onTransferRequested(MoneyTransferRequestedEnvelope $event)
 {
     $this->assertProcessWasNotStarted($event->getTransaction());
     $process = new TransferProcess(Transaction::fromString($event->getTransaction()), AccountNumber::fromString($event->getSourceAccountNumber()), AccountNumber::fromString($event->getTargetAccountNumber()), $event->getAmount());
     $process->withdrawFromSource();
     $this->bus->handle(new TransferWithdrawCommand((string) $process->getSourceAccountNumber(), (int) $process->getAmount(), (string) $process->getTransaction()));
     $this->process[$event->getTransaction()] = $process;
 }
 function it_appends_deposit_entry_when_money_were_withdrawn()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $openAccount = new AccountOpenedEvent($accountNumber);
     $this->onAccountOpened(AccountOpenedEnvelope::wrap($openAccount));
     $withdraw = new MoneyWereWithdrawnEvent($accountNumber, new Withdraw(Transaction::generate(), 100));
     $this->onMoneyWereWithdrawn(MoneyWereWithdrawnEnvelope::wrap($withdraw));
     $this->getAccount('123ABC')->getHistory()[1]->getAmount()->shouldReturn(100);
 }
 function it_decreases_balance_when_money_were_withdrawn()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $openAccount = new AccountOpenedEvent($accountNumber);
     $event = AccountOpenedEnvelope::wrap($openAccount);
     $this->onAccountOpened($event);
     $withdraw = new MoneyWereWithdrawnEvent($accountNumber, new Withdraw(Transaction::generate(), 100));
     $event = MoneyWereWithdrawnEnvelope::wrap($withdraw);
     $this->onMoneyWereWithdrawn($event);
     $this->getAccount('123ABC')->getBalance()->shouldReturn(-100);
 }
예제 #9
0
 public function handle(OpenAccountCommand $command)
 {
     $account = Account::open(AccountNumber::fromString($command->getAccountNumber()));
     $this->accounting->addAccount($account);
     $this->accounting->commit();
 }
예제 #10
0
 function let()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $deposit = new Deposit(Transaction::fromString('000'), 100);
     $this->beConstructedWith($accountNumber, $deposit);
 }
예제 #11
0
 function it_can_not_be_created_with_amount_smaller_than_1()
 {
     $this->shouldThrow(\InvalidArgumentException::class)->during('__construct', [Transaction::fromString('000'), AccountNumber::fromString('123ABC'), -100]);
 }
 function let()
 {
     $event = new MoneyTransferRequestedEvent(AccountNumber::fromString('123ABC'), new Transfer(Transaction::fromString('000'), AccountNumber::fromString('456DEF'), 100));
     $this->beConstructedThrough('wrap', [$event]);
 }
예제 #13
0
 function let()
 {
     $this->beConstructedWith(AccountNumber::fromString('123ABC'), 0);
 }
예제 #14
0
 function let()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $transfer = new Transfer(Transaction::fromString('000'), AccountNumber::fromString('456DEF'), 100);
     $this->beConstructedWith($accountNumber, $transfer);
 }
예제 #15
0
 function it_is_equal_when_number_is_equal()
 {
     $this->beConstructedThrough('fromString', ['123ABC']);
     $this->equals(AccountNumber::fromString('123ABC'))->shouldReturn(true);
     $this->equals(AccountNumber::fromString('567DEF'))->shouldReturn(false);
 }
예제 #16
0
파일: Account.php 프로젝트: potfur/journal
 private function applyAccountOpenedEvent(AccountOpenedEvent $event)
 {
     $this->number = AccountNumber::fromString($event->getAccountNumber());
     $this->balance = 0;
 }
예제 #17
0
 function let()
 {
     $this->beConstructedWith(Transaction::fromString('000'), AccountNumber::fromString('123ABC'), AccountNumber::fromString('456DEF'), 100);
 }
예제 #18
0
 function it_can_decreased_balance_by_set_amount()
 {
     $this->beConstructedWith(AccountNumber::fromString('123ABC'));
     $this->decreaseBy(100);
     $this->getBalance()->shouldReturn(-100);
 }
예제 #19
0
 function let()
 {
     $event = new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100));
     $this->beConstructedThrough('wrap', [$event]);
 }
예제 #20
0
 function create_money_transfer_deposit_envelope()
 {
     return MoneyWereDepositedEnvelope::wrap(new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100)));
 }
예제 #21
0
 function let()
 {
     $event = new AccountOpenedEvent(AccountNumber::fromString('123ABC'));
     $this->beConstructedThrough('wrap', [$event]);
 }