Skip to content

Commit

Permalink
Merge pull request #2317 from Haehnchen/feature/service-controller
Browse files Browse the repository at this point in the history
provide more tests for special route placeholder metadata syntax and provide a cleanup method to filter them out for presentable
  • Loading branch information
Haehnchen authored Mar 30, 2024
2 parents feefbd8 + 010cd2d commit 56a8a59
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void processElementsWithName(@NotNull String name, @NotNull Processor<? s

processor.process((NavigationItemPresentableOverwrite.create(
entry.getSecond(),
path,
route.getPathPresentable(),
Symfony2Icons.ROUTE,
"Symfony Route",
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ public String getPath() {
return path;
}

/**
* Replace all special placeholder metadata to have just the variable
*
* - /{page3<\d+>!}/ => /{page3}/
*/
public String getPathPresentable() {
return this.path.replaceAll("\\{!?(\\w+)[<[^}].*>]*}", "{$1}");
}

@NotNull
@Override
public Collection<String> getMethods() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,37 @@ public void testPathVariablesForDefault() {
assertTrue(variables.containsAll(Arrays.asList("foo", "foobar", "Foobar2")));
}

@Test
public void testPathVariablesForDefault2() {
StubIndexedRoute route = new StubIndexedRoute("foobar");
route.setPath("/foo/{!foo<.*>}/aaa{foobar<.*>}aaa/{page<\\d+>!1}/{page2<\\d+}>}/aaaa/{page3<\\{}d+}>}/");

Set<String> variables = new Route(route).getVariables();
assertEquals(5, variables.size());
assertTrue(variables.containsAll(Arrays.asList("foo", "foobar", "page", "page2", "page3")));
}

@Test
public void testPathVariablesForWildcardInlineRequirements() {
StubIndexedRoute route = new StubIndexedRoute("foobar");
route.setPath("/foo/{!foo<.*>}/aaa{foobar<.*>}aaa/{page<\\d+>}/{page2<\\d+}>}/aaaa/{page3<\\{}d+}>}/");
route.setPath("/foo/{!foo<.*>}/aaa{foobar<.*>}aaa/{page<\\d+>}/{page2<\\d+>}}/aaaa/{page3<\\d+>}/");

Set<String> variables = new Route(route).getVariables();
assertEquals(5, variables.size());

assertTrue(variables.containsAll(Arrays.asList("foo", "foobar", "page", "page2", "page3")));
}

@Test
public void testPathPresentable() {
StubIndexedRoute route = new StubIndexedRoute("foobar");
route.setPath("/foo/{!foo<.*>}/aaa{foobar<.*>}aaa/{page<\\d+>}/{page2<\\d+>}}/aaaa/{page3<\\d+>}/");
Route route1 = new Route(route);
assertEquals("/foo/{foo}/aaa{foobar}aaa/{page}/{page2}}/aaaa/{page3}/", route1.getPathPresentable());

route = new StubIndexedRoute("foobar");
route.setPath("/blog/{page<\\d+>?1}/{page1<\\d+>?!car}/{page2<\\d+>?!1}/{parameter_name?default_value}");
Route route2 = new Route(route);
assertEquals("/blog/{page}/{page1}/{page2}/{parameter_name}", route2.getPathPresentable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public void testAnnotationIndexOfMethodPatternAndClassPrefixWithSpecialPath() {

assertEquals("blog_home_special", route.getName());
assertEquals("/foo/edit/{!id<.*>}/{!id<\\d+>}////", route.getPath());

RouteInterface route1 = getFirstValue("blog_home_the_special_placeholder_one");
assertEquals("/blog/{page<\\d+>?1}/{page1<\\d+>?}/{page2<\\d+>?}/{parameter_name?default_value}", route1.getPath());
}

public void testAnnotationThatEmptyRouteNameUseBundleMethodName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public function attributesPathFoo2()
{
}

#[Route('/blog/{page<\d+>?1}/{page1<\d+>?}/{page2<\d+>?}/{parameter_name?default_value}', name: "blog_home_the_special_placeholder_one")]
public function theSpecialPlaceholderOne()
{
}

#[Route([
'cs' => '/foobar/baz/{id}',
'sk' => '/foobarbaz/bat/{id}',
Expand Down

0 comments on commit 56a8a59

Please sign in to comment.