Skip to content

Commit

Permalink
Revert "Merge pull request #12 from naxvog/wildcard-ns"
Browse files Browse the repository at this point in the history
This reverts commit be0551f, reversing
changes made to 0a27e55.
  • Loading branch information
nunomaduro committed Sep 29, 2024
1 parent be0551f commit 3a6d6b2
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 95 deletions.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
Expand Down
4 changes: 1 addition & 3 deletions src/Factories/LayerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public function make(LayerOptions $options, string $name, bool $onlyUserDefinedU
return $object;
}, $this->objectsStorage->allByNamespace($name, $onlyUserDefinedUses));

$layer = str_contains($name, '*')
? Layer::fromBase($objects)->leaveByNameRegex('/'.strtr(preg_quote($name, '/'), ['\\*' => '[^\\\\]+']).'/')
: Layer::fromBase($objects)->leaveByNameStart($name);
$layer = Layer::fromBase($objects)->leaveByNameStart($name);

foreach ($options->exclude as $exclude) {
$layer = $layer->excludeByNameStart($exclude);
Expand Down
4 changes: 2 additions & 2 deletions src/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use IteratorAggregate;
use PHPUnit\Architecture\Elements\Layer\Layer as BaseLayer;
use PHPUnit\Architecture\Elements\Layer\LayerLeave;
use PHPUnit\Architecture\Elements\ObjectDescription;
use Traversable;

/**
* @method Layer assertDoesNotDependOn(string ...$objects)
* @method Layer excludeByNameStart(string $name)
* @mixin LayerLeave
* @method Layer exclude(callable $callback)
* @method Layer leaveByNameStart(string $name)
*
* @implements IteratorAggregate<int, ObjectDescription>
*/
Expand Down
8 changes: 3 additions & 5 deletions src/Repositories/ObjectsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function allByNamespace(string $namespace, bool $onlyUserDefinedUses = tr

$objectsPerPrefix = array_values(array_filter(array_reduce($directories, fn (array $files, string $fileOrDirectory): array => array_merge($files, array_values(array_map(
static fn (SplFileInfo $file): ?ObjectDescription => ObjectDescriptionFactory::make($file->getPathname(), $onlyUserDefinedUses),
is_dir($fileOrDirectory) || str_contains($fileOrDirectory, '*') ? iterator_to_array(Finder::create()->files()->in($fileOrDirectory)->name('*.php')) : [new SplFileInfo($fileOrDirectory)],
is_dir($fileOrDirectory) ? iterator_to_array(Finder::create()->files()->in($fileOrDirectory)->name('*.php')) : [new SplFileInfo($fileOrDirectory)],
))), [])));

$objects = [...$objects, ...$this->cachedObjectsPerPrefix[$prefix][(int) $onlyUserDefinedUses] = $objectsPerPrefix];
Expand Down Expand Up @@ -151,15 +151,13 @@ private function directoriesByNamespace(string $name): array

$directoriesByNamespace[$name] = [...$directoriesByNamespace[$name] ?? [], ...array_values(array_filter(array_map(static function (string $directory) use ($prefix): string {
$fileOrDirectory = $directory.DIRECTORY_SEPARATOR.$prefix;

if (is_dir($fileOrDirectory)) {
return $fileOrDirectory;
}
if (str_contains($fileOrDirectory, '*')) {
return $fileOrDirectory;
}

return $fileOrDirectory.'.php';
}, $directories), static fn (string $fileOrDirectory): bool => is_dir($fileOrDirectory) || str_contains($fileOrDirectory, '*') || file_exists($fileOrDirectory)))];
}, $directories), static fn (string $fileOrDirectory): bool => is_dir($fileOrDirectory) || file_exists($fileOrDirectory)))];
}
}

Expand Down
10 changes: 0 additions & 10 deletions tests/Fixtures/Domains/A/Contracts/Models/Bazable.php

This file was deleted.

12 changes: 0 additions & 12 deletions tests/Fixtures/Domains/A/Models/Article.php

This file was deleted.

10 changes: 0 additions & 10 deletions tests/Fixtures/Domains/B/Contracts/Models/Bazable.php

This file was deleted.

12 changes: 0 additions & 12 deletions tests/Fixtures/Domains/B/Models/Article.php

This file was deleted.

22 changes: 0 additions & 22 deletions tests/Layer.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php

use Tests\Fixtures\Domains\A\Contracts\Models\Bazable as BazableDomainA;
use Tests\Fixtures\Domains\A\Models\Article as ArticleDomainA;
use Tests\Fixtures\Domains\B\Contracts\Models\Bazable as BazableDomainB;
use Tests\Fixtures\Domains\B\Models\Article as ArticleDomainB;
use Tests\Fixtures\Enums\Color;
use Tests\Fixtures\Enums\ColorThatDependsOnColor;
use Tests\Fixtures\Misc\DependOnGlobalFunctions;
Expand All @@ -27,24 +23,6 @@
->toOnlyUse('Pest\Support\Str');
});

it('loads namespaces', function () {
expect('Tests\Fixtures\Domains\A\Models')
->getTargets()
->toBe([ArticleDomainA::class]);
});

it('loads namespaces using wildcards', function () {
expect('Tests\Fixtures\Domains\*\Models')
->getTargets()
->toBe([ArticleDomainA::class, ArticleDomainB::class]);
});

it('loads namespaces using multiple wildcards', function () {
expect('Tests\Fixtures\Domains\*\*\Models')
->getTargets()
->toBe([BazableDomainA::class, BazableDomainB::class]);
});

it('does support enums', function () {
expect(Color::class)->toUseNothing()
->and(ColorThatDependsOnColor::class)->toUse([Color::class]);
Expand Down
19 changes: 0 additions & 19 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use Pest\Arch\Exceptions\ArchExpectationFailedException;
use Pest\Arch\Expectations\Targeted;
use Pest\Arch\Objects\ObjectDescription;

uses()->beforeEach(function () {
$this->arch()->ignore([
Expand All @@ -25,20 +23,3 @@
->toBe($line);
});
});

expect()->extend('getTargets', function () {
$classes = [];
Targeted::make(
$this,
function (ObjectDescription $object) use (&$classes): bool {
$classes[] = $object->name;

return true;
},
'',
fn ($path) => 0,
);
$this->value = $classes;

return $this;
});

0 comments on commit 3a6d6b2

Please sign in to comment.