78 lines
3.0 KiB
PHP
78 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Fbrinker\ExtensionCheck\Tests\Unit\Command;
|
|
|
|
use Fbrinker\ExtensionCheck\Command\CheckCommand;
|
|
use Fbrinker\ExtensionCheck\Extension\ExtensionCheck;
|
|
use Fbrinker\ExtensionCheck\Output\SymfonyStyleFactory;
|
|
use Fbrinker\ExtensionCheck\Parser\FileParser;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
class CheckCommandTest extends TestCase
|
|
{
|
|
public function testExecuteEmpty(): void
|
|
{
|
|
$sut = $this->createEmptySut();
|
|
|
|
$commandTester = new CommandTester($sut);
|
|
$commandTester->execute([]);
|
|
|
|
$result = $commandTester->getDisplay();
|
|
|
|
$this->assertStringContainsStringIgnoringCase("Files: 0", $result);
|
|
$this->assertStringContainsStringIgnoringCase("0 Classes, 0 Functions, 0 Constants", $result);
|
|
$this->assertStringContainsStringIgnoringCase("Loaded Extensions: 0", $result);
|
|
$this->assertStringContainsStringIgnoringCase("0 Used, 0 Unused", $result);
|
|
}
|
|
|
|
public function testExecuteWithResults(): void
|
|
{
|
|
$sut = $this->createSutWithResult();
|
|
|
|
$commandTester = new CommandTester($sut);
|
|
$commandTester->execute([]);
|
|
|
|
$result = $commandTester->getDisplay();
|
|
|
|
$this->assertStringContainsStringIgnoringCase("Files: 3", $result);
|
|
$this->assertStringContainsStringIgnoringCase("3 Classes, 2 Functions, 1 Constants", $result);
|
|
$this->assertStringContainsStringIgnoringCase("Loaded Extensions: 2", $result);
|
|
$this->assertStringContainsStringIgnoringCase("1 Used, 1 Unused", $result);
|
|
$this->assertStringContainsStringIgnoringCase("Used [Usage: class]", $result);
|
|
}
|
|
|
|
private function createEmptySut(): CheckCommand
|
|
{
|
|
$symfonyStyleFactory = new SymfonyStyleFactory();
|
|
$fileParserMock = $this->createMock(FileParser::class);
|
|
$fileParserMock->method('parseFiles')->willReturn([
|
|
[],
|
|
[],
|
|
[],
|
|
]);
|
|
$extensionCheckMock = $this->createMock(ExtensionCheck::class);
|
|
$extensionCheckMock->method('checkUsages')->willReturn([]);
|
|
return new CheckCommand($symfonyStyleFactory, $fileParserMock, $extensionCheckMock);
|
|
}
|
|
|
|
private function createSutWithResult(): CheckCommand
|
|
{
|
|
$symfonyStyleFactory = new SymfonyStyleFactory();
|
|
$fileParserMock = $this->createMock(FileParser::class);
|
|
$fileParserMock->method('getFileCount')->willReturn(3);
|
|
$fileParserMock->method('parseFiles')->willReturn([
|
|
['A', 'B', 'C'],
|
|
['gotoA', 'gotoB'],
|
|
['CONST_C'],
|
|
]);
|
|
$extensionCheckMock = $this->createMock(ExtensionCheck::class);
|
|
$extensionCheckMock->method('getLoadedExtensionsCount')->willReturn(2);
|
|
$extensionCheckMock->method('checkUsages')->willReturn(['Used' => ['class' => true]]);
|
|
$extensionCheckMock->method('getUnused')->willReturn(['Unused']);
|
|
return new CheckCommand($symfonyStyleFactory, $fileParserMock, $extensionCheckMock);
|
|
}
|
|
}
|