-
Notifications
You must be signed in to change notification settings - Fork 190
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 1 commit
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 |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ final class IteratorTest extends MenuTestCase | |
| public function testIterator(): void | ||
| { | ||
| $count = 0; | ||
| foreach ($this->pt1 as $key => $value) { | ||
| foreach ($this->pt1->getChildren() as $key => $value) { | ||
|
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. why ? This should not be needed. This test is even meant to cover the iterable API of the menu IMO, based on its name.
Contributor
Author
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. Fixed at 2ccbffb |
||
| ++$count; | ||
| $this->assertEquals('Child '.$count, $key); | ||
| $this->assertEquals('Child '.$count, $value->getLabel()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,8 +57,23 @@ public function testMatching(callable $callback, ?bool $expected): void | |
| */ | ||
| public static function provideData(): iterable | ||
| { | ||
| yield 'matching' => [fn (): ?bool => true, true]; | ||
| yield 'not matching' => [fn (): ?bool => false, false]; | ||
| yield 'skipping' => [fn (): ?bool => null, null]; | ||
| yield 'matching' => [[self::class, 'matchingCallable'], true]; | ||
| yield 'not matching' => [[self::class, 'notMatchingCallable'], false]; | ||
| yield 'skipping' => [[self::class, 'skippingCallable'], null]; | ||
|
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. Why this change ?
Contributor
Author
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. Originally was Line CallbackVoterTest.php :60 Anonymous function never returns null so it can be removed from the return type. But I over complicate doing a static function instead of closure. Reverting only solving the nullables at cf50474 |
||
| } | ||
|
|
||
| private static function matchingCallable(): bool | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| private static function notMatchingCallable(): bool | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| private static function skippingCallable(): null | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,11 +13,11 @@ final class MenuItemTreeTest extends MenuTestCase | |
| { | ||
| public function testSampleTreeIntegrity(): void | ||
| { | ||
| $this->assertCount(2, $this->menu); | ||
| $this->assertCount(3, $this->menu['Parent 1']); | ||
| $this->assertCount(1, $this->menu['Parent 2']); | ||
| $this->assertCount(1, $this->menu['Parent 2']['Child 4']); | ||
| $this->assertEquals('Grandchild 1', $this->menu['Parent 2']['Child 4']['Grandchild 1']->getName()); | ||
| $this->assertCount(2, $this->menu->getChildren()); | ||
| $this->assertCount(3, $this->pt1->getChildren()); | ||
| $this->assertCount(1, $this->pt2->getChildren()); | ||
| $this->assertCount(1, $this->ch4->getChildren()); | ||
| $this->assertEquals('Grandchild 1', $this->gc1->getName()); | ||
|
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 is totally changing the assertions being done. It does not test the integrity of the ArrayAccess anymore.
Contributor
Author
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. Fixed at 584ec1e and other cases for ensure the ArrayAccess instead getChildren |
||
| } | ||
|
|
||
| public function testGetLevel(): void | ||
|
|
@@ -120,13 +120,13 @@ public function testActsLikeLastWithNoDisplayedItem(): void | |
| public function testArrayAccess(): void | ||
| { | ||
| $this->menu->addChild('Child Menu'); | ||
| $this->assertEquals('Child Menu', $this->menu['Child Menu']->getName()); | ||
| $this->assertNull($this->menu['Fake']); | ||
| $this->assertEquals('Child Menu', $this->menu->getChildren()['Child Menu']->getName()); | ||
|
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 is not testing the ArrayAccess implementation anymore, while this is what the test is about.
Contributor
Author
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. Fixed at 2d5281f |
||
| $this->assertNull($this->menu->getChild('Fake')); | ||
|
|
||
| $this->menu['New Child'] = 'New Label'; | ||
| $this->assertEquals(MenuItem::class, \get_class($this->menu['New Child'])); | ||
| $this->assertEquals('New Child', $this->menu['New Child']->getName()); | ||
| $this->assertEquals('New Label', $this->menu['New Child']->getLabel()); | ||
| $this->menu->addChild('New Child', ['label' => 'New Label']); | ||
| $this->assertEquals(MenuItem::class, \get_class($this->menu->getChildren()['New Child'])); | ||
| $this->assertEquals('New Child', $this->menu->getChildren()['New Child']->getName()); | ||
| $this->assertEquals('New Label', $this->menu->getChildren()['New Child']->getLabel()); | ||
|
|
||
| unset($this->menu['New Child']); | ||
| $this->assertNull($this->menu['New Child']); | ||
|
|
@@ -204,14 +204,14 @@ public function testRemoveChild(): void | |
| $this->assertCount(4, $this->ch4); | ||
| $this->ch4->removeChild('gc4'); | ||
| $this->assertCount(3, $this->ch4); | ||
| $this->assertTrue($this->ch4->getChild('Grandchild 1')->isFirst()); | ||
| $this->assertTrue($this->ch4->getChild('gc3')->isLast()); | ||
| $this->assertTrue($this->gc1->isFirst()); | ||
| $this->assertTrue($gc3->isLast()); | ||
| } | ||
|
|
||
| public function testRemoveFakeChild(): void | ||
| { | ||
| $this->menu->removeChild('fake'); | ||
| $this->assertCount(2, $this->menu); | ||
| $this->assertCount(2, $this->menu->getChildren()); | ||
| } | ||
|
|
||
| public function testReAddRemovedChild(): void | ||
|
|
@@ -243,7 +243,7 @@ public function testGetUri(): void | |
| { | ||
| $this->addChildWithExternalUrl(); | ||
| $this->assertNull($this->pt1->getUri()); | ||
| $this->assertEquals('http://www.symfony-reloaded.org', $this->menu['child']->getUri()); | ||
| $this->assertEquals('http://www.symfony-reloaded.org', $this->menu->getChildren()['child']->getUri()); | ||
| } | ||
|
|
||
| protected function addChildWithExternalUrl(): void | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,21 +9,21 @@ | |
|
|
||
| abstract class MenuTestCase extends TestCase | ||
| { | ||
| protected ItemInterface|null $menu; | ||
| protected ?ItemInterface $menu; | ||
|
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. To me, the right fix is to make all those properties non-nullable and removing the
Contributor
Author
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. Changed in f1db5be |
||
|
|
||
| protected ItemInterface|null $pt1; | ||
| protected ?ItemInterface $pt1; | ||
|
|
||
| protected ItemInterface|null $ch1; | ||
| protected ?ItemInterface $ch1; | ||
|
|
||
| protected ItemInterface|null $ch2; | ||
| protected ?ItemInterface $ch2; | ||
|
|
||
| protected ItemInterface|null $ch3; | ||
| protected ?ItemInterface $ch3; | ||
|
|
||
| protected ItemInterface|null $pt2; | ||
| protected ?ItemInterface $pt2; | ||
|
|
||
| protected ItemInterface|null $ch4; | ||
| protected ?ItemInterface $ch4; | ||
|
|
||
| protected ItemInterface|null $gc1; | ||
| protected ?ItemInterface $gc1; | ||
|
Contributor
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. Why?
Contributor
Author
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. It is just sugar syntax for union types, very common in my opinion in a lot projects
Contributor
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. Okay, so the change is abosutely unrealted to and irrelevant for the goal that you're trying to achieve? Let's revert it then?
Contributor
Author
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. Changed in f1db5be |
||
|
|
||
| protected function setUp(): void | ||
| { | ||
|
|
||
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.
I'd rather use
new IteratorIterator($this->menu), which is the built-in way in PHP to wrap a Traversable into an Iterator.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.
Fixed at 3f6fef6