Skip to content

Commit 78e5bd6

Browse files
authored
Allow comments & empty lines in baseline (#29)
1 parent c288c1a commit 78e5bd6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ return [
4545
Tiime\TestedRoutesCheckerBundle\TiimeTestedRoutesCheckerBundle::class => ['dev' => true, 'test' => true],
4646
];
4747
```
48+
49+
## Using baseline to ignore some routes
50+
51+
You can ignore some routes with a `.tiime-trc-baseline` file with 1 route per line.

src/IgnoredRoutesStorage.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ public function getRoutes(): array
5353
throw new \RuntimeException('Unable to load ignored routes from given file.');
5454
}
5555

56+
$routes = array_filter($routes, static function (string $route): bool {
57+
return !str_starts_with($route, '#') && '' !== $route;
58+
});
59+
60+
$routes = array_map(static function (string $route): string {
61+
if (false === $pos = stripos($route, ' #')) {
62+
return $route;
63+
}
64+
65+
return mb_substr($route, 0, $pos);
66+
}, $routes);
67+
5668
return array_values(array_unique($routes));
5769
}
5870
}

tests/IgnoredRoutesStorageTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public function testStorage(): void
2626
$this->assertSame([], $storage->getRoutes());
2727

2828
$storage->saveRoute('route1');
29-
$storage->saveRoute('route2');
29+
$storage->saveRoute('route2 # This comment will be ignored');
30+
$storage->saveRoute(''); // Empty line will be ignored
3031
$storage->saveRoute('route3');
32+
$storage->saveRoute('# This is a comment which will be ignored');
3133
$storage->saveRoute('route2');
3234
$storage->saveRoutes(['route2', 'route4', 'route5']);
3335

0 commit comments

Comments
 (0)