-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#58 add support for native classes as data
- Loading branch information
Showing
4 changed files
with
75 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Swaggest\JsonSchema\Tests\Helper; | ||
|
||
|
||
class SimpleClass | ||
{ | ||
public $id; | ||
public $username; | ||
public $email; | ||
|
||
|
||
// checking leak of private/protected properties | ||
protected $temp1; | ||
private $temp2; | ||
|
||
public function __construct() | ||
{ | ||
$this->temp1 = 'temp1'; | ||
$this->temp2 = 'temp2'; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace Swaggest\JsonSchema\Tests\PHPUnit\Suite; | ||
|
||
use Swaggest\JsonSchema\Constraint\Format; | ||
use Swaggest\JsonSchema\InvalidValue; | ||
use Swaggest\JsonSchema\Schema; | ||
use Swaggest\JsonSchema\Tests\Helper\SimpleClass; | ||
|
||
class Issue58Test extends \PHPUnit_Framework_TestCase | ||
{ | ||
private function getData() | ||
{ | ||
$data = new SimpleClass(); | ||
$data->id = 1234; | ||
$data->username = "John"; | ||
$data->email = "john@doe.com"; | ||
return $data; | ||
} | ||
|
||
private function getSchema() | ||
{ | ||
$schema = Schema::object(); | ||
$schema | ||
->setProperty('id', Schema::integer()) | ||
->setProperty('username', Schema::string()) | ||
->setProperty('email', Schema::string()->setFormat(Format::EMAIL)); | ||
|
||
// checking leak of private/protected properties | ||
$schema->additionalProperties = false; | ||
return $schema; | ||
} | ||
|
||
public function testSimpleClass() | ||
{ | ||
$this->getSchema()->out($this->getData()); | ||
} | ||
|
||
public function testSimpleClassFailed() | ||
{ | ||
$data = $this->getData(); | ||
$data->email = 'bla-bla'; | ||
$this->setExpectedException(get_class(new InvalidValue())); | ||
$this->getSchema()->out($data); | ||
} | ||
|
||
} |