tests/Activerules/Nugget/NuggetTest-Dev.php
3. namespace Activerules\Nugget;
5. use PHPUnit\Framework\TestCase;
Extended class (NuggetTestDev)
11. class NuggetTestDev 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. $validPersonAddressArray = array_merge($validPersonArray, array('address'=>array('type'=>'street')));
25. $this->validPersonAddress = json_encode($validPersonAddressArray);
27. $invalidPersonArray = ['noName'=>'Brian'];
28. $this->invalidPerson = json_encode($invalidPersonArray);
30. $invalidPersonAddressEnumArray = array_merge($validPersonArray, array('address'=>array('type'=>'nostreet')));
31. $this->invalidPersonAddressEnum = json_encode($invalidPersonAddressEnumArray);
33. $invalidPersonAddressArray = array_merge($validPersonArray, array('address'=>array('notype'=>'street')));
34. $this->invalidPersonAddress = json_encode($invalidPersonAddressArray);
36. // All test will have these variables available to them under $this->
New instance (Activerules\Nugget\Nugget)
37. $this->nugget = new \Activerules\Nugget\Nugget();
38. $this->localPersonSchema = $dereferencer->dereference('file://' . dirname(dirname(dirname(__DIR__))) . '/schema/person.json');
39. $this->localRefPersonSchema = $dereferencer->dereference('file://' . dirname(dirname(dirname(__DIR__))) . '/schema/refPerson.json');
40. $this->remotePersonSchema = $dereferencer->dereference('https://rawgit.com/bwinkers/nugget/master/tests/Activerules/Nugget/schema/person.json');
44. * This gets called after each test function
46. public function tearDown()
48. //$this->myClass = null;
52. * A known valid schema should pass validation
54. public function testValidDataPasses()
56. $result = $this->nugget->meetsSchema($this->validPerson, $this->localPersonSchema);
58. $this->assertEquals(true, $result);
62. * A known invalid schema should fail validation
64. public function testInvalidDataFails()
66. $result = $this->nugget->meetsSchema($this->invalidPerson, $this->localPersonSchema);
68. $this->assertEquals(false, $result);
72. * A known valid schema, fetched remotely, should pass validation
74. public function testValidDataPassesRemoteSchema()
76. $result = $this->nugget->meetsSchema($this->validPerson, $this->remotePersonSchema);
78. $this->assertEquals(true, $result);
82. * A known valid schema, fetched remotely, should pass validation
84. public function testInvalidDataFailsRemoteSchema()
86. $result = $this->nugget->meetsSchema($this->invalidPerson, $this->remotePersonSchema);
88. $this->assertEquals(false, $result);
92. * A valid object should pass a referenced remote schema validation
94. public function testValidDataPassesReferencedSchema()
96. $result = $this->nugget->meetsSchema($this->validPersonAddress, $this->localPersonSchema);
98. $this->assertEquals(true, $result);
102. * An invalid object should pass a referenced remote schema validation
104. public function testInvalidDataFailsLocalSchema()
106. $result = $this->nugget->meetsSchema($this->invalidPersonAddress, $this->localPersonSchema);
108. $this->assertEquals(false, $result);
112. * A valid object should pass a referenced remote schema validation
114. public function testStringNotInEnumFails()
116. $result = $this->nugget->meetsSchema($this->invalidPersonAddressEnum, $this->localPersonSchema);
118. $this->assertEquals(false, $result);
122. * Validate using a local reference
124. public function testLocalFileRefs()
126. $result = $this->nugget->meetsSchema($this->validPersonAddress, $this->localRefPersonSchema);
128. $this->assertEquals(true, $result);