This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdapterResolver.spec.php
130 lines (127 loc) · 5.4 KB
/
AdapterResolver.spec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* This file is part of CoverallsKit.
*
* (c) Noritaka Horio <holy.shared.design@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace coverallskit\spec;
use coverallskit\Environment;
use coverallskit\environment\AdapterResolver;
use coverallskit\environment\CircleCI;
use coverallskit\environment\CodeShip;
use coverallskit\environment\DroneIO;
use coverallskit\environment\General;
use coverallskit\environment\Jenkins;
use coverallskit\environment\TravisCI;
use coverallskit\exception\EnvironmentAdapterNotFoundException;
describe(AdapterResolver::class, function () {
describe('#resolveByEnvironment', function () {
context('when supported', function () {
context('when circle-ci', function () {
beforeEach(function () {
$environment = new Environment([
'CI' => 'true',
'CIRCLECI' => 'true',
'CIRCLE_BUILD_NUM' => '10',
'COVERALLS_REPO_TOKEN' => 'token'
]);
$this->resolver = new AdapterResolver($environment);
});
it('return detect circle-ci adapter', function () {
$adapter = $this->resolver->resolveByEnvironment();
expect($adapter)->toBeAnInstanceOf(CircleCI::class);
});
});
context('when drone.io', function () {
beforeEach(function () {
$environment = new Environment([
'CI' => 'true',
'DRONE' => 'true',
'DRONE_BUILD_NUMBER' => '10',
'COVERALLS_REPO_TOKEN' => 'token'
]);
$this->resolver = new AdapterResolver($environment);
});
it('return detect drone.io adapter', function () {
$adapter = $this->resolver->resolveByEnvironment();
expect($adapter)->toBeAnInstanceOf(DroneIO::class);
});
});
context('when travis-ci', function () {
beforeEach(function () {
$environment = new Environment([
'CI' => 'true',
'TRAVIS' => 'true',
'TRAVIS_JOB_ID' => '10',
'COVERALLS_REPO_TOKEN' => 'token'
]);
$this->resolver = new AdapterResolver($environment);
});
it('return detect travis-ci adapter', function () {
$adapter = $this->resolver->resolveByEnvironment();
expect($adapter)->toBeAnInstanceOf(TravisCI::class);
});
});
context('when codeship', function () {
beforeEach(function () {
$environment = new Environment([
'CI' => 'true',
'CI_NAME' => 'codeship',
'CI_BUILD_NUMBER' => '10',
'COVERALLS_REPO_TOKEN' => 'token'
]);
$this->resolver = new AdapterResolver($environment);
});
it('return detect codeship adapter', function () {
$adapter = $this->resolver->resolveByEnvironment();
expect($adapter)->toBeAnInstanceOf(CodeShip::class);
});
});
context('when jenkins', function () {
beforeEach(function () {
$environment = new Environment([
'BUILD_NUMBER' => '10',
'JENKINS_URL' => 'http://example.com'
]);
$this->resolver = new AdapterResolver($environment);
});
it('return detect jenkins adapter', function () {
$adapter = $this->resolver->resolveByEnvironment();
expect($adapter)->toBeAnInstanceOf(Jenkins::class);
});
});
});
context('when not supported', function () {
beforeEach(function () {
$environment = new Environment([]);
$this->resolver = new AdapterResolver($environment);
});
it('return general adapter', function () {
$adapter = $this->resolver->resolveByEnvironment();
expect($adapter)->toBeAnInstanceOf(General::class);
});
});
});
describe('#resolveByName', function () {
beforeEach(function () {
$environment = new Environment([]);
$this->detector = new AdapterResolver($environment);
});
context('when supported', function () {
it('return detect adapter', function () {
$adapter = $this->resolver->resolveByName('circle-ci');
expect($adapter)->toBeAnInstanceOf(CircleCI::class);
});
});
context('when not supported', function () {
it('throw \coverallskit\exception\EnvironmentAdapterNotFoundException exception', function () {
expect(function () {
$this->resolver->resolveByName('not_found');
})->toThrow(EnvironmentAdapterNotFoundException::class);
});
});
});
});