@@ -13,26 +13,26 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ListenerTest extends TestCase |
| 15 | 15 | { |
| 16 | - /** @var Listener */ |
|
| 17 | - private $listener; |
|
| 16 | + /** @var Listener */ |
|
| 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 Listener(Event::POOL_NEW_THREAD, $this->callback); |
|
| 27 | - } |
|
| 22 | + public function setUp() |
|
| 23 | + { |
|
| 24 | + $this->callback = function(){ |
|
| 25 | + }; |
|
| 26 | + $this->listener = new Listener(Event::POOL_NEW_THREAD, $this->callback); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function test_listener() |
|
| 30 | - { |
|
| 31 | - $this->assertSame(Event::POOL_NEW_THREAD, $this->listener->getEventName()); |
|
| 32 | - $this->assertSame($this->listener, $this->listener->setEventName(Event::POOL_POST_WAIT_TICK)); |
|
| 33 | - $this->assertSame(Event::POOL_POST_WAIT_TICK, $this->listener->getEventName()); |
|
| 34 | - $this->assertSame($this->listener, $this->listener->setCallback($this->callback)); |
|
| 35 | - $this->listener->notify(new Event('test')); |
|
| 36 | - } |
|
| 29 | + public function test_listener() |
|
| 30 | + { |
|
| 31 | + $this->assertSame(Event::POOL_NEW_THREAD, $this->listener->getEventName()); |
|
| 32 | + $this->assertSame($this->listener, $this->listener->setEventName(Event::POOL_POST_WAIT_TICK)); |
|
| 33 | + $this->assertSame(Event::POOL_POST_WAIT_TICK, $this->listener->getEventName()); |
|
| 34 | + $this->assertSame($this->listener, $this->listener->setCallback($this->callback)); |
|
| 35 | + $this->listener->notify(new Event('test')); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -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 Listener(Event::POOL_NEW_THREAD, function() { |
|
| 28 | - }); |
|
| 29 | - $this->assertSame([], $this->mediator->getListeners()); |
|
| 30 | - $this->assertSame($this->mediator, $this->mediator->addListener($listener)); |
|
| 31 | - $this->assertSame([Event::POOL_NEW_THREAD => [$listener]], $this->mediator->getListeners()); |
|
| 32 | - $this->assertSame($this->mediator, $this->mediator->removeListener(new Listener('fake', function(){ |
|
| 33 | - }))); |
|
| 34 | - $this->mediator->notify(Event::POOL_NEW_THREAD, new Event('unit-event')); |
|
| 35 | - $this->assertSame($this->mediator, $this->mediator->removeListener($listener)); |
|
| 36 | - } |
|
| 25 | + public function test_listeners() |
|
| 26 | + { |
|
| 27 | + $listener = new Listener(Event::POOL_NEW_THREAD, function() { |
|
| 28 | + }); |
|
| 29 | + $this->assertSame([], $this->mediator->getListeners()); |
|
| 30 | + $this->assertSame($this->mediator, $this->mediator->addListener($listener)); |
|
| 31 | + $this->assertSame([Event::POOL_NEW_THREAD => [$listener]], $this->mediator->getListeners()); |
|
| 32 | + $this->assertSame($this->mediator, $this->mediator->removeListener(new Listener('fake', function(){ |
|
| 33 | + }))); |
|
| 34 | + $this->mediator->notify(Event::POOL_NEW_THREAD, new Event('unit-event')); |
|
| 35 | + $this->assertSame($this->mediator, $this->mediator->removeListener($listener)); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -17,96 +17,96 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class ThreadPoolTest extends TestCase |
| 19 | 19 | { |
| 20 | - /** @var ThreadPool */ |
|
| 21 | - private $threadPool; |
|
| 22 | - |
|
| 23 | - protected function setUp() |
|
| 24 | - { |
|
| 25 | - $this->threadPool = new ThreadPool(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function test_constructor_destructor() |
|
| 29 | - { |
|
| 30 | - $this->assertAttributeEquals([], 'threads', $this->threadPool); |
|
| 31 | - $this->assertAttributeEquals([], 'runningThreads', $this->threadPool); |
|
| 32 | - $this->assertAttributeEquals([], 'toRunThreads', $this->threadPool); |
|
| 33 | - $this->assertAttributeEquals(false, 'isRunning', $this->threadPool); |
|
| 34 | - $this->assertAttributeEquals(0, 'maxRunningThreadNb', $this->threadPool); |
|
| 35 | - $this->assertSame(Mediator::class, get_class($this->threadPool->getMediator())); |
|
| 36 | - |
|
| 37 | - unset($this->threadPool); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function test_getThreads() |
|
| 41 | - { |
|
| 42 | - $threads = [new Thread()]; |
|
| 43 | - $this->assertSame($this->threadPool, $this->threadPool->setThreads($threads)); |
|
| 44 | - $this->assertSame($threads, $this->threadPool->getThreads()); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function test_addThread() |
|
| 48 | - { |
|
| 49 | - $thread = new Thread(); |
|
| 50 | - $this->assertSame($this->threadPool, $this->threadPool->addThread($thread)); |
|
| 51 | - $this->assertContains($thread, $this->threadPool->getThreads()); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function test_getMaxRunningThreadNb() |
|
| 55 | - { |
|
| 56 | - $this->assertSame(0, $this->threadPool->getMaxRunningThreadNb()); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function test_setMaxRunningThreadNb() |
|
| 60 | - { |
|
| 61 | - $this->assertSame($this->threadPool, $this->threadPool->setMaxRunningThreadNb(10)); |
|
| 62 | - $this->assertSame(10, $this->threadPool->getMaxRunningThreadNb()); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function test_getToRunThreads() |
|
| 66 | - { |
|
| 67 | - $this->assertSame([], $this->threadPool->getToRunThreads()); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function test_getRunningThreads() |
|
| 71 | - { |
|
| 72 | - $this->assertSame([], $this->threadPool->getRunningThreads()); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @throws \Wonderland\Thread\Exception\ThreadException |
|
| 77 | - */ |
|
| 78 | - public function test_run() |
|
| 79 | - { |
|
| 80 | - $thread = new Thread(); |
|
| 81 | - $thread->setCallback(function (){ return 0; |
|
| 82 | - |
|
| 83 | - }); |
|
| 84 | - $thread->setProcessName('unitTest'); |
|
| 85 | - $threads = []; |
|
| 86 | - $listener = new Listener(Event::POOL_NEW_THREAD, function (){ |
|
| 87 | - }); |
|
| 88 | - |
|
| 89 | - $this->threadPool->setMaxRunningThreadNb(10); |
|
| 90 | - $this->assertSame($this->threadPool, $this->threadPool->addListener($listener)); |
|
| 91 | - for ($i = 0; $i < 20; |
|
| 20 | + /** @var ThreadPool */ |
|
| 21 | + private $threadPool; |
|
| 22 | + |
|
| 23 | + protected function setUp() |
|
| 24 | + { |
|
| 25 | + $this->threadPool = new ThreadPool(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function test_constructor_destructor() |
|
| 29 | + { |
|
| 30 | + $this->assertAttributeEquals([], 'threads', $this->threadPool); |
|
| 31 | + $this->assertAttributeEquals([], 'runningThreads', $this->threadPool); |
|
| 32 | + $this->assertAttributeEquals([], 'toRunThreads', $this->threadPool); |
|
| 33 | + $this->assertAttributeEquals(false, 'isRunning', $this->threadPool); |
|
| 34 | + $this->assertAttributeEquals(0, 'maxRunningThreadNb', $this->threadPool); |
|
| 35 | + $this->assertSame(Mediator::class, get_class($this->threadPool->getMediator())); |
|
| 36 | + |
|
| 37 | + unset($this->threadPool); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function test_getThreads() |
|
| 41 | + { |
|
| 42 | + $threads = [new Thread()]; |
|
| 43 | + $this->assertSame($this->threadPool, $this->threadPool->setThreads($threads)); |
|
| 44 | + $this->assertSame($threads, $this->threadPool->getThreads()); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function test_addThread() |
|
| 48 | + { |
|
| 49 | + $thread = new Thread(); |
|
| 50 | + $this->assertSame($this->threadPool, $this->threadPool->addThread($thread)); |
|
| 51 | + $this->assertContains($thread, $this->threadPool->getThreads()); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function test_getMaxRunningThreadNb() |
|
| 55 | + { |
|
| 56 | + $this->assertSame(0, $this->threadPool->getMaxRunningThreadNb()); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function test_setMaxRunningThreadNb() |
|
| 60 | + { |
|
| 61 | + $this->assertSame($this->threadPool, $this->threadPool->setMaxRunningThreadNb(10)); |
|
| 62 | + $this->assertSame(10, $this->threadPool->getMaxRunningThreadNb()); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function test_getToRunThreads() |
|
| 66 | + { |
|
| 67 | + $this->assertSame([], $this->threadPool->getToRunThreads()); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function test_getRunningThreads() |
|
| 71 | + { |
|
| 72 | + $this->assertSame([], $this->threadPool->getRunningThreads()); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @throws \Wonderland\Thread\Exception\ThreadException |
|
| 77 | + */ |
|
| 78 | + public function test_run() |
|
| 79 | + { |
|
| 80 | + $thread = new Thread(); |
|
| 81 | + $thread->setCallback(function (){ return 0; |
|
| 82 | + |
|
| 83 | + }); |
|
| 84 | + $thread->setProcessName('unitTest'); |
|
| 85 | + $threads = []; |
|
| 86 | + $listener = new Listener(Event::POOL_NEW_THREAD, function (){ |
|
| 87 | + }); |
|
| 88 | + |
|
| 89 | + $this->threadPool->setMaxRunningThreadNb(10); |
|
| 90 | + $this->assertSame($this->threadPool, $this->threadPool->addListener($listener)); |
|
| 91 | + for ($i = 0; $i < 20; |
|
| 92 | 92 | $i++) { $threads[] = clone $thread; |
| 93 | - } |
|
| 94 | - $this->assertSame($this->threadPool, $this->threadPool->addThread($thread)); |
|
| 95 | - $this->assertSame($this->threadPool, $this->threadPool->setThreads($threads)); |
|
| 93 | + } |
|
| 94 | + $this->assertSame($this->threadPool, $this->threadPool->addThread($thread)); |
|
| 95 | + $this->assertSame($this->threadPool, $this->threadPool->setThreads($threads)); |
|
| 96 | 96 | |
| 97 | - $this->threadPool->run(); |
|
| 97 | + $this->threadPool->run(); |
|
| 98 | 98 | |
| 99 | - $this->assertSame($this->threadPool, $this->threadPool->removeListener($listener)); |
|
| 100 | - } |
|
| 99 | + $this->assertSame($this->threadPool, $this->threadPool->removeListener($listener)); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @throws ThreadException |
|
| 104 | - */ |
|
| 105 | - public function test_run_exception() |
|
| 106 | - { |
|
| 107 | - $this->expectException(ThreadException::class); |
|
| 108 | - $this->threadPool->run(); |
|
| 102 | + /** |
|
| 103 | + * @throws ThreadException |
|
| 104 | + */ |
|
| 105 | + public function test_run_exception() |
|
| 106 | + { |
|
| 107 | + $this->expectException(ThreadException::class); |
|
| 108 | + $this->threadPool->run(); |
|
| 109 | 109 | |
| 110 | - } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | } |
@@ -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 Thread(); |
|
| 22 | - $thread->setProcessName('unit-test'); |
|
| 23 | - $thread->setCallback($callback); |
|
| 17 | + public function test_create() |
|
| 18 | + { |
|
| 19 | + $callback = function(){ |
|
| 20 | + }; |
|
| 21 | + $thread = new Thread(); |
|
| 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 | } |
@@ -13,78 +13,78 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ThreadTest extends TestCase |
| 15 | 15 | { |
| 16 | - /** @var Thread */ |
|
| 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 Thread(); |
|
| 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 Thread(); |
|
| 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 Thread(); |
|
| 84 | - $thread->setCallback(function() { return null; |
|
| 85 | - |
|
| 86 | - }); |
|
| 87 | - $thread->run('unit-test'); |
|
| 88 | - } |
|
| 16 | + /** @var Thread */ |
|
| 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 Thread(); |
|
| 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 Thread(); |
|
| 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 Thread(); |
|
| 84 | + $thread->setCallback(function() { return null; |
|
| 85 | + |
|
| 86 | + }); |
|
| 87 | + $thread->run('unit-test'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | } |
@@ -13,43 +13,43 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EventTest extends TestCase |
| 15 | 15 | { |
| 16 | - /** @var Event */ |
|
| 17 | - private $event; |
|
| 18 | - |
|
| 19 | - /** @var Thread */ |
|
| 20 | - private $thread; |
|
| 21 | - |
|
| 22 | - public function setUp() |
|
| 23 | - { |
|
| 24 | - $this->thread = new Thread(); |
|
| 25 | - $this->event = new Event('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 Event */ |
|
| 17 | + private $event; |
|
| 18 | + |
|
| 19 | + /** @var Thread */ |
|
| 20 | + private $thread; |
|
| 21 | + |
|
| 22 | + public function setUp() |
|
| 23 | + { |
|
| 24 | + $this->thread = new Thread(); |
|
| 25 | + $this->event = new Event('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 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | declare( strict_types = 1 ); |
| 3 | 3 | |
| 4 | 4 | if ( PHP_SAPI !== 'cli' ) { |
| 5 | - die( 'Not an entry point' ); |
|
| 5 | + die( 'Not an entry point' ); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | error_reporting( -1 ); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | ini_set( 'display_errors', '1' ); |
| 11 | 11 | |
| 12 | 12 | if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) { |
| 13 | - die( 'You need to install this package with Composer before you can run the tests' ); |
|
| 13 | + die( 'You need to install this package with Composer before you can run the tests' ); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | require_once __DIR__ . '/../vendor/autoload.php'; |