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

CallFuncMemorySnifferTest::testCanConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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