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:----lSk13wyklGiJ4h/EGpxbMm76/wcC2UC96tlxWWOhBa3TpbUxGuZoB+UyCgNKzgBOO9HMHHgDn1gd365H2aEUidWf18wbWUIBaa7W9mmXXhcDt9i1cu1cc9qUhj75SJ7CZ1IhrMPxmAVa08R+InCYcmayFvGw3uAkk5LJW/OAxqEovanhcUyOX8g5wcSNGKC3qNTRoLrlI79rhdjudLzSlWScZPQ/P0SLBPBDXKowUZa+uND0M5nQVsjRGIZJWgp3MlV2d7qAu1NwI3wsC6+VWcOt4t62cHbae+Zl19DkgzcfUERefuSFZJ7ZsER38iDRkY8BWqKcivpacH+aqg6X1XdgFdwoOGmHe/Ml3OHi/vJjduHa4BTaKfYdc1Umt4o2jCiktY9JBbB1a0sQajD4IkVva91LaUV5aXPf93ur7RA9/3WgEJ28hf3+Tpoj4uMczf1Hegz5MQJvmkUrD1lSlsZfGRPW/BtZt1vCE/1e0cPF6vkczX5g8vTsPpgH05N7vkdAb5aLT+TK8h8QhY8JF7LqJ3DIh0e3bYaHElQR+f5LThqEPrEob9WEZoJg1xl38IVZTXDXMBdO2Q6kfDsNVGzm396/xNljTzrkz7bzkKREHGubPhwStapIxSEyFi/msjSfKaz3mi5DNNZnZk/CTpHATJp3tu6wdKRS/8WsQ5A=----ATTACHMENT:----NjIwMjY2MDMzMjgzNTkzNyA3NzA1MDg3MjYyMTAxODEwIDQ4NTE5MTE5MDE4MTUxMDA=