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:----XHwf1tlwyqWr+Q2EUDq3b+Pz1dgLF365nXNcua7Bd2vLHdrB09Dej5DhFeg4DISp2cP37yExcAU98dtsUf6oaPcoHXDPE0XGxAqAvzGuZphRRIYEOpavUDpydtAHpriarglDg+lJqJ+CewnEOD+lCmDHRXK/16Y9LDexilmAAFUQIBBK1IoPg6bDTxZNGJoNEq59X2PAvddkDNmIHVXInKN5JXpr4P9omREvwuyYVs2wzQ/wOmTYtSfnjPXoerf4VcHFotEZKDxVrWF6by4Z2dM+01JFj7PxaUJiIM7HLddZFwiu/+7ZtkcxaU6E8seGXbM+VNTU6NA51xadvMZzPnze8/aiQr18OawO8Dp+M+u6qWX7/uSVsmMbuaYc7RRidTtm6K2w8myM5F/+zEaRZEPKFAHcNu/03gFFHs0seJLhYnfQg1/B1/t7K/quEQ6/SCr6RRgFxhAGpDl6yqzLnPiA+X8benw3a/FYnP+Q8kvPAE7ovtTTrUn05kDng8/HEeV3aLl3vOWSzGqf/QGz3xt/WgvGC4GIJ/5cVdxWsy8hvfKuz7oyXkd9fShmhxhnaJ3FGx1qZCTbLsK7I01rJTlOc8+YWLii9eLWUwSByhBEbkiT6Ia0BhGxBNFJKtBaXAlrtbxqf6dwD6pXhRuHd6LSo9VkRSdYD4yvem42Tcg=----ATTACHMENT:----MTE3MDA1MTkzODY4MjU2MCAxNjk3OTM1Njg1MTM1NDg0IDU0ODA2MjQ3MDQ1NTU5Njg=