Merge pull request #91 from RectorPHP/tests-coverage-3

improve coverage
This commit is contained in:
Tomáš Votruba 2017-10-17 07:56:57 +02:00 committed by GitHub
commit edc53b861e
3 changed files with 19 additions and 6 deletions

View File

@ -16,7 +16,7 @@ final class ConstFetchResolver implements PerNodeValueResolverInterface
/**
* @param ConstFetch $constFetchNode
*/
public function resolve(Node $constFetchNode): ?bool
public function resolve(Node $constFetchNode): bool
{
$name = $constFetchNode->name->toString();
if ($name === 'true') {
@ -26,9 +26,5 @@ final class ConstFetchResolver implements PerNodeValueResolverInterface
if ($name === 'false') {
return false;
}
if ($name === 'null') {
return null;
}
}
}

View File

@ -26,9 +26,10 @@ final class NodeValueResolverTest extends AbstractContainerAwareTestCase
$arrayNode = new Array_([
new ArrayItem(new String_('hi')),
new ArrayItem(BuilderHelpers::normalizeValue(true)),
new ArrayItem(BuilderHelpers::normalizeValue(false)),
]);
$resolved = $this->nodeValueResolver->resolve($arrayNode);
$this->assertSame(['hi', true], $resolved);
$this->assertSame(['hi', true, false], $resolved);
}
}

View File

@ -2,6 +2,7 @@
namespace Rector\Tests\Rector;
use Rector\Exception\Rector\RectorNotFoundException;
use Rector\Rector\RectorCollector;
use Rector\Tests\AbstractContainerAwareTestCase;
use Rector\Tests\Rector\RectorCollectorSource\DummyRector;
@ -17,6 +18,9 @@ final class RectorCollectorTest extends AbstractContainerAwareTestCase
{
$this->rectorCollector = $this->container->get(RectorCollector::class);
$this->rectorCollector->addRector(new DummyRector);
$dummyRector = $this->rectorCollector->getRector(DummyRector::class);
$this->assertInstanceOf(DummyRector::class, $dummyRector);
}
public function testCounts(): void
@ -32,4 +36,16 @@ final class RectorCollectorTest extends AbstractContainerAwareTestCase
$this->assertArrayHasKey(DummyRector::class, $rectors);
$this->assertInstanceOf(DummyRector::class, $rectors[DummyRector::class]);
}
public function testGetNonExistinsRector(): void
{
$this->expectException(RectorNotFoundException::class);
$this->expectExceptionMessage(sprintf(
'Rectors class "%s" was not found. Available rectors are: "%s".',
'MissingRector',
DummyRector::class
));
$this->rectorCollector->getRector('MissingRector');
}
}