Passed
Pull Request — master (#10)
by Alice
02:01
created
tests/unit/Implementation/TestListener.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -8,22 +8,22 @@
 block discarded – undo
8 8
 class TestListener extends AbstractListener
9 9
 {
10 10
 
11
-	/**
12
-	 * @return array
13
-	 */
14
-	public function getEventMapping(): array
15
-	{
16
-		return [
17
-			PoolEvent::POOL_NEW_THREAD => 'onNewThread'
18
-		];
19
-	}
11
+    /**
12
+     * @return array
13
+     */
14
+    public function getEventMapping(): array
15
+    {
16
+        return [
17
+            PoolEvent::POOL_NEW_THREAD => 'onNewThread'
18
+        ];
19
+    }
20 20
 
21
-	/**
22
-	 * @param PoolEvent $event
23
-	 */
24
-	public function onNewThread(PoolEvent $event)
25
-	{
21
+    /**
22
+     * @param PoolEvent $event
23
+     */
24
+    public function onNewThread(PoolEvent $event)
25
+    {
26 26
 
27
-	}
27
+    }
28 28
 
29 29
 }
Please login to merge, or discard this patch.
tests/unit/Implementation/TestEvent.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@
 block discarded – undo
7 7
 class TestEvent implements EventInterface
8 8
 {
9 9
 
10
-	/**
11
-	 * @return string
12
-	 */
13
-	public function getEventName(): string
14
-	{
15
-		return 'test-unit-event';
16
-	}
10
+    /**
11
+     * @return string
12
+     */
13
+    public function getEventName(): string
14
+    {
15
+        return 'test-unit-event';
16
+    }
17 17
 
18 18
 }
Please login to merge, or discard this patch.
tests/unit/Implementation/ExceptionThread.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,24 +7,24 @@
 block discarded – undo
7 7
 class ExceptionThread extends AbstractThread
8 8
 {
9 9
 
10
-	/**
11
-	 * Return the name of the method to process during the thread
12
-	 *
13
-	 * @return string
14
-	 */
15
-	protected function getMethodName(): string
16
-	{
17
-		return 'method';
18
-	}
10
+    /**
11
+     * Return the name of the method to process during the thread
12
+     *
13
+     * @return string
14
+     */
15
+    protected function getMethodName(): string
16
+    {
17
+        return 'method';
18
+    }
19 19
 
20
-	/**
21
-	 * Return the list of dependencies that will be passed as parameters of the method referenced by getMethodName
22
-	 *
23
-	 * @return array
24
-	 */
25
-	protected function getDependencies(): array
26
-	{
27
-		return ['toto'];
28
-	}
20
+    /**
21
+     * Return the list of dependencies that will be passed as parameters of the method referenced by getMethodName
22
+     *
23
+     * @return array
24
+     */
25
+    protected function getDependencies(): array
26
+    {
27
+        return ['toto'];
28
+    }
29 29
 
30 30
 }
Please login to merge, or discard this patch.
tests/unit/Mediator/MediatorTest.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,23 +15,23 @@
 block discarded – undo
15 15
  */
16 16
 class MediatorTest extends TestCase
17 17
 {
18
-	/** @var Mediator */
19
-	private $mediator;
18
+    /** @var Mediator */
19
+    private $mediator;
20 20
 
21
-	public function setUp()
22
-	{
23
-		$this->mediator = new Mediator();
24
-	}
21
+    public function setUp()
22
+    {
23
+        $this->mediator = new Mediator();
24
+    }
25 25
 
26
-	public function test_listeners()
27
-	{
28
-		$listener = new TestListener();
29
-		$this->assertSame([], $this->mediator->getListeners());
30
-		$this->assertSame($this->mediator, $this->mediator->addListener($listener));
31
-		$this->assertSame([$listener], $this->mediator->getListeners());
32
-		$this->assertSame($this->mediator, $this->mediator->removeListener(new TestListener()));
33
-		$this->mediator->notify(new PoolEvent(PoolEvent::POOL_NEW_THREAD));
34
-		$this->assertSame($this->mediator, $this->mediator->removeListener($listener));
35
-	}
26
+    public function test_listeners()
27
+    {
28
+        $listener = new TestListener();
29
+        $this->assertSame([], $this->mediator->getListeners());
30
+        $this->assertSame($this->mediator, $this->mediator->addListener($listener));
31
+        $this->assertSame([$listener], $this->mediator->getListeners());
32
+        $this->assertSame($this->mediator, $this->mediator->removeListener(new TestListener()));
33
+        $this->mediator->notify(new PoolEvent(PoolEvent::POOL_NEW_THREAD));
34
+        $this->assertSame($this->mediator, $this->mediator->removeListener($listener));
35
+    }
36 36
 
37 37
 }
Please login to merge, or discard this patch.
tests/unit/Event/EventTest.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -14,43 +14,43 @@
 block discarded – undo
14 14
  */
15 15
 class EventTest extends TestCase
16 16
 {
17
-	/** @var PoolEvent */
18
-	private $event;
19
-
20
-	/** @var AbstractThread */
21
-	private $thread;
22
-
23
-	public function setUp()
24
-	{
25
-		$this->thread = new SuccessThread('');
26
-		$this->event = new PoolEvent('unit-test');
27
-		$this->event->setThread($this->thread);
28
-	}
29
-
30
-	public function test_event()
31
-	{
32
-		$this->assertSame('unit-test', $this->event->getEventName());
33
-		$this->assertSame(0, $this->event->getMaxRunningThreadNb());
34
-		$this->assertSame(0, $this->event->getRunningThreadNb());
35
-		$this->assertSame(0, $this->event->getThreadDoneNb());
36
-		$this->assertSame(0, $this->event->getThreadLeftNb());
37
-		$this->assertSame(0, $this->event->getThreadNb());
38
-		$this->assertSame($this->thread, $this->event->getThread());
39
-
40
-		$this->assertSame($this->event, $this->event->setThread($this->thread));
41
-		$this->assertSame($this->event, $this->event->setMaxRunningThreadNb(100));
42
-		$this->assertSame($this->event, $this->event->setEventName('fake'));
43
-		$this->assertSame($this->event, $this->event->setRunningThreadNb(10));
44
-		$this->assertSame($this->event, $this->event->setThreadDoneNb(90));
45
-		$this->assertSame($this->event, $this->event->setThreadLeftNb(10));
46
-		$this->assertSame($this->event, $this->event->setThreadNb(10));
47
-
48
-		$this->assertSame('fake', $this->event->getEventName());
49
-		$this->assertSame(100, $this->event->getMaxRunningThreadNb());
50
-		$this->assertSame(10, $this->event->getRunningThreadNb());
51
-		$this->assertSame(90, $this->event->getThreadDoneNb());
52
-		$this->assertSame(10, $this->event->getThreadLeftNb());
53
-		$this->assertSame(10, $this->event->getThreadNb());
54
-	}
17
+    /** @var PoolEvent */
18
+    private $event;
19
+
20
+    /** @var AbstractThread */
21
+    private $thread;
22
+
23
+    public function setUp()
24
+    {
25
+        $this->thread = new SuccessThread('');
26
+        $this->event = new PoolEvent('unit-test');
27
+        $this->event->setThread($this->thread);
28
+    }
29
+
30
+    public function test_event()
31
+    {
32
+        $this->assertSame('unit-test', $this->event->getEventName());
33
+        $this->assertSame(0, $this->event->getMaxRunningThreadNb());
34
+        $this->assertSame(0, $this->event->getRunningThreadNb());
35
+        $this->assertSame(0, $this->event->getThreadDoneNb());
36
+        $this->assertSame(0, $this->event->getThreadLeftNb());
37
+        $this->assertSame(0, $this->event->getThreadNb());
38
+        $this->assertSame($this->thread, $this->event->getThread());
39
+
40
+        $this->assertSame($this->event, $this->event->setThread($this->thread));
41
+        $this->assertSame($this->event, $this->event->setMaxRunningThreadNb(100));
42
+        $this->assertSame($this->event, $this->event->setEventName('fake'));
43
+        $this->assertSame($this->event, $this->event->setRunningThreadNb(10));
44
+        $this->assertSame($this->event, $this->event->setThreadDoneNb(90));
45
+        $this->assertSame($this->event, $this->event->setThreadLeftNb(10));
46
+        $this->assertSame($this->event, $this->event->setThreadNb(10));
47
+
48
+        $this->assertSame('fake', $this->event->getEventName());
49
+        $this->assertSame(100, $this->event->getMaxRunningThreadNb());
50
+        $this->assertSame(10, $this->event->getRunningThreadNb());
51
+        $this->assertSame(90, $this->event->getThreadDoneNb());
52
+        $this->assertSame(10, $this->event->getThreadLeftNb());
53
+        $this->assertSame(10, $this->event->getThreadNb());
54
+    }
55 55
 
56 56
 }
Please login to merge, or discard this patch.
tests/unit/ThreadTest.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -17,55 +17,55 @@
 block discarded – undo
17 17
  */
18 18
 class ThreadTest extends TestCase
19 19
 {
20
-	/** @var AbstractThread */
21
-	private $thread;
20
+    /** @var AbstractThread */
21
+    private $thread;
22 22
 
23
-	public function setUp()
24
-	{
25
-		$this->thread = new SuccessThread('unit-test');
26
-		$this->thread->setMediator(new Mediator());
27
-		$this->thread->setPid(1);
28
-	}
23
+    public function setUp()
24
+    {
25
+        $this->thread = new SuccessThread('unit-test');
26
+        $this->thread->setMediator(new Mediator());
27
+        $this->thread->setPid(1);
28
+    }
29 29
 
30
-	public function test_pid()
31
-	{
32
-		$this->assertSame(1, $this->thread->getPid());
33
-		$this->assertSame($this->thread, $this->thread->setPid(100));
34
-		$this->assertSame(100, $this->thread->getPid());
35
-	}
30
+    public function test_pid()
31
+    {
32
+        $this->assertSame(1, $this->thread->getPid());
33
+        $this->assertSame($this->thread, $this->thread->setPid(100));
34
+        $this->assertSame(100, $this->thread->getPid());
35
+    }
36 36
 
37
-	public function test_processName()
38
-	{
39
-		$this->assertSame('unit-test', $this->thread->getProcessName());
40
-	}
37
+    public function test_processName()
38
+    {
39
+        $this->assertSame('unit-test', $this->thread->getProcessName());
40
+    }
41 41
 
42
-	/**
43
-	 * @throws ThreadException
44
-	 */
45
-	public function test_run()
46
-	{
47
-		$this->assertSame(0, $this->thread->run());
48
-	}
42
+    /**
43
+     * @throws ThreadException
44
+     */
45
+    public function test_run()
46
+    {
47
+        $this->assertSame(0, $this->thread->run());
48
+    }
49 49
 
50
-	/**
51
-	 * @throws ThreadException
52
-	 */
53
-	public function test_run_exception()
54
-	{
55
-		$this->expectException(ThreadException::class);
56
-		$thread = new ExceptionThread('unit-test');
57
-		$thread->run();
50
+    /**
51
+     * @throws ThreadException
52
+     */
53
+    public function test_run_exception()
54
+    {
55
+        $this->expectException(ThreadException::class);
56
+        $thread = new ExceptionThread('unit-test');
57
+        $thread->run();
58 58
 
59
-	}
59
+    }
60 60
 
61
-	/**
62
-	 * @throws ThreadException
63
-	 */
64
-	public function test_run_exception_status()
65
-	{
66
-		$this->expectException(ThreadException::class);
67
-		$thread = new ErrorThread('unit-test');
68
-		$thread->run();
69
-	}
61
+    /**
62
+     * @throws ThreadException
63
+     */
64
+    public function test_run_exception_status()
65
+    {
66
+        $this->expectException(ThreadException::class);
67
+        $thread = new ErrorThread('unit-test');
68
+        $thread->run();
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
tests/unit/ThreadPoolTest.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -19,89 +19,89 @@
 block discarded – undo
19 19
  */
20 20
 class ThreadPoolTest extends TestCase
21 21
 {
22
-	/** @var ThreadPool */
23
-	private $threadPool;
24
-
25
-	protected function setUp()
26
-	{
27
-		$this->threadPool = new ThreadPool();
28
-	}
29
-
30
-	public function test_constructor_destructor()
31
-	{
32
-		$this->assertAttributeEquals([], 'threads', $this->threadPool);
33
-		$this->assertAttributeEquals([], 'runningThreads', $this->threadPool);
34
-		$this->assertAttributeEquals([], 'toRunThreads', $this->threadPool);
35
-		$this->assertAttributeEquals(false, 'isRunning', $this->threadPool);
36
-		$this->assertAttributeEquals(0, 'maxRunningThreadNb', $this->threadPool);
37
-
38
-		unset($this->threadPool);
39
-	}
40
-
41
-	public function test_getThreads()
42
-	{
43
-		$threads = [new SuccessThread('')];
44
-		$this->assertSame($this->threadPool, $this->threadPool->setThreads($threads));
45
-		$this->assertSame($threads, $this->threadPool->getThreads());
46
-	}
47
-
48
-	public function test_addThread()
49
-	{
50
-		$thread = new SuccessThread('');
51
-		$this->assertSame($this->threadPool, $this->threadPool->addThread($thread));
52
-		$this->assertContains($thread, $this->threadPool->getThreads());
53
-	}
54
-
55
-	public function test_getMaxRunningThreadNb()
56
-	{
57
-		$this->assertSame(0, $this->threadPool->getMaxRunningThreadNb());
58
-	}
59
-
60
-	public function test_setMaxRunningThreadNb()
61
-	{
62
-		$this->assertSame($this->threadPool, $this->threadPool->setMaxRunningThreadNb(10));
63
-		$this->assertSame(10, $this->threadPool->getMaxRunningThreadNb());
64
-	}
65
-
66
-	public function test_getToRunThreads()
67
-	{
68
-		$this->assertSame([], $this->threadPool->getToRunThreads());
69
-	}
70
-
71
-	public function test_getRunningThreads()
72
-	{
73
-		$this->assertSame([], $this->threadPool->getRunningThreads());
74
-	}
75
-
76
-	/**
77
-	 * @throws \Wonderland\Thread\Exception\ThreadException
78
-	 */
79
-	public function test_run()
80
-	{
81
-		$thread = new SuccessThread('');
82
-		$threads = [];
83
-		$listener = new TestListener();
84
-
85
-		$this->threadPool->setMaxRunningThreadNb(10);
86
-		$this->assertSame($this->threadPool, $this->threadPool->addListener($listener));
87
-		for ($i = 0; $i < 20; $i++) {
88
-			$threads[] = clone $thread;
89
-		}
90
-		$this->assertSame($this->threadPool, $this->threadPool->addThread($thread));
91
-		$this->assertSame($this->threadPool, $this->threadPool->setThreads($threads));
92
-
93
-		$this->threadPool->run();
94
-
95
-		$this->assertSame($this->threadPool, $this->threadPool->removeListener($listener));
96
-	}
97
-
98
-	/**
99
-	 * @throws ThreadException
100
-	 */
101
-	public function test_run_exception()
102
-	{
103
-		$this->expectException(ThreadException::class);
104
-		$this->threadPool->run();
105
-	}
22
+    /** @var ThreadPool */
23
+    private $threadPool;
24
+
25
+    protected function setUp()
26
+    {
27
+        $this->threadPool = new ThreadPool();
28
+    }
29
+
30
+    public function test_constructor_destructor()
31
+    {
32
+        $this->assertAttributeEquals([], 'threads', $this->threadPool);
33
+        $this->assertAttributeEquals([], 'runningThreads', $this->threadPool);
34
+        $this->assertAttributeEquals([], 'toRunThreads', $this->threadPool);
35
+        $this->assertAttributeEquals(false, 'isRunning', $this->threadPool);
36
+        $this->assertAttributeEquals(0, 'maxRunningThreadNb', $this->threadPool);
37
+
38
+        unset($this->threadPool);
39
+    }
40
+
41
+    public function test_getThreads()
42
+    {
43
+        $threads = [new SuccessThread('')];
44
+        $this->assertSame($this->threadPool, $this->threadPool->setThreads($threads));
45
+        $this->assertSame($threads, $this->threadPool->getThreads());
46
+    }
47
+
48
+    public function test_addThread()
49
+    {
50
+        $thread = new SuccessThread('');
51
+        $this->assertSame($this->threadPool, $this->threadPool->addThread($thread));
52
+        $this->assertContains($thread, $this->threadPool->getThreads());
53
+    }
54
+
55
+    public function test_getMaxRunningThreadNb()
56
+    {
57
+        $this->assertSame(0, $this->threadPool->getMaxRunningThreadNb());
58
+    }
59
+
60
+    public function test_setMaxRunningThreadNb()
61
+    {
62
+        $this->assertSame($this->threadPool, $this->threadPool->setMaxRunningThreadNb(10));
63
+        $this->assertSame(10, $this->threadPool->getMaxRunningThreadNb());
64
+    }
65
+
66
+    public function test_getToRunThreads()
67
+    {
68
+        $this->assertSame([], $this->threadPool->getToRunThreads());
69
+    }
70
+
71
+    public function test_getRunningThreads()
72
+    {
73
+        $this->assertSame([], $this->threadPool->getRunningThreads());
74
+    }
75
+
76
+    /**
77
+     * @throws \Wonderland\Thread\Exception\ThreadException
78
+     */
79
+    public function test_run()
80
+    {
81
+        $thread = new SuccessThread('');
82
+        $threads = [];
83
+        $listener = new TestListener();
84
+
85
+        $this->threadPool->setMaxRunningThreadNb(10);
86
+        $this->assertSame($this->threadPool, $this->threadPool->addListener($listener));
87
+        for ($i = 0; $i < 20; $i++) {
88
+            $threads[] = clone $thread;
89
+        }
90
+        $this->assertSame($this->threadPool, $this->threadPool->addThread($thread));
91
+        $this->assertSame($this->threadPool, $this->threadPool->setThreads($threads));
92
+
93
+        $this->threadPool->run();
94
+
95
+        $this->assertSame($this->threadPool, $this->threadPool->removeListener($listener));
96
+    }
97
+
98
+    /**
99
+     * @throws ThreadException
100
+     */
101
+    public function test_run_exception()
102
+    {
103
+        $this->expectException(ThreadException::class);
104
+        $this->threadPool->run();
105
+    }
106 106
 
107 107
 }
Please login to merge, or discard this patch.
src/Factory/EventPoolFactory.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -10,27 +10,27 @@
 block discarded – undo
10 10
 class EventPoolFactory
11 11
 {
12 12
 
13
-	/**
14
-	 * @param string                                $eventName
15
-	 * @param ThreadPool|AbstractThreadPoolMediator $pool
16
-	 * @param AbstractThread|null                   $thread
17
-	 * @return PoolEvent
18
-	 */
19
-	public static function create(
20
-		string $eventName,
21
-		AbstractThreadPoolMediator $pool,
22
-		?AbstractThread $thread = null
23
-	): PoolEvent
24
-	{
25
-		$event = new PoolEvent($eventName);
26
-		$event->setThreadNb(count($pool->getThreads()));
27
-		$event->setThreadDoneNb(count($pool->getThreads()) - count($pool->getToRunThreads()));
28
-		$event->setMaxRunningThreadNb($pool->getMaxRunningThreadNb());
29
-		$event->setThreadLeftNb(count($pool->getToRunThreads()));
30
-		$event->setRunningThreadNb(count($pool->getRunningThreads()));
31
-		$event->setThread($thread);
13
+    /**
14
+     * @param string                                $eventName
15
+     * @param ThreadPool|AbstractThreadPoolMediator $pool
16
+     * @param AbstractThread|null                   $thread
17
+     * @return PoolEvent
18
+     */
19
+    public static function create(
20
+        string $eventName,
21
+        AbstractThreadPoolMediator $pool,
22
+        ?AbstractThread $thread = null
23
+    ): PoolEvent
24
+    {
25
+        $event = new PoolEvent($eventName);
26
+        $event->setThreadNb(count($pool->getThreads()));
27
+        $event->setThreadDoneNb(count($pool->getThreads()) - count($pool->getToRunThreads()));
28
+        $event->setMaxRunningThreadNb($pool->getMaxRunningThreadNb());
29
+        $event->setThreadLeftNb(count($pool->getToRunThreads()));
30
+        $event->setRunningThreadNb(count($pool->getRunningThreads()));
31
+        $event->setThread($thread);
32 32
 
33
-		return $event;
34
-	}
33
+        return $event;
34
+    }
35 35
 
36 36
 }
Please login to merge, or discard this patch.
src/Mediator/Mediator.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -7,50 +7,50 @@
 block discarded – undo
7 7
 
8 8
 class Mediator
9 9
 {
10
-	/** @var ListenerInterface[] */
11
-	private $listeners = [];
12
-
13
-	/**
14
-	 * @return ListenerInterface[]
15
-	 */
16
-	public function getListeners(): array
17
-	{
18
-		return $this->listeners;
19
-	}
20
-
21
-	/**
22
-	 * @param ListenerInterface $listener
23
-	 * @return Mediator
24
-	 */
25
-	public function addListener(ListenerInterface $listener): self
26
-	{
27
-		$this->listeners[] = $listener;
28
-
29
-		return $this;
30
-	}
31
-
32
-	/**
33
-	 * @param ListenerInterface $listener
34
-	 * @return Mediator
35
-	 */
36
-	public function removeListener(ListenerInterface $listener): self
37
-	{
38
-		$key = array_search($listener, $this->listeners, true);
39
-		if (false !== $key) {
40
-			unset($this->listeners[$key]);
41
-		}
42
-
43
-		return $this;
44
-	}
45
-
46
-	/**
47
-	 * @param EventInterface $event
48
-	 */
49
-	public function notify(EventInterface $event)
50
-	{
51
-		foreach ($this->listeners as $listener) {
52
-			$listener->notify($event);
53
-		}
54
-	}
10
+    /** @var ListenerInterface[] */
11
+    private $listeners = [];
12
+
13
+    /**
14
+     * @return ListenerInterface[]
15
+     */
16
+    public function getListeners(): array
17
+    {
18
+        return $this->listeners;
19
+    }
20
+
21
+    /**
22
+     * @param ListenerInterface $listener
23
+     * @return Mediator
24
+     */
25
+    public function addListener(ListenerInterface $listener): self
26
+    {
27
+        $this->listeners[] = $listener;
28
+
29
+        return $this;
30
+    }
31
+
32
+    /**
33
+     * @param ListenerInterface $listener
34
+     * @return Mediator
35
+     */
36
+    public function removeListener(ListenerInterface $listener): self
37
+    {
38
+        $key = array_search($listener, $this->listeners, true);
39
+        if (false !== $key) {
40
+            unset($this->listeners[$key]);
41
+        }
42
+
43
+        return $this;
44
+    }
45
+
46
+    /**
47
+     * @param EventInterface $event
48
+     */
49
+    public function notify(EventInterface $event)
50
+    {
51
+        foreach ($this->listeners as $listener) {
52
+            $listener->notify($event);
53
+        }
54
+    }
55 55
 
56 56
 }
Please login to merge, or discard this patch.