Completed
Push — master ( cfa1fe...7d0624 )
by Martijn
19s queued 11s
created

OutputTest::testAllCases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
class OutputTest extends SwaggerGen_TestCase
4
{
5
6
	/**
7
	 * @covers \SwaggerGen\Exception::__construct
8
	 * @dataProvider provideAllCases
9
	 */
10
	public function testAllCases($name, $files, $expected)
11
	{
12
		$SwaggerGen = new \SwaggerGen\SwaggerGen('example.com', '/base');
13
		$actual = $SwaggerGen->getSwagger($files, array(), \SwaggerGen\SwaggerGen::FORMAT_JSON);
14
		$this->assertJsonStringEqualsJsonString($expected, $this->normalizeJson($actual), $name);
15
	}
16
17
	/**
18
	 * Normalizes and pretty-prints json (whitespace mostly)
19
	 *
20
	 * This is useful to get better diff results when assertions fail.
21
	 *
22
	 * @param string $json
23
	 * @return string
24
	 */
25
	private function normalizeJson($json)
26
	{
27
		return json_encode(
28
			json_decode($json), 
29
			PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0
30
		);
31
	}
32
	
33
	public function provideAllCases()
34
	{
35
		$cases = array();
36
		
37
		foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) {
38
			$path = realpath($dir);					
39
			$json = $this->normalizeJson(file_get_contents($path . '/expected.json'));
40
			
41
			$files = array();
42
			if (file_exists($path . '/source.php')) {
43
				$files[] = $path . '/source.php';
44
			}
45
			if (file_exists($path . '/source.txt')) {
46
				$files[] = $path . '/source.txt';
47
			}
48
			
49
			$cases[] = array(
50
				basename($dir),
51
				$files,
52
				$json
53
			);
54
		}
55
		
56
		return $cases;
57
	}
58
59
}
60