diff --git a/README.md b/README.md index 0f6f734..af743fb 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,7 @@ return [ Tiime\TestedRoutesCheckerBundle\TiimeTestedRoutesCheckerBundle::class => ['dev' => true, 'test' => true], ]; ``` + +## Using baseline to ignore some routes + +You can ignore some routes with a `.tiime-trc-baseline` file with 1 route per line. diff --git a/src/IgnoredRoutesStorage.php b/src/IgnoredRoutesStorage.php index 4eed8dc..b7166b5 100644 --- a/src/IgnoredRoutesStorage.php +++ b/src/IgnoredRoutesStorage.php @@ -53,6 +53,18 @@ public function getRoutes(): array throw new \RuntimeException('Unable to load ignored routes from given file.'); } + $routes = array_filter($routes, static function (string $route): bool { + return !str_starts_with($route, '#') && '' !== $route; + }); + + $routes = array_map(static function (string $route): string { + if (false === $pos = stripos($route, ' #')) { + return $route; + } + + return mb_substr($route, 0, $pos); + }, $routes); + return array_values(array_unique($routes)); } } diff --git a/tests/IgnoredRoutesStorageTest.php b/tests/IgnoredRoutesStorageTest.php index 83cd433..0f321dd 100644 --- a/tests/IgnoredRoutesStorageTest.php +++ b/tests/IgnoredRoutesStorageTest.php @@ -26,8 +26,10 @@ public function testStorage(): void $this->assertSame([], $storage->getRoutes()); $storage->saveRoute('route1'); - $storage->saveRoute('route2'); + $storage->saveRoute('route2 # This comment will be ignored'); + $storage->saveRoute(''); // Empty line will be ignored $storage->saveRoute('route3'); + $storage->saveRoute('# This is a comment which will be ignored'); $storage->saveRoute('route2'); $storage->saveRoutes(['route2', 'route4', 'route5']);