/** * Tests connecting callables to events * @return void */ public function testConnect() { $collection = new Collection(); $mock = new ListenerMock(); $mockself = new ListenerMockSelfConnect(); $collection->connect('event1', array($mock, 'listen1')); $this->assertEquals(1, $collection->count()); $this->assertInstanceOf('Nimbles\\Core\\Event', $collection['event1']); $this->assertEquals('event1', $collection['event1']->getName()); $this->assertEquals(1, $collection['event1']->count()); $this->assertSame(array(array($mock, 'listen1')), $collection['event1']->getArrayCopy()); $collection->connect('event1', array($mock, 'listen2')); $this->assertEquals(1, $collection->count()); $this->assertEquals(2, $collection['event1']->count()); $this->assertSame(array(array($mock, 'listen1'), array($mock, 'listen2')), $collection['event1']->getArrayCopy()); $collection->connect('event2', array(array($mock, 'listen3'))); $this->assertEquals(2, $collection->count()); $this->assertInstanceOf('Nimbles\\Core\\Event', $collection['event2']); $this->assertEquals('event2', $collection['event2']->getName()); $this->assertEquals(1, $collection['event2']->count()); $this->assertSame(array(array($mock, 'listen3')), $collection['event2']->getArrayCopy()); $collection->connect($mockself); $this->assertEquals(3, $collection->count()); $this->assertEquals(3, $collection['event1']->count()); $this->assertSame(array(array($mock, 'listen1'), array($mock, 'listen2'), array($mockself, 'listen1')), $collection['event1']->getArrayCopy()); $this->assertEquals(2, $collection['event2']->count()); $this->assertSame(array(array($mock, 'listen3'), array($mockself, 'listen2')), $collection['event2']->getArrayCopy()); $this->assertInstanceOf('Nimbles\\Core\\Event', $collection['event3']); $this->assertEquals('event3', $collection['event3']->getName()); $this->assertEquals(1, $collection['event3']->count()); $this->assertSame(array(array($mockself, 'listen3')), $collection['event3']->getArrayCopy()); $this->setExpectedException('Nimbles\\Core\\Event\\Exception\\InvalidConnections'); $collection->connect(new ListenerMockInvalidSelfConnect()); }