19
19
*/
20
20
class ApibFileParserTest extends LunrBaseTest
21
21
{
22
+
23
+ private ApibFileParser $ class ;
24
+
22
25
/**
23
26
* Set up tests.
24
27
*
25
28
* @return void Test is now set up.
26
29
*/
27
30
public function setUp (): void
28
31
{
29
- $ this ->class = new ApibFileParser (__DIR__ . '/ApibFileParserTest.php ' );
30
- $ this ->reflection = new ReflectionClass ( ' PHPDraft\In\ApibFileParser ' );
32
+ $ this ->class = new ApibFileParser (__DIR__ . '/ApibFileParserTest.php ' );
33
+ $ this ->baseSetUp ( $ this -> class );
31
34
}
32
35
33
36
/**
@@ -36,9 +39,7 @@ public function setUp(): void
36
39
*/
37
40
public function testLocationSetup (): void
38
41
{
39
- $ property = $ this ->reflection ->getProperty ('location ' );
40
- $ property ->setAccessible (true );
41
- $ this ->assertSame (__DIR__ . '/ ' , $ property ->getValue ($ this ->class ));
42
+ $ this ->assertPropertyEquals ('location ' , __DIR__ . '/ ' );
42
43
}
43
44
44
45
/**
@@ -47,9 +48,7 @@ public function testLocationSetup(): void
47
48
*/
48
49
public function testFilenameSetup (): void
49
50
{
50
- $ property = $ this ->reflection ->getProperty ('filename ' );
51
- $ property ->setAccessible (true );
52
- $ this ->assertSame (__DIR__ . '/ApibFileParserTest.php ' , $ property ->getValue ($ this ->class ));
51
+ $ this ->assertPropertySame ('filename ' , __DIR__ . '/ApibFileParserTest.php ' );
53
52
}
54
53
55
54
/**
@@ -63,9 +62,7 @@ public function testFilenameSetupWrong(): void
63
62
$ this ->expectExceptionMessageMatches ('/API File not found: .*\/drafter\/non_existing_including_apib/ ' );
64
63
$ this ->expectExceptionCode (1 );
65
64
66
- $ property = $ this ->reflection ->getProperty ('filename ' );
67
- $ property ->setAccessible (true );
68
- $ property ->setValue ($ this ->class , TEST_STATICS . '/drafter/non_existing_including_apib ' );
65
+ $ this ->set_reflection_property_value ('filename ' , TEST_STATICS . '/drafter/non_existing_including_apib ' );
69
66
$ this ->class ->parse ();
70
67
}
71
68
@@ -75,21 +72,15 @@ public function testFilenameSetupWrong(): void
75
72
*/
76
73
public function testParseBasic (): void
77
74
{
78
- $ property = $ this ->reflection ->getProperty ('filename ' );
79
- $ property ->setAccessible (true );
80
- $ property ->setValue ($ this ->class , TEST_STATICS . '/drafter/apib/including.apib ' );
81
- $ loc_property = $ this ->reflection ->getProperty ('location ' );
82
- $ loc_property ->setAccessible (true );
83
- $ loc_property ->setValue ($ this ->class , TEST_STATICS . '/drafter/apib/ ' );
84
-
85
- $ this ->mock_function ('curl_exec ' , function () {
86
- return 'hello ' ;
87
- });
75
+ $ this ->set_reflection_property_value ('filename ' , TEST_STATICS . '/drafter/apib/including.apib ' );
76
+ $ this ->set_reflection_property_value ('location ' , TEST_STATICS . '/drafter/apib/ ' );
77
+
78
+
79
+ $ this ->mock_function ('curl_exec ' , fn () => 'hello ' );
80
+
88
81
$ this ->class ->parse ();
89
- $ this ->unmock_function ('curl_exec ' );
90
82
91
- $ full_property = $ this ->reflection ->getProperty ('full_apib ' );
92
- $ full_property ->setAccessible (true );
83
+ $ this ->unmock_function ('curl_exec ' );
93
84
94
85
$ text = "FORMAT: 1A \nHOST: https://owner-api.teslamotors.com \n" ;
95
86
$ text .= "EXTRA_HOSTS: https://test.owner-api.teslamotors.com \nSOMETHING: INFO \n\n" ;
@@ -98,7 +89,7 @@ public function testParseBasic(): void
98
89
$ text .= " functionality to monitor and control the Model S remotely. \n\nTEST " ;
99
90
$ text .= "\n\n# Hello \nThis is a test. \nhello " ;
100
91
101
- $ this ->assertSame ( $ text , $ full_property -> getValue ( $ this -> class ) );
92
+ $ this ->assertPropertyEquals ( ' full_apib ' , $ text );
102
93
$ this ->assertSame ($ text , $ this ->class ->__toString ());
103
94
}
104
95
0 commit comments