SilverStripeVersionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testGetConstraint() 0 4 1
A testGetConstraintValidity() 0 4 1
A constraintProvider() 0 19 1
1
<?php
2
/**
3
 * Tests for the SilverStripeVersion model
4
 *
5
 * @package mysite
6
 */
7
class SilverStripeVersionTest extends SapphireTest
8
{
9
    /**
10
     * @var SilverStripeVersion
11
     */
12
    protected $version;
13
14
    /**
15
     * Create a test version
16
     *
17
     * {@inheritDoc}
18
     */
19
    public function setUp()
20
    {
21
        parent::setUp();
22
        $this->version = new SilverStripeVersion(
23
            [
24
                'Major' => 4,
25
                'Minor' => 1
26
            ]
27
        );
28
    }
29
30
    /**
31
     * Ensure that a simple string is returned for the version, which can be used for comparing composer
32
     * constraints against for validity
33
     */
34
    public function testGetConstraint()
35
    {
36
        $this->assertSame('4.1.0', (string) $this->version);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<SilverStripeVersionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
    }
38
39
    /**
40
     * Test various composer constraints against the version to see if this SilverStripe version would apply to
41
     * the module
42
     *
43
     * @dataProvider constraintProvider
44
     * @param string $constraint
45
     * @param bool   $expected
46
     */
47
    public function testGetConstraintValidity($constraint, $expected)
48
    {
49
        $this->assertSame($expected, $this->version->getConstraintValidity($constraint));
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<SilverStripeVersionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
    }
51
52
    /**
53
     * @return array[]
54
     */
55
    public function constraintProvider()
56
    {
57
        return [
58
            ['1.0.0', false],
59
            ['~3.2', false],
60
            ['^3.2', false],
61
            ['>=3.2', true], // warning!!
62
            ['>=3.2,<4', false],
63
            ['4.0.0', false],
64
            ['~4.0.0', false],
65
            ['^4.0', true],
66
            ['>=4.0.0', true],
67
            ['~4.2.3', false],
68
            ['<5.0.0', true],
69
            ['^5.0.0', false],
70
            ['^3.5|^4.0', true],
71
            ['^3.5|^5.0', false]
72
        ];
73
    }
74
}
75