Skip to content

Commit

Permalink
Add templates to existing form test assets
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Nov 23, 2023
1 parent 8a57ade commit 4fb5884
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions test/Integration/TestAsset/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Form\Form as BaseForm;
use Laminas\Form\FormElementManager;

/** @extends BaseForm<array<string, mixed>> */
final class Form extends BaseForm
{
/** @var null|FormElementManager */
Expand Down
1 change: 1 addition & 0 deletions test/TestAsset/Annotation/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Laminas\Form\Form as BaseForm;

/** @extends BaseForm<array<string, mixed>> */
class Form extends BaseForm
{
}
18 changes: 16 additions & 2 deletions test/TestAsset/CreateAddressForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
use Laminas\Form\Form;
use Laminas\Hydrator\ClassMethodsHydrator;

/**
* @psalm-type Payload = array{
* street: non-empty-string,
* phones: list<array{id: mixed, number: non-empty-string}>,
* city: array{
* name: non-empty-string,
* zipCode: non-empty-string,
* country: array{
* name: non-empty-string,
* continent: non-empty-string,
* },
* },
* }
* @extends Form<Payload>
*/
class CreateAddressForm extends Form
{
public function __construct()
Expand All @@ -15,8 +30,7 @@ public function __construct()

$this
->setAttribute('method', 'post')
->setHydrator(new ClassMethodsHydrator(false))
->setInputFilter(new InputFilter());
->setHydrator(new ClassMethodsHydrator(false));

$address = new AddressFieldset();
$address->setUseAsBaseFieldset(true);
Expand Down
1 change: 1 addition & 0 deletions test/TestAsset/CustomCreatedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateTime;
use Laminas\Form\Form;

/** @extends Form<array<string, mixed>> */
class CustomCreatedForm extends Form
{
public function __construct(private DateTime $created, ?string $name = null, array $options = [])
Expand Down
1 change: 1 addition & 0 deletions test/TestAsset/FileInputFilterProviderForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Laminas\Form\Form;

/** @extends Form<array<string, mixed>> */
class FileInputFilterProviderForm extends Form
{
/**
Expand Down
2 changes: 1 addition & 1 deletion test/TestAsset/FormCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use Laminas\Form\Element\Color as ColorElement;
use Laminas\Form\Form;

/** @extends Form<array<string, mixed>> */
class FormCollection extends Form
{
public function __construct()
{
parent::__construct('collection');
$this->setInputFilter(new InputFilter());

$element = new ColorElement('color');
$this->add([
Expand Down
1 change: 1 addition & 0 deletions test/TestAsset/InputFilterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Form\Form;
use Laminas\InputFilter\InputFilterProviderInterface;

/** @extends Form<array{foo: non-empty-string}> */
class InputFilterProvider extends Form implements InputFilterProviderInterface
{
/**
Expand Down
1 change: 1 addition & 0 deletions test/TestAsset/InputFilterProviderWithFieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Form\Form;
use Laminas\InputFilter\InputFilterProviderInterface;

/** @extends Form<array{foo: non-empty-string}> */
class InputFilterProviderWithFieldset extends Form implements InputFilterProviderInterface
{
/**
Expand Down
1 change: 1 addition & 0 deletions test/TestAsset/InvokableForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Laminas\Form\Form;

/** @extends Form<array<string, mixed>> */
final class InvokableForm extends Form
{
}
1 change: 1 addition & 0 deletions test/TestAsset/NestedCollectionsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Laminas\Form\Fieldset;
use Laminas\Form\Form;

/** @extends Form<array<string, mixed>> */
class NestedCollectionsForm extends Form
{
public function __construct()
Expand Down
4 changes: 2 additions & 2 deletions test/TestAsset/NewProductForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Form\Form;
use Laminas\Hydrator\ClassMethodsHydrator;

/** @extends Form<array<string, mixed>> */
class NewProductForm extends Form
{
public function __construct()
Expand All @@ -15,8 +16,7 @@ public function __construct()

$this
->setAttribute('method', 'post')
->setHydrator(new ClassMethodsHydrator())
->setInputFilter(new InputFilter());
->setHydrator(new ClassMethodsHydrator());

$fieldset = new ProductFieldset();
$fieldset->setUseAsBaseFieldset(true);
Expand Down
5 changes: 2 additions & 3 deletions test/TestAsset/OrphansForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

use Laminas\Form\Element\Collection;
use Laminas\Form\Form;
use LaminasTest\Form\TestAsset\OrphansFieldset;

/** @extends Form<array<string, mixed>> */
class OrphansForm extends Form
{
public function __construct()
{
parent::__construct('orphans');

$this->setAttribute('method', 'post')
->setBindOnValidate(self::BIND_ON_VALIDATE)
->setInputFilter(new InputFilter());
->setBindOnValidate(self::BIND_ON_VALIDATE);

//adds a collection of 2
$this->add(
Expand Down

0 comments on commit 4fb5884

Please sign in to comment.