Completed
Pull Request — master (#20)
by
unknown
02:35
created

OutputTest::normalizeJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
class OutputTest extends SwaggerGen_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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(json_decode($json), JSON_PRETTY_PRINT);
28
	}
29
	
30
	public function provideAllCases() {
31
		$cases = array();
32
		
33
		foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) {					
34
			$path = realpath($dir);					
35
			$json = $this->normalizeJson(file_get_contents($path . '/expected.json'));
36
			
37
			$files = array();
38
			if (file_exists($path . '/source.php')) {
39
				$files[] = $path . '/source.php';
40
			}
41
			if (file_exists($path . '/source.txt')) {
42
				$files[] = $path . '/source.txt';
43
			}
44
			
45
			$cases[] = array(
46
				basename($dir),
47
				$files,
48
				$json
49
			);
50
		}
51
		
52
		return $cases;
53
	}
54
55
}
56