public function update(BankAccount $ba)
 {
     if (!isset($this->identityMap[$ba])) {
         throw new MapperException('Object has no ID, cannot update.');
     }
     $this->db->exec(sprintf('UPDATE bankaccount SET balance = %f WHERE id = %d;', $ba->getBalance(), $this->identityMap[$ba]));
 }
Beispiel #2
0
 /**
  * @covers BankAccount::getBalance
  * @group balanceIsInitiallyZero
  * @group specification
  */
 public function testBalanceIsInitiallyZero()
 {
     /* @Given a fresh bank account */
     $ba = new BankAccount();
     /* @When I ask it for its balance */
     $balance = $ba->getBalance();
     /* @Then I should get 0 */
     $this->assertEquals(0, $balance);
 }
 public function testOldAccountInfoInitiallySet()
 {
     $bank_account = new BankAccount('15934903649620486', $this->pdo);
     $this->assertEquals(100, $bank_account->getBalance());
     $this->assertEquals('15934903649620486', $bank_account->getAccountNumber());
     $bank_account = new BankAccount('15936487230215067', $this->pdo);
     $this->assertEquals(1216, $bank_account->getBalance());
     $this->assertEquals('15936487230215067', $bank_account->getAccountNumber());
     $bank_account = new BankAccount('12348612357236185', $this->pdo);
     $this->assertEquals(89, $bank_account->getBalance());
     $this->assertEquals('12348612357236185', $bank_account->getAccountNumber());
 }
Beispiel #4
0
 public function testDepositShouldRegisterWithAfipWhenAmoutGreaterThanAHundred()
 {
     // arrange
     $account = new BankAccount('Nicolas');
     $value = 500;
     $afipMock = $this->getMock('Afip', array('registerTransaction'));
     $afipMock->expects($this->once())->method('registerTransaction')->with($this->equalTo('Nicolas'), $this->equalTo($value));
     $account->setAfip($afipMock);
     $amountToTransfer = 500;
     // act
     $account->deposit(500);
     // assert
     $this->assertEquals($amountToTransfer, $account->getBalance());
 }
<?php

class BankAccount
{
    private $balance = 0;
    function makeDeposit($amount)
    {
        // Add to the current balance
        $this->balance += $amount;
        echo '<br>Deposited: $' . number_format($amount, 2);
    }
    function makeWithdrawal($amount)
    {
        // Subtract from the current balance
        $this->balance -= $amount;
        echo '<br>Withdrew: $' . number_format($amount, 2);
    }
    function getBalance()
    {
        echo '<br>Current Balance: $' . number_format($this->balance, 2);
    }
}
$myAccount = new BankAccount();
$myAccount->makeDeposit(100.0);
$myAccount->makeWithdrawal(40.0);
$myAccount->getBalance();
 public function test_deposit()
 {
     $ba = new BankAccount();
     $ba->deposit(100);
     $this->assertEquals(100, $ba->getBalance());
 }
Beispiel #7
0
 public function testBalanceIsInitiallyZero()
 {
     $ba = new BankAccount();
     $balance = $ba->getBalance();
     $this->assertEquals(0, $balance);
 }
 /**
  * @depends testDepositingMoneyWorks
  * @covers  BankAccount::withdrawMoney
  */
 public function testWithdrawingMoneyWorks(BankAccount $ba)
 {
     $ba->withdrawMoney(1);
     $this->assertEquals(0, $ba->getBalance());
 }
Beispiel #9
0
 public function getTotalMoney()
 {
     return $this->bank_account->getBalance();
 }
 /** @dataProvider withdrawDataProvider 
  * @param BankAccount $bank_account_stub
  */
 public function testWithdraw($bank_account_stub, $money, $expected_balance)
 {
     $bank_account_stub->withdraw($money);
     $this->assertEquals($expected_balance, $bank_account_stub->getBalance());
 }
 public function testWithdrawDecreasesBalance()
 {
     $this->_account->withdraw(100);
     $this->assertEquals(-100, $this->_account->getBalance());
 }