-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test coverage for coercion API * Complete test coverage for SchemaStorage * Add test coverage for ObjectIterator * Add tests for ConstraintError * Add exception test for JsonPointer * MabeEnum\Enum appears to use singletons - add testing const * Don't check this line for coverage mbstring is on all test platforms, so this line will never be reached. * Add test for TypeConstraint::validateTypeNameWording() * Add test for exception on TypeConstraint::validateType() * PHPunit doesn't like an explanation with its @codeCoverageIgnore... * Add various tests for UriRetriever * Add tests for FileGetContents * Add tests for JsonSchema\Uri\Retrievers\Curl * Add missing bad-syntax test file * Restrict ignore to the exception line only * Fix exception scope
- Loading branch information
1 parent
b8d2611
commit 705dcbd
Showing
14 changed files
with
396 additions
and
20 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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the JsonSchema package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JsonSchema\Tests; | ||
|
||
use JsonSchema\ConstraintError; | ||
|
||
class ConstraintErrorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGetValidMessage() | ||
{ | ||
$e = ConstraintError::ALL_OF(); | ||
$this->assertEquals('Failed to match all schemas', $e->getMessage()); | ||
} | ||
|
||
public function testGetInvalidMessage() | ||
{ | ||
$e = ConstraintError::MISSING_ERROR(); | ||
|
||
$this->setExpectedException( | ||
'\JsonSchema\Exception\InvalidArgumentException', | ||
'Missing error message for missingError' | ||
); | ||
$e->getMessage(); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the JsonSchema package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JsonSchema\Tests\Iterators; | ||
|
||
use JsonSchema\Iterator\ObjectIterator; | ||
|
||
class ObjectIteratorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected $testObject; | ||
|
||
public function setUp() | ||
{ | ||
$this->testObject = (object) array( | ||
'subOne' => (object) array( | ||
'propertyOne' => 'valueOne', | ||
'propertyTwo' => 'valueTwo', | ||
'propertyThree' => 'valueThree' | ||
), | ||
'subTwo' => (object) array( | ||
'propertyFour' => 'valueFour', | ||
'subThree' => (object) array( | ||
'propertyFive' => 'valueFive', | ||
'propertySix' => 'valueSix' | ||
) | ||
), | ||
'propertySeven' => 'valueSeven' | ||
); | ||
} | ||
|
||
public function testCreate() | ||
{ | ||
$i = new ObjectIterator($this->testObject); | ||
|
||
$this->assertInstanceOf('\JsonSchema\Iterator\ObjectIterator', $i); | ||
} | ||
|
||
public function testInitialState() | ||
{ | ||
$i = new ObjectIterator($this->testObject); | ||
|
||
$this->assertEquals($this->testObject, $i->current()); | ||
} | ||
|
||
public function testCount() | ||
{ | ||
$i = new ObjectIterator($this->testObject); | ||
|
||
$this->assertEquals(4, $i->count()); | ||
} | ||
|
||
public function testKey() | ||
{ | ||
$i = new ObjectIterator($this->testObject); | ||
|
||
while ($i->key() != 2) { | ||
$i->next(); | ||
} | ||
|
||
$this->assertEquals($this->testObject->subTwo->subThree, $i->current()); | ||
} | ||
|
||
public function testAlwaysObjects() | ||
{ | ||
$i= new ObjectIterator($this->testObject); | ||
|
||
foreach ($i as $item) { | ||
$this->assertInstanceOf('\StdClass', $item); | ||
} | ||
} | ||
|
||
public function testReachesAllProperties() | ||
{ | ||
$i = new ObjectIterator($this->testObject); | ||
|
||
$count = 0; | ||
foreach ($i as $item) { | ||
$count += count(get_object_vars($item)); | ||
} | ||
|
||
$this->assertEquals(10, $count); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace JsonSchema\Tests\Uri\Retrievers | ||
{ | ||
use JsonSchema\Uri\Retrievers\Curl; | ||
|
||
class CurlTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testRetrieveFile() | ||
{ | ||
$c = new Curl(); | ||
$c->retrieve(realpath(__DIR__ . '/../../fixtures/foobar.json')); | ||
} | ||
|
||
public function testRetrieveNonexistantFile() | ||
{ | ||
$c = new Curl(); | ||
|
||
$this->setExpectedException( | ||
'\JsonSchema\Exception\ResourceNotFoundException', | ||
'JSON schema not found' | ||
); | ||
$c->retrieve(__DIR__ . '/notARealFile'); | ||
} | ||
|
||
public function testNoContentType() | ||
{ | ||
$c = new Curl(); | ||
$c->retrieve(realpath(__DIR__ . '/../../fixtures') . '/foobar-noheader.json'); | ||
} | ||
} | ||
} | ||
|
||
namespace JsonSchema\Uri\Retrievers | ||
{ | ||
function curl_exec($curl) | ||
{ | ||
$uri = curl_getinfo($curl, \CURLINFO_EFFECTIVE_URL); | ||
|
||
if ($uri === realpath(__DIR__ . '/../../fixtures/foobar.json')) { | ||
// return file with headers | ||
$headers = implode("\n", array( | ||
'Content-Type: application/json' | ||
)); | ||
|
||
return sprintf("%s\r\n\r\n%s", $headers, file_get_contents($uri)); | ||
} elseif ($uri === realpath(__DIR__ . '/../../fixtures') . '/foobar-noheader.json') { | ||
// return file without headers | ||
$uri = realpath(__DIR__ . '/../../fixtures/foobar.json'); | ||
|
||
return "\r\n\r\n" . file_get_contents($uri); | ||
} | ||
|
||
// fallback to real curl_exec | ||
return \curl_exec($curl); | ||
} | ||
} |
Oops, something went wrong.