annotate vendor/symfony/event-dispatcher/Tests/GenericEventTest.php @ 0:4c8ae668cc8c

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