|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
namespace SM\AirbrakeBundle\Tests\Builder; |
|
6
|
|
|
|
|
7
|
|
|
use Airbrake\Notifier; |
|
8
|
|
|
use SM\AirbrakeBundle\Builder\NotifierBuilder; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Test the functionality of the builder that handles Notifiers. |
|
12
|
|
|
* |
|
13
|
|
|
* @package SM\AirbrakeBundle\Tests\Builder |
|
14
|
|
|
* @author Petre Pătrașc <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class NotifierBuilderTest extends \PHPUnit_Framework_TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
const EMPTY_STRING = ''; |
|
19
|
|
|
const INVALID_STRING = ' '; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var NotifierBuilder |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $notifierBuilder; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritDoc |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->notifierBuilder = new NotifierBuilder; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testGivenThatAnEmptyProjectKeyIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
36
|
|
|
$this->expectExceptionMessage('Project API key cannot be empty'); |
|
37
|
|
|
|
|
38
|
|
|
$this->notifierBuilder->withProjectKey(self::EMPTY_STRING); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testGivenThatAnInvalidProjectKeyIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
44
|
|
|
$this->expectExceptionMessage('Project API key cannot be empty'); |
|
45
|
|
|
|
|
46
|
|
|
$this->notifierBuilder->withProjectKey(self::INVALID_STRING); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testGivenThatAnEmptyProjectIdIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
52
|
|
|
$this->expectExceptionMessage('Project ID cannot be empty'); |
|
53
|
|
|
|
|
54
|
|
|
$this->notifierBuilder->withProjectId(self::EMPTY_STRING); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testGivenThatAnInvalidProjectIdIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
60
|
|
|
$this->expectExceptionMessage('Project ID cannot be empty'); |
|
61
|
|
|
|
|
62
|
|
|
$this->notifierBuilder->withProjectId(self::INVALID_STRING); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testGivenThatAnEmptyHostIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
68
|
|
|
$this->expectExceptionMessage('Host cannot be empty'); |
|
69
|
|
|
|
|
70
|
|
|
$this->notifierBuilder->withHost(self::EMPTY_STRING); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testGivenThatAnInvalidHostIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
76
|
|
|
$this->expectExceptionMessage('Host cannot be empty'); |
|
77
|
|
|
|
|
78
|
|
|
$this->notifierBuilder->withHost(self::INVALID_STRING); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testGivenThatAnEmptyHttpClientIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
84
|
|
|
$this->expectExceptionMessage('HTTP client cannot be empty'); |
|
85
|
|
|
|
|
86
|
|
|
$this->notifierBuilder->withHttpClient(self::EMPTY_STRING); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testGivenThatAnInvalidHttpClientIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
92
|
|
|
$this->expectExceptionMessage('HTTP client cannot be empty'); |
|
93
|
|
|
|
|
94
|
|
|
$this->notifierBuilder->withHttpClient(self::INVALID_STRING); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGivenThatAnEmptyRootDirectoryIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
100
|
|
|
$this->expectExceptionMessage('Root directory cannot be empty'); |
|
101
|
|
|
|
|
102
|
|
|
$this->notifierBuilder->withRootDirectory(self::EMPTY_STRING); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testGivenThatAnInvalidRootDirectoryIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
108
|
|
|
$this->expectExceptionMessage('Root directory cannot be empty'); |
|
109
|
|
|
|
|
110
|
|
|
$this->notifierBuilder->withRootDirectory(self::INVALID_STRING); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function testGivenThatAnEmptyEnvironmentIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
116
|
|
|
$this->expectExceptionMessage('Environment cannot be empty'); |
|
117
|
|
|
|
|
118
|
|
|
$this->notifierBuilder->withEnvironment(self::EMPTY_STRING); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testGivenThatAnInvalidEnvironmentDirectoryIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
122
|
|
|
{ |
|
123
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
124
|
|
|
$this->expectExceptionMessage('Environment cannot be empty'); |
|
125
|
|
|
|
|
126
|
|
|
$this->notifierBuilder->withEnvironment(self::INVALID_STRING); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function testGivenThatAnEmptyAppVersionIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
130
|
|
|
{ |
|
131
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
132
|
|
|
$this->expectExceptionMessage('App version cannot be empty'); |
|
133
|
|
|
|
|
134
|
|
|
$this->notifierBuilder->withAppVersion(self::EMPTY_STRING); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function testGivenThatAnInvalidAppVersionDirectoryIsProvidedThenAConfigurationExceptionWillBeThrown() |
|
138
|
|
|
{ |
|
139
|
|
|
$this->expectException('SM\AirbrakeBundle\Exception\AirbrakeConfigurationException'); |
|
140
|
|
|
$this->expectExceptionMessage('App version cannot be empty'); |
|
141
|
|
|
|
|
142
|
|
|
$this->notifierBuilder->withAppVersion(self::INVALID_STRING); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function testGivenThatAValidParametersAreProvidedThenTheNotifierInstanceWillBeConstructedCorrectly() |
|
146
|
|
|
{ |
|
147
|
|
|
$notifierInstance = $this->notifierBuilder |
|
148
|
|
|
->withProjectKey('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') |
|
149
|
|
|
->withProjectId('000000') |
|
150
|
|
|
->withHost('api.airbrake.io') |
|
151
|
|
|
->withRootDirectory('/var/www/app/') |
|
152
|
|
|
->withIgnoredExceptions([ |
|
153
|
|
|
'Symfony\Component\HttpKernel\Exception\HttpException', |
|
154
|
|
|
'Symfony\Component\Security\Core\Exception\AccessDeniedException', |
|
155
|
|
|
]) |
|
156
|
|
|
->withEnvironment('PRD') |
|
157
|
|
|
->withAppVersion('1.0') |
|
158
|
|
|
->build(); |
|
159
|
|
|
|
|
160
|
|
|
$this->assertTrue($notifierInstance instanceof Notifier); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|