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(); }
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(); }
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(); }
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); }
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_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); }
function create_money_transfer_deposit_envelope() { return MoneyWereDepositedEnvelope::wrap(new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100))); }
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); }
function let() { $event = new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100)); $this->beConstructedThrough('wrap', [$event]); }
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]); }