1919 */
2020class ApibFileParserTest extends LunrBaseTest
2121{
22+
23+ private ApibFileParser $ class ;
24+
2225 /**
2326 * Set up tests.
2427 *
2528 * @return void Test is now set up.
2629 */
2730 public function setUp (): void
2831 {
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 );
3134 }
3235
3336 /**
@@ -36,9 +39,7 @@ public function setUp(): void
3639 */
3740 public function testLocationSetup (): void
3841 {
39- $ property = $ this ->reflection ->getProperty ('location ' );
40- $ property ->setAccessible (true );
41- $ this ->assertSame (__DIR__ . '/ ' , $ property ->getValue ($ this ->class ));
42+ $ this ->assertPropertyEquals ('location ' , __DIR__ . '/ ' );
4243 }
4344
4445 /**
@@ -47,9 +48,7 @@ public function testLocationSetup(): void
4748 */
4849 public function testFilenameSetup (): void
4950 {
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 ' );
5352 }
5453
5554 /**
@@ -63,9 +62,7 @@ public function testFilenameSetupWrong(): void
6362 $ this ->expectExceptionMessageMatches ('/API File not found: .*\/drafter\/non_existing_including_apib/ ' );
6463 $ this ->expectExceptionCode (1 );
6564
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 ' );
6966 $ this ->class ->parse ();
7067 }
7168
@@ -75,21 +72,15 @@ public function testFilenameSetupWrong(): void
7572 */
7673 public function testParseBasic (): void
7774 {
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+
8881 $ this ->class ->parse ();
89- $ this ->unmock_function ('curl_exec ' );
9082
91- $ full_property = $ this ->reflection ->getProperty ('full_apib ' );
92- $ full_property ->setAccessible (true );
83+ $ this ->unmock_function ('curl_exec ' );
9384
9485 $ text = "FORMAT: 1A \nHOST: https://owner-api.teslamotors.com \n" ;
9586 $ text .= "EXTRA_HOSTS: https://test.owner-api.teslamotors.com \nSOMETHING: INFO \n\n" ;
@@ -98,7 +89,7 @@ public function testParseBasic(): void
9889 $ text .= " functionality to monitor and control the Model S remotely. \n\nTEST " ;
9990 $ text .= "\n\n# Hello \nThis is a test. \nhello " ;
10091
101- $ this ->assertSame ( $ text , $ full_property -> getValue ( $ this -> class ) );
92+ $ this ->assertPropertyEquals ( ' full_apib ' , $ text );
10293 $ this ->assertSame ($ text , $ this ->class ->__toString ());
10394 }
10495
0 commit comments