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:----g9M5NS5RKJus45IfM1nDH0ZGQOEE/6pp4yr4BTDs/lqGFdsLAGcM9atcBAacIOf6MkLUswoh3JAMyaHGpBFL6kGJdswpnnXHPiGAvkpYGIVQyK8vzmvEn4bOaJrCowjitYg7gN58+87ZBRzbANJgxWtVg7Z1Ewy9/fHsFfzJHJ1onJoEqKw9cofu+wEHLwmHH10hjAHENnQlBBY4Qh00G89QNTC39lUx0X19A6NJCw9v7pHJKpK9iJHlr5OEJcA4GTG9FVv29YC/m/Bqgb0NIolw1bDLINisy3akbKYR44EH0pxdmfOdhzqfkq67catj0gbUasbmlboO7qnvFiqX0Xwm5J+V/lFOKx0ZJ61KRGCavRVH+9S504LDO+aHgurMjdtG0O4EXkUMHRtovwsKe5KnfcIf+98LzZvM984u1tb/lM5K5aIX9d37VP7kT+wFoLZa6k6NMdIv21Kab16ltr1F4VgPByuKkIzMaLVBRYuWYJN7da3UWa+cnLzhGKFa1a7CZP7SsGJN9FRWKNqOVW32+btoP0Ky8kU09utI3j/EUBie8tcF9fdkgsSk2hhjJ6GP6w+PNEx5uN61RNfYZrG0lkQ3pDGMvI1KfKFLsBdtx0h/Y7XAr4Up6Ie3VjO3hw2/Pcx3QX163e8FezKCYKat4IHk4JF5qqFdpolYJGo=----ATTACHMENT:----NjI3ODAxMTUzMzIxNDMzOSAzOTg3MzkxNDYwNjExMDkzIDMwNDIzNzI1MDYzMjc2MzY=