2018-04-02 22:43:47 +02:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Rector\Tests\RectorDefinition;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Rector\RectorDefinition\CodeSample;
|
|
|
|
use Rector\RectorDefinition\RectorDefinition;
|
2018-04-08 17:41:06 +02:00
|
|
|
use stdClass;
|
|
|
|
use TypeError;
|
2018-04-02 22:43:47 +02:00
|
|
|
|
|
|
|
final class RectorDefinitionTest extends TestCase
|
|
|
|
{
|
|
|
|
public function test(): void
|
|
|
|
{
|
|
|
|
$rectorDefinition = new RectorDefinition('Some description', [
|
2018-04-02 23:10:27 +02:00
|
|
|
new CodeSample('Code before', 'Code after'),
|
2018-04-02 22:43:47 +02: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());
|
|
|
|
}
|
2018-04-08 17:41:06 +02:00
|
|
|
|
|
|
|
public function testInvalidCodeSamplesType(): void
|
|
|
|
{
|
|
|
|
$this->expectException(TypeError::class);
|
|
|
|
new RectorDefinition('Some description', [new stdClass()]);
|
|
|
|
}
|
|
|
|
|
2019-02-12 00:30:10 +01:00
|
|
|
public function testEmptyCodeSamples(): void
|
2018-04-08 17:41:06 +02:00
|
|
|
{
|
2019-02-12 00:30:10 +01:00
|
|
|
$rectorDefinition = new RectorDefinition('Some description');
|
|
|
|
$this->assertCount(0, $rectorDefinition->getCodeSamples());
|
2018-04-08 17:41:06 +02:00
|
|
|
}
|
2018-04-02 22:43:47 +02:00
|
|
|
}
|