-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkerPoolTest.php
52 lines (48 loc) · 1.04 KB
/
WorkerPoolTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
use PHPUnit\Framework\TestCase;
use App\Patterns\Creational\Pool\Worker\WorkerPool;
class WorkerPoolTest extends TestCase {
/**
* get new instance
*
* @param void
* @return void
*/
public function testCanGetNewInstancesWithGet()
{
$pool = new WorkerPool;
$worker1 = $pool->get();
$worker2 = $pool->get();
$this->assertCount(2, $pool);
$this->assertNotSame($worker1, $worker2);
}
/**
* reuse the same instance after disposing
*
* @param void
* @return void
*/
public function testCanGetSameInstanceTwiceWhenDisposing()
{
$pool = new WorkerPool;
$worker1 = $pool->get();
$pool->dispose($worker1);
$worker2 = $pool->get();
$this->assertCount(1, $pool);
$this->assertSame($worker1, $worker2);
}
/**
* throw error on exceeding the worker limit
*
* @param void
* @return void
*/
public function testShouldThrowExceptionOnExceedingLimit()
{
$this->expectException(\Exception::class);
$pool = new WorkerPool;
for($i = 0; $i < 20; $i++) {
$pool->get();
}
}
}