|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Utility; |
|
6
|
|
|
|
|
7
|
|
|
use Ktomk\Pipelines\Cli\Args; |
|
8
|
|
|
use Ktomk\Pipelines\Cli\Streams; |
|
9
|
|
|
use Ktomk\Pipelines\File\File; |
|
10
|
|
|
use Ktomk\Pipelines\TestCase; |
|
11
|
|
|
use UnexpectedValueException; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class ValidationOptionsTest |
|
15
|
|
|
* |
|
16
|
|
|
* @package Ktomk\Pipelines\Utility |
|
17
|
|
|
* @covers \Ktomk\Pipelines\Utility\ValidationOptions |
|
18
|
|
|
*/ |
|
19
|
|
|
class ValidationOptionsTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testCreation() |
|
22
|
|
|
{ |
|
23
|
|
|
$args = new Args(array('test-cmd')); |
|
24
|
|
|
$output = new Streams(); |
|
25
|
|
|
$file = File::createFromFile(__DIR__ . '/../../data/yml/bitbucket-pipelines.yml'); |
|
26
|
|
|
|
|
27
|
|
|
$options = new ValidationOptions($args, $output, $file); |
|
28
|
|
|
self::assertInstanceOf('Ktomk\Pipelines\Utility\ValidationOptions', $options); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testBind() |
|
32
|
|
|
{ |
|
33
|
|
|
$args = new Args(array('test-cmd')); |
|
34
|
|
|
$output = new Streams(); |
|
35
|
|
|
$file = File::createFromFile(__DIR__ . '/../../data/yml/bitbucket-pipelines.yml'); |
|
36
|
|
|
|
|
37
|
|
|
$options = ValidationOptions::bind($args, $output, $file); |
|
38
|
|
|
self::assertInstanceOf('Ktomk\Pipelines\Utility\ValidationOptions', $options); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function provideTestRunArgs() |
|
42
|
|
|
{ |
|
43
|
|
|
return array( |
|
44
|
|
|
array(array(), null), |
|
45
|
|
|
array(array('--validate'), 0), |
|
46
|
|
|
array(array('--validate=' . __DIR__ . '/../../../bitbucket-pipelines.yml'), 0), |
|
47
|
|
|
array(array('--validate=' . __DIR__ . '/../../data/yml/invalid-service-definitions.yml'), 1), |
|
48
|
|
|
array(array('--validate=' . __DIR__ . '/../../data/yml/invalid-pipeline-step.yml'), 1), |
|
49
|
|
|
array(array('--validate=' . __DIR__ . '/../../data/yml/error.yml'), 0), |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param array $arguments |
|
55
|
|
|
* @param int $expected |
|
56
|
|
|
* |
|
57
|
|
|
* @dataProvider provideTestRunArgs |
|
58
|
|
|
* |
|
59
|
|
|
* @throws \ReflectionException |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testRun(array $arguments, $expected) |
|
62
|
|
|
{ |
|
63
|
|
|
$args = new Args(array_merge(array('test-cmd'), $arguments)); |
|
64
|
|
|
$output = new Streams(); |
|
65
|
|
|
$file = File::createFromFile(__DIR__ . '/../../../bitbucket-pipelines.yml'); |
|
66
|
|
|
|
|
67
|
|
|
$options = new ValidationOptions($args, $output, $file); |
|
68
|
|
|
|
|
69
|
|
|
try { |
|
70
|
|
|
$options->run(); |
|
71
|
|
|
self::assertNull($expected); |
|
72
|
|
|
} catch (StatusException $e) { |
|
73
|
|
|
self::assertSame($expected, $e->getCode()); |
|
74
|
|
|
} catch (UnexpectedValueException $e) { |
|
75
|
|
|
self::assertSame($expected, $e->getCode()); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|