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

OutputTest::normalizeJson()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
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(
28
			json_decode($json), 
29
			PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0
30
		);
31
	}
32
	
33
	public function provideAllCases() {
34
		$cases = array();
35
		
36
		foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) {					
37
			$path = realpath($dir);					
38
			$json = $this->normalizeJson(file_get_contents($path . '/expected.json'));
39
			
40
			$files = array();
41
			if (file_exists($path . '/source.php')) {
42
				$files[] = $path . '/source.php';
43
			}
44
			if (file_exists($path . '/source.txt')) {
45
				$files[] = $path . '/source.txt';
46
			}
47
			
48
			$cases[] = array(
49
				basename($dir),
50
				$files,
51
				$json
52
			);
53
		}
54
		
55
		return $cases;
56
	}
57
58
}
59