Skip to content

Commit

Permalink
test phpdocumentor path/notPath
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Feb 22, 2021
1 parent 4a77546 commit 0881f19
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion tests/Iterator/PhpDocumentorIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kcs\ClassFinder\Tests\Iterator;

use Kcs\ClassFinder\Fixtures\Psr0;
use Kcs\ClassFinder\Fixtures\Psr4;
use Kcs\ClassFinder\Iterator\PhpDocumentorIterator;
use phpDocumentor\Reflection\Php\Class_;
Expand All @@ -16,7 +17,7 @@

class PhpDocumentorIteratorTest extends TestCase
{
public function testIteratorShouldWork()
public function testIteratorShouldWork(): void
{
$iterator = new PhpDocumentorIterator(
realpath(__DIR__ . '/../../data/Composer/Psr4')
Expand All @@ -37,4 +38,49 @@ public function testIteratorShouldWork()
self::assertArrayHasKey(Psr4\FooTrait::class, $classes);
self::assertInstanceOf(Trait_::class, $classes[Psr4\FooTrait::class]);
}

public function testComposerIteratorShouldFilterNotIntersectingPath(): void
{
$iterator = new PhpDocumentorIterator(
realpath(__DIR__ . '/../../data/Composer')
);

$iterator->in([__DIR__ . '/../..' . '/data/Composer/Psr?']);
$classes = iterator_to_array($iterator);

self::assertArrayHasKey(Psr4\BarBar::class, $classes);
self::assertInstanceOf(Class_::class, $classes[Psr4\BarBar::class]);
self::assertArrayHasKey(Psr4\Foobar::class, $classes);
self::assertInstanceOf(Class_::class, $classes[Psr4\Foobar::class]);
self::assertArrayHasKey(Psr4\AbstractClass::class, $classes);
self::assertInstanceOf(Class_::class, $classes[Psr4\AbstractClass::class]);
self::assertArrayHasKey(Psr4\SubNs\FooBaz::class, $classes);
self::assertInstanceOf(Class_::class, $classes[Psr4\SubNs\FooBaz::class]);
self::assertArrayHasKey(Psr4\FooInterface::class, $classes);
self::assertInstanceOf(Interface_::class, $classes[Psr4\FooInterface::class]);
self::assertArrayHasKey(Psr4\FooTrait::class, $classes);
self::assertInstanceOf(Trait_::class, $classes[Psr4\FooTrait::class]);

self::assertArrayHasKey(Psr0\BarBar::class, $classes);
self::assertInstanceOf(Class_::class, $classes[Psr0\BarBar::class]);
self::assertArrayHasKey(Psr0\Foobar::class, $classes);
self::assertInstanceOf(Class_::class, $classes[Psr0\Foobar::class]);
self::assertArrayHasKey(Psr0\SubNs\FooBaz::class, $classes);
self::assertInstanceOf(Class_::class, $classes[Psr0\SubNs\FooBaz::class]);

$iterator->path(['/Sub.*/']);
$classes = iterator_to_array($iterator);

self::assertEquals([
Psr0\SubNs\FooBaz::class,
Psr4\SubNs\FooBaz::class,
], array_keys($classes));

$iterator->path(['/Sub.*/'])->notPath(['/sr4/']);
$classes = iterator_to_array($iterator);

self::assertEquals([
Psr0\SubNs\FooBaz::class,
], array_keys($classes));
}
}

0 comments on commit 0881f19

Please sign in to comment.