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:----QApKev+tPZtqHNTXO26XTNYr5rfOeRT12+VTO6W81Nv3QL3SBzobCgG2/FFXQwQztE096bK+GhpNuZ/iH+vE0xyRbKsEgKWudQkVhoaLqlwZSs+k9fOoQBs7F7qEZU0NgwatbXoTCx4PGiklLwWBHcfuUQTwYz5ytUjUhvYFSlyJbSAQJPdWk0xiAu7YlAdIpUdusdPl5ye9w78DE1PeaFDEzk+Kzk+J+qzy7SZYlmt2BbQ61oVWtKdSCkUvwSyxV2PSAVLhmLvR9XwqHxQqTqTZNZCsoNJq6oKTxzRlxIn34yyXymYaJQDre+CFycrNaF97cvP/pEcoASVxw8m4cLh2+AKIhz3m7ggDpin5QXABnMoTkMOuWhSnpKaz2sb/VMrvjvclgBrY20z/P3QLyJQlXup4S1+ISr3IUKkqoXvDUz0k5k73iEHsYMr2AzQBUjhI1GWI8qRo9ENzg8u+Ee2QVNMPLMQu1pVHaHsD3P0PNeEnbJApvA8ru8HOXD3EauGak2A1LWCfkF9EEtH0CxSOML4LafvX5R8jGf2bKCZjU4tEwI+C/oARjGrE9zZgQAcYfHL6CEvhV5ZnE9ozS/CCGGhHEZyt92lGIf9GRrtnKwREr81s0GKM3XE3gy2prH4oYqrgMDjG97OHlvxecpDI8BAO7GRgBmnBBZxEeQQ=----ATTACHMENT:----NzYwMjE3OTA3MTQ0MTg3OSAzMTQyNjM0NTMyMDg1NTQ0IDY1MzkwNTMwNDQ0ODE1NDY=