add object pool pattern

This commit is contained in:
Jan Brecka
2014-03-24 16:51:49 +01:00
parent b0b0d4a1a4
commit d779b1e86a
7 changed files with 166 additions and 0 deletions

32
Tests/Pool/PoolTest.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace DesignPatterns\Tests\Pool;
use DesignPatterns\Pool\Pool;
class TestWorker
{
public $id = 1;
}
class PoolTest extends \PHPUnit_Framework_TestCase
{
public function testPool()
{
$pool = new Pool('DesignPatterns\Tests\Pool\TestWorker');
$worker = $pool->get();
$this->assertEquals(1, $worker->id);
$worker->id = 5;
$pool->dispose($worker);
$this->assertEquals(5, $pool->get()->id);
$this->assertEquals(1, $pool->get()->id);
}
}