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:----otvO8EXteha0ecxs0504GuHLHA4a4ctCT2HnLdqKDGOjajHteYAgbManL7o9R/f+BBI8piHjt5Mz1Tzcrti4xrKf+eBzpb0vusxn6uhggHUfEnuBvhyP7BiwtUzEbwtI19IZnGQMpY2WlX5uSQPZZSBiQwV32yoDunR1+pMb12VHg3SUkY+iXxlWFjRy3MAM2i1Uxq8+wjFrf/ehorwH3XRR/F7hqGaos8oifc4M0zWnf7I1s5Q1Iy5+z1uaw08InmSwHAbjmZhB0L+8zaSESmb7r/H72amZVrK4DuzI+9455YfVgq6rUe5Gj59C0qQiLipu9Zm8kGlaJNorSvxL4Exk3RnK0L06VmEUrhBeh2AwDkVmDhxYijCDSHntM6Cw9/cY5m1BBPUKwUidLc7SQznvy19PbG4XnxQh3sZhpVHdqdZoCJHIjqsud9B4tak3Xy9zI8aJZj2CpGBTxATSy89pP0ptmvm15R3EfegYcraneo2osKwn8XZz8Vun1DpaNL1Pk8TEUHAaahFX9xYdWv3ndagEjhsglVhwxyIxIHI0mp3fwehDUeEW2LkKhu7JZcbmVnEeW/sOZb/LURmLzNUyAeK+VNz23Mc4cEOcUsbB1V2jW3xbHQHWrdby6vq/OgAN79bhgrlk0xTOw6sQAMySWy443ynSTlT4XAUg0wI=----ATTACHMENT:----MTYxNDIyNjU2NjUyMTE3OCA4MDk3MTkzNzk2OTc2NzI4IDY4NDM5MDU0NjM0NzcxMDk=