diff --git a/README.md b/README.md index 70de20b..b525eda 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ presenterTestCoverage: presenterDir: %appDir%/Modules tempDir: %tempDir% testDir: %appDir%/../tests/Crawler + em: @App\Model\Doctrine\EntityManager ``` ### 1.3 Příklad testované třídy diff --git a/src/Console/CheckUrlCommand.php b/src/Console/CheckUrlCommand.php index d0c01d7..ae37943 100644 --- a/src/Console/CheckUrlCommand.php +++ b/src/Console/CheckUrlCommand.php @@ -12,15 +12,15 @@ class CheckUrlCommand extends Command { protected array $config = []; protected Service $service; - + protected static $defaultName = 'adt:presenterTestCoverage'; - + public function __construct(Service $service) { parent::__construct(); $this->service = $service; } - + public function setConfig(array $config = []): void { @@ -38,7 +38,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v $output->getFormatter()->setStyle('danger', new OutputFormatterStyle('red')); } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): ?int { $this->service->getRobotLoader()->rebuild(); @@ -53,5 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void foreach ($this->service->getMissingMethods() as $_missingMethod) { $output->writeln("" . $_missingMethod . "" ); } + + return 0; } } diff --git a/src/DI/PresenterTestCoverageExtension.php b/src/DI/PresenterTestCoverageExtension.php index cac126b..c11671f 100644 --- a/src/DI/PresenterTestCoverageExtension.php +++ b/src/DI/PresenterTestCoverageExtension.php @@ -5,16 +5,17 @@ use ADT\PresenterTestCoverage\Console\CheckUrlCommand; use ADT\PresenterTestCoverage\Service; -class PresenterTestCoverageExtension extends \Nette\DI\CompilerExtension +class PresenterTestCoverageExtension extends \Nette\DI\CompilerExtension { public function loadConfiguration(): void { $config = $this->validateConfig([ 'appNamespacePrefix' => 'App', - 'crawlerNamespacePrefix' => NULL, - 'presenterDir' => NULL, - 'tempDir' => NULL, - 'testDir' => NULL, + 'crawlerNamespacePrefix' => null, + 'presenterDir' => null, + 'tempDir' => null, + 'testDir' => null, + 'em' => null ]); $builder = $this->getContainerBuilder(); diff --git a/src/Service.php b/src/Service.php index 18c871f..d94afcf 100644 --- a/src/Service.php +++ b/src/Service.php @@ -2,6 +2,7 @@ namespace ADT\PresenterTestCoverage; +use Doctrine\ORM\EntityManagerInterface; use Nette\Loaders\RobotLoader; use Nette\Utils\Strings; @@ -11,13 +12,17 @@ class Service protected array $config = []; protected ?RobotLoader $robotLoader = null; + protected static ?EntityManagerInterface $em; + public function setConfig(array $config = []): self { $this->config = $config; + self::$em = $this->config['em']; return $this; } + public function getFoundMethods(): array { $methods = []; @@ -30,6 +35,7 @@ public function getFoundMethods(): array return $methods; } + public function getMissingMethods(): array { $methods = []; @@ -42,6 +48,7 @@ public function getMissingMethods(): array return $methods; } + public function getUrls(?string $prefix = null): array { $urls = []; @@ -49,15 +56,16 @@ public function getUrls(?string $prefix = null): array if ($prefix && !Strings::startsWith($method, $prefix)) { continue; } - + list($class, $method) = explode('::', $method); - + $urls = array_merge($urls, (new $class)->$method()); } return $urls; } + protected function getMethods() : array { $methods = []; @@ -86,6 +94,7 @@ protected function getMethods() : array return $methods; } + protected static function isMethodToTest(string $methodName) : bool { if (Strings::startsWith($methodName, static::$testMethodPrefix)) { @@ -95,6 +104,7 @@ protected static function isMethodToTest(string $methodName) : bool return false; } + protected function getTestClassAndMethod(string $presenterClass, string $presenterMethod): string { return @@ -106,6 +116,7 @@ protected function getTestClassAndMethod(string $presenterClass, string $present . '::' . $presenterMethod; } + protected function isMethodCovered(string $testMethod) : bool { list($testClass, $testMethod) = explode('::', $testMethod); @@ -127,6 +138,7 @@ protected function isMethodCovered(string $testMethod) : bool return $urls && is_array($urls); } + public function getRobotLoader(): RobotLoader { if (!$this->robotLoader) { @@ -138,4 +150,10 @@ public function getRobotLoader(): RobotLoader return $this->robotLoader; } + + + public static function getEm(): ?EntityManagerInterface + { + return self::$em; + } }