Skip to content

Commit

Permalink
added type inference tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 9, 2021
1 parent ee2c2b8 commit aab0f87
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ jobs:
- run: vendor/bin/tester tests -s -C


type_tests:
name: Type Inference
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

- run: composer install --no-progress --prefer-dist
- run: composer test-phpstan


code_coverage:
name: Code Coverage
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"minimum-stability": "dev",
"scripts": {
"phpstan": "phpstan analyse",
"test-phpstan": "phpstan analyse -c tests/phpstan-tests.neon",
"tester": "tester tests -s"
},
"extra": {
Expand Down
5 changes: 5 additions & 0 deletions tests/phpstan-tests.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5

paths:
- types
60 changes: 60 additions & 0 deletions tests/types/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 comments on commit aab0f87

Please sign in to comment.