Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / event-dispatcher / Tests / GenericEventTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\EventDispatcher\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\EventDispatcher\GenericEvent;
16
17 /**
18  * Test class for Event.
19  */
20 class GenericEventTest extends TestCase
21 {
22     /**
23      * @var GenericEvent
24      */
25     private $event;
26
27     private $subject;
28
29     /**
30      * Prepares the environment before running a test.
31      */
32     protected function setUp()
33     {
34         $this->subject = new \stdClass();
35         $this->event = new GenericEvent($this->subject, array('name' => 'Event'));
36     }
37
38     /**
39      * Cleans up the environment after running a test.
40      */
41     protected function tearDown()
42     {
43         $this->subject = null;
44         $this->event = null;
45     }
46
47     public function testConstruct()
48     {
49         $this->assertEquals($this->event, new GenericEvent($this->subject, array('name' => 'Event')));
50     }
51
52     /**
53      * Tests Event->getArgs().
54      */
55     public function testGetArguments()
56     {
57         // test getting all
58         $this->assertSame(array('name' => 'Event'), $this->event->getArguments());
59     }
60
61     public function testSetArguments()
62     {
63         $result = $this->event->setArguments(array('foo' => 'bar'));
64         $this->assertAttributeSame(array('foo' => 'bar'), 'arguments', $this->event);
65         $this->assertSame($this->event, $result);
66     }
67
68     public function testSetArgument()
69     {
70         $result = $this->event->setArgument('foo2', 'bar2');
71         $this->assertAttributeSame(array('name' => 'Event', 'foo2' => 'bar2'), 'arguments', $this->event);
72         $this->assertEquals($this->event, $result);
73     }
74
75     public function testGetArgument()
76     {
77         // test getting key
78         $this->assertEquals('Event', $this->event->getArgument('name'));
79     }
80
81     /**
82      * @expectedException \InvalidArgumentException
83      */
84     public function testGetArgException()
85     {
86         $this->event->getArgument('nameNotExist');
87     }
88
89     public function testOffsetGet()
90     {
91         // test getting key
92         $this->assertEquals('Event', $this->event['name']);
93
94         // test getting invalid arg
95         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
96         $this->assertFalse($this->event['nameNotExist']);
97     }
98
99     public function testOffsetSet()
100     {
101         $this->event['foo2'] = 'bar2';
102         $this->assertAttributeSame(array('name' => 'Event', 'foo2' => 'bar2'), 'arguments', $this->event);
103     }
104
105     public function testOffsetUnset()
106     {
107         unset($this->event['name']);
108         $this->assertAttributeSame(array(), 'arguments', $this->event);
109     }
110
111     public function testOffsetIsset()
112     {
113         $this->assertArrayHasKey('name', $this->event);
114         $this->assertArrayNotHasKey('nameNotExist', $this->event);
115     }
116
117     public function testHasArgument()
118     {
119         $this->assertTrue($this->event->hasArgument('name'));
120         $this->assertFalse($this->event->hasArgument('nameNotExist'));
121     }
122
123     public function testGetSubject()
124     {
125         $this->assertSame($this->subject, $this->event->getSubject());
126     }
127
128     public function testHasIterator()
129     {
130         $data = array();
131         foreach ($this->event as $key => $value) {
132             $data[$key] = $value;
133         }
134         $this->assertEquals(array('name' => 'Event'), $data);
135     }
136 }