mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-25 09:11:17 +02:00
53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\ChainOfResponsibilities\Tests;
|
|
|
|
use DesignPatterns\Behavioral\ChainOfResponsibilities\Handler;
|
|
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\HttpInMemoryCacheHandler;
|
|
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowDatabaseHandler;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ChainTest extends TestCase
|
|
{
|
|
/**
|
|
* @var Handler
|
|
*/
|
|
private $chain;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->chain = new HttpInMemoryCacheHandler(
|
|
['/foo/bar?index=1' => 'Hello In Memory!'],
|
|
new SlowDatabaseHandler()
|
|
);
|
|
}
|
|
|
|
public function testCanRequestKeyInFastStorage()
|
|
{
|
|
$uri = $this->createMock('Psr\Http\Message\UriInterface');
|
|
$uri->method('getPath')->willReturn('/foo/bar');
|
|
$uri->method('getQuery')->willReturn('index=1');
|
|
|
|
$request = $this->createMock('Psr\Http\Message\RequestInterface');
|
|
$request->method('getMethod')
|
|
->willReturn('GET');
|
|
$request->method('getUri')->willReturn($uri);
|
|
|
|
$this->assertSame('Hello In Memory!', $this->chain->handle($request));
|
|
}
|
|
|
|
public function testCanRequestKeyInSlowStorage()
|
|
{
|
|
$uri = $this->createMock('Psr\Http\Message\UriInterface');
|
|
$uri->method('getPath')->willReturn('/foo/baz');
|
|
$uri->method('getQuery')->willReturn('');
|
|
|
|
$request = $this->createMock('Psr\Http\Message\RequestInterface');
|
|
$request->method('getMethod')
|
|
->willReturn('GET');
|
|
$request->method('getUri')->willReturn($uri);
|
|
|
|
$this->assertSame('Hello World!', $this->chain->handle($request));
|
|
}
|
|
}
|