Skip to content

Commit 1b2f6c3

Browse files
committed
Switch out test system for a framework
1 parent 819b472 commit 1b2f6c3

26 files changed

+291
-418
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
}
1919
],
2020
"require": {
21-
"php": "5.6.* || 7.*",
21+
"php": "~7.1",
2222
"ql/uri-template": "1.*",
2323
"michelf/php-markdown": "1.*",
24-
"lukasoppermann/http-status": "2.*"
24+
"lukasoppermann/http-status": "2.*",
25+
"ext-json": "*"
2526
},
2627
"require-dev": {
28+
"lunr/halo": "*",
2729
"phpunit/phpunit": "~7.0",
2830
"theseer/autoload": "1.*"
2931
},

src/PHPDraft/Core/BaseTest.php

Lines changed: 0 additions & 181 deletions
This file was deleted.

src/PHPDraft/In/ApibFileParser.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ public function __construct($filename = 'index.apib')
5050
set_include_path(get_include_path() . ':' . $this->location);
5151
}
5252

53+
/**
54+
* Get parse the apib file.
55+
*
56+
* @return $this self reference.
57+
*/
5358
public function parse()
5459
{
55-
$this->full_apib = $this->get_apib($this->filename);
60+
$this->full_apib = $this->get_apib($this->filename, $this->location);
5661

5762
return $this;
5863
}
@@ -61,19 +66,22 @@ public function parse()
6166
* Parse a given API Blueprint file
6267
* This changes all `include(file)` tags to the contents of the file.
6368
*
64-
* @param string $filename File to parse
69+
* @param string $filename File to parse.
70+
* @param string|null $rel_path File location to look.
71+
*
72+
* @throws ExecutionException when the file could not be found.
6573
*
66-
* @return string The full API blueprint file
74+
* @return string The full API blueprint file.
6775
*/
68-
private function get_apib($filename)
76+
private function get_apib($filename, $rel_path = NULL)
6977
{
70-
$path = $this->file_path($filename);
78+
$path = $this->file_path($filename, $rel_path);
7179
$file = file_get_contents($path);
7280
$matches = [];
7381
preg_match_all('<!-- include\(([\S\s]*?)(\.[a-z]*?)\) -->', $file, $matches);
7482
for ($i = 0; $i < count($matches[1]); $i++) {
7583
$file = str_replace('<!-- include(' . $matches[1][$i] . $matches[2][$i] . ') -->',
76-
$this->get_apib($matches[1][$i] . $matches[2][$i]), $file);
84+
$this->get_apib($matches[1][$i] . $matches[2][$i], dirname($path)), $file);
7785
}
7886

7987
preg_match_all('<!-- schema\(([a-z0-9_.\/\:]*?)\) -->', $file, $matches);
@@ -88,23 +96,35 @@ private function get_apib($filename)
8896
* Check if an APIB file exists.
8997
*
9098
* @param string $filename File to check
99+
* @param string|null $rel_path File location to look.
91100
*
92101
* @throws ExecutionException when the file could not be found.
93102
*
94103
* @return string
95104
*/
96-
private function file_path($filename)
105+
private function file_path($filename, $rel_path = NULL)
97106
{
98-
$path = $this->location . $filename;
99-
if (file_exists($path)) {
100-
return $path;
107+
// Absolute path
108+
if (file_exists($filename)) {
109+
return $filename;
101110
}
102-
$path = stream_resolve_include_path($filename);
103-
if ($path === FALSE || !file_exists($path)) {
104-
throw new ExecutionException("API File not found: $filename", 1);
111+
112+
// Path relative to the top file
113+
if ($rel_path !== null && file_exists($rel_path . $filename)) {
114+
return $rel_path . $filename;
115+
}
116+
117+
// Path relative to the top file
118+
if (file_exists($this->location . $filename)) {
119+
return $this->location . $filename;
120+
}
121+
122+
$included_path = stream_resolve_include_path($filename);
123+
if ($included_path !== FALSE) {
124+
return $included_path;
105125
}
106126

107-
return $path;
127+
throw new ExecutionException("API File not found: $filename", 1);
108128
}
109129

110130
/**

src/PHPDraft/In/Tests/ApibFileParserTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88

99
namespace PHPDraft\In\Tests;
1010

11-
use PHPDraft\Core\BaseTest;
11+
use Lunr\Halo\LunrBaseTest;
1212
use PHPDraft\In\ApibFileParser;
1313
use ReflectionClass;
1414

1515
/**
1616
* Class ApibFileParserTest
1717
* @covers \PHPDraft\In\ApibFileParser
1818
*/
19-
class ApibFileParserTest extends BaseTest
19+
class ApibFileParserTest extends LunrBaseTest
2020
{
2121

2222
/**
2323
* Set up tests.
2424
*
2525
* @return void Test is now set up.
2626
*/
27-
public function setUp()
27+
public function setUp(): void
2828
{
2929
$this->class = new ApibFileParser(__DIR__ . '/ApibFileParserTest.php');
3030
$this->reflection = new ReflectionClass('PHPDraft\In\ApibFileParser');
@@ -34,7 +34,7 @@ public function setUp()
3434
* Test if setup is successful
3535
* @return void
3636
*/
37-
public function testLocationSetup()
37+
public function testLocationSetup(): void
3838
{
3939
$property = $this->reflection->getProperty('location');
4040
$property->setAccessible(true);
@@ -45,7 +45,7 @@ public function testLocationSetup()
4545
* Test if setup is successful
4646
* @return void
4747
*/
48-
public function testFilenameSetup()
48+
public function testFilenameSetup(): void
4949
{
5050
$property = $this->reflection->getProperty('filename');
5151
$property->setAccessible(true);
@@ -60,7 +60,7 @@ public function testFilenameSetup()
6060
*
6161
* @return void
6262
*/
63-
public function testFilenameSetupWrong()
63+
public function testFilenameSetupWrong(): void
6464
{
6565
$property = $this->reflection->getProperty('filename');
6666
$property->setAccessible(true);
@@ -72,7 +72,7 @@ public function testFilenameSetupWrong()
7272
* Test if setup is successful
7373
* @return void
7474
*/
75-
public function testParseBasic()
75+
public function testParseBasic(): void
7676
{
7777
$property = $this->reflection->getProperty('filename');
7878
$property->setAccessible(true);
@@ -81,7 +81,7 @@ public function testParseBasic()
8181
$loc_property->setAccessible(true);
8282
$loc_property->setValue($this->class, TEST_STATICS . '/drafter/apib/');
8383

84-
$this->mock_function('curl_exec', 'hello');
84+
$this->mock_function('curl_exec', function() { return 'hello';});
8585
$this->class->parse();
8686
$this->unmock_function('curl_exec');
8787

src/PHPDraft/Model/Category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function parse($object)
5353

5454
break;
5555
default:
56-
continue;
56+
continue 2;
5757
break;
5858
}
5959
}

src/PHPDraft/Model/Elements/Tests/ArrayStructureElementTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
namespace PHPDraft\Model\Elements\Tests;
1010

11-
use PHPDraft\Core\BaseTest;
11+
use Lunr\Halo\LunrBaseTest;
1212
use PHPDraft\Model\Elements\ArrayStructureElement;
1313

1414
/**
1515
* Class ArrayStructureTest
16-
* @covers PHPDraft\Model\Elements\ArrayStructureElement
16+
* @covers \PHPDraft\Model\Elements\ArrayStructureElement
1717
*/
18-
class ArrayStructureElementTest extends BaseTest
18+
class ArrayStructureElementTest extends LunrBaseTest
1919
{
2020

2121
/**

0 commit comments

Comments
 (0)