-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78dc9f6
commit f06c567
Showing
31 changed files
with
983 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
<?php | ||
/** | ||
* This file contains the TestBase.php | ||
* This file contains the BaseTest.php | ||
* | ||
* @package php-drafter\SOMETHING | ||
* @package PHPDraft\Core | ||
* @author Sean Molenaar<[email protected]> | ||
*/ | ||
|
||
namespace PHPDraft\Core; | ||
|
||
|
||
use PHPUnit_Framework_TestCase; | ||
use ReflectionClass; | ||
|
||
/** | ||
* Class BaseTest | ||
*/ | ||
class BaseTest extends PHPUnit_Framework_TestCase | ||
{ | ||
const FUNCTION_ID = '_phpdraftbu'; | ||
|
@@ -27,14 +29,34 @@ class BaseTest extends PHPUnit_Framework_TestCase | |
*/ | ||
protected $reflection; | ||
|
||
/** | ||
* Clear up tests | ||
* @return void | ||
*/ | ||
public function tearDown() | ||
{ | ||
unset($this->class); | ||
unset($this->reflection); | ||
} | ||
|
||
/** | ||
* Mock an internal function | ||
* | ||
* @param string $name function name | ||
* @param string $mock function to replace it with | ||
* | ||
* @return void | ||
*/ | ||
protected function mock_function($name, $mock) | ||
{ | ||
if (function_exists($name . self::FUNCTION_ID) === FALSE) | ||
{ | ||
runkit_function_copy($name, $name . self::FUNCTION_ID); | ||
} | ||
|
||
runkit_function_redefine($name, '', $mock); | ||
} | ||
|
||
/** | ||
* Unmock a PHP function. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,37 +2,42 @@ | |
/** | ||
* This file contains the ApibFileParserTest.php | ||
* | ||
* @package php-drafter\SOMETHING | ||
* @package PHPDraft\In | ||
* @author Sean Molenaar<[email protected]> | ||
*/ | ||
|
||
namespace PHPDraft\In\Tests; | ||
|
||
|
||
use PHPDraft\Core\BaseTest; | ||
use PHPDraft\In\ApibFileParser; | ||
use ReflectionClass; | ||
|
||
/** | ||
* Class ApibFileParserTest | ||
* @covers PHPDraft\In\ApibFileParser | ||
*/ | ||
class ApibFileParserTest extends BaseTest | ||
{ | ||
|
||
/** | ||
* Set up tests | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->class = new ApibFileParser(__DIR__.'/ApibFileParserTest.php'); | ||
$this->class = new ApibFileParser(__DIR__ . '/ApibFileParserTest.php'); | ||
$this->reflection = new ReflectionClass('PHPDraft\In\ApibFileParser'); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
unset($this->class); | ||
unset($this->reflection); | ||
} | ||
|
||
/** | ||
* Test if setup is successful | ||
* @return void | ||
*/ | ||
public function testSetup() | ||
{ | ||
$property = $this->reflection->getProperty('location'); | ||
$property->setAccessible(TRUE); | ||
$this->assertSame(__DIR__.'/', $property->getValue($this->class)); | ||
$this->assertSame(__DIR__ . '/', $property->getValue($this->class)); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,80 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: smillernl | ||
* Date: 2-9-16 | ||
* Time: 15:21 | ||
* This file contains the ArrayStructureElement.php | ||
* | ||
* @package PHPDraft\Model\Elements | ||
* @author Sean Molenaar<[email protected]> | ||
*/ | ||
|
||
namespace PHPDraft\Model\Elements; | ||
|
||
use PHPDraft\Model\StructureElement; | ||
|
||
class ArrayStructureElement extends DataStructureElement implements StructureElement | ||
/** | ||
* Class ArrayStructureElement | ||
*/ | ||
class ArrayStructureElement extends ObjectStructureElement implements StructureElement | ||
{ | ||
|
||
/** | ||
* Type of objects in the array | ||
* Parse an array object | ||
* | ||
* @param \stdClass $object APIb Item to parse | ||
* @param array $dependencies List of dependencies build | ||
* | ||
* @var | ||
* @return $this | ||
*/ | ||
public $type_of; | ||
|
||
public function parse($item, &$dependencies) | ||
public function parse($object, &$dependencies) | ||
{ | ||
$this->element = (isset($item->element)) ? $item->element : 'array'; | ||
$this->value = (isset($item->content)) ? $item->content : null; | ||
|
||
if (isset($item->content)) { | ||
foreach ($item->content as $key => $sub_item) { | ||
$this->type[$key] = $sub_item->element; | ||
switch ($sub_item->element) { | ||
case 'array': | ||
$value = new ArrayStructureElement(); | ||
$this->value[$key] = $value->parse($sub_item, $dependencies); | ||
break; | ||
case 'object': | ||
$value = new DataStructureElement(); | ||
$this->value[$key] = $value->parse($sub_item, $dependencies); | ||
break; | ||
case 'enum': | ||
$value = new EnumStructureElement(); | ||
$this->value[$key] = $value->parse($sub_item, $dependencies); | ||
break; | ||
default: | ||
$this->value[$key] = (isset($sub_item->content)) ? $sub_item->content : null; | ||
break; | ||
} | ||
$this->element = (isset($object->element)) ? $object->element : 'array'; | ||
|
||
$this->parse_common($object, $dependencies); | ||
|
||
if(!isset($object->content->value->content)) | ||
{ | ||
$this->value = []; | ||
return $this; | ||
} | ||
|
||
foreach ($object->content->value->content as $sub_item) | ||
{ | ||
if (!in_array($sub_item->element, self::DEFAULTS)) | ||
{ | ||
$dependencies[] = $sub_item->element; | ||
} | ||
|
||
$this->value[] = (isset($sub_item->element)) ? $sub_item->element : ''; | ||
} | ||
|
||
$this->deps = $dependencies; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Provide HTML representation | ||
* | ||
* @return string | ||
*/ | ||
function __toString() | ||
{ | ||
if (!is_array($this->type)) { | ||
return ''; | ||
} | ||
$return = '<ul class="list-group">'; | ||
foreach ($this->type as $key => $item) { | ||
$type = | ||
(in_array($item, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(' ', '-', | ||
strtolower($item)) . '">' . $item . '</a>'; | ||
|
||
$value = | ||
(isset($this->value[$key])) ? ': <span class="example-value pull-right">' . json_encode($this->value[$key]) . '</span>' : null; | ||
if (!is_array($this->value)) | ||
{ | ||
return '<span class="example-value pull-right">[ ]</span>'; | ||
} | ||
|
||
foreach ($this->value as $item) { | ||
$type = (in_array($this->value, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(' ', '-', | ||
strtolower($item)) . '">' . $item . '</a>'; | ||
|
||
$return .= '<li class="list-group-item">' . $type . $value . '</li>'; | ||
$return .= '<li class="list-group-item">' . $type . '</li>'; | ||
} | ||
|
||
$return .= '</ul>'; | ||
|
||
return $return; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.