Skip to content

Commit 3815fb1

Browse files
authored
feat: better code coverage scipt + docs + cleanup (#211)
1 parent 0699f26 commit 3815fb1

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

bin/coverage-checker.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
declare(strict_types=1);
66

77
$argv = $argv ?? [];
8-
$inputFile = $argv[1];
8+
if (count($argv) !== 3) {
9+
throw new InvalidArgumentException('Two arguments are required by this script: 1) the clover file report path. 2) the code coverage threshold.');
10+
}
11+
12+
[,$inputFile, $threshold] = $argv;
913

10-
if (!is_numeric($argv[2])) {
14+
if (!is_numeric($threshold)) {
1115
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
1216
}
13-
$percentage = min(100, max(0, (int) $argv[2]));
17+
$percentage = min(100, max(0, (int) $threshold));
1418

1519
if (!file_exists($inputFile)) {
1620
throw new InvalidArgumentException('Invalid input file provided');

src/Controller/SlugifyAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class SlugifyAction extends AbstractController
2222
* Simple API endpoint returning JSON. For a more serious API, please use API Platform 🕸.
2323
* We can use the MapQueryParameter attribute to inject GET parameters.
2424
*
25-
* @see https://api-platform.com/
25+
* @see https://api-platform.com
2626
*/
2727
#[Route(path: '/api/slugify', name: self::class)]
2828
public function __invoke(StringHelper $stringHelper, #[MapQueryParameter] string $title): Response

src/Form/Type/RegisterForm.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4343
;
4444
}
4545

46+
/**
47+
* @see https://www.strangebuzz.com/en/blog/disable-the-html5-validation-of-all-your-symfony-forms-with-a-feature-flag
48+
*/
4649
public function configureOptions(OptionsResolver $resolver): void
4750
{
4851
$resolver->setDefaults([

src/Twig/Extension/MarkdownExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717
}
1818

1919
/**
20-
* Add the missing anchors on demo website homepage displaying the Github README.
20+
* Add the missing anchors on demo website homepage displaying the GitHub README.
2121
*
2222
* @see https://microsymfony.ovh
2323
* @see https://github.com/strangebuzz/MicroSymfony/blob/main/README.md?plain=1
@@ -30,7 +30,7 @@ public function addHeadersAnchors(string $html): string
3030

3131
// Allow to have the same "buggy" anchors as GitHub
3232
/** @var \DOMNodeList<\DOMNode> $tags */
33-
$tags = (new \DOMXPath($dom))->query('//h2 | //h3');
33+
$tags = new \DOMXPath($dom)->query('//h2 | //h3');
3434
foreach ($tags as $headerTag) {
3535
$slug = $this->stringHelper->slugify($headerTag->textContent);
3636
/** @var \DOMElement $headerTag */

tests/Functional/Controller/FormActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
final class FormActionTest extends WebTestCase
1010
{
11-
private const FORM_SUBMIT_BUTTON_ID = 'register_form_save';
11+
private const string FORM_SUBMIT_BUTTON_ID = 'register_form_save';
1212

1313
public function testFormValidationErrors(): void
1414
{

tests/Functional/Controller/StaticRoutesSmokeTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ final class StaticRoutesSmokeTest extends WebTestCase
1919
public function testRoutesDoNotReturnInternalError(string $httpMethod, string $routeName, string $routePath): void
2020
{
2121
$client = self::createClient();
22-
2322
$client->request($httpMethod, $routePath);
24-
2523
$response = $client->getResponse();
2624
self::assertLessThan(
2725
500,
@@ -39,9 +37,7 @@ public static function provideRouteCollection(): \Generator
3937

4038
/** @var RouterInterface $router */
4139
$router = self::getContainer()->get(RouterInterface::class);
42-
4340
$routes = $router->getRouteCollection();
44-
4541
self::ensureKernelShutdown();
4642

4743
if (!$routes->count()) {
@@ -57,8 +53,7 @@ public static function provideRouteCollection(): \Generator
5753
public static function extractRoutesFromRouter(RouterInterface $router): \Generator
5854
{
5955
foreach ($router->getRouteCollection() as $routeName => $route) {
60-
$compiledRoute = $route->compile();
61-
$variables = $compiledRoute->getVariables();
56+
$variables = $route->compile()->getVariables();
6257
if (\count($variables) > 0) {
6358
$defaults = $route->getDefaults();
6459
$defaultsKeys = array_keys($defaults);
@@ -71,6 +66,8 @@ public static function extractRoutesFromRouter(RouterInterface $router): \Genera
7166

7267
$methods = $route->getMethods();
7368
if (!$methods) {
69+
// If we get there, it is because your route doesn't have methods requirment.
70+
// You can add one by adding ` methods: ['GET']` to your Route attribute.
7471
$methods[] = 'GET';
7572
}
7673

0 commit comments

Comments
 (0)