io = $this->getMock('Cake\Console\ConsoleIo', ['table', 'out', 'err']); $this->shell = new RoutesShell($this->io); Router::connect('/articles/:action/*', ['controller' => 'Articles']); Router::connect('/bake/:controller/:action', ['plugin' => 'Bake']); } /** * tearDown * * @return void */ public function tearDown() { parent::tearDown(); Router::reload(); unset($this->io, $this->shell); } /** * Test checking an non-existing route. * * @return void */ public function testMain() { $this->io->expects($this->at(0)) ->method('table') ->with( $this->logicalAnd( $this->contains(['Route name', 'URI template', 'Defaults']), $this->contains([ 'articles:_action', '/articles/:action/*', '{"controller":"Articles","action":"index","plugin":null}' ]) ) ); $this->shell->main(); } /** * Test checking an existing route. * * @return void */ public function testCheck() { $this->io->expects($this->at(0)) ->method('table') ->with( $this->logicalAnd( $this->contains(['Route name', 'URI template', 'Defaults']), $this->contains([ '', '/articles/index', '{"action":"index","pass":[],"controller":"Articles","plugin":null}' ]) ) ); $this->shell->check('/articles/index'); } /** * Test checking an non-existing route. * * @return void */ public function testCheckNotFound() { $this->io->expects($this->at(0)) ->method('err') ->with($this->stringContains('did not match')); $this->shell->check('/nope'); } /** * Test generating URLs * * @return void */ public function testGenerate() { $this->io->expects($this->never()) ->method('err'); $this->io->expects($this->at(0)) ->method('out') ->with($this->stringContains('> /articles/index')); $this->io->expects($this->at(1)) ->method('out') ->with($this->stringContains('> /articles/view/2/3')); $this->shell->args = ['controller:Articles', 'action:index']; $this->shell->generate(); $this->shell->args = ['controller:Articles', 'action:view', '2', '3']; $this->shell->generate(); } /** * Test generating URLs * * @return void */ public function testGenerateMissing() { $this->io->expects($this->at(0)) ->method('err') ->with($this->stringContains('do not match')); $this->shell->args = ['controller:Derp']; $this->shell->generate(); } }