Completed
Pull Request — master (#4)
by mw
18:43 queued 17:12
created

CallFuncMemorySnifferTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 7 1
A testCallWithoutArguments() 0 19 1
A testCallWithArguments() 0 19 1
A testInvalidCallThrowsException() 0 7 1
1
<?php
2
3
namespace Onoi\CallbackContainer\Tests;
4
5
use Onoi\CallbackContainer\CallFuncMemorySniffer;
6
7
/**
8
 * @covers \Onoi\CallbackContainer\CallFuncMemorySniffer
9
 * @group onoi-callback-container
10
 *
11
 * @license GNU GPL v2+
12
 * @since 2.0
13
 *
14
 * @author mwjames
15
 */
16
class CallFuncMemorySnifferTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testCanConstruct() {
19
20
		$this->assertInstanceOf(
21
			'\Onoi\CallbackContainer\CallFuncMemorySniffer',
22
			new CallFuncMemorySniffer()
23
		);
24
	}
25
26
	public function testCallWithoutArguments() {
27
28
		$instance = new CallFuncMemorySniffer();
29
30
		$this->assertEquals(
31
			'Foo',
32
			$instance->call( function(){ return 'Foo'; } )
33
		);
34
35
		$this->assertInternalType(
36
			'integer',
37
			$instance->getMemoryUsed()
38
		);
39
40
		$this->assertInternalType(
41
			'float',
42
			$instance->getTimeUsed()
43
		);
44
	}
45
46
	public function testCallWithArguments() {
47
48
		$instance = new CallFuncMemorySniffer();
49
50
		$this->assertEquals(
51
			'Foo-abc',
52
			$instance->call( function( $arg ) { return 'Foo-'. $arg; }, array( 'abc' ) )
53
		);
54
55
		$this->assertInternalType(
56
			'integer',
57
			$instance->getMemoryUsed()
58
		);
59
60
		$this->assertInternalType(
61
			'float',
62
			$instance->getTimeUsed()
63
		);
64
	}
65
66
	public function testInvalidCallThrowsException() {
67
68
		$instance = new CallFuncMemorySniffer();
69
70
		$this->setExpectedException( 'RuntimeException' );
71
		$instance->call( 'foo' );
72
	}
73
74
}
75