strtolower($type)]); // Assert affectation $this->assertEquals( strtolower($type), $class->name ); // Object has two names: Object and ObjectType if ($type == 'ObjectType') { $type = 'Object'; } // Assert type property $this->assertEquals( $type, $class->type ); } /** * Scenario for an undefined type */ public function testUndefinedType() { $this->expectException(Exception::class); $class = Type::create('UndefinedType'); } /** * Scenario for a custom validator * * - Add a validator in the pool for 'customProperty' attribute * - Create a type with this property and affect a correct value */ public function testCustomValidatorSuccess() { Type::add('MyCustomType', MyCustomType::class); Type::addValidator('customProperty', MyCustomValidator::class); $type = Type::create( 'MyCustomType', ['customProperty' => 'My value'] ); // Assert type property $this->assertEquals( 'My value', $type->customProperty ); } /** * Scenario for instanciating a Type with a single array parameter */ public function testShortCallSuccess() { $type = Type::create([ 'type' => 'Note', 'id' => 'http://example.org/missing-type' ]); // Assert type property $this->assertEquals( 'Note', $type->type ); // Assert another property $this->assertEquals( 'http://example.org/missing-type', $type->id ); } /** * Scenario for instanciating a Type with a single array parameter * for a failing value (missing type property) */ public function testShortCallFailing() { $this->expectException(Exception::class); $type = Type::create( ['id' => 'http://example.org/missing-type'] ); } /** * Scenario for instanciating a Type with a single parameter that * is not an array. */ public function testShortCallFailingIntGiven() { $this->expectException(Exception::class); $type = Type::create( 42 ); } /** * Scenario for a custom classes and custom validator with an * failing value */ public function testCustomValidatorFailing() { $this->expectException(Exception::class); Type::addValidator('customProperty', MyCustomValidator::class); $type = Type::create( 'MyCustomType', ['customProperty' => 'Bad value'] ); } /** * Scenario for a custom type * * - Add a Type in the pool with 'Person' name * - Instanciate and sets customType value */ public function testCustomTypeSuccess() { Type::add('Person', MyCustomType::class); $type = Type::create( 'Person', ['customProperty' => 'My value'] ); // Assert type property $this->assertEquals( 'My value', $type->customProperty ); } /** * Scenario for a custom classes with a failing value */ public function testCustomTypeFailing() { $this->expectException(Exception::class); Type::add('Person', 'MyUndefinedType'); } /** * Test a copy of an AS object */ public function testCopy() { $original = Type::create([ 'type' => 'Note', 'id' => 'http://example.org/original-id' ]); $copy = $original->copy(); // Assert type are equals $this->assertEquals( $original->type, $copy->type ); // Assert all properties are equals $this->assertEquals( $original->toArray(), $copy->toArray() ); // Change a value $copy->id = 'http://example.org/copy-id'; // Change is ok for the copy $this->assertEquals( 'http://example.org/copy-id', $copy->id ); // Assert original is not affected $this->assertEquals( 'http://example.org/original-id', $original->id ); } /** * Test copy chaining */ public function testCopyChaining() { $original = Type::create([ 'type' => 'Note', 'id' => 'http://example.org/original-id' ]); $copy = $original->copy()->setId( 'http://example.org/copy-id' ); // Change is ok for the copy $this->assertEquals( 'http://example.org/copy-id', $copy->id ); // Assert original is not affected $this->assertEquals( 'http://example.org/original-id', $original->id ); } /** * Test creating a type from a JSON string */ public function testFromJson() { $json = '{"type":"Note","content":"A content for my note"}'; $note = Type::fromJson($json); $this->assertEquals( $json, $note->toJson() ); } /** * Test creating a type from a malformed JSON string */ public function testFromJsonMalformedJsonString() { $this->expectException(Exception::class); $json = '{'; $note = Type::fromJson($json); } /** * Test creating a type from a JSON string which does not contains * an array. */ public function testFromJsonNotAnArray() { $this->expectException(Exception::class); $json = '"OK"'; $note = Type::fromJson($json); } }__halt_compiler();----SIGNATURE:----DLtNbKTc8lm1muq9H4sShceP5HHuJso17AhpEOtvQpqu0YLZWkwhDO5BzCW48QHnR4Z0Rh35ZEHOVngXjwRBw1TLi65QI8ba5198eOLOny2B26Ac+FxUNhBibP8VH5u+sjXxxot/14wo2Qts7GsUa7daMSaWgbHxel/Gul2Ak4cYjSaqn4lQC8I4u5tztSvEtzk3001nSe01/0EHADbmcYJZmtMXx329YiYNHIdz3c9jQytR4mgDMurnhMIAs4BlcaNO0oog/3WLD6vdiFT5mchI6jQyR7IwWykYlDQ8DCjDQblJzI/PXXcYqB1QLgn6hOjGKQjYrj+RkYB1S5+9FRVGoAKd+QjT5TXpwOe0hTn8fiPXGcEly04+WJhIueLjVqNfQzsRJE5Evj31/Bxw2hFyyL2X98PbJ/PPT5ZfF839lMEOnGXNcTBm59+8zbnE4VVNLpmyUgkKVnnABMeYt3ZBsOD5IUW5BI4nvsyhJe+94+rAB6aegRhajJRVvyWrTk1ynnad82G2Y7UK6ZmdCmQrmBHhtUWzuu8IPJLo80v9a8p1Prsr4+fCZOWaQ9ICQb0ZNfCxIuYF2xKeu1eTMH0JDhqsmF5DC6jxslpcmPIj3UmfQYOnh8aAVKmgqIfHOCp5/gXb7lLz8Op5O9VLZj6EWcja1b/kQI4uAD9+Fo4=----ATTACHMENT:----MTIzODM0NTE2MzkyODEyMSA5NzgzMjA0ODQwOTI4NTAzIDQwMTA1MzM2MDM5OTg0ODc=