|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jalle19\StatusManager\Test\Configuration\Reader; |
|
4
|
|
|
|
|
5
|
|
|
use Jalle19\StatusManager\Configuration\Reader\YamlReader; |
|
6
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class YamlReaderTest |
|
10
|
|
|
* @package Jalle19\StatusManager\Test\Configuration\Reader |
|
11
|
|
|
* @copyright Copyright © Sam Stenvall 2016- |
|
12
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
class YamlReaderTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
public function testReader() |
|
18
|
|
|
{ |
|
19
|
|
|
$configuration = [ |
|
20
|
|
|
'foo' => 'bar', |
|
21
|
|
|
'baz', |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
$tmpFile = $this->getTemporaryFilePath(); |
|
25
|
|
|
file_put_contents($tmpFile, Yaml::dump($configuration)); |
|
26
|
|
|
|
|
27
|
|
|
$reader = new YamlReader($tmpFile); |
|
28
|
|
|
$this->assertEquals($configuration, $reader->readConfiguration()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @expectedException \Jalle19\StatusManager\Exception\InvalidConfigurationException |
|
34
|
|
|
* @expectedExceptionMessageRegExp *The configuration file does not* |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testMissingFile() |
|
37
|
|
|
{ |
|
38
|
|
|
$reader = new YamlReader('/tmp/does/not/exist'); |
|
39
|
|
|
$reader->readConfiguration(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @expectedException \Jalle19\StatusManager\Exception\InvalidConfigurationException |
|
45
|
|
|
* @expectedExceptionMessageRegExp *Failed to parse* |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testUnparsableConfiguration() |
|
48
|
|
|
{ |
|
49
|
|
|
$tmpFile = $this->getTemporaryFilePath(); |
|
50
|
|
|
file_put_contents($tmpFile, "\t\tfail"); |
|
51
|
|
|
|
|
52
|
|
|
$reader = new YamlReader($tmpFile); |
|
53
|
|
|
$reader->readConfiguration(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
private function getTemporaryFilePath() |
|
61
|
|
|
{ |
|
62
|
|
|
return tempnam(sys_get_temp_dir(), 'yaml'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|