Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Fix: Ignore non-existent exclude classes #30

Merged
merged 2 commits into from
Sep 19, 2017
Merged
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
11 changes: 0 additions & 11 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ final protected function assertClassesSatisfySpecification(callable $specificati

$directory = \realpath($directory);

$nonExistentExcludeClassNames = \array_filter($excludeClassNames, function (string $excludeClassName) {
return false === \class_exists($excludeClassName);
});

if (0 < \count($nonExistentExcludeClassNames)) {
throw new \InvalidArgumentException(\sprintf(
'Exclude class names need to be specified as existing classes, but "%s" does not exist.',
\implode('", "', $excludeClassNames)
));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also increase test coverage as this was never tested.


$classFileLocator = new File\ClassFileLocator($directory);

/** @var File\PhpClassFile[] $classFiles */
Expand Down
51 changes: 51 additions & 0 deletions test/Unit/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ public function testAssertClassesAreAbstractOrFinalWithExcludeClassNamesSucceeds
);
}

public function testAssertClassesAreAbstractOrFinalWithExcludeClassNamesIgnoresNonExistentExcludeClassNames()
{
$directory = __DIR__ . '/../Fixture/ClassesAreAbstractOrFinal';
$excludeClassNames = [
Fixture\ClassesAreAbstractOrFinal\NotAllAbstractOrFinal\AlsoNeitherAbstractNorFinal::class,
Fixture\ClassesAreAbstractOrFinal\NotAllAbstractOrFinal\NeitherAbstractNorFinal::class,
__NAMESPACE__ . '\\NonExistentClass',
];

$this->assertClassesAreAbstractOrFinal(
$directory,
$excludeClassNames
);
}

public function testAssertClassesHaveTestsRejectsNonExistentDirectory()
{
$directory = __DIR__ . '/../Fixture/NonExistentDirectory';
Expand Down Expand Up @@ -387,6 +402,25 @@ public function testAssertClassesHaveTestsWithExcludeClassNamesSucceedsWhenFound
);
}

public function testAssertClassesHaveTestsWithExcludeClassNamesIgnoresNonExistentExcludeClassNames()
{
$directory = __DIR__ . '/../Fixture/ClassesHaveTests/NotAllClassesHaveTests';
$namespace = 'Localheinz\\Test\\Util\\Test\\Fixture\\ClassesHaveTests\\NotAllClassesHaveTests\\';
$testNamespace = 'Localheinz\\Test\\Util\\Test\\Fixture\\ClassesHaveTests\\NotAllClassesHaveTests\\Test\\';
$excludeClassNames = [
Fixture\ClassesHaveTests\NotAllClassesHaveTests\AnotherExampleClass::class,
Fixture\ClassesHaveTests\NotAllClassesHaveTests\OneMoreExampleClass::class,
__NAMESPACE__ . '\\NonExistentClass',
];

$this->assertClassesHaveTests(
$directory,
$namespace,
$testNamespace,
$excludeClassNames
);
}

public function testAssertClassesSatisfySpecificationRejectsNonExistentDirectory()
{
$directory = __DIR__ . '/../Fixture/NonExistentDirectory';
Expand Down Expand Up @@ -520,6 +554,23 @@ function (string $className) {
);
}

public function testAssertClassesSatisfySpecificationWithExcludeClassNamesIgnoresNonExistentExcludeClassNames()
{
$directory = __DIR__ . '/../Fixture/ClassesSatisfySpecification';
$excludeClassNames = [
Fixture\ClassesSatisfySpecification\AnotherExampleClass::class,
__NAMESPACE__ . '\\NonExistentClass',
];

$this->assertClassesSatisfySpecification(
function (string $className) {
return Fixture\ClassesSatisfySpecification\ExampleClass::class === $className;
},
$directory,
$excludeClassNames
);
}

/**
* @dataProvider providerNotClass
*
Expand Down