Completed
Push — master ( b3f9bf...16b026 )
by Sam
03:02
created

YamlReaderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 1
cbo 3
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testReader() 0 13 1
A testMissingFile() 0 5 1
A testUnparsableConfiguration() 0 8 1
A getTemporaryFilePath() 0 4 1
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 &copy; 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