tests/Activerules/Nugget/NuggetTest.php
3. namespace Activerules\Nugget;
5. use PHPUnit\Framework\TestCase;
Extended class (NuggetTest)
11. class NuggetTest extends TestCase {
14. * This gets called before all test functions
16. public function setUp()
18. // Use the League dereferencer
Static method call (Activerules\JsonReference\Dereferencer::draft4)
19. $dereferencer = \Activerules\JsonReference\Dereferencer::draft4();
21. // A known valid Person object, it has a name property.
22. $this->validPerson = '{"name":"Brian"}';
24. // A known invalid Person object, it has NO name property.
25. $this->invalidPerson = '{"noName":"Brian"}';
27. // A known valid Person/Address object, it has a name property and the address has a type.
28. $this->validPersonAddress = '{"name":"Brian","address": {"type": "street"} }';
31. // A known valid Person/Address object, it has a name property and the address has a type.
32. $this->invalidPersonAddressEnum = '{"name":"Brian","address": {"type": "notstreet"} }';
33. // A known valid Person/Address object, it has a name property and the address has a type.
34. $this->invalidPersonAddress = '{"name":"Brian","address": {"notype":"street"}}';
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://' . __DIR__ . '/schema/person.json');
40. // NOTE: NO REMOTE SCHEMA TESTS IN THIS FILE!
41. // This test gets run by Travis CI and for some as of yet unresolved reason it does not work with remote schema.
42. //$this->remotePersonSchema = $dereferencer->dereference('https://rawgit.com/bwinkers/nugget/master/tests/Activerules/Nugget/objects/person.json');
46. * This gets called after each test function
48. public function tearDown()
50. //$this->myClass = null;
54. * A known valid schema should pass validation
56. public function testValidDataPasses()
58. $result = $this->nugget->meetsSchema($this->validPerson, $this->localPersonSchema);
60. $this->assertEquals(true, $result);
64. * A known invalid schema should fail validation
66. public function testInvalidDataFails()
68. $result = $this->nugget->meetsSchema($this->invalidPerson, $this->localPersonSchema);
70. $this->assertEquals(false, $result);