/** * Tests the JEventDispatcher::getInstance method. * * @return void * * @since 11.3 * @covers JEventDispatcher::getInstance */ public function testGetInstance() { $mock = JEventDispatcher::getInstance(); $this->assertInstanceOf( 'JEventDispatcherInspector', $mock ); $this->object->setInstance(null); $instance = JEventDispatcher::getInstance(); $this->assertInstanceOf( 'JEventDispatcher', $instance, 'Tests that getInstance returns a JEventDispatcher object.' ); // Push a new instance into the class. JEventDispatcherInspector::setInstance('foo'); $this->assertThat( JEventDispatcher::getInstance(), $this->equalTo('foo'), 'Tests that a subsequent call to JEventDispatcher::getInstance returns the cached singleton.' ); JEventDispatcherInspector::setInstance($mock); }
/** * Allows the internal singleton to be set and mocked. * * @param JEventDispatcher $instance A dispatcher object. * * @return void * * @since 11.3 */ public function setInstance($instance) { self::$instance = $instance; }