Completed
Pull Request — master (#49)
by
unknown
02:05
created

LegacyFormHelperTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsLegacy() 0 10 1
A testGetType() 0 11 1
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\Util
12
{
13
    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...
14
    {
15
        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...
16
        return !$LegacyFormHelperTest_legacySymfonyVersion;
17
    }
18
}
19
20
namespace Fresh\DoctrineEnumBundle\Tests\Util
21
{
22
    use Fresh\DoctrineEnumBundle\Tests\Fixtures\DBAL\Types\BasketballPositionType;
0 ignored issues
show
Coding Style introduced by
USE declarations must go after the first namespace declaration
Loading history...
23
    use Fresh\DoctrineEnumBundle\Util\LegacyFormHelper;
0 ignored issues
show
Coding Style introduced by
USE declarations must go after the first namespace declaration
Loading history...
24
25
    /**
26
     * LegacyFormHelperTest
27
     *
28
     * @author Jaik Dean <[email protected]>
29
     *
30
     * @coversClass \Fresh\DoctrineEnumBundle\Util\LegacyFormHelper
31
     */
32
    class LegacyFormHelperTest extends \PHPUnit_Framework_TestCase
33
    {
34
        /**
35
         * Test that the helper identifies whether we’re running a legacy
36
         * version of Symfony.
37
         */
38
        public function testIsLegacy()
39
        {
40
            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...
41
42
            $LegacyFormHelperTest_legacySymfonyVersion = true;
43
            $this->assertEquals(true, LegacyFormHelper::isLegacy());
44
45
            $LegacyFormHelperTest_legacySymfonyVersion = false;
46
            $this->assertEquals(false, LegacyFormHelper::isLegacy());
47
        }
48
49
        /**
50
         * Test that the correct form field type is returned for current and legacy
51
         * versions of Symfony.
52
         */
53
        public function testGetType()
54
        {
55
            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...
56
            $formType = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
57
58
            $LegacyFormHelperTest_legacySymfonyVersion = true;
59
            $this->assertEquals('choice', LegacyFormHelper::getType($formType));
60
61
            $LegacyFormHelperTest_legacySymfonyVersion = false;
62
            $this->assertEquals($formType, LegacyFormHelper::getType($formType));
63
        }
64
    }
65
}
66