Passed
Push — test ( d838cf...cef4a5 )
by Tom
03:29
created

ReferenceSearchTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A assertDefault() 0 4 1
A testSearching() 0 4 1
A testSearchByBracePatternInBranch() 0 4 1
A testSearchFirstPatternNoHit() 0 4 1
A getFirstStepName() 0 5 1
A doSetUp() 0 4 1
A testSearchDirect() 0 7 1
A testSearchNothing() 0 4 1
A searchReference() 0 4 1
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File;
6
7
use Ktomk\Pipelines\Runner\Reference;
8
use Ktomk\Pipelines\TestCase;
9
10
/**
11
 * @covers \Ktomk\Pipelines\File\Pipelines::searchReference()
12
 * @covers \Ktomk\Pipelines\File\Pipelines::searchTypeReference()
13
 * @covers \Ktomk\Pipelines\File\PipelinesReferences
14
 */
15
class ReferenceSearchTest extends TestCase
16
{
17
    /**
18
     * @var Pipelines
19
     */
20
    private $pipelines;
21
22
    protected function doSetUp()
23
    {
24
        parent::doSetUp();
25
        $this->pipelines = File::createFromFile(__DIR__ . '/../../data/yml/bitbucket-pipelines.yml')->getPipelines();
26
    }
27
28
    public function searchReference($ref = null)
29
    {
30
        return $this->pipelines->searchReference(
31
            Reference::create($ref)
32
        );
33
    }
34
35
    public function testSearching()
36
    {
37
        $actual = $this->searchReference('branch:feature/unicorns');
38
        self::assertNotNull($actual);
39
    }
40
41
    public function testSearchDirect()
42
    {
43
        $actual = $this->searchReference('branch:feature/unicorns');
44
        self::assertSame('feature/*', $this->getFirstStepName($actual));
0 ignored issues
show
Bug introduced by
It seems like $actual can also be of type null; however, parameter $pipeline of Ktomk\Pipelines\File\Ref...est::getFirstStepName() does only seem to accept Ktomk\Pipelines\File\Pipeline, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        self::assertSame('feature/*', $this->getFirstStepName(/** @scrutinizer ignore-type */ $actual));
Loading history...
45
46
        $actual = $this->searchReference('branch:feature/bb-123-fix-links');
47
        self::assertSame('feature/bb-123-fix-links', $this->getFirstStepName($actual));
48
    }
49
50
    public function testSearchFirstPatternNoHit()
51
    {
52
        $actual = $this->searchReference('tag:blue-moon-unicorn-release');
53
        $this->assertDefault($actual);
0 ignored issues
show
Bug introduced by
It seems like $actual can also be of type null; however, parameter $pipeline of Ktomk\Pipelines\File\Ref...chTest::assertDefault() does only seem to accept Ktomk\Pipelines\File\Pipeline, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        $this->assertDefault(/** @scrutinizer ignore-type */ $actual);
Loading history...
54
    }
55
56
    public function testSearchNothing()
57
    {
58
        $actual = $this->searchReference();
59
        $this->assertDefault($actual);
0 ignored issues
show
Bug introduced by
It seems like $actual can also be of type null; however, parameter $pipeline of Ktomk\Pipelines\File\Ref...chTest::assertDefault() does only seem to accept Ktomk\Pipelines\File\Pipeline, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        $this->assertDefault(/** @scrutinizer ignore-type */ $actual);
Loading history...
60
    }
61
62
    public function testSearchByBracePatternInBranch()
63
    {
64
        $actual = $this->searchReference('branch:bar');
65
        self::assertSame('foo and bar branches', $this->getFirstStepName($actual));
0 ignored issues
show
Bug introduced by
It seems like $actual can also be of type null; however, parameter $pipeline of Ktomk\Pipelines\File\Ref...est::getFirstStepName() does only seem to accept Ktomk\Pipelines\File\Pipeline, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        self::assertSame('foo and bar branches', $this->getFirstStepName(/** @scrutinizer ignore-type */ $actual));
Loading history...
66
    }
67
68
    private function getFirstStepName(Pipeline $pipeline)
69
    {
70
        $steps = $pipeline->getSteps();
71
72
        return $steps[0]->getName();
73
    }
74
75
    private function assertDefault(Pipeline $pipeline)
76
    {
77
        $default = $this->pipelines->getDefault();
78
        self::assertSame($default, $pipeline, 'is default pipeline');
79
    }
80
}
81