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 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(); }
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(); }
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); }
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); }
public function handle(OpenAccountCommand $command) { $account = Account::open(AccountNumber::fromString($command->getAccountNumber())); $this->accounting->addAccount($account); $this->accounting->commit(); }
function let() { $accountNumber = AccountNumber::fromString('123ABC'); $deposit = new Deposit(Transaction::fromString('000'), 100); $this->beConstructedWith($accountNumber, $deposit); }
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]); }
function let() { $this->beConstructedWith(AccountNumber::fromString('123ABC'), 0); }
function let() { $accountNumber = AccountNumber::fromString('123ABC'); $transfer = new Transfer(Transaction::fromString('000'), AccountNumber::fromString('456DEF'), 100); $this->beConstructedWith($accountNumber, $transfer); }
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); }
private function applyAccountOpenedEvent(AccountOpenedEvent $event) { $this->number = AccountNumber::fromString($event->getAccountNumber()); $this->balance = 0; }
function let() { $this->beConstructedWith(Transaction::fromString('000'), AccountNumber::fromString('123ABC'), AccountNumber::fromString('456DEF'), 100); }
function it_can_decreased_balance_by_set_amount() { $this->beConstructedWith(AccountNumber::fromString('123ABC')); $this->decreaseBy(100); $this->getBalance()->shouldReturn(-100); }
function let() { $event = new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100)); $this->beConstructedThrough('wrap', [$event]); }
function create_money_transfer_deposit_envelope() { return MoneyWereDepositedEnvelope::wrap(new MoneyWereDepositedEvent(AccountNumber::fromString('123ABC'), new Deposit(Transaction::fromString('000'), 100))); }
function let() { $event = new AccountOpenedEvent(AccountNumber::fromString('123ABC')); $this->beConstructedThrough('wrap', [$event]); }