Skip to content

Commit 3d506b6

Browse files
committed
Write tests for command
1 parent a28afb3 commit 3d506b6

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/RoutesChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\Routing\RouterInterface;
88
use Tiime\TestedRoutesCheckerBundle\RouteStorage\RouteStorageInterface;
99

10-
final class RoutesChecker
10+
class RoutesChecker
1111
{
1212
public function __construct(
1313
private readonly RouterInterface $router,

tests/Command/CheckCommandTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tiime\TestedRoutesCheckerBundle\Tests\RouteStorage;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Console\Tester\CommandTester;
9+
use Tiime\TestedRoutesCheckerBundle\Command\CheckCommand;
10+
use Tiime\TestedRoutesCheckerBundle\RoutesChecker;
11+
12+
final class CheckCommandTest extends TestCase
13+
{
14+
public function testWithoutUntestedRoutes(): void
15+
{
16+
$routesChecker = $this->createMock(RoutesChecker::class);
17+
$routesChecker->expects($this->once())->method('getUntestedRoutes')->willReturn([]);
18+
19+
$commandTester = new CommandTester(new CheckCommand($routesChecker, 10, __DIR__.'/ignored_routes'));
20+
21+
$commandTester->execute([]);
22+
23+
$commandTester->assertCommandIsSuccessful();
24+
25+
$output = $commandTester->getDisplay();
26+
$this->assertStringContainsString('[OK] Congrats, all routes have been tested!', $output);
27+
}
28+
29+
public function testWithUntestedRoutes(): void
30+
{
31+
$routesChecker = $this->createMock(RoutesChecker::class);
32+
$routesChecker->expects($this->once())->method('getUntestedRoutes')->willReturn(['route1', 'route2']);
33+
34+
$commandTester = new CommandTester(new CheckCommand($routesChecker, 10, __DIR__.'/ignored_routes'));
35+
36+
$commandTester->execute([]);
37+
38+
$this->assertSame(1, $commandTester->getStatusCode());
39+
40+
$output = $commandTester->getDisplay();
41+
$this->assertStringContainsString('[ERROR] Found 2 non tested routes!', $output);
42+
}
43+
}

0 commit comments

Comments
 (0)