Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/Console/CheckUrlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();

Expand All @@ -53,5 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
foreach ($this->service->getMissingMethods() as $_missingMethod) {
$output->writeln("<danger>" . $_missingMethod . "</danger>" );
}

return 0;
}
}
11 changes: 6 additions & 5 deletions src/DI/PresenterTestCoverageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 20 additions & 2 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ADT\PresenterTestCoverage;

use Doctrine\ORM\EntityManagerInterface;
use Nette\Loaders\RobotLoader;
use Nette\Utils\Strings;

Expand All @@ -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 = [];
Expand All @@ -30,6 +35,7 @@ public function getFoundMethods(): array
return $methods;
}


public function getMissingMethods(): array
{
$methods = [];
Expand All @@ -42,22 +48,24 @@ public function getMissingMethods(): array
return $methods;
}


public function getUrls(?string $prefix = null): array
{
$urls = [];
foreach ($this->getFoundMethods() as $method) {
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 = [];
Expand Down Expand Up @@ -86,6 +94,7 @@ protected function getMethods() : array
return $methods;
}


protected static function isMethodToTest(string $methodName) : bool
{
if (Strings::startsWith($methodName, static::$testMethodPrefix)) {
Expand All @@ -95,6 +104,7 @@ protected static function isMethodToTest(string $methodName) : bool
return false;
}


protected function getTestClassAndMethod(string $presenterClass, string $presenterMethod): string
{
return
Expand All @@ -106,6 +116,7 @@ protected function getTestClassAndMethod(string $presenterClass, string $present
. '::' . $presenterMethod;
}


protected function isMethodCovered(string $testMethod) : bool
{
list($testClass, $testMethod) = explode('::', $testMethod);
Expand All @@ -127,6 +138,7 @@ protected function isMethodCovered(string $testMethod) : bool
return $urls && is_array($urls);
}


public function getRobotLoader(): RobotLoader
{
if (!$this->robotLoader) {
Expand All @@ -138,4 +150,10 @@ public function getRobotLoader(): RobotLoader

return $this->robotLoader;
}


public static function getEm(): ?EntityManagerInterface
{
return self::$em;
}
}