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

Dedicated static function to parse out mutator name #1331

Merged
merged 7 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/Mutator/GetMutatorName.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@

namespace Infection\Mutator;

use function end;
use function explode;

/**
* @internal
*/
trait GetMutatorName
{
final public function getName(): string
{
$parts = explode('\\', static::class);

return (string) end($parts);
return MutatorFactory::getMutatorNameForClassName(static::class);
}
}
7 changes: 7 additions & 0 deletions src/Mutator/MutatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ public function create(array $resolvedMutators): array

return $mutators;
}

public static function getMutatorNameForClassName(string $className): string
{
$parts = explode('\\', $className);

return (string) end($parts);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Closest place where Mutator::getName() is used.

}
8 changes: 8 additions & 0 deletions tests/phpunit/Mutator/MutatorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use Infection\Mutator\Mutator;
use Infection\Mutator\MutatorFactory;
use Infection\Mutator\ProfileList;
use Infection\Mutator\Sort\Spaceship;
use Infection\PhpParser\Visitor\ReflectionVisitor;
use Infection\Reflection\ClassReflection;
use Infection\Tests\SingletonContainer;
Expand Down Expand Up @@ -166,6 +167,13 @@ public function test_it_cannot_create_an_unknown_mutator(): void
}
}

public function test_it_can_parse_name(): void
{
$name = $this->mutatorFactory::getMutatorNameForClassName(Spaceship::class);

$this->assertSame('Spaceship', $name);
}

private function createBoolNode(string $boolean, string $functionName, ClassReflection $reflectionMock): Node
{
return new Node\Expr\ConstFetch(
Expand Down