-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathApibFileParserTest.php
More file actions
116 lines (101 loc) · 3.58 KB
/
ApibFileParserTest.php
File metadata and controls
116 lines (101 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* This file contains the ApibFileParserTest.php
*
* @package PHPDraft\In
* @author Sean Molenaar<sean@seanmolenaar.eu>
*/
namespace PHPDraft\In\Tests;
use Lunr\Halo\LunrBaseTest;
use PHPDraft\In\ApibFileParser;
use ReflectionClass;
/**
* Class ApibFileParserTest
* @covers \PHPDraft\In\ApibFileParser
*/
class ApibFileParserTest extends LunrBaseTest
{
/**
* Set up tests.
*
* @return void Test is now set up.
*/
public function setUp(): void
{
$this->class = new ApibFileParser(__DIR__ . '/ApibFileParserTest.php');
$this->reflection = new ReflectionClass('PHPDraft\In\ApibFileParser');
}
/**
* Test if setup is successful
* @return void
*/
public function testLocationSetup(): void
{
$property = $this->reflection->getProperty('location');
$property->setAccessible(true);
$this->assertSame(__DIR__ . '/', $property->getValue($this->class));
}
/**
* Test if setup is successful
* @return void
*/
public function testFilenameSetup(): void
{
$property = $this->reflection->getProperty('filename');
$property->setAccessible(true);
$this->assertSame(__DIR__ . '/ApibFileParserTest.php', $property->getValue($this->class));
}
/**
* Test if exception when the file doesn't exist
*
* @return void
*/
public function testFilenameSetupWrong(): void
{
$this->expectException('\PHPDraft\Parse\ExecutionException');
$this->expectExceptionMessageMatches('/API File not found: .*\/drafter\/non_existing_including_apib/');
$this->expectExceptionCode(1);
$property = $this->reflection->getProperty('filename');
$property->setAccessible(true);
$property->setValue($this->class, TEST_STATICS . '/drafter/non_existing_including_apib');
$this->class->parse();
}
/**
* Test if setup is successful
* @return void
*/
public function testParseBasic(): void
{
$property = $this->reflection->getProperty('filename');
$property->setAccessible(true);
$property->setValue($this->class, TEST_STATICS . '/drafter/apib/including.apib');
$loc_property = $this->reflection->getProperty('location');
$loc_property->setAccessible(true);
$loc_property->setValue($this->class, TEST_STATICS . '/drafter/apib/');
$this->mock_function('curl_exec', function () {
return 'hello';
});
$this->class->parse();
$this->unmock_function('curl_exec');
$full_property = $this->reflection->getProperty('full_apib');
$full_property->setAccessible(true);
$text = "FORMAT: 1A\nHOST: https://owner-api.teslamotors.com\n";
$text .= "EXTRA_HOSTS: https://test.owner-api.teslamotors.com\nSOMETHING: INFO\n\n";
$text .= "# Tesla Model S JSON API\nThis is unofficial documentation of the";
$text .= " Tesla Model S JSON API used by the iOS and Android apps. It features";
$text .= " functionality to monitor and control the Model S remotely.\n\nTEST";
$text .= "\n\n# Hello\nThis is a test.\nhello";
$this->assertSame($text, $full_property->getValue($this->class));
$this->assertSame($text, $this->class->__toString());
}
/**
* Test setting content
*
* @covers \PHPDraft\In\ApibFileParser::set_apib_content
*/
public function testSetContent(): void
{
$this->class->set_apib_content('content');
$this->assertEquals('content', $this->get_reflection_property_value('full_apib'));
}
}