tests/Activerules/Nugget/NuggetTest.php

 
Procedures Status
NuggetTest::setUp Issues 2
NuggetTest::tearDown Testable
NuggetTest::testValidDataPasses Testable
NuggetTest::testInvalidDataFails Testable
 
 
1. <?php
3. namespace Activerules\Nugget;
5. use PHPUnit\Framework\TestCase;
8. // Need more test
Extended class (NuggetTest)  
11. class NuggetTest extends TestCase {
13. /**
14. * This gets called before all test functions
15. */
16. public function setUp()
17. {
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');
43. }
45. /**
46. * This gets called after each test function
47. */
48. public function tearDown()
49. {
50. //$this->myClass = null;
51. }
53. /**
54. * A known valid schema should pass validation
55. */
56. public function testValidDataPasses()
57. {
58. $result = $this->nugget->meetsSchema($this->validPerson, $this->localPersonSchema);
60. $this->assertEquals(true, $result);
61. }
63. /**
64. * A known invalid schema should fail validation
65. */
66. public function testInvalidDataFails()
67. {
68. $result = $this->nugget->meetsSchema($this->invalidPerson, $this->localPersonSchema);
70. $this->assertEquals(false, $result);
71. }
73. }
 
Generated Thu, 11 Jan 2018 21:56:06 -0800 by PHP_Testability