FFFF Dependent number type input validation fixed by forgie1 · Pull Request #290 · nette/forms · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added type inference tests
  • Loading branch information
dg committed May 12, 8000 2022
commit 8c2092a94c564cea3090b4d6b8cfe97a8351e5de
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"nette/tester": "^2.4",
"latte/latte": "^2.10.2 || ^3.0",
"tracy/tracy": "^2.8",
"phpstan/phpstan-nette": "^0.12"
"phpstan/phpstan-nette": "^1.0"
},
"conflict": {
"nette/di": "<3.0-stable",
Expand Down
31 changes: 31 additions & 0 deletions tests/types/ControlsReturnTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* @phpVersion 8.0
*/

declare(strict_types=1);

require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/TestCase.php';


class ControlsReturnTypeTest extends PHPStan\Testing\TypeInferenceTestCase
{
/** @return iterable<mixed> */
public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/Controls.getValue().php');
}


/** @dataProvider dataFileAsserts */
public function testFileAsserts(string $assertType, string $file, mixed ...$args): void
{
$this->assertFileAsserts($assertType, $file, ...$args);
}
}


$testCase = new ControlsReturnTypeTest;
$testCase->run();
22 changes: 22 additions & 0 deletions tests/types/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PHPUnit\Framework;

use Tester\Assert;


abstract class TestCase extends \Tester\TestCase
{
protected function assertSame(mixed $expected, mixed $actual, string $message = ''): void
{
Assert::same($expected, $actual, $message);
}


protected function assertTrue(mixed $actual, string $message = ''): void
{
Assert::true($actual, $message);
}
}
60 changes: 60 additions & 0 deletions tests/types/data/Controls.getValue().php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

use Nette\Forms\Form;
use function PHPStan\Testing\assertType;


$form = new Form;

$input = $form->addText('Text');
assertType('string|null', $input->getValue());

$input = $form->addPassword('Password');
assertType('string|null', $input->getValue());

$input = $form->addTextArea('TextArea');
assertType('string|null', $input->getValue());

$input = $form->addEmail('Email');
assertType('string|null', $input->getValue());

$input = $form->addInteger('Integer');
assertType('string|null', $input->getValue());

$input = $form->addUpload('Upload');
assertType('array<Nette\Http\FileUpload>|Nette\Http\FileUpload|null', $input->getValue());

$input = $form->addMultiUpload('MultiUpload');
assertType('array<Nette\Http\FileUpload>|Nette\Http\FileUpload|null', $input->getValue());

$input = $form->addHidden('Hidden');
assertType('string|null', $input->getValue());

$input = $form->addCheckbox('Checkbox');
assertType('bool|null', $input->getValue());

$input = $form->addRadioList('RadioList');
assertType('int|string|null', $input->getValue());

$input = $form->addCheckboxList('CheckboxList');
assertType('array<(int|string)>', $input->getValue());

$input = $form->addSelect('Select');
assertType('int|string|null', $input->getValue());

$input = $form->addMultiSelect('MultiSelect');
assertType('array<(int|string)>', $input->getValue());

$input = $form->addSubmit('Submit');
assertType('string|null', $input->getValue());

$input = $form->addButton('Button');
assertType('string|null', $input->getValue());

$input = $form->addImageButton('ImageButton');
assertType('array|null', $input->getValue());

$input = $form->addImage('Image');
assertType('array|null', $input->getValue());
0