-
Notifications
You must be signed in to change notification settings - Fork 192
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) { | ||
|
||
| ++$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]; | ||
|
||
| } | ||
|
|
||
| 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()); | ||
|
||
| } | ||
|
|
||
| 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()); | ||
|
||
| $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; | ||
|
||
|
|
||
| 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; | ||
|
||
|
|
||
| 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