|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Runner; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use Ktomk\Pipelines\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers \Ktomk\Pipelines\Runner\Reference |
|
12
|
|
|
*/ |
|
13
|
|
|
class ReferenceTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testCreation() |
|
16
|
|
|
{ |
|
17
|
|
|
$ref = Reference::create(null); |
|
18
|
|
|
self::assertNotNull($ref); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return array |
|
23
|
|
|
*/ |
|
24
|
|
|
public function provideRefs() |
|
25
|
|
|
{ |
|
26
|
|
|
return array( |
|
27
|
|
|
array(null, false), |
|
28
|
|
|
array('', false), |
|
29
|
|
|
array('bar:', false), |
|
30
|
|
|
array('tag', false), |
|
31
|
|
|
array('tag:', false), |
|
32
|
|
|
array('tag:1.0.0', true), |
|
33
|
|
|
array('branch:feature/drop-support', true), |
|
34
|
|
|
array('pr:feature-42', true), |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @dataProvider provideRefs |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $string |
|
42
|
|
|
* @param bool $valid |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testValidation($string, $valid) |
|
45
|
|
|
{ |
|
46
|
|
|
self::assertSame($valid, Reference::valid($string), sprintf('reference "%s"', $string)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @dataProvider provideRefs |
|
51
|
|
|
* |
|
52
|
|
|
* @param $string |
|
53
|
|
|
* @param $valid |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testParsing($string, $valid) |
|
56
|
|
|
{ |
|
57
|
|
|
try { |
|
58
|
|
|
$this->addToAssertionCount(1); |
|
59
|
|
|
$type = Reference::create($string); |
|
60
|
|
|
if (null !== $string && !$valid) { |
|
61
|
|
|
self::fail('An expected exception has not been thrown'); |
|
62
|
|
|
} |
|
63
|
|
|
self::assertNotNull($type); |
|
64
|
|
|
if (null !== $string) { |
|
65
|
|
|
self::assertNotNull($type->getType()); |
|
66
|
|
|
self::assertNotNull($type->getName()); |
|
67
|
|
|
} |
|
68
|
|
|
} catch (InvalidArgumentException $e) { |
|
69
|
|
|
if ($valid) { |
|
70
|
|
|
self::fail('Exception'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testNullObject() |
|
76
|
|
|
{ |
|
77
|
|
|
$ref = new Reference(null); |
|
78
|
|
|
self::assertNull($ref->getType()); |
|
79
|
|
|
self::assertNull($ref->getName()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testGetPipelinesType() |
|
83
|
|
|
{ |
|
84
|
|
|
$f = function ($ref) { |
|
85
|
|
|
return Reference::create($ref)->getPipelinesType(); |
|
86
|
|
|
}; |
|
87
|
|
|
|
|
88
|
|
|
self::assertNull($f(null)); |
|
89
|
|
|
self::assertSame('bookmarks', $f('bookmark:stable')); |
|
90
|
|
|
self::assertSame('branches', $f('branch:master')); |
|
91
|
|
|
self::assertSame('tags', $f('tag:1.0.0')); |
|
92
|
|
|
self::assertSame('pull-requests', $f('pr:feature')); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|