Esempio n. 1
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();
 }
Esempio n. 2
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();
 }
Esempio n. 3
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();
 }
Esempio n. 4
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);
 }
Esempio n. 5
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;
 }
Esempio n. 6
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);
 }
 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_handles_transfer_deposit_command(AccountingInterface $accounting, Account $account)
 {
     $account->deposit(Argument::type(Deposit::class))->shouldBeCalled();
     $accounting->getAccount(Argument::type(AccountNumber::class))->willReturn($account);
     $accounting->commit()->shouldBeCalled();
     $command = new TransferDepositCommand('123ABC', 100, Transaction::fromString('000'));
     $this->beConstructedWith($accounting);
     $this->handle($command);
 }
 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);
 }
Esempio n. 10
0
 function create_money_transfer_deposit_envelope()
 {
     return MoneyWereDepositedEnvelope::wrap(new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100)));
 }
Esempio n. 11
0
 function it_can_not_be_created_with_amount_smaller_than_1()
 {
     $this->shouldThrow(\InvalidArgumentException::class)->during('__construct', [Transaction::fromString('000'), -100]);
 }
 function let()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $deposit = new Deposit(Transaction::fromString('000'), 100);
     $this->beConstructedWith($accountNumber, $deposit);
 }
 function let()
 {
     $accountNumber = AccountNumber::fromString('123ABC');
     $transfer = new Transfer(Transaction::fromString('000'), AccountNumber::fromString('456DEF'), 100);
     $this->beConstructedWith($accountNumber, $transfer);
 }
Esempio n. 14
0
 function let()
 {
     $event = new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100));
     $this->beConstructedThrough('wrap', [$event]);
 }
Esempio n. 15
0
 function let()
 {
     $this->beConstructedWith(Transaction::fromString('000'), AccountNumber::fromString('123ABC'), AccountNumber::fromString('456DEF'), 100);
 }
 function let()
 {
     $event = new MoneyTransferRequestedEvent(AccountNumber::fromString('123ABC'), new Transfer(Transaction::fromString('000'), AccountNumber::fromString('456DEF'), 100));
     $this->beConstructedThrough('wrap', [$event]);
 }