Completed
Push — master ( ffb65a...cd6af5 )
by mw
01:39
created

DispatchContextTest::testNewFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Onoi\EventDispatcher\Tests;
4
5
use Onoi\EventDispatcher\DispatchContext;
6
7
/**
8
 * @covers \Onoi\EventDispatcher\DispatchContext
9
 *
10
 * @group onoi-event-dispatcher
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class DispatchContextTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$this->assertInstanceOf(
22
			'\Onoi\EventDispatcher\DispatchContext',
23
			new DispatchContext()
24
		);
25
	}
26
27
	public function testRoundtrip() {
28
29
		$instance = new DispatchContext();
30
31
		$this->assertFalse(
32
			$instance->has( 'FOO' )
33
		);
34
35
		$instance->set( 'foo', 'bar' );
36
37
		$this->assertTrue(
38
			$instance->has( 'FOO' )
39
		);
40
41
		$this->assertEquals(
42
			'bar',
43
			$instance->get( 'FOO' )
44
		);
45
46
		$instance->set( 'foo', new \stdClass );
47
48
		$this->assertEquals(
49
			new \stdClass,
50
			$instance->get( 'FOO' )
51
		);
52
	}
53
54
	public function testNewFromArray() {
55
56
		$instance = DispatchContext::newFromArray( [ 'FOO' => 123 ] );
57
58
		$this->assertTrue(
59
			$instance->has( 'FOO' )
60
		);
61
62
		$this->assertEquals(
63
			123,
64
			$instance->get( 'foo' )
65
		);
66
	}
67
68
	public function testChangePropagationState() {
69
70
		$instance = new DispatchContext();
71
72
		$this->assertFalse(
73
			$instance->isPropagationStopped()
74
		);
75
76
		$instance->set( 'proPagationSTOP', true );
77
78
		$this->assertTrue(
79
			$instance->isPropagationStopped()
80
		);
81
	}
82
83
	public function testUnknownKeyThrowsException() {
84
85
		$instance = new DispatchContext();
86
87
		$this->setExpectedException( 'InvalidArgumentException' );
88
		$instance->get( 'FOO' );
89
	}
90
91
}
92