Passed
Branch master (dae886)
by Alice
02:15
created

ThreadTest::test_pid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
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\Thread;
8
9
/**
10
 * Class ThreadTest
11
 * @package Wonderland\Thread\Tests
12
 * @author Alice Praud <[email protected]>
13
 */
14
class ThreadTest extends TestCase
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
	}
89
90
}
91