tests/Activerules/Nugget/NuggetTest-Dev.php

 
Procedures Status
NuggetTestDev::setUp Issues 2
NuggetTestDev::tearDown Testable
NuggetTestDev::testValidDataPasses Testable
NuggetTestDev::testInvalidDataFails Testable
NuggetTestDev::testValidDataPassesRemoteSchema Testable
NuggetTestDev::testInvalidDataFailsRemoteSchema Testable
NuggetTestDev::testValidDataPassesReferencedSchema Testable
NuggetTestDev::testInvalidDataFailsLocalSchema Testable
NuggetTestDev::testStringNotInEnumFails Testable
NuggetTestDev::testLocalFileRefs Testable
 
 
1. <?php
3. namespace Activerules\Nugget;
5. use PHPUnit\Framework\TestCase;
8. // Need more test
Extended class (NuggetTestDev)  
11. class NuggetTestDev extends TestCase {
13. /**
14. * This gets called before all test functions
15. */
16. public function setUp()
17. {
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');
41. }
43. /**
44. * This gets called after each test function
45. */
46. public function tearDown()
47. {
48. //$this->myClass = null;
49. }
51. /**
52. * A known valid schema should pass validation
53. */
54. public function testValidDataPasses()
55. {
56. $result = $this->nugget->meetsSchema($this->validPerson, $this->localPersonSchema);
58. $this->assertEquals(true, $result);
59. }
61. /**
62. * A known invalid schema should fail validation
63. */
64. public function testInvalidDataFails()
65. {
66. $result = $this->nugget->meetsSchema($this->invalidPerson, $this->localPersonSchema);
68. $this->assertEquals(false, $result);
69. }
71. /**
72. * A known valid schema, fetched remotely, should pass validation
73. */
74. public function testValidDataPassesRemoteSchema()
75. {
76. $result = $this->nugget->meetsSchema($this->validPerson, $this->remotePersonSchema);
78. $this->assertEquals(true, $result);
79. }
81. /**
82. * A known valid schema, fetched remotely, should pass validation
83. */
84. public function testInvalidDataFailsRemoteSchema()
85. {
86. $result = $this->nugget->meetsSchema($this->invalidPerson, $this->remotePersonSchema);
88. $this->assertEquals(false, $result);
89. }
91. /**
92. * A valid object should pass a referenced remote schema validation
93. */
94. public function testValidDataPassesReferencedSchema()
95. {
96. $result = $this->nugget->meetsSchema($this->validPersonAddress, $this->localPersonSchema);
98. $this->assertEquals(true, $result);
99. }
101. /**
102. * An invalid object should pass a referenced remote schema validation
103. */
104. public function testInvalidDataFailsLocalSchema()
106. $result = $this->nugget->meetsSchema($this->invalidPersonAddress, $this->localPersonSchema);
108. $this->assertEquals(false, $result);
111. /**
112. * A valid object should pass a referenced remote schema validation
113. */
114. public function testStringNotInEnumFails()
116. $result = $this->nugget->meetsSchema($this->invalidPersonAddressEnum, $this->localPersonSchema);
118. $this->assertEquals(false, $result);
121. /**
122. * Validate using a local reference
123. */
124. public function testLocalFileRefs()
126. $result = $this->nugget->meetsSchema($this->validPersonAddress, $this->localRefPersonSchema);
128. $this->assertEquals(true, $result);
 
Generated Thu, 11 Jan 2018 21:56:06 -0800 by PHP_Testability