Skip to content

Commit

Permalink
Add coverage + fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasvts committed Sep 2, 2022
1 parent 05bdb2f commit 7809926
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/Infrastructure/AutoloadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@ public function isIncludedInWhiteList(string $className): bool
{
/** @var null|string|array<array-key, string> $includedClassNames */
$includedClassNames = $this->config->get(self::WHITE_LIST_CONFIG_KEY, []);
if (empty($includedClassNames)) {
return true;
}
return $this->isClassNameInConfig($includedClassNames, $className);
}

public function isExcludedInBlackList(string $className): bool
{
/** @var null|string|array<array-key, string> $excludedClassNames */
$excludedClassNames = $this->config->get(self::BLACK_LIST_CONFIG_KEY, []);
if (empty($excludedClassNames)) {
return false;
}
return $this->isClassNameInConfig($excludedClassNames, $className);
}

/**
* @param null|string|array<array-key, string> $config
* @param string|array<array-key, string> $config
* @param string $className
*
* @return bool
*/
private function isClassNameInConfig($config, string $className): bool
{
if (empty($config)) {
return false;
}

if (is_array($config)) {
foreach ($config as $includedClassName) {
if (strpos($className, $includedClassName) !== false) {
Expand Down
28 changes: 26 additions & 2 deletions tests/Unit/Infrastructure/AutoloadConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace TeamSquad\Tests\Unit\Infrastructure;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;
use TeamSquad\EventBus\Domain\SecureEvent;
use TeamSquad\EventBus\Infrastructure\AutoloadConfig;

class AutoloadConfigTest extends TestCase
Expand All @@ -24,6 +26,28 @@ protected function setUp(): void
);
}

public function test_is_included_in_white_list_when_white_list_is_empty(): void
{
$this->sut = new AutoloadConfig(
[
AutoloadConfig::WHITE_LIST_CONFIG_KEY => [],
AutoloadConfig::BLACK_LIST_CONFIG_KEY => ['Tests'],
]
);
self::assertTrue($this->sut->isIncludedInWhiteList('TeamsquadIo'));
}

public function test_is_included_in_black_list_when_black_list_is_empty(): void
{
$this->sut = new AutoloadConfig(
[
AutoloadConfig::WHITE_LIST_CONFIG_KEY => [],
AutoloadConfig::BLACK_LIST_CONFIG_KEY => [],
]
);
self::assertFalse($this->sut->isExcludedInBlackList('TeamsquadIo'));
}

/**
* @dataProvider classNamesProvider
*/
Expand All @@ -49,9 +73,9 @@ public function classNamesProvider(): array
{
return [
['TeamsquadIo\SlackService\Domain\Events\AdminCall', true, false],
['TeamSquad\EventBus\Domain\SecureEvent', false, false],
[SecureEvent::class, false, false],
['TeamSquad\Tests\Domain\SecureEvent', false, true],
['Symfony\Component\Yaml\Yaml', false, false],
[Yaml::class, false, false],
];
}
}

0 comments on commit 7809926

Please sign in to comment.