tests/Activerules/Nugget/NuggetLimitToSchemaTest.php
3. namespace Activerules\Nugget;
5. use PHPUnit\Framework\TestCase;
Extended class (NuggetLimitToSchemaTest)
11. class NuggetLimitToSchemaTest extends TestCase {
14. * This gets called before all test functions
16. public function setUp()
18. // Use the Activerules dereferencer
Static method call (Activerules\JsonReference\Dereferencer::draft4)
19. $dereferencer = \Activerules\JsonReference\Dereferencer::draft4();
21. $validPersonArray = ['name'=>'Brian'];
22. $this->validPerson = json_encode($validPersonArray);
24. $dirtyPersonArray = array_merge($validPersonArray, array('lorem'=>array('remove'=>'me'), 'ipsum'=>'More BAD text to remove.'));
25. $this->dirtyPerson = json_encode($dirtyPersonArray);
27. // All test will have these variables available to them under $this->
New instance (Activerules\Nugget\Nugget)
28. $this->nugget = new \Activerules\Nugget\Nugget();
29. $this->personSchema = $dereferencer->dereference('file://' . __DIR__ . '/schema/person.json');
30. //$this->personSchema = $dereferencer->dereference('https://rawgit.com/bwinkers/nugget/master/tests/Activerules/Nugget/objects/person.json');
35. * This gets called after each test function
37. public function tearDown()
39. //$this->myClass = null;
44. * A known valid schema, fetched remotely, should pass validation
46. public function testLimitingToSchema()
48. $cleanPerson = $this->nugget->limitToSchema($this->dirtyPerson, $this->personSchema);
50. $this->assertEquals($cleanPerson, $this->validPerson);
52. $result = $this->nugget->meetsSchema($cleanPerson, $this->personSchema);
54. $this->assertEquals(true, $result);
58. * A known valid schema, fetched remotely, should pass validation
60. public function testLimitingToSchemaNoJson()
62. $cleanPerson = $this->nugget->limitToSchema($this->dirtyPerson, $this->personSchema, false);
64. $this->assertEquals(true, is_array($cleanPerson));