Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public static function asRoutePath(string $value): string

public static function asRouteName(string $value): string
{
return self::asTwigVariable($value);
$routeName = self::asTwigVariable($value);

return str_starts_with($routeName, 'app_') ? $routeName : 'app_'.$routeName;
}

public static function asSnakeCase(string $value): string
Expand Down
2 changes: 1 addition & 1 deletion src/Test/MakerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function getMakerInstance(string $makerClass): MakerInterface
}

// a cheap way to guess the service id
$serviceId = $serviceId ?? sprintf('maker.maker.%s', Str::asRouteName((new \ReflectionClass($makerClass))->getShortName()));
$serviceId = $serviceId ?? sprintf('maker.maker.%s', Str::asSnakeCase((new \ReflectionClass($makerClass))->getShortName()));

return $this->kernel->getContainer()->get($serviceId);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,19 @@ public function asHumanWordsTests()
yield [' FooBar', 'Foo Bar'];
yield [' Foo Bar ', 'Foo Bar'];
}

/**
* @dataProvider provideAsRouteName
*/
public function testAsRouteName(string $value, string $expectedRouteName)
{
$this->assertSame($expectedRouteName, Str::asRouteName($value));
}

public function provideAsRouteName()
{
yield ['Example', 'app_example'];
yield ['AppExample', 'app_example'];
yield ['Apple', 'app_apple'];
}
}