Skip to content

Commit c67a0d5

Browse files
committed
added type inference tests
1 parent 8831e01 commit c67a0d5

File tree

4 files changed

+114
-1
lines changed

4 files changed

+114
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"nette/tester": "^2.4",
2727
"latte/latte": "^2.10.2 || ^3.0",
2828
"tracy/tracy": "^2.8",
29-
"phpstan/phpstan-nette": "^0.12"
29+
"phpstan/phpstan-nette": "^1.0"
3030
},
3131
"conflict": {
3232
"nette/di": "<3.0-stable",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* @phpVersion 8.0
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
require __DIR__ . '/../bootstrap.php';
10+
require __DIR__ . '/TestCase.php';
11+
12+
13+
class ControlsReturnTypeTest extends PHPStan\Testing\TypeInferenceTestCase
14+
{
15+
/** @return iterable<mixed> */
16+
public function dataFileAsserts(): iterable
17+
{
18+
yield from $this->gatherAssertTypes(__DIR__ . '/data/Controls.getValue().php');
19+
}
20+
21+
22+
/** @dataProvider dataFileAsserts */
23+
public function testFileAsserts(string $assertType, string $file, mixed ...$args): void
24+
{
25+
$this->assertFileAsserts($assertType, $file, ...$args);
26+
}
27+
}
28+
29+
30+
$testCase = new ControlsReturnTypeTest;
31+
$testCase->run();

tests/types/TestCase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPUnit\Framework;
6+
7+
use Tester\Assert;
8+
9+
10+
abstract class TestCase extends \Tester\TestCase
11+
{
12+
protected function assertSame(mixed $expected, mixed $actual, string $message = ''): void
13+
{
14+
Assert::same($expected, $actual, $message);
15+
}
16+
17+
18+
protected function assertTrue(mixed $actual, string $message = ''): void
19+
{
20+
Assert::true($actual, $message);
21+
}
22+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nette\Forms\Form;
6+
use function PHPStan\Testing\assertType;
7+
8+
9+
$form = new Form;
10+
11+
$input = $form->addText('Text');
12+
assertType('string|null', $input->getValue());
13+
14+
$input = $form->addPassword('Password');
15+
assertType('string|null', $input->getValue());
16+
17+
$input = $form->addTextArea('TextArea');
18+
assertType('string|null', $input->getValue());
19+
20+
$input = $form->addEmail('Email');
21+
assertType('string|null', $input->getValue());
22+
23+
$input = $form->addInteger('Integer');
24+
assertType('string|null', $input->getValue());
25+
26+
$input = $form->addUpload('Upload');
27+
assertType('array<Nette\Http\FileUpload>|Nette\Http\FileUpload|null', $input->getValue());
28+
29+
$input = $form->addMultiUpload('MultiUpload');
30+
assertType('array<Nette\Http\FileUpload>|Nette\Http\FileUpload|null', $input->getValue());
31+
32+
$input = $form->addHidden('Hidden');
33+
assertType('string|null', $input->getValue());
34+
35+
$input = $form->addCheckbox('Checkbox');
36+
assertType('bool|null', $input->getValue());
37+
38+
$input = $form->addRadioList('RadioList');
39+
assertType('int|string|null', $input->getValue());
40+
41+
$input = $form->addCheckboxList('CheckboxList');
42+
assertType('array<(int|string)>', $input->getValue());
43+
44+
$input = $form->addSelect('Select');
45+
assertType('int|string|null', $input->getValue());
46+
47+
$input = $form->addMultiSelect('MultiSelect');
48+
assertType('array<(int|string)>', $input->getValue());
49+
50+
$input = $form->addSubmit('Submit');
51+
assertType('string|null', $input->getValue());
52+
53+
$input = $form->addButton('Button');
54+
assertType('string|null', $input->getValue());
55+
56+
$input = $form->addImageButton('ImageButton');
57+
assertType('array|null', $input->getValue());
58+
59+
$input = $form->addImage('Image');
60+
assertType('array|null', $input->getValue());

0 commit comments

Comments
 (0)