mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-21 23:31:14 +02:00
27 lines
782 B
PHP
27 lines
782 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Structural\Proxy\Tests;
|
|
|
|
use DesignPatterns\Structural\Proxy\BankAccountProxy;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ProxyTest extends TestCase
|
|
{
|
|
public function testProxyWillOnlyExecuteExpensiveGetBalanceOnce()
|
|
{
|
|
$bankAccount = new BankAccountProxy();
|
|
$bankAccount->deposit(30);
|
|
|
|
// this time balance is being calculated
|
|
$this->assertSame(30, $bankAccount->getBalance());
|
|
|
|
// inheritance allows for BankAccountProxy to behave to an outsider exactly like ServerBankAccount
|
|
$bankAccount->deposit(50);
|
|
|
|
// this time the previously calculated balance is returned again without re-calculating it
|
|
$this->assertSame(30, $bankAccount->getBalance());
|
|
}
|
|
}
|