-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ef4dce
commit d5960d8
Showing
9 changed files
with
166 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Symfony; | ||
|
||
use PHPStan\Rules\Methods\CallMethodsRule; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @extends RuleTestCase<CallMethodsRule> | ||
*/ | ||
class CallMethodsRuleTest extends RuleTestCase | ||
{ | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return self::getContainer()->getByType(CallMethodsRule::class); | ||
} | ||
|
||
public function testExtension(): void | ||
{ | ||
$this->analyse([__DIR__ . '/data/form_options.php'], []); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/../../../extension.neon', | ||
__DIR__ . '/../../../vendor/phpstan/phpstan-strict-rules/rules.neon', | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace GenericFormOptionsType; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\NumberType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use function PHPStan\Testing\assertType; | ||
|
||
class DataClass | ||
{ | ||
} | ||
|
||
/** | ||
* @extends AbstractType<DataClass, array{required: string, optional: int}> | ||
*/ | ||
class DataClassType extends AbstractType | ||
{ | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
assertType('string', $options['required']); | ||
assertType('int', $options['optional']); | ||
|
||
$builder | ||
->add('foo', NumberType::class) | ||
->add('bar', TextType::class) | ||
; | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver | ||
->setDefaults([ | ||
'data_class' => DataClass::class, | ||
'optional' => 0, | ||
]) | ||
->setRequired('required') | ||
->setAllowedTypes('required', 'string') | ||
->setAllowedTypes('optional', 'int') | ||
; | ||
} | ||
|
||
} | ||
|
||
class FormFactoryAwareClass | ||
{ | ||
|
||
/** @var FormFactoryInterface */ | ||
private $formFactory; | ||
|
||
public function __construct(FormFactoryInterface $formFactory) | ||
{ | ||
$this->formFactory = $formFactory; | ||
} | ||
|
||
public function doSomething(): void | ||
{ | ||
$form = $this->formFactory->create(DataClassType::class, new DataClass()); | ||
assertType('Symfony\Component\Form\FormInterface<GenericFormOptionsType\DataClass>', $form); | ||
} | ||
|
||
public function doSomethingWithOption(): void | ||
{ | ||
$form = $this->formFactory->create(DataClassType::class, new DataClass(), ['required' => 'foo']); | ||
assertType('Symfony\Component\Form\FormInterface<GenericFormOptionsType\DataClass>', $form); | ||
} | ||
|
||
public function doSomethingWithInvalidOption(): void | ||
{ | ||
$form = $this->formFactory->create(DataClassType::class, new DataClass(), ['required' => 42]); | ||
assertType('Symfony\Component\Form\FormInterface<GenericFormOptionsType\DataClass>', $form); | ||
} | ||
|
||
} | ||
|
||
class FormController extends AbstractController | ||
{ | ||
|
||
public function doSomething(): void | ||
{ | ||
$form = $this->createForm(DataClassType::class, new DataClass()); | ||
assertType('Symfony\Component\Form\FormInterface<GenericFormOptionsType\DataClass>', $form); | ||
} | ||
|
||
public function doSomethingWithOption(): void | ||
{ | ||
$form = $this->createForm(DataClassType::class, new DataClass(), ['required' => 'foo']); | ||
assertType('Symfony\Component\Form\FormInterface<GenericFormOptionsType\DataClass>', $form); | ||
} | ||
|
||
public function doSomethingWithInvalidOption(): void | ||
{ | ||
$form = $this->createForm(DataClassType::class, new DataClass(), ['required' => 42]); | ||
assertType('Symfony\Component\Form\FormInterface<GenericFormOptionsType\DataClass>', $form); | ||
} | ||
|
||
} |