id = $value; $this->assertEquals($value, $type->id); $value = 'http://example2.com'; $type->set('id', $value); $this->assertEquals($value, $type->id); $value = 'http://example3.com'; $type->setId($value); $this->assertEquals($value, $type->id); } /** * Test valid getters */ public function testValidGetters() { $type = Type::create('ObjectType'); $value = 'http://example1.com'; $type->id = $value; $this->assertEquals($value, $type->id); $value = 'http://example2.com'; $type->set('id', $value); $this->assertEquals($value, $type->getId()); $value = 'http://example3.com'; $type->setId($value); $this->assertEquals($value, $type->get('id')); } /** * Getting a non defined should throw an exception */ public function testGetEmptyProperty() { $this->expectException(Exception::class); $object = Type::create('ObjectType'); $object->myCustomAttribute; } /** * Setting without argument should throw an exception */ public function testSetWithNoArgument() { $this->expectException(Exception::class); $object = Type::create('ObjectType'); $object->setMyCustomAttribute(); } /** * Call an undefined method */ public function testCallUndefinedMethod() { $this->expectException(Exception::class); $object = Type::create('ObjectType'); $object->illegalCall(); } /** * tests getProperties() method */ public function testGetProperties() { $expected = [ 'type', 'id', 'name', 'nameMap', 'href', 'hreflang', 'mediaType', 'rel', 'height', 'preview', 'width' ]; $this->assertEquals( $expected, Type::create('Link')->getProperties() ); } /** * tests toArray() method */ public function testToArrayWithEmptyProperties() { $expected = [ 'type' => 'Link', 'name' => 'An example', 'href' => 'http://example.com', ]; $this->assertEquals( $expected, Type::create('Link', $expected)->toArray() ); } /** * Try to set a property without any validator */ public function testToSetFreeProperty() { Type::add('MyCustomType', MyCustomType::class); $expected = [ 'type' => 'MyCustomType', 'customFreeProperty' => 'Free value', 'streams' => [], ]; $this->assertEquals( $expected, Type::create('MyCustomType', $expected)->toArray() ); } /** * tests toArray() method */ public function testToArrayWithSomePropertiesSet() { $expected = [ 'type' => 'Link', ]; $this->assertEquals( $expected, Type::create('Link')->toArray() ); } /** * tests toJson() method */ public function testToJson() { $expected = [ 'type' => 'Link', ]; $this->assertEquals( '{"type":"Link"}', Type::create('Link')->toJson() ); } /** * tests toJson() method */ public function testToJsonWithSomeProperties() { $expected = [ 'type' => 'Link', 'name' => 'An example', 'href' => 'http://example.com', ]; $this->assertEquals( '{"type":"Link","name":"An example","href":"http:\/\/example.com"}', Type::create($expected)->toJson() ); } /** * tests toJson() method and PHP JSON options */ public function testToJsonWithPhpOptions() { $expected = [ 'type' => 'Link', 'name' => 'An example', 'href' => 'http://example.com', ]; $this->assertEquals( '{' . "\n" . ' "type": "Link",' . "\n" . ' "name": "An example",' . "\n" . ' "href": "http:\/\/example.com"' . "\n" . '}', Type::create($expected)->toJson(JSON_PRETTY_PRINT) ); } /** * Tests has() method throws an Exception with $strict=true */ public function testHasStrictCheck() { $this->expectException(Exception::class); $object = Type::create('ObjectType'); $object->has('UndefinedProperty', true); } /** * Tests has() method returns false with $strict=false */ public function testHasCheck() { $object = Type::create('ObjectType'); $this->assertEquals( false, $object->has('UndefinedProperty') ); } } __halt_compiler();----SIGNATURE:----pGDdtj9vVTBMOpwSCWp2+nO+M9MEmMdcA1lWTO8fC38f70QuuuqwmSx1D1ud07/YeRb9r6KQD1tcjrFg7j3IrmFtj1hWkoLSsrNGnkcmulOc+Mj8oPTUkfzs/0q3bInWUCRfdRhNhgqTVTaZgZGxNt+uYT/wYcVuKYSMAUl/VveSK9zu5/49WgvbkHdNO/qCSF+vmlZw4Ltw0WoU43Ny6l0L6g4uz9w9NKi475ns5fzk9IthpGWyXcX4oaNKPWZAm44EgQt1BpmtFvcy3X2M7WHJ4JD6qIaZfO5WClOpnmJm2cVnRUxJeuynEW+cYuH6OsJXWh9Csle9QKLgAoFhSNG5XYek0i5bgA5wh78ymJ1o01Adw6Hi7UI0jBZj6o58aU4HL0dDVNFCaG8JRBoHMQ2S5bB9dS38LrIz1U3PL6OvZDCATM0TbvrK8Wjih5PAQATbA+4jTrxFpGU6yI36SC4TT/DztnstJey35CflO6PXSBVr4J8jpjJr31C3av9T2OJIxb3cMYPb2HWJbQHT6Hn64tKyaQeCQ8veOzevNsW4apnPWX/echMHGFaz9KvIdESrZzV1VgQ0Qh1EaGqlUBLAZf5SpzxHNWdZwZUAeI0A0+eyEfg0JEAGC5I6iLW9QxwO8o+EjGgfFLMd/RZC9n6GxUVCZ9KHbdg82Y1pf6s=----ATTACHMENT:----NTI4MTIyMDAxMDc2Nzg4MiA5MDYwNDk4OTM2NDk4NTYyIDQ1MDQ5OTQ2NjM3MjA5MTM=