Completed
Push — master ( 8d6a89...35c84b )
by Aimeos
09:03
created

PcntlTest::testRunException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Aimeos\MW\Process;
4
5
6
class PcntlTest extends \PHPUnit\Framework\TestCase
7
{
8
	protected function setUp()
9
	{
10
		if( function_exists( 'pcntl_fork' ) === false ) {
11
			$this->markTestSkipped( 'PCNTL extension not available' );
12
		}
13
	}
14
15
16
	public function testIsAvailable()
17
	{
18
		$object = new \Aimeos\MW\Process\Pcntl();
19
		$this->assertTrue( $object->isAvailable() );
20
	}
21
22
23
	public function testRun()
24
	{
25
		$fcn = function() { sleep( 1 ); };
26
		$start = microtime( true );
27
28
		$object = new \Aimeos\MW\Process\Pcntl();
29
		$object->start( $fcn, [] )->start( $fcn, [] )->wait();
30
31
		$msec = ( microtime( true ) - $start );
32
		$this->assertGreaterThan( 1, $msec );
33
		$this->assertLessThan( 2, $msec );
34
	}
35
36
37
	public function testRunException()
38
	{
39
		$fcn = function() { throw new \Exception(); };
40
41
		$object = new \Aimeos\MW\Process\Pcntl();
42
43
		$this->setExpectedException( '\Aimeos\MW\Process\Exception' );
44
		$object->start( $fcn, [], true )->wait();
45
	}
46
}
47