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 * Creates exception
* *
* @param array|object|string $source Source of the class's / trait's name. It can be an array of objects, * @param string $source Source of name of the class or trait
* namespaces, object or namespace. * @param bool $forClass (optional) If is set to true, message of this exception for class is prepared. Otherwise
* @param bool $forClass (optional) If is set to true, message of this exception for class is * - for trait.
* prepared. Otherwise - for trait.
* @return CannotResolveClassNameException * @return CannotResolveClassNameException
*/ */
public static function create($source, bool $forClass = true): CannotResolveClassNameException public static function create(string $source, bool $forClass = true): CannotResolveClassNameException
{ {
$forWho = 'trait'; $forWho = 'trait';
$value = ''; $value = '';
@@ -37,7 +36,7 @@ class CannotResolveClassNameException extends Exception
} }
if (is_scalar($source)) { 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?'; $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 // Oops, cannot resolve class
if (null === $className) { if (null === $className) {
throw CannotResolveClassNameException::create($class); throw CannotResolveClassNameException::create('');
} }
$childClasses = []; $childClasses = [];
@@ -541,12 +541,12 @@ class Reflection
// Oops, cannot resolve class // Oops, cannot resolve class
if (null === $className || '' === $className) { if (null === $className || '' === $className) {
throw CannotResolveClassNameException::create($class); throw CannotResolveClassNameException::create('');
} }
// Oops, cannot resolve trait // Oops, cannot resolve trait
if (null === $traitName || '' === $traitName) { if (null === $traitName || '' === $traitName) {
throw new CannotResolveClassNameException($class, false); throw CannotResolveClassNameException::create('', false);
} }
$reflection = new ReflectionClass($className); $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, * @param string $source Source of name of the class or trait
* namespaces, object or namespace. * @param bool $forClass (optional) If is set to true, message of this exception for class is prepared.
* @param bool $forClass If is set to true, message of this exception for class is prepared. * Otherwise - for trait.
* Otherwise - for trait. * @param string $expectedMessage Expected exception's message
* @param string $expectedMessage Expected exception's message
* *
* @dataProvider provideClassName * @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); $exception = CannotResolveClassNameException::create($source, $forClass);
static::assertSame($expectedMessage, $exception->getMessage()); static::assertSame($expectedMessage, $exception->getMessage());
@@ -70,12 +77,9 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
]; ];
yield[ yield[
[ stdClass::class,
new stdClass(),
new stdClass(),
],
true, 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. "" * @param mixed $invalidClass Empty value, e.g. ""
* @dataProvider provideEmptyValue * @dataProvider provideEmptyValue
*/ */
public function testGetChildClassesInvalidClass($invalidClass) public function testGetChildClassesInvalidClass($invalidClass): void
{ {
$this->expectException(CannotResolveClassNameException::class); $this->expectException(CannotResolveClassNameException::class);
@@ -206,7 +206,7 @@ class ReflectionTest extends BaseTestCase
* *
* @dataProvider provideInvalidClassAndTrait * @dataProvider provideInvalidClassAndTrait
*/ */
public function testUsesTraitInvalidClass($class, $trait) public function testUsesTraitInvalidClass($class, $trait): void
{ {
$this->expectException(CannotResolveClassNameException::class); $this->expectException(CannotResolveClassNameException::class);
self::assertNull(Reflection::usesTrait($class, $trait)); self::assertNull(Reflection::usesTrait($class, $trait));
@@ -577,7 +577,7 @@ class ReflectionTest extends BaseTestCase
* *
* @return Generator * @return Generator
*/ */
public function provideInvalidClassAndTrait() public function provideInvalidClassAndTrait(): ?Generator
{ {
yield[ yield[
'', '',
@@ -593,11 +593,6 @@ class ReflectionTest extends BaseTestCase
0, 0,
0, 0,
]; ];
yield[
[],
[],
];
} }
/** /**