Passed
Pull Request — master (#10)
by Alice
02:01
created

ThreadTest::test_run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wonderland\Thread\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use Wonderland\Thread\Exception\ThreadException;
7
use Wonderland\Thread\AbstractThread;
8
use Wonderland\Thread\Mediator\Mediator;
9
use Wonderland\Thread\Tests\Implementation\ErrorThread;
10
use Wonderland\Thread\Tests\Implementation\ExceptionThread;
11
use Wonderland\Thread\Tests\Implementation\SuccessThread;
12
13
/**
14
 * Class ThreadTest
15
 * @package Wonderland\Thread\Tests
16
 * @author Alice Praud <[email protected]>
17
 */
18
class ThreadTest extends TestCase
19
{
20
	/** @var AbstractThread */
21
	private $thread;
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
	}
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
	}
36
37
	public function test_processName()
38
	{
39
		$this->assertSame('unit-test', $this->thread->getProcessName());
40
	}
41
42
	/**
43
	 * @throws ThreadException
44
	 */
45
	public function test_run()
46
	{
47
		$this->assertSame(0, $this->thread->run());
48
	}
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();
58
59
	}
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
	}
70
71
}
72