errorLevel = error_reporting(E_ALL ^ E_USER_DEPRECATED); } /** * teardown function * * @return void */ public function tearDown() { parent::tearDown(); error_reporting($this->errorLevel); } /** * Test add filter * * @return void */ public function testAddFilter() { $mw = $this->getMockBuilder('Cake\Routing\DispatcherFilter') ->setMethods(['beforeDispatch']) ->getMock(); $result = DispatcherFactory::add($mw); $this->assertSame($mw, $result); } /** * Test add filter as a string * * @return void */ public function testAddFilterString() { $result = DispatcherFactory::add('Routing'); $this->assertInstanceOf('Cake\Routing\Filter\RoutingFilter', $result); } /** * Test add filter missing * * @return void */ public function testAddFilterMissing() { $this->expectException(\Cake\Routing\Exception\MissingDispatcherFilterException::class); DispatcherFactory::add('NopeSauce'); } /** * Test add filter * * @return void */ public function testAddFilterWithOptions() { $config = ['config' => 'value', 'priority' => 999]; $result = DispatcherFactory::add('Routing', $config); $this->assertInstanceOf('Cake\Routing\Filter\RoutingFilter', $result); $this->assertEquals($config['config'], $result->getConfig('config')); $this->assertEquals($config['priority'], $result->getConfig('priority')); } /** * Test creating a dispatcher with the factory * * @return void */ public function testCreate() { $mw = $this->getMockBuilder('Cake\Routing\DispatcherFilter') ->setMethods(['beforeDispatch']) ->getMock(); DispatcherFactory::add($mw); $result = DispatcherFactory::create(); $this->assertInstanceOf('Cake\Routing\Dispatcher', $result); $this->assertCount(1, $result->filters()); } /** * test create() -> dispatch() -> response flow. * * @return void */ public function testCreateDispatchWithFilters() { $url = new ServerRequest([ 'url' => 'posts', 'params' => [ 'controller' => 'Posts', 'action' => 'index', 'pass' => [], 'bare' => true, ], ]); $response = $this->getMockBuilder('Cake\Http\Response') ->setMethods(['send']) ->getMock(); $response->expects($this->once()) ->method('send') ->will($this->returnSelf()); DispatcherFactory::add('ControllerFactory'); DispatcherFactory::add('Append'); $dispatcher = DispatcherFactory::create(); $result = $dispatcher->dispatch($url, $response); $this->assertEquals('posts index appended content', $result->body()); } }