From 63819c14e5ccf9403f404349a73df8044e0d8a4c Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 27 May 2019 08:39:33 +0200 Subject: [PATCH] Create test --- lib/NoUselessInlineAnnotationsRule.php | 40 ++++++++++ tests/NoUselessInlineAnnotationsRuleTest.php | 45 +++++++++++ .../fixture.php | 77 +++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 lib/NoUselessInlineAnnotationsRule.php create mode 100644 tests/NoUselessInlineAnnotationsRuleTest.php create mode 100644 tests/TestAsset/NoUselessInlineAnnotationsRule/fixture.php diff --git a/lib/NoUselessInlineAnnotationsRule.php b/lib/NoUselessInlineAnnotationsRule.php new file mode 100644 index 0000000..8cbb56c --- /dev/null +++ b/lib/NoUselessInlineAnnotationsRule.php @@ -0,0 +1,40 @@ +broker = $broker; + } + + public function getNodeType(): string + { + return Assign::class; + } + + /** + * @param \PhpParser\Node\Expr\Assign $node + * @param \PHPStan\Analyser\Scope $scope + * + * @return string[] errors + */ + public function processNode(Node $node, Scope $scope): array + { + r($node); + } +} diff --git a/tests/NoUselessInlineAnnotationsRuleTest.php b/tests/NoUselessInlineAnnotationsRuleTest.php new file mode 100644 index 0000000..cc76c82 --- /dev/null +++ b/tests/NoUselessInlineAnnotationsRuleTest.php @@ -0,0 +1,45 @@ +createBroker(); + + return new NoUselessInlineAnnotationsRule($broker); + } + + public function testClassConstant() + { + $this->analyse( + [ + __DIR__ . '/TestAsset/NoUselessInlineAnnotationsRule/fixture.php', + ], + [ + [ + 'Function mkdir is unsafe to use, rely on Symfony component Filesystem::mkdir instead.', + 9, + ], + [ + 'Function readlink is unsafe to use, rely on Symfony component Filesystem::readlink instead.', + 12, + ], + [ + 'Function touch is unsafe to use, rely on Symfony component Filesystem::touch instead.', + 15, + ], + ] + ); + } +} diff --git a/tests/TestAsset/NoUselessInlineAnnotationsRule/fixture.php b/tests/TestAsset/NoUselessInlineAnnotationsRule/fixture.php new file mode 100644 index 0000000..659525c --- /dev/null +++ b/tests/TestAsset/NoUselessInlineAnnotationsRule/fixture.php @@ -0,0 +1,77 @@ +bar1(); + + /** @var Bar $foo2 */ + $foo2 = $this->bar2(); + + /** @var Bar $foo2bis */ + $foo2bis = $this->bar2bis(); + + /** @var Bar[] $foo3 */ + $foo3 = $this->bar3(); + + /** @var Bar $foo4 */ + $foo4 = $this->bar4(); + + $no = $this->bar1(); + $no = $this->bar2(); + $no = $this->bar2bis(); + $no = $this->bar3(); + $no = $this->bar4(); + + /** @var Bar[] $xyz */ + $foo1 = $this->bar1(); + + /** @var Bar $xyz */ + $foo2 = $this->bar2(); + + /** @var Bar $xyz */ + $foo2bis = $this->bar2bis(); + + /** @var Bar[] $xyz */ + $foo3 = $this->bar3(); + + /** @var Bar $xyz */ + $foo4 = $this->bar4(); + } + + /** + * @return Bar[] + */ + public function bar1(): array + { + return [new Bar()]; + } + + public function bar2(): Bar + { + return new Bar(); + } + + /** + * @return Bar + */ + public function bar2bis() + { + return new Bar(); + } + + public function bar3(): array + { + return [new Bar()]; + } + + public function bar4() + { + return new Bar(); + } +} + +class Bar {}