From 443af54a5523779989136b5ce6d75d7d1ee27266 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 18 Jun 2018 13:22:30 +0200 Subject: [PATCH] In: Add support for non apib includes --- src/PHPDraft/In/ApibFileParser.php | 10 ++++++---- src/PHPDraft/In/Tests/ApibFileParserTest.php | 8 +++++--- tests/statics/drafter/apib/include.md | 3 +++ tests/statics/drafter/apib/including.apib | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 tests/statics/drafter/apib/include.md diff --git a/src/PHPDraft/In/ApibFileParser.php b/src/PHPDraft/In/ApibFileParser.php index dcf93165..924dda57 100644 --- a/src/PHPDraft/In/ApibFileParser.php +++ b/src/PHPDraft/In/ApibFileParser.php @@ -70,10 +70,10 @@ private function get_apib($filename) $this->file_check($filename); $file = file_get_contents($filename); $matches = []; - preg_match_all('', $file, $matches); - foreach ($matches[1] as $value) { - $file = str_replace('', - $this->get_apib($this->location . $value . '.apib'), $file); + preg_match_all('', $file, $matches); + for ($i = 0; $i < count($matches[1]); $i++) { + $file = str_replace('', + $this->get_apib($this->location . $matches[1][$i] . $matches[2][$i]), $file); } preg_match_all('', $file, $matches); @@ -89,6 +89,8 @@ private function get_apib($filename) * * @param string $filename File to check * + * @throws ExecutionException when the file could not be found. + * * @return void */ private function file_check($filename) diff --git a/src/PHPDraft/In/Tests/ApibFileParserTest.php b/src/PHPDraft/In/Tests/ApibFileParserTest.php index a3699268..52dafc02 100644 --- a/src/PHPDraft/In/Tests/ApibFileParserTest.php +++ b/src/PHPDraft/In/Tests/ApibFileParserTest.php @@ -20,8 +20,9 @@ class ApibFileParserTest extends BaseTest { /** - * Set up tests - * @return void + * Set up tests. + * + * @return void Test is now set up. */ public function setUp() { @@ -88,7 +89,8 @@ public function testParseBasic() $full_property->setAccessible(true); $text = "FORMAT: 1A\nHOST: https://owner-api.teslamotors.com\nEXTRA_HOSTS: https://test.owner-api.teslamotors.com\nSOMETHING: INFO\n\n"; - $text .="# Tesla Model S JSON API\nThis is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.\n\nTEST\nhello"; + $text .="# Tesla Model S JSON API\nThis is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features 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()); diff --git a/tests/statics/drafter/apib/include.md b/tests/statics/drafter/apib/include.md new file mode 100644 index 00000000..d6e70077 --- /dev/null +++ b/tests/statics/drafter/apib/include.md @@ -0,0 +1,3 @@ + +# Hello +This is a test. \ No newline at end of file diff --git a/tests/statics/drafter/apib/including.apib b/tests/statics/drafter/apib/including.apib index a730adde..c28a8f4d 100644 --- a/tests/statics/drafter/apib/including.apib +++ b/tests/statics/drafter/apib/including.apib @@ -7,4 +7,5 @@ SOMETHING: INFO This is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely. + \ No newline at end of file