annotate vendor/symfony/event-dispatcher/Tests/GenericEventTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
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 $this->subject = new \stdClass();
Chris@17 35 $this->event = new GenericEvent($this->subject, ['name' => 'Event']);
Chris@0 36 }
Chris@0 37
Chris@0 38 /**
Chris@0 39 * Cleans up the environment after running a test.
Chris@0 40 */
Chris@0 41 protected function tearDown()
Chris@0 42 {
Chris@0 43 $this->subject = null;
Chris@0 44 $this->event = null;
Chris@0 45 }
Chris@0 46
Chris@0 47 public function testConstruct()
Chris@0 48 {
Chris@17 49 $this->assertEquals($this->event, new GenericEvent($this->subject, ['name' => 'Event']));
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Tests Event->getArgs().
Chris@0 54 */
Chris@0 55 public function testGetArguments()
Chris@0 56 {
Chris@0 57 // test getting all
Chris@17 58 $this->assertSame(['name' => 'Event'], $this->event->getArguments());
Chris@0 59 }
Chris@0 60
Chris@0 61 public function testSetArguments()
Chris@0 62 {
Chris@17 63 $result = $this->event->setArguments(['foo' => 'bar']);
Chris@17 64 $this->assertAttributeSame(['foo' => 'bar'], 'arguments', $this->event);
Chris@0 65 $this->assertSame($this->event, $result);
Chris@0 66 }
Chris@0 67
Chris@0 68 public function testSetArgument()
Chris@0 69 {
Chris@0 70 $result = $this->event->setArgument('foo2', 'bar2');
Chris@17 71 $this->assertAttributeSame(['name' => 'Event', 'foo2' => 'bar2'], 'arguments', $this->event);
Chris@0 72 $this->assertEquals($this->event, $result);
Chris@0 73 }
Chris@0 74
Chris@0 75 public function testGetArgument()
Chris@0 76 {
Chris@0 77 // test getting key
Chris@0 78 $this->assertEquals('Event', $this->event->getArgument('name'));
Chris@0 79 }
Chris@0 80
Chris@0 81 /**
Chris@0 82 * @expectedException \InvalidArgumentException
Chris@0 83 */
Chris@0 84 public function testGetArgException()
Chris@0 85 {
Chris@0 86 $this->event->getArgument('nameNotExist');
Chris@0 87 }
Chris@0 88
Chris@0 89 public function testOffsetGet()
Chris@0 90 {
Chris@0 91 // test getting key
Chris@0 92 $this->assertEquals('Event', $this->event['name']);
Chris@0 93
Chris@0 94 // test getting invalid arg
Chris@0 95 $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
Chris@0 96 $this->assertFalse($this->event['nameNotExist']);
Chris@0 97 }
Chris@0 98
Chris@0 99 public function testOffsetSet()
Chris@0 100 {
Chris@0 101 $this->event['foo2'] = 'bar2';
Chris@17 102 $this->assertAttributeSame(['name' => 'Event', 'foo2' => 'bar2'], 'arguments', $this->event);
Chris@0 103 }
Chris@0 104
Chris@0 105 public function testOffsetUnset()
Chris@0 106 {
Chris@0 107 unset($this->event['name']);
Chris@17 108 $this->assertAttributeSame([], 'arguments', $this->event);
Chris@0 109 }
Chris@0 110
Chris@0 111 public function testOffsetIsset()
Chris@0 112 {
Chris@14 113 $this->assertArrayHasKey('name', $this->event);
Chris@14 114 $this->assertArrayNotHasKey('nameNotExist', $this->event);
Chris@0 115 }
Chris@0 116
Chris@0 117 public function testHasArgument()
Chris@0 118 {
Chris@0 119 $this->assertTrue($this->event->hasArgument('name'));
Chris@0 120 $this->assertFalse($this->event->hasArgument('nameNotExist'));
Chris@0 121 }
Chris@0 122
Chris@0 123 public function testGetSubject()
Chris@0 124 {
Chris@0 125 $this->assertSame($this->subject, $this->event->getSubject());
Chris@0 126 }
Chris@0 127
Chris@0 128 public function testHasIterator()
Chris@0 129 {
Chris@17 130 $data = [];
Chris@0 131 foreach ($this->event as $key => $value) {
Chris@0 132 $data[$key] = $value;
Chris@0 133 }
Chris@17 134 $this->assertEquals(['name' => 'Event'], $data);
Chris@0 135 }
Chris@0 136 }