2, 'slug' => 'article-slug', ]); $route = $route = new EntityRoute( '/articles/:category_id/:slug', [ '_name' => 'articlesView', ] ); $result = $route->match([ 'slug' => 'other-slug', '_entity' => $entity, '_name' => 'articlesView', ]); $this->assertEquals('/articles/2/other-slug', $result); } /** * test that routes match their pattern. * * @return void */ public function testMatchEntityObject() { $entity = new Article([ 'category_id' => 2, 'slug' => 'article-slug', ]); $route = $route = new EntityRoute( '/articles/:category_id/:slug', [ '_name' => 'articlesView', ] ); $result = $route->match([ '_entity' => $entity, '_name' => 'articlesView', ]); $this->assertEquals('/articles/2/article-slug', $result); } /** * test that routes match their pattern. * * @return void */ public function testMatchUnderscoreBetweenVar() { $entity = new Article([ 'category_id' => 2, 'slug' => 'article-slug', ]); $route = $route = new EntityRoute( '/articles/:category_id_:slug', [ '_name' => 'articlesView', ] ); $result = $route->match([ '_entity' => $entity, '_name' => 'articlesView', ]); $this->assertEquals('/articles/2_article-slug', $result); } /** * test that routes match their pattern. * * @return void */ public function testMatchingArray() { $entity = [ 'category_id' => 2, 'slug' => 'article-slug', ]; $route = new EntityRoute( '/articles/:category_id/:slug', [ '_name' => 'articlesView', '_entity' => $entity, ] ); $result = $route->match([ '_entity' => $entity, '_name' => 'articlesView', ]); $this->assertEquals('/articles/2/article-slug', $result); } /** * Test invalid entity option value * * @expectedException \RuntimeException * @expectedExceptionMessage Route `/` expects the URL option `_entity` to be an array or object implementing \ArrayAccess, but `string` passed. */ public function testInvalidEntityValueException() { $route = new EntityRoute('/', [ '_entity' => 'Something else', ]); $route->match([ '_entity' => 'something-else', ]); } }