Completed
Push — master ( 3ed581...8222a4 )
by Artem
02:07
created

LegacyFormHelperTest::testIsLegacy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the FreshDoctrineEnumBundle
4
 *
5
 * (c) Artem Genvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\DoctrineEnumBundle\Tests\Util {
12
13
    use Fresh\DoctrineEnumBundle\Tests\Fixtures\DBAL\Types\BasketballPositionType;
14
    use Fresh\DoctrineEnumBundle\Util\LegacyFormHelper;
15
16
    /**
17
     * LegacyFormHelperTest
18
     *
19
     * @author Jaik Dean <[email protected]>
20
     *
21
     * @coversClass \Fresh\DoctrineEnumBundle\Util\LegacyFormHelper
22
     */
23
    class LegacyFormHelperTest extends \PHPUnit_Framework_TestCase
24
    {
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
47
            $formType = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
48
49
            $LegacyFormHelperTest_legacySymfonyVersion = true;
50
            $this->assertEquals('choice', LegacyFormHelper::getType($formType));
51
52
            $LegacyFormHelperTest_legacySymfonyVersion = false;
53
            $this->assertEquals($formType, LegacyFormHelper::getType($formType));
54
        }
55
    }
56
}
57
58
namespace Fresh\DoctrineEnumBundle\Util {
59
60
    function method_exists($class, $method)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $method is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62
        global $LegacyFormHelperTest_legacySymfonyVersion;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
63
        return !$LegacyFormHelperTest_legacySymfonyVersion;
64
    }
65
}
66