|
8 | 8 | * file that was distributed with this source code.
|
9 | 9 | */
|
10 | 10 |
|
11 |
| -namespace Fresh\DoctrineEnumBundle\Tests\Util { |
| 11 | +namespace Fresh\DoctrineEnumBundle\Tests\Util; |
12 | 12 |
|
13 |
| - use Fresh\DoctrineEnumBundle\Tests\Fixtures\DBAL\Types\BasketballPositionType; |
14 |
| - use Fresh\DoctrineEnumBundle\Util\LegacyFormHelper; |
| 13 | +use Fresh\DoctrineEnumBundle\Util\LegacyFormHelper; |
15 | 14 |
|
| 15 | +/** |
| 16 | + * LegacyFormHelperTest |
| 17 | + * |
| 18 | + * @author Jaik Dean <jaik@fluoresce.co> |
| 19 | + * @author Artem Genvald <genvaldartem@gmail.com> |
| 20 | + */ |
| 21 | +class LegacyFormHelperTest extends \PHPUnit_Framework_TestCase |
| 22 | +{ |
16 | 23 | /**
|
17 |
| - * LegacyFormHelperTest |
18 |
| - * |
19 |
| - * @author Jaik Dean <jaik@fluoresce.co> |
20 |
| - * |
21 |
| - * @coversClass \Fresh\DoctrineEnumBundle\Util\LegacyFormHelper |
| 24 | + * @dataProvider dataProviderForIsLegacyTest |
22 | 25 | */
|
23 |
| - class LegacyFormHelperTest extends \PHPUnit_Framework_TestCase |
| 26 | + public function testIsLegacy($majorVersion, $expectedLegacyStatus) |
24 | 27 | {
|
25 |
| - /** |
26 |
| - * Test that the helper identifies whether we’re running a legacy |
27 |
| - * version of Symfony. |
28 |
| - */ |
29 |
| - public function testIsLegacy() |
30 |
| - { |
31 |
| - global $LegacyFormHelperTest_legacySymfonyVersion; |
32 |
| - |
33 |
| - $LegacyFormHelperTest_legacySymfonyVersion = true; |
34 |
| - $this->assertEquals(true, LegacyFormHelper::isLegacy()); |
35 |
| - |
36 |
| - $LegacyFormHelperTest_legacySymfonyVersion = false; |
37 |
| - $this->assertEquals(false, LegacyFormHelper::isLegacy()); |
38 |
| - } |
39 |
| - |
40 |
| - /** |
41 |
| - * Test that the correct form field type is returned for current and legacy |
42 |
| - * versions of Symfony. |
43 |
| - */ |
44 |
| - public function testGetType() |
45 |
| - { |
46 |
| - global $LegacyFormHelperTest_legacySymfonyVersion; |
47 |
| - $formType = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'; |
| 28 | + $this->assertEquals($expectedLegacyStatus, LegacyFormHelper::isLegacy($majorVersion)); |
| 29 | + } |
48 | 30 |
|
49 |
| - $LegacyFormHelperTest_legacySymfonyVersion = true; |
50 |
| - $this->assertEquals('choice', LegacyFormHelper::getType($formType)); |
| 31 | + public function dataProviderForIsLegacyTest() |
| 32 | + { |
| 33 | + return [ |
| 34 | + [1, true], |
| 35 | + [2, true], |
| 36 | + [3, false], |
| 37 | + ]; |
| 38 | + } |
51 | 39 |
|
52 |
| - $LegacyFormHelperTest_legacySymfonyVersion = false; |
53 |
| - $this->assertEquals($formType, LegacyFormHelper::getType($formType)); |
54 |
| - } |
| 40 | + /** |
| 41 | + * @dataProvider dataProviderForGetTypeTest |
| 42 | + */ |
| 43 | + public function testGetType($majorVersion, $expectedFormType) |
| 44 | + { |
| 45 | + $this->assertEquals( |
| 46 | + $expectedFormType, |
| 47 | + LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\ChoiceType', $majorVersion) |
| 48 | + ); |
55 | 49 | }
|
56 |
| -} |
57 | 50 |
|
58 |
| -namespace Fresh\DoctrineEnumBundle\Util { |
| 51 | + /** |
| 52 | + * @return array |
| 53 | + */ |
| 54 | + public function dataProviderForGetTypeTest() |
| 55 | + { |
| 56 | + return [ |
| 57 | + [2, 'choice'], |
| 58 | + [3, 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'], |
| 59 | + ]; |
| 60 | + } |
59 | 61 |
|
60 |
| - function method_exists($class, $method) |
| 62 | + /** |
| 63 | + * @expectedException \InvalidArgumentException |
| 64 | + * @expectedExceptionMessage Form type with class "Symfony\Component\Form\Extension\Core\Type\TextType" can not be found. Please check for typos or add it to the map in LegacyFormHelper |
| 65 | + */ |
| 66 | + public function testExceptionForGetUnsupportedType() |
61 | 67 | {
|
62 |
| - global $LegacyFormHelperTest_legacySymfonyVersion; |
63 |
| - return !$LegacyFormHelperTest_legacySymfonyVersion; |
| 68 | + LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\TextType', 2); |
64 | 69 | }
|
65 | 70 | }
|
0 commit comments