rector/tests/RectorDefinition/RectorDefinitionTest.php

42 lines
1.2 KiB
PHP
Raw Normal View History

2018-04-02 20:43:47 +00:00
<?php declare(strict_types=1);
namespace Rector\Tests\RectorDefinition;
use PHPUnit\Framework\TestCase;
use Rector\Exception\RectorDefinition\CodeSamplesMissingException;
2018-04-02 20:43:47 +00:00
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
use stdClass;
use TypeError;
2018-04-02 20:43:47 +00:00
final class RectorDefinitionTest extends TestCase
{
public function test(): void
{
$rectorDefinition = new RectorDefinition('Some description', [
2018-04-02 21:10:27 +00:00
new CodeSample('Code before', 'Code after'),
2018-04-02 20:43:47 +00:00
]);
$this->assertSame('Some description', $rectorDefinition->getDescription());
$codeSamples = $rectorDefinition->getCodeSamples();
$this->assertCount(1, $codeSamples);
$codeSample = $codeSamples[0];
$this->assertSame('Code before', $codeSample->getCodeBefore());
$this->assertSame('Code after', $codeSample->getCodeAfter());
}
public function testInvalidCodeSamplesType(): void
{
$this->expectException(TypeError::class);
new RectorDefinition('Some description', [new stdClass()]);
}
public function testInvalidCodeSamplesCount(): void
{
$this->expectException(CodeSamplesMissingException::class);
new RectorDefinition('Some description', []);
}
2018-04-02 20:43:47 +00:00
}