-
Notifications
You must be signed in to change notification settings - Fork 191
feat: add tests folder with phpstan level 8 solved all errors #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
73826fc
22f988d
65678ec
6e591d5
f1db5be
3f6fef6
2d5281f
b70d44a
584ec1e
2ccbffb
cf50474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,6 @@ parameters: | |
| treatPhpDocTypesAsCertain: false | ||
| paths: | ||
| - src | ||
| - tests | ||
| includes: | ||
| - phpstan-baseline.neon | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,13 +11,17 @@ final class CurrentItemFilterIteratorTest extends MenuTestCase | |
| { | ||
| public function testSimpleFiltering(): void | ||
| { | ||
| $this->pt1->setCurrent(true); | ||
| $this->ch2->setCurrent(true); | ||
| $this->gc1->setCurrent(true); | ||
| $pt1 = $this->pt1; | ||
| $ch2 = $this->ch2; | ||
| $gc1 = $this->gc1; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those changes should be reverted |
||
| $menu = $this->menu; | ||
| $pt1->setCurrent(true); | ||
| $ch2->setCurrent(true); | ||
| $gc1->setCurrent(true); | ||
|
|
||
| $names = []; | ||
| // FilterIterator expects an Iterator implementation explicitly, not an IteratorAggregate. | ||
| $iterator = new CurrentItemFilterIterator($this->menu->getIterator(), new Matcher()); | ||
| $iterator = new CurrentItemFilterIterator(new \IteratorIterator($this->menu), new Matcher()); | ||
|
|
||
| foreach ($iterator as $value) { | ||
| $names[] = $value->getName(); | ||
|
|
@@ -28,13 +32,17 @@ public function testSimpleFiltering(): void | |
|
|
||
| public function testFiltering(): void | ||
| { | ||
| $this->pt1->setCurrent(true); | ||
| $this->ch2->setCurrent(true); | ||
| $this->gc1->setCurrent(true); | ||
| $pt1 = $this->pt1; | ||
| $ch2 = $this->ch2; | ||
| $gc1 = $this->gc1; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those changes should be reverted |
||
| $menu = $this->menu; | ||
| $pt1->setCurrent(true); | ||
| $ch2->setCurrent(true); | ||
| $gc1->setCurrent(true); | ||
|
|
||
| $names = []; | ||
| $iterator = new CurrentItemFilterIterator( | ||
| new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::SELF_FIRST), | ||
| new \RecursiveIteratorIterator(new RecursiveItemIterator($menu), \RecursiveIteratorIterator::SELF_FIRST), | ||
| new Matcher() | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,17 @@ final class DisplayedItemFilterIteratorTest extends MenuTestCase | |
| { | ||
| public function testFiltering(): void | ||
| { | ||
| $this->ch1->setDisplay(false); | ||
| $this->ch2->setDisplay(false); | ||
| $this->ch4->setDisplayChildren(false); | ||
| $ch1 = $this->ch1; | ||
| $ch2 = $this->ch2; | ||
| $ch4 = $this->ch4; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those changes should be reverted |
||
| $menu = $this->menu; | ||
| $ch1->setDisplay(false); | ||
| $ch2->setDisplay(false); | ||
| $ch4->setDisplayChildren(false); | ||
|
|
||
| $names = []; | ||
| $iterator = new \RecursiveIteratorIterator( | ||
| new DisplayedItemFilterIterator(new RecursiveItemIterator($this->menu)), | ||
| new DisplayedItemFilterIterator(new RecursiveItemIterator(new \ArrayIterator($menu->getChildren()))), | ||
| \RecursiveIteratorIterator::SELF_FIRST | ||
| ); | ||
| foreach ($iterator as $value) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,22 +16,22 @@ public function testExtensions(): void | |
| $extension1 = $this->getMockBuilder(ExtensionInterface::class)->getMock(); | ||
| $extension1->expects($this->once()) | ||
| ->method('buildOptions') | ||
| ->with(['foo' => 'bar']) | ||
| ->willReturn(['uri' => 'foobar']); | ||
| ->with(['uri' => 'foobar']) | ||
| ->willReturnArgument(0); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes the behavior of the test. |
||
| $extension1->expects($this->once()) | ||
| ->method('buildItem') | ||
| ->with($this->isInstanceOf(ItemInterface::class), $this->containsCustom('foobar')); | ||
| ->with($this->isInstanceOf(ItemInterface::class), $this->containsEqual('foobar')); | ||
|
|
||
| $factory->addExtension($extension1); | ||
|
|
||
| $extension2 = $this->getMockBuilder(ExtensionInterface::class)->getMock(); | ||
| $extension2->expects($this->once()) | ||
| ->method('buildOptions') | ||
| ->with(['foo' => 'baz']) | ||
| ->willReturn(['foo' => 'bar']); | ||
| $extension1->expects($this->once()) | ||
| ->willReturn(['uri' => 'foobar']); | ||
| $extension2->expects($this->once()) | ||
| ->method('buildItem') | ||
| ->with($this->isInstanceOf(ItemInterface::class), $this->containsCustom('foobar')); | ||
| ->with($this->isInstanceOf(ItemInterface::class), $this->containsEqual('foobar')); | ||
|
|
||
| $factory->addExtension($extension2, 10); | ||
|
|
||
|
|
@@ -57,16 +57,5 @@ public function testCreateItem(): void | |
| $this->assertEquals('foo', $item->getLinkAttribute('class')); | ||
| } | ||
|
|
||
| private function containsCustom(string $value): ?object | ||
| { | ||
| if (\method_exists($this, 'contains')) { | ||
| return $this->contains($value); | ||
| } | ||
|
|
||
| if (\method_exists($this, 'containsEqual')) { | ||
| return $this->containsEqual($value); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be reverted. the place where phpstan is reported an error is inside
testBreadcrumbsArrayInvalidData, which is specifically testing the runtime behavior when passing invalid data (as not all users of the library might be using static analysis to catch such usage, and the code has some defense against that in that case).the proper way to fix the phpstan warning is to use
@phpstan-expect-errorto make phpstan aware that an error is expected in that line.