|
| 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