Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Replace wildcard e2e test with unit one #5000

Merged
merged 1 commit into from
Sep 11, 2023
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
1 change: 0 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- 'e2e/parallel-reflection-resolver'
- 'e2e/applied-rule-removed-node'
- 'e2e/parallel with space'
- 'e2e/wildcards-path-config'
- 'e2e/wildcards-path-import-config'
- 'e2e/different-path-over-skip-config'

Expand Down
1 change: 0 additions & 1 deletion e2e/wildcards-path-config/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions e2e/wildcards-path-config/composer.json

This file was deleted.

40 changes: 0 additions & 40 deletions e2e/wildcards-path-config/expected-output.diff

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions e2e/wildcards-path-config/rector.php

This file was deleted.

14 changes: 8 additions & 6 deletions packages/NodeNameResolver/NodeNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
final class NodeNameResolver
{
/**
* @var array<string, NodeNameResolverInterface|null>
* Used to check if a string might contain a regex or fnmatch pattern
*/
private array $nodeNameResolversByClass = [];
private const REGEX_WILDCARD_CHARS = ['*', '#', '~', '/'];

/**
* Used to check if a string might contain a regex or fnmatch pattern
* @var array<string, NodeNameResolverInterface|null>
*/
private const REGEX_WILDCARD_CHARS = ['*', '#', '~', '/'];
private array $nodeNameResolversByClass = [];

/**
* @param NodeNameResolverInterface[] $nodeNameResolvers
Expand Down Expand Up @@ -190,9 +190,11 @@ public function isStringName(string $resolvedName, string $desiredName): bool
return true;
}

foreach(self::REGEX_WILDCARD_CHARS as $char) {
foreach (self::REGEX_WILDCARD_CHARS as $char) {
if (str_contains($desiredName, $char)) {
throw new ShouldNotHappenException('Matching of regular expressions is no longer supported. Use $this->getName() and compare with e.g. str_ends_with() or str_starts_with() instead.');
throw new ShouldNotHappenException(
'Matching of regular expressions is no longer supported. Use $this->getName() and compare with e.g. str_ends_with() or str_starts_with() instead.'
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

$rectorConfig->ruleWithConfiguration(AddAllowDynamicPropertiesAttributeRector::class, [
'*\Fixture\Process\*',
'Rector\Tests\Transform\Rector\Class_\AddAllowDynamicPropertiesAttributeRector\Fixture\DefinedClass\AddAllowDynamicProperties'
'Rector\Tests\Transform\Rector\Class_\AddAllowDynamicPropertiesAttributeRector\Fixture\DefinedClass\AddAllowDynamicProperties',
]);
};
4 changes: 2 additions & 2 deletions rules/CodingStyle/ClassNameImport/UseImportsTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Rector\CodingStyle\ClassNameImport;

use PhpParser\Node\Stmt\Namespace_;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use PhpParser\NodeTraverser;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ private function shouldSkip(Class_ $class): bool

private function isExistsWithWildCards(string $className): bool
{
$wildcardTransformOnNamespaces = array_filter($this->transformOnNamespaces, static fn(string $transformOnNamespace): bool => str_contains($transformOnNamespace, '*'));
$wildcardTransformOnNamespaces = array_filter(
$this->transformOnNamespaces,
static fn (string $transformOnNamespace): bool => str_contains($transformOnNamespace, '*')
);
foreach ($wildcardTransformOnNamespaces as $wildcardTransformOnNamespace) {
if (! fnmatch($wildcardTransformOnNamespace, $className, FNM_NOESCAPE)) {
continue;
Expand All @@ -175,7 +178,10 @@ private function isExistsWithWildCards(string $className): bool

private function isExistsWithClassName(string $className): bool
{
$transformedClassNames = array_filter($this->transformOnNamespaces, static fn(string $transformOnNamespace): bool => ! str_contains($transformOnNamespace, '*'));
$transformedClassNames = array_filter(
$this->transformOnNamespaces,
static fn (string $transformOnNamespace): bool => ! str_contains($transformOnNamespace, '*')
);
foreach ($transformedClassNames as $transformedClassName) {
if (! $this->nodeNameResolver->isStringName($className, $transformedClassName)) {
continue;
Expand Down
3 changes: 3 additions & 0 deletions src/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @see \Rector\Core\Tests\Configuration\ConfigurationFactoryTest
*/
final class ConfigurationFactory
{
public function __construct(
Expand Down
13 changes: 13 additions & 0 deletions tests-paths/path/wildcard-nested/some_directory/AnotherFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\Utils\Path\WhildcardNested;

final class AnotherFile
{
public function run()
{
return 123;
}
}
13 changes: 13 additions & 0 deletions tests-paths/path/wildcard-next/some_directory/YetAnotherFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\Utils\Path\WhildcardNested;

final class YetAnotherFile
{
public function run()
{
return 123;
}
}
38 changes: 38 additions & 0 deletions tests/Configuration/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\Configuration;

use Rector\Core\Configuration\ConfigurationFactory;
use Rector\Core\FileSystem\FilesFinder;
use Rector\Testing\PHPUnit\AbstractTestCase;

final class ConfigurationFactoryTest extends AbstractTestCase
{
public function test(): void
{
$configurationFactory = $this->make(ConfigurationFactory::class);
$configuration = $configurationFactory->createForTests([
__DIR__ . '/../../tests-paths/path/*/some_directory/*',
]);

$filesFinder = $this->make(FilesFinder::class);

$filePaths = $filesFinder->findInDirectoriesAndFiles($configuration->getPaths());
$this->assertCount(2, $filePaths);

$firstFilePath = $filePaths[0];
$secondFilePath = $filePaths[1];

$this->assertSame(
realpath(__DIR__ . '/../../tests-paths/path/wildcard-nested/some_directory/AnotherFile.php'),
realpath($firstFilePath)
);

$this->assertSame(
realpath(__DIR__ . '/../../tests-paths/path/wildcard-next/some_directory/YetAnotherFile.php'),
realpath($secondFilePath),
);
}
}
10 changes: 0 additions & 10 deletions tests/config/downgrade-phpstan-parser.php

This file was deleted.