|
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)); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testSearchNothing() |
|
57
|
|
|
{ |
|
58
|
|
|
$actual = $this->searchReference(); |
|
59
|
|
|
$this->assertDefault($actual); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testSearchByBracePatternInBranch() |
|
63
|
|
|
{ |
|
64
|
|
|
$actual = $this->searchReference('branch:bar'); |
|
65
|
|
|
self::assertSame('foo and bar branches', $this->getFirstStepName($actual)); |
|
|
|
|
|
|
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
|
|
|
|