Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\Fixture;

use Rector\Tests\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\Source\ValidatedBase;

class SkipsParentConstructor extends ValidatedBase
{
private bool $validated = false;

public function __construct()
{
$this->validate();
$this->validated = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\Source;

abstract class ValidatedBase
{
protected function validate(): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// A child class may bypass the constructor and depend on the declared property default
if (! $node->isFinal()) {
return null;
}

$hasChanged = false;

$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
Expand Down
12 changes: 6 additions & 6 deletions tests/Bin/RectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ final class RectorTest extends TestCase
public static function outputProvider(): Iterator
{
yield 'Version' => [
'command' => PHP_BINARY . ' bin/rector --version',
'expectedOutput' => "Rector @package_version@" . PHP_EOL,
'command' => PHP_BINARY . ' bin/rector --version',
'expectedOutput' => 'Rector @package_version@' . PHP_EOL,
];
yield 'Exception with previous console output' => [
'command' => PHP_BINARY . ' bin/rector -c tests/Bin/config/incorrect-phpstan-files.php',
'expectedOutput' => PHP_EOL . " [ERROR] Rector\\NodeTypeResolver\\DependencyInjection\\PHPStanServicesFactory " . PHP_EOL . PHP_EOL . " [ERROR] Unexpected item 'parameters › invalidParameters'. " . PHP_EOL . PHP_EOL,
'command' => PHP_BINARY . ' bin/rector -c tests/Bin/config/incorrect-phpstan-files.php',
'expectedOutput' => PHP_EOL . ' [ERROR] Rector\\NodeTypeResolver\\DependencyInjection\\PHPStanServicesFactory ' . PHP_EOL . PHP_EOL . " [ERROR] Unexpected item 'parameters › invalidParameters'. " . PHP_EOL . PHP_EOL,
];
yield 'Exception with previous console output in JSON format' => [
'command' => PHP_BINARY . ' bin/rector -c tests/Bin/config/incorrect-phpstan-files.php --output-format json',
'command' => PHP_BINARY . ' bin/rector -c tests/Bin/config/incorrect-phpstan-files.php --output-format json',
'expectedOutput' => '{"fatal_errors":["Rector\\\\NodeTypeResolver\\\\DependencyInjection\\\\PHPStanServicesFactory","Unexpected item \'parameters › invalidParameters\'."]}',
];
}
Expand All @@ -35,6 +35,6 @@ public function testConsoleOutput(string $command, string $expectedOutput): void
{
$process = Process::fromShellCommandline($command);
$process->run();
$this->assertSame($expectedOutput, preg_replace("/ +/", " ", $process->getOutput()));
$this->assertSame($expectedOutput, preg_replace('/ +/', ' ', $process->getOutput()));
}
}