Skip to content

Commit

Permalink
Merge pull request #18 from kynx/filter-abstract-forms
Browse files Browse the repository at this point in the history
Do not process abstract forms
  • Loading branch information
kynx authored Feb 23, 2024
2 parents 94b3bdf + e807894 commit 73d2041
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Locator/RecursiveFormFileIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function current(): FormFile|null
if (! $current instanceof ReflectionClass) {
return null;
}
if ($current->isAbstract()) {
return null;
}

try {
$form = $this->formElementManager->get($current->getName());
Expand Down
11 changes: 11 additions & 0 deletions test/Locator/Asset/AbstractForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace KynxTest\Laminas\FormShape\Locator\Asset;

use Laminas\Form\Form;

abstract class AbstractForm extends Form
{
}
11 changes: 11 additions & 0 deletions test/Locator/RecursiveFormFileIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Kynx\Laminas\FormShape\Locator\FormFile;
use Kynx\Laminas\FormShape\Locator\RecursiveFormFileIterator;
use KynxTest\Laminas\FormShape\Locator\Asset\AbstractForm;
use KynxTest\Laminas\FormShape\Locator\Asset\TestForm;
use Laminas\Form\Exception\InvalidElementException;
use Laminas\Form\Fieldset;
Expand Down Expand Up @@ -42,6 +43,16 @@ public function testCurrentReturnsNullForNonReflectionEntry(): void
self::assertNull($actual);
}

public function testCurrentReturnsNullForAbstractForm(): void
{
$reflection = new ReflectionClass(AbstractForm::class);
$this->innerIterator->offsetSet(0, $reflection);
$this->innerIterator->rewind();

$actual = $this->iterator->current();
self::assertNull($actual);
}

public function testCurrentReturnsNullWhenFormElementManagerThrowsException(): void
{
$reflection = new ReflectionClass(TestForm::class);
Expand Down
11 changes: 7 additions & 4 deletions test/Locator/RecursiveReflectionIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use FilesystemIterator;
use Kynx\Laminas\FormShape\Locator\RecursiveReflectionIterator;
use Kynx\Laminas\FormShape\Locator\ReflectionProvider;
use KynxTest\Laminas\FormShape\Locator\Asset\AbstractForm;
use KynxTest\Laminas\FormShape\Locator\Asset\Sub\SubForm;
use KynxTest\Laminas\FormShape\Locator\Asset\TestForm;
use Laminas\Form\FormInterface;
Expand Down Expand Up @@ -35,8 +36,9 @@ protected function setUp(): void
public function testIteratorRecursesFileInfo(): void
{
$expected = [
__DIR__ . '/Asset/TestForm.php' => new ReflectionClass(TestForm::class),
__DIR__ . '/Asset/Sub/SubForm.php' => new ReflectionClass(SubForm::class),
__DIR__ . '/Asset/AbstractForm.php' => new ReflectionClass(AbstractForm::class),
__DIR__ . '/Asset/TestForm.php' => new ReflectionClass(TestForm::class),
__DIR__ . '/Asset/Sub/SubForm.php' => new ReflectionClass(SubForm::class),
];
$flags = FilesystemIterator::SKIP_DOTS;
$reflectionProvider = new ReflectionProvider($this->loader, FormInterface::class);
Expand All @@ -50,8 +52,9 @@ public function testIteratorRecursesFileInfo(): void
public function testIteratorRecursesStrings(): void
{
$expected = [
__DIR__ . '/Asset/TestForm.php' => new ReflectionClass(TestForm::class),
__DIR__ . '/Asset/Sub/SubForm.php' => new ReflectionClass(SubForm::class),
__DIR__ . '/Asset/AbstractForm.php' => new ReflectionClass(AbstractForm::class),
__DIR__ . '/Asset/TestForm.php' => new ReflectionClass(TestForm::class),
__DIR__ . '/Asset/Sub/SubForm.php' => new ReflectionClass(SubForm::class),
];
$flags = FilesystemIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_PATHNAME;
$reflectionProvider = new ReflectionProvider($this->loader, FormInterface::class);
Expand Down

0 comments on commit 73d2041

Please sign in to comment.