Increase Mutation Score Indicator (MSI) by removing "src/Exception/Reflection/CannotResolveClassNameException.php:29 [M] TrueValue" mutant

This commit is contained in:
Meritoo
2019-08-10 21:32:40 +02:00
parent a5148de31c
commit a86a10c51e
4 changed files with 26 additions and 28 deletions

View File

@@ -21,13 +21,12 @@ class CannotResolveClassNameException extends Exception
/**
* Creates exception
*
* @param array|object|string $source Source of the class's / trait's name. It can be an array of objects,
* namespaces, object or namespace.
* @param bool $forClass (optional) If is set to true, message of this exception for class is
* prepared. Otherwise - for trait.
* @param string $source Source of name of the class or trait
* @param bool $forClass (optional) If is set to true, message of this exception for class is prepared. Otherwise
* - for trait.
* @return CannotResolveClassNameException
*/
public static function create($source, bool $forClass = true): CannotResolveClassNameException
public static function create(string $source, bool $forClass = true): CannotResolveClassNameException
{
$forWho = 'trait';
$value = '';
@@ -37,7 +36,7 @@ class CannotResolveClassNameException extends Exception
}
if (is_scalar($source)) {
$value = sprintf(' %s', (string)$source);
$value = sprintf(' %s', $source);
}
$template = 'Name of %s from given \'%s\'%s cannot be resolved. Is there everything ok?';

View File

@@ -437,7 +437,7 @@ class Reflection
// Oops, cannot resolve class
if (null === $className) {
throw CannotResolveClassNameException::create($class);
throw CannotResolveClassNameException::create('');
}
$childClasses = [];
@@ -541,12 +541,12 @@ class Reflection
// Oops, cannot resolve class
if (null === $className || '' === $className) {
throw CannotResolveClassNameException::create($class);
throw CannotResolveClassNameException::create('');
}
// Oops, cannot resolve trait
if (null === $traitName || '' === $traitName) {
throw new CannotResolveClassNameException($class, false);
throw CannotResolveClassNameException::create('', false);
}
$reflection = new ReflectionClass($className);

View File

@@ -34,16 +34,23 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
);
}
public function testCreateUsingDefaults(): void
{
$exception = CannotResolveClassNameException::create(stdClass::class);
$expectedMessage = 'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?';
static::assertSame($expectedMessage, $exception->getMessage());
}
/**
* @param array|object|string $source Source of the class's / trait's name. It can be an array of objects,
* namespaces, object or namespace.
* @param bool $forClass If is set to true, message of this exception for class is prepared.
* Otherwise - for trait.
* @param string $expectedMessage Expected exception's message
* @param string $source Source of name of the class or trait
* @param bool $forClass (optional) If is set to true, message of this exception for class is prepared.
* Otherwise - for trait.
* @param string $expectedMessage Expected exception's message
*
* @dataProvider provideClassName
*/
public function testCreate($source, bool $forClass, string $expectedMessage): void
public function testCreate(string $source, bool $forClass, string $expectedMessage): void
{
$exception = CannotResolveClassNameException::create($source, $forClass);
static::assertSame($expectedMessage, $exception->getMessage());
@@ -70,12 +77,9 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
];
yield[
[
new stdClass(),
new stdClass(),
],
stdClass::class,
true,
'Name of class from given \'array\' cannot be resolved. Is there everything ok?',
'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?',
];
}
}

View File

@@ -125,7 +125,7 @@ class ReflectionTest extends BaseTestCase
* @param mixed $invalidClass Empty value, e.g. ""
* @dataProvider provideEmptyValue
*/
public function testGetChildClassesInvalidClass($invalidClass)
public function testGetChildClassesInvalidClass($invalidClass): void
{
$this->expectException(CannotResolveClassNameException::class);
@@ -206,7 +206,7 @@ class ReflectionTest extends BaseTestCase
*
* @dataProvider provideInvalidClassAndTrait
*/
public function testUsesTraitInvalidClass($class, $trait)
public function testUsesTraitInvalidClass($class, $trait): void
{
$this->expectException(CannotResolveClassNameException::class);
self::assertNull(Reflection::usesTrait($class, $trait));
@@ -577,7 +577,7 @@ class ReflectionTest extends BaseTestCase
*
* @return Generator
*/
public function provideInvalidClassAndTrait()
public function provideInvalidClassAndTrait(): ?Generator
{
yield[
'',
@@ -593,11 +593,6 @@ class ReflectionTest extends BaseTestCase
0,
0,
];
yield[
[],
[],
];
}
/**