@@ -13,26 +13,26 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ListenerTest extends TestCase |
| 15 | 15 | { |
| 16 | - /** @var AbstractListener */ |
|
| 17 | - private $listener; |
|
| 16 | + /** @var AbstractListener */ |
|
| 17 | + private $listener; |
|
| 18 | 18 | |
| 19 | - /** @var callable */ |
|
| 20 | - private $callback; |
|
| 19 | + /** @var callable */ |
|
| 20 | + private $callback; |
|
| 21 | 21 | |
| 22 | - public function setUp() |
|
| 23 | - { |
|
| 24 | - $this->callback = function(){ |
|
| 25 | - }; |
|
| 26 | - $this->listener = new AbstractListener(PoolEvent::POOL_NEW_THREAD, $this->callback); |
|
| 27 | - } |
|
| 22 | + public function setUp() |
|
| 23 | + { |
|
| 24 | + $this->callback = function(){ |
|
| 25 | + }; |
|
| 26 | + $this->listener = new AbstractListener(PoolEvent::POOL_NEW_THREAD, $this->callback); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function test_listener() |
|
| 30 | - { |
|
| 31 | - $this->assertSame(PoolEvent::POOL_NEW_THREAD, $this->listener->getEventName()); |
|
| 32 | - $this->assertSame($this->listener, $this->listener->setEventName(PoolEvent::POOL_POST_WAIT_TICK)); |
|
| 33 | - $this->assertSame(PoolEvent::POOL_POST_WAIT_TICK, $this->listener->getEventName()); |
|
| 34 | - $this->assertSame($this->listener, $this->listener->setCallback($this->callback)); |
|
| 35 | - $this->listener->notify(new PoolEvent('test')); |
|
| 36 | - } |
|
| 29 | + public function test_listener() |
|
| 30 | + { |
|
| 31 | + $this->assertSame(PoolEvent::POOL_NEW_THREAD, $this->listener->getEventName()); |
|
| 32 | + $this->assertSame($this->listener, $this->listener->setEventName(PoolEvent::POOL_POST_WAIT_TICK)); |
|
| 33 | + $this->assertSame(PoolEvent::POOL_POST_WAIT_TICK, $this->listener->getEventName()); |
|
| 34 | + $this->assertSame($this->listener, $this->listener->setCallback($this->callback)); |
|
| 35 | + $this->listener->notify(new PoolEvent('test')); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function setUp() |
| 23 | 23 | { |
| 24 | - $this->callback = function(){ |
|
| 24 | + $this->callback = function() { |
|
| 25 | 25 | }; |
| 26 | 26 | $this->listener = new AbstractListener(PoolEvent::POOL_NEW_THREAD, $this->callback); |
| 27 | 27 | } |
@@ -14,25 +14,25 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class MediatorTest extends TestCase |
| 16 | 16 | { |
| 17 | - /** @var Mediator */ |
|
| 18 | - private $mediator; |
|
| 17 | + /** @var Mediator */ |
|
| 18 | + private $mediator; |
|
| 19 | 19 | |
| 20 | - public function setUp() |
|
| 21 | - { |
|
| 22 | - $this->mediator = new Mediator(); |
|
| 23 | - } |
|
| 20 | + public function setUp() |
|
| 21 | + { |
|
| 22 | + $this->mediator = new Mediator(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function test_listeners() |
|
| 26 | - { |
|
| 27 | - $listener = new AbstractListener(PoolEvent::POOL_NEW_THREAD, function() { |
|
| 28 | - }); |
|
| 29 | - $this->assertSame([], $this->mediator->getListeners()); |
|
| 30 | - $this->assertSame($this->mediator, $this->mediator->addListener($listener)); |
|
| 31 | - $this->assertSame([PoolEvent::POOL_NEW_THREAD => [$listener]], $this->mediator->getListeners()); |
|
| 32 | - $this->assertSame($this->mediator, $this->mediator->removeListener(new AbstractListener('fake', function(){ |
|
| 33 | - }))); |
|
| 34 | - $this->mediator->notify(PoolEvent::POOL_NEW_THREAD, new PoolEvent('unit-event')); |
|
| 35 | - $this->assertSame($this->mediator, $this->mediator->removeListener($listener)); |
|
| 36 | - } |
|
| 25 | + public function test_listeners() |
|
| 26 | + { |
|
| 27 | + $listener = new AbstractListener(PoolEvent::POOL_NEW_THREAD, function() { |
|
| 28 | + }); |
|
| 29 | + $this->assertSame([], $this->mediator->getListeners()); |
|
| 30 | + $this->assertSame($this->mediator, $this->mediator->addListener($listener)); |
|
| 31 | + $this->assertSame([PoolEvent::POOL_NEW_THREAD => [$listener]], $this->mediator->getListeners()); |
|
| 32 | + $this->assertSame($this->mediator, $this->mediator->removeListener(new AbstractListener('fake', function(){ |
|
| 33 | + }))); |
|
| 34 | + $this->mediator->notify(PoolEvent::POOL_NEW_THREAD, new PoolEvent('unit-event')); |
|
| 35 | + $this->assertSame($this->mediator, $this->mediator->removeListener($listener)); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | $this->assertSame([], $this->mediator->getListeners()); |
| 30 | 30 | $this->assertSame($this->mediator, $this->mediator->addListener($listener)); |
| 31 | 31 | $this->assertSame([PoolEvent::POOL_NEW_THREAD => [$listener]], $this->mediator->getListeners()); |
| 32 | - $this->assertSame($this->mediator, $this->mediator->removeListener(new AbstractListener('fake', function(){ |
|
| 32 | + $this->assertSame($this->mediator, $this->mediator->removeListener(new AbstractListener('fake', function() { |
|
| 33 | 33 | }))); |
| 34 | 34 | $this->mediator->notify(PoolEvent::POOL_NEW_THREAD, new PoolEvent('unit-event')); |
| 35 | 35 | $this->assertSame($this->mediator, $this->mediator->removeListener($listener)); |
@@ -13,78 +13,78 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ThreadTest extends TestCase |
| 15 | 15 | { |
| 16 | - /** @var AbstractThread */ |
|
| 17 | - private $thread; |
|
| 18 | - |
|
| 19 | - private $callback; |
|
| 20 | - |
|
| 21 | - public function setUp() |
|
| 22 | - { |
|
| 23 | - $this->callback = function (){ return 0; |
|
| 24 | - |
|
| 25 | - }; |
|
| 26 | - |
|
| 27 | - $this->thread = new AbstractThread(); |
|
| 28 | - $this->thread->setPid(1); |
|
| 29 | - $this->thread->setProcessName('unit-test'); |
|
| 30 | - $this->thread->setCallback($this->callback); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function test_pid() |
|
| 34 | - { |
|
| 35 | - $this->assertSame(1, $this->thread->getPid()); |
|
| 36 | - $this->assertSame($this->thread, $this->thread->setPid(100)); |
|
| 37 | - $this->assertSame(100, $this->thread->getPid()); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function test_processName() |
|
| 41 | - { |
|
| 42 | - $this->assertSame('unit-test', $this->thread->getProcessName()); |
|
| 43 | - $this->assertSame($this->thread, $this->thread->setProcessName('unit')); |
|
| 44 | - $this->assertSame('unit', $this->thread->getProcessName()); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function test_callback() |
|
| 48 | - { |
|
| 49 | - $callback = function(){ return 1; |
|
| 50 | - |
|
| 51 | - }; |
|
| 52 | - |
|
| 53 | - $this->assertSame($this->callback, $this->thread->getCallback()); |
|
| 54 | - $this->assertSame($this->thread, $this->thread->setCallback($callback)); |
|
| 55 | - $this->assertSame($callback, $this->thread->getCallback()); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @throws ThreadException |
|
| 60 | - */ |
|
| 61 | - public function test_run() |
|
| 62 | - { |
|
| 63 | - $this->assertSame(0, $this->thread->run('unit-test')); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @throws ThreadException |
|
| 68 | - */ |
|
| 69 | - public function test_run_exception() |
|
| 70 | - { |
|
| 71 | - $this->expectException(ThreadException::class); |
|
| 72 | - $thread = new AbstractThread(); |
|
| 73 | - $thread->run('unit-test'); |
|
| 74 | - |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @throws ThreadException |
|
| 79 | - */ |
|
| 80 | - public function test_run_exception_status() |
|
| 81 | - { |
|
| 82 | - $this->expectException(ThreadException::class); |
|
| 83 | - $thread = new AbstractThread(); |
|
| 84 | - $thread->setCallback(function() { return null; |
|
| 85 | - |
|
| 86 | - }); |
|
| 87 | - $thread->run('unit-test'); |
|
| 88 | - } |
|
| 16 | + /** @var AbstractThread */ |
|
| 17 | + private $thread; |
|
| 18 | + |
|
| 19 | + private $callback; |
|
| 20 | + |
|
| 21 | + public function setUp() |
|
| 22 | + { |
|
| 23 | + $this->callback = function (){ return 0; |
|
| 24 | + |
|
| 25 | + }; |
|
| 26 | + |
|
| 27 | + $this->thread = new AbstractThread(); |
|
| 28 | + $this->thread->setPid(1); |
|
| 29 | + $this->thread->setProcessName('unit-test'); |
|
| 30 | + $this->thread->setCallback($this->callback); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function test_pid() |
|
| 34 | + { |
|
| 35 | + $this->assertSame(1, $this->thread->getPid()); |
|
| 36 | + $this->assertSame($this->thread, $this->thread->setPid(100)); |
|
| 37 | + $this->assertSame(100, $this->thread->getPid()); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function test_processName() |
|
| 41 | + { |
|
| 42 | + $this->assertSame('unit-test', $this->thread->getProcessName()); |
|
| 43 | + $this->assertSame($this->thread, $this->thread->setProcessName('unit')); |
|
| 44 | + $this->assertSame('unit', $this->thread->getProcessName()); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function test_callback() |
|
| 48 | + { |
|
| 49 | + $callback = function(){ return 1; |
|
| 50 | + |
|
| 51 | + }; |
|
| 52 | + |
|
| 53 | + $this->assertSame($this->callback, $this->thread->getCallback()); |
|
| 54 | + $this->assertSame($this->thread, $this->thread->setCallback($callback)); |
|
| 55 | + $this->assertSame($callback, $this->thread->getCallback()); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @throws ThreadException |
|
| 60 | + */ |
|
| 61 | + public function test_run() |
|
| 62 | + { |
|
| 63 | + $this->assertSame(0, $this->thread->run('unit-test')); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @throws ThreadException |
|
| 68 | + */ |
|
| 69 | + public function test_run_exception() |
|
| 70 | + { |
|
| 71 | + $this->expectException(ThreadException::class); |
|
| 72 | + $thread = new AbstractThread(); |
|
| 73 | + $thread->run('unit-test'); |
|
| 74 | + |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @throws ThreadException |
|
| 79 | + */ |
|
| 80 | + public function test_run_exception_status() |
|
| 81 | + { |
|
| 82 | + $this->expectException(ThreadException::class); |
|
| 83 | + $thread = new AbstractThread(); |
|
| 84 | + $thread->setCallback(function() { return null; |
|
| 85 | + |
|
| 86 | + }); |
|
| 87 | + $thread->run('unit-test'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | } |
@@ -14,16 +14,16 @@ |
||
| 14 | 14 | class ThreadFactoryTest extends TestCase |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - public function test_create() |
|
| 18 | - { |
|
| 19 | - $callback = function(){ |
|
| 20 | - }; |
|
| 21 | - $thread = new AbstractThread(); |
|
| 22 | - $thread->setProcessName('unit-test'); |
|
| 23 | - $thread->setCallback($callback); |
|
| 17 | + public function test_create() |
|
| 18 | + { |
|
| 19 | + $callback = function(){ |
|
| 20 | + }; |
|
| 21 | + $thread = new AbstractThread(); |
|
| 22 | + $thread->setProcessName('unit-test'); |
|
| 23 | + $thread->setCallback($callback); |
|
| 24 | 24 | |
| 25 | - $this->assertSame($thread->getCallback(), ThreadFactory::create('unit-test', $callback)->getCallback()); |
|
| 26 | - $this->assertSame($thread->getProcessName(), ThreadFactory::create('unit-test', $callback)->getProcessName()); |
|
| 27 | - } |
|
| 25 | + $this->assertSame($thread->getCallback(), ThreadFactory::create('unit-test', $callback)->getCallback()); |
|
| 26 | + $this->assertSame($thread->getProcessName(), ThreadFactory::create('unit-test', $callback)->getProcessName()); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function test_create() |
| 18 | 18 | { |
| 19 | - $callback = function(){ |
|
| 19 | + $callback = function() { |
|
| 20 | 20 | }; |
| 21 | 21 | $thread = new AbstractThread(); |
| 22 | 22 | $thread->setProcessName('unit-test'); |
@@ -13,43 +13,43 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EventTest extends TestCase |
| 15 | 15 | { |
| 16 | - /** @var PoolEvent */ |
|
| 17 | - private $event; |
|
| 18 | - |
|
| 19 | - /** @var AbstractThread */ |
|
| 20 | - private $thread; |
|
| 21 | - |
|
| 22 | - public function setUp() |
|
| 23 | - { |
|
| 24 | - $this->thread = new AbstractThread(); |
|
| 25 | - $this->event = new PoolEvent('unit-test'); |
|
| 26 | - $this->event->setThread($this->thread); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function test_event() |
|
| 30 | - { |
|
| 31 | - $this->assertSame('unit-test', $this->event->getEventName()); |
|
| 32 | - $this->assertSame(0, $this->event->getMaxRunningThreadNb()); |
|
| 33 | - $this->assertSame(0, $this->event->getRunningThreadNb()); |
|
| 34 | - $this->assertSame(0, $this->event->getThreadDoneNb()); |
|
| 35 | - $this->assertSame(0, $this->event->getThreadLeftNb()); |
|
| 36 | - $this->assertSame(0, $this->event->getThreadNb()); |
|
| 37 | - $this->assertSame($this->thread, $this->event->getThread()); |
|
| 38 | - |
|
| 39 | - $this->assertSame($this->event, $this->event->setThread($this->thread)); |
|
| 40 | - $this->assertSame($this->event, $this->event->setMaxRunningThreadNb(100)); |
|
| 41 | - $this->assertSame($this->event, $this->event->setEventName('fake')); |
|
| 42 | - $this->assertSame($this->event, $this->event->setRunningThreadNb(10)); |
|
| 43 | - $this->assertSame($this->event, $this->event->setThreadDoneNb(90)); |
|
| 44 | - $this->assertSame($this->event, $this->event->setThreadLeftNb(10)); |
|
| 45 | - $this->assertSame($this->event, $this->event->setThreadNb(10)); |
|
| 46 | - |
|
| 47 | - $this->assertSame('fake', $this->event->getEventName()); |
|
| 48 | - $this->assertSame(100, $this->event->getMaxRunningThreadNb()); |
|
| 49 | - $this->assertSame(10, $this->event->getRunningThreadNb()); |
|
| 50 | - $this->assertSame(90, $this->event->getThreadDoneNb()); |
|
| 51 | - $this->assertSame(10, $this->event->getThreadLeftNb()); |
|
| 52 | - $this->assertSame(10, $this->event->getThreadNb()); |
|
| 53 | - } |
|
| 16 | + /** @var PoolEvent */ |
|
| 17 | + private $event; |
|
| 18 | + |
|
| 19 | + /** @var AbstractThread */ |
|
| 20 | + private $thread; |
|
| 21 | + |
|
| 22 | + public function setUp() |
|
| 23 | + { |
|
| 24 | + $this->thread = new AbstractThread(); |
|
| 25 | + $this->event = new PoolEvent('unit-test'); |
|
| 26 | + $this->event->setThread($this->thread); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function test_event() |
|
| 30 | + { |
|
| 31 | + $this->assertSame('unit-test', $this->event->getEventName()); |
|
| 32 | + $this->assertSame(0, $this->event->getMaxRunningThreadNb()); |
|
| 33 | + $this->assertSame(0, $this->event->getRunningThreadNb()); |
|
| 34 | + $this->assertSame(0, $this->event->getThreadDoneNb()); |
|
| 35 | + $this->assertSame(0, $this->event->getThreadLeftNb()); |
|
| 36 | + $this->assertSame(0, $this->event->getThreadNb()); |
|
| 37 | + $this->assertSame($this->thread, $this->event->getThread()); |
|
| 38 | + |
|
| 39 | + $this->assertSame($this->event, $this->event->setThread($this->thread)); |
|
| 40 | + $this->assertSame($this->event, $this->event->setMaxRunningThreadNb(100)); |
|
| 41 | + $this->assertSame($this->event, $this->event->setEventName('fake')); |
|
| 42 | + $this->assertSame($this->event, $this->event->setRunningThreadNb(10)); |
|
| 43 | + $this->assertSame($this->event, $this->event->setThreadDoneNb(90)); |
|
| 44 | + $this->assertSame($this->event, $this->event->setThreadLeftNb(10)); |
|
| 45 | + $this->assertSame($this->event, $this->event->setThreadNb(10)); |
|
| 46 | + |
|
| 47 | + $this->assertSame('fake', $this->event->getEventName()); |
|
| 48 | + $this->assertSame(100, $this->event->getMaxRunningThreadNb()); |
|
| 49 | + $this->assertSame(10, $this->event->getRunningThreadNb()); |
|
| 50 | + $this->assertSame(90, $this->event->getThreadDoneNb()); |
|
| 51 | + $this->assertSame(10, $this->event->getThreadLeftNb()); |
|
| 52 | + $this->assertSame(10, $this->event->getThreadNb()); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |