Passed
Push — main ( 2c83d5...fb3f8a )
by Siad
05:21
created

VersionCompareConditionTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 23
dl 0
loc 52
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testDefaultCompareIsFalseForSmallerRevision() 0 5 1
A testCanUseDifferentOperator() 0 6 1
A testDefaultCompareIsTrueForSameRevision() 0 5 1
A testDefaultCompareIsTrueForBiggerRevision() 0 5 1
A setUp() 0 3 1
A testUseDebugMode() 0 7 1
A testCanNotUseUnsupportedOperator() 0 5 1
1
<?php
2
3
namespace Phing\Test\Task\System\Condition;
4
5
use Phing\Exception\BuildException;
6
7
/**
8
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
10
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
15
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
16
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
17
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
18
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
 *
20
 * This software consists of voluntary contributions made by many individuals
21
 * and is licensed under the LGPL. For more information please see
22
 * <http://phing.info>.
23
 */
24
class VersionCompareConditionTest extends \PHPUnit\Framework\TestCase
25
{
26
    protected $condition;
27
28
    public function setUp(): void
29
    {
30
        $this->condition = new \Phing\Task\System\Condition\VersionCompareCondition();
31
    }
32
33
    public function testDefaultCompareIsFalseForSmallerRevision()
34
    {
35
        $this->condition->setVersion('1.2.7');
36
        $this->condition->setDesiredVersion('1.3');
37
        $this->assertFalse($this->condition->evaluate());
38
    }
39
40
    public function testDefaultCompareIsTrueForBiggerRevision()
41
    {
42
        $this->condition->setVersion('1.6.2');
43
        $this->condition->setDesiredVersion('1.3');
44
        $this->assertTrue($this->condition->evaluate());
45
    }
46
47
    public function testDefaultCompareIsTrueForSameRevision()
48
    {
49
        $this->condition->setVersion('1.3');
50
        $this->condition->setDesiredVersion('1.3');
51
        $this->assertTrue($this->condition->evaluate());
52
    }
53
54
    public function testCanUseDifferentOperator()
55
    {
56
        $this->condition->setVersion('1.2.7');
57
        $this->condition->setDesiredVersion('1.3');
58
        $this->condition->setOperator('<=');
59
        $this->assertTrue($this->condition->evaluate());
60
    }
61
62
    public function testUseDebugMode()
63
    {
64
        $this->condition->setVersion('1.2.7');
65
        $this->condition->setDesiredVersion('1.3');
66
        $this->condition->setDebug(true);
67
        $this->expectOutputString('Assertion that 1.2.7 >= 1.3 failed' . PHP_EOL);
68
        $this->condition->evaluate();
69
    }
70
71
    public function testCanNotUseUnsupportedOperator()
72
    {
73
        $this->expectException(BuildException::class);
74
75
        $this->condition->setOperator('<<<<');
76
    }
77
}
78