From e5050f64defd8e7071e80f9ad7dbbf68fef7c6fd Mon Sep 17 00:00:00 2001 From: Marco Reni Date: Tue, 16 Jan 2018 17:35:10 +0100 Subject: [PATCH] Tests to replicate issue 76 --- .../Php/Symfony/FormTypeChoicesTest.php | 18 ++++++++++++++++ .../Symfony/SimpleChoicePassFunctionType.php | 19 +++++++++++++++++ .../SimpleChoicePassStaticFunctionType.php | 21 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/Resources/Php/Symfony/SimpleChoicePassFunctionType.php create mode 100644 tests/Resources/Php/Symfony/SimpleChoicePassStaticFunctionType.php diff --git a/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php b/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php index 768c924..28c1c4b 100644 --- a/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php +++ b/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php @@ -86,4 +86,22 @@ public function testChoiceTranslationDomain() // We should not have "test_c" $this->assertEquals(4, $collection->count(), 'We should ignore choices where "choice_translation_domain" is "false"'); } + + public function testFunctions() + { + $collection = $this->getSourceLocations(new FormTypeChoices(), Resources\Php\Symfony\SimpleChoicePassFunctionType::class); + + $this->assertCount(1, $collection, print_r($collection, true)); + $this->assertEquals('label1', $collection->get(0)->getMessage()); + $this->assertEquals(10, $collection->get(0)->getLine()); + } + + public function testStaticFunctions() + { + $collection = $this->getSourceLocations(new FormTypeChoices(), Resources\Php\Symfony\SimpleChoicePassStaticFunctionType::class); + + $this->assertCount(1, $collection, print_r($collection, true)); + $this->assertEquals('label1', $collection->get(0)->getMessage()); + $this->assertEquals(10, $collection->get(0)->getLine()); + } } diff --git a/tests/Resources/Php/Symfony/SimpleChoicePassFunctionType.php b/tests/Resources/Php/Symfony/SimpleChoicePassFunctionType.php new file mode 100644 index 0000000..c9280f9 --- /dev/null +++ b/tests/Resources/Php/Symfony/SimpleChoicePassFunctionType.php @@ -0,0 +1,19 @@ + 'key' + ]; +}; + +class SimpleChoicePassFunctionType +{ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('issue_76', null, [ + 'choices' => getChoices(), + ]); + } +} diff --git a/tests/Resources/Php/Symfony/SimpleChoicePassStaticFunctionType.php b/tests/Resources/Php/Symfony/SimpleChoicePassStaticFunctionType.php new file mode 100644 index 0000000..752fc04 --- /dev/null +++ b/tests/Resources/Php/Symfony/SimpleChoicePassStaticFunctionType.php @@ -0,0 +1,21 @@ + 'key' + ]; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('issue_76', null, [ + 'choices' => Resources\Php\Symfony\SimpleChoicePassStaticFunctionType::getChoices(), + ]); + } +}