Thank you very much for creating Rector, ppl!
| Subject |
Details |
| PHP version |
PHP 7.3 |
| Full Command |
vendor/bin/rector --level php73 --debug process lib/experiment/tests/Unit/Events/AbstractEventTest.php |
Current Behaviour
If I run it with --debug flag, it throws an exception. This doesn't happen if I don't put the flag there, but the file is changed in a weird way: removes all blank lines and adds the FQCN to most class references.
Running with debug flag:
$ vendor/bin/rector --level php73 --debug process lib/experiment/tests/Unit/Events/AbstractEventTest.php
Rector v0.5.9
[parsing] /opt/acme.com/project/lib/experiment/tests/Unit/Events/AbstractEventTest.php
PHP Fatal error: Uncaught Rector\Exception\ShouldNotHappenException in /opt/acme.com/project/vendor/rector/rector/src/NodeContainer/ParsedNodesByType.php:486
Stack trace:
#0 /opt/acme.com/project/vendor/rector/rector/src/NodeContainer/ParsedNodesByType.php(387): Rector\NodeContainer\ParsedNodesByType->addClassConstant(Object(PhpParser\Node\Stmt\ClassConst))
#1 /opt/acme.com/project/vendor/rector/rector/packages/NodeTypeResolver/src/NodeVisitor/NodeCollectorNodeVisitor.php(27): Rector\NodeContainer\ParsedNodesByType->collect(Object(PhpParser\Node\Stmt\ClassConst))
#2 /opt/acme.com/project/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(200): Rector\NodeTypeResolver\NodeVisitor\NodeCollectorNodeVisitor->enterNode(Object(PhpParser\Node\Stmt\ClassConst))
#3 /opt/acme.com/project/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(114): PhpParser\NodeTraverser->traverseArray(Array)
#4 /opt/acme.com/project/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(146): PhpParser\NodeTraverse in /opt/acme.com/project/vendor/rector/rector/src/NodeContainer/ParsedNodesByType.php on line 486
Running without debug flag:
$ vendor/bin/rector --level php73 process lib/experiment/tests/Unit/Events/AbstractEventTest.php
Rector v0.5.9
3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) lib/experiment/tests/Unit/Events/AbstractEventTest.php
---------- begin diff ----------
--- Original
+++ New
@@ -1,6 +1,6 @@
<?php
-declare(strict_types=1);
+declare (strict_types=1);
namespace Acme\Experiment\Test\Unit\Events;
@@ -10,16 +10,14 @@
use Acme\Experiment\Events\AbstractEvent;
use Acme\Experiment\Events\EventInterface;
use Acme\Experiment\ExperimentInterface;
-
/**
* @internal
*
* @small
*/
-final class AbstractEventTest extends TestCase
+final class AbstractEventTest extends \PHPUnit\Framework\TestCase
{
public const VERSION_A = 'version-a';
-
/**
* @test
*/
@@ -28,26 +26,23 @@
$event = $this->getEvent(self::VERSION_A);
self::assertSame(self::VERSION_A, $event->getName());
}
-
/**
* @test
*/
public function invalid_argument(): void
{
- $this->expectException(InvalidArgumentException::class);
- $this->expectExceptionMessageRegExp('/^Event name \\[invalid\\] is not matching any valid names of class ".+". Valid values are \\[version-a\\].$/');
-
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessageRegExp('/^Event name \[invalid\] is not matching any valid names of class ".+". Valid values are \[version-a\].$/');
$this->getEvent('invalid');
}
-
- private function getEvent(string $eventName): EventInterface
+ private function getEvent(string $eventName): \Acme\Experiment\Events\EventInterface
{
- return new class($eventName) extends AbstractEvent {
- private const VERSION_A = AbstractEventTest::VERSION_A;
-
- public function getExperiment(): ExperimentInterface
+ return new class($eventName) extends \Acme\Experiment\Events\AbstractEvent
+ {
+ private const VERSION_A = \Acme\Experiment\Test\Unit\Events\AbstractEventTest::VERSION_A;
+ public function getExperiment(): \Acme\Experiment\ExperimentInterface
{
- return Mockery::mock(ExperimentInterface::class);
+ return \Mockery::mock(\Acme\Experiment\ExperimentInterface::class);
}
};
}
----------- end diff -----------
[ERROR] Could not process "lib/experiment/tests/Unit/Events/AbstractEventTest.php" file, due to:
"".
[ERROR] Could not process "lib/experiment/tests/Unit/Events/AbstractEventTest.php" file, due to:
"".
Minimal PHP Code Causing Issue
I don't know where the problem is exactly so here's the whole class:
<?php
declare(strict_types=1);
namespace Acme\Experiment\Test\Unit\Events;
use InvalidArgumentException;
use Mockery;
use PHPUnit\Framework\TestCase;
use Acme\Experiment\Events\AbstractEvent;
use Acme\Experiment\Events\EventInterface;
use Acme\Experiment\ExperimentInterface;
/**
* @internal
*
* @small
*/
final class AbstractEventTest extends TestCase
{
public const VERSION_A = 'version-a';
/**
* @test
*/
public function get_event_name(): void
{
$event = $this->getEvent(self::VERSION_A);
self::assertSame(self::VERSION_A, $event->getName());
}
/**
* @test
*/
public function invalid_argument(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/^Event name \\[invalid\\] is not matching any valid names of class ".+". Valid values are \\[version-a\\].$/');
$this->getEvent('invalid');
}
private function getEvent(string $eventName): EventInterface
{
return new class($eventName) extends AbstractEvent {
private const VERSION_A = AbstractEventTest::VERSION_A;
public function getExperiment(): ExperimentInterface
{
return Mockery::mock(ExperimentInterface::class);
}
};
}
}
Expected Behaviour
It shouldn't throw an exception nor show any error, and probably not change anything in the class being analysed.
Let me know if you need some more information.
Thank you very much for creating Rector, ppl!
Current Behaviour
If I run it with
--debugflag, it throws an exception. This doesn't happen if I don't put the flag there, but the file is changed in a weird way: removes all blank lines and adds the FQCN to most class references.Running with debug flag:
Running without debug flag:
Minimal PHP Code Causing Issue
I don't know where the problem is exactly so here's the whole class:
Expected Behaviour
It shouldn't throw an exception nor show any error, and probably not change anything in the class being analysed.
Let me know if you need some more information.