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:----fuojs+NiNqCeoJzNA9PTWecQjxmDlbqrc2FwvJ3Er56ZITlVhkI5P+uCoDetBYOgKT9673aIaAK2fP/2qouSkTYAcbacMsi6ycaVw8WMVWQbvMxr48BJLKiYv41O2uhNcZ6yBoR+9R+RVA/GesxdJjqkwIc8EO4+7xNlaZI630BUzdUxhUdpcmx8rOlB0XYND05/N6NM8WhSD4pjv669Gc3k4QSny2jmuL42FXgYD/G0wGTRcKEoGjJRTH0qrhbje04wOj3X7/hUhvzZyeRlFl4NabzIKz5QqiWZs/xacrDE+B73M8l5f0OtY6uI1DT39fb/wO9FIZqGHRA339rbJvB4oDBBIl+UqnfX8QWmlkNwC/v+w5v1aRSydyQ9r92YqX+ay2BB9VcUnTdh+JBEV7SgG2DNtE3baQP42kAT+B3EnV2D7xuQ27hpmOvTbioT1oWRkVLRP9yT2Q18DzO/xqFqsem5XFO9/bU6gxjPV0jKCDdCIoFZI+6/aDYfMBDsnZ9lW/zhLS0kUvK2ivlSliLIjXR4V/VaCj3YIWK6yg/M+sMVtk4ttub2O1Wy7rOQ1K5mVv73bMLM9OkJJ+zTPjMeP9mTO4K/NcODah13xgZ6ho1JfT+IrbBk0osi/imAW15jtEJUBppDZ/7Vo0GlhgAWSQf9cjvCXOp9ikYubVg=----ATTACHMENT:----Nzg4MjYyODg4NjQ1MTkyNSA0OTU0NjQ1MDY1NTMxNDc1IDcyOTc2ODI2Mzg5ODYyMjQ=