setIdentifier('testIdentifier') ->setCardinality('single') ->setBaseType('testBaseType') ->setEpoch('testEpoch'); $this->assertSame(json_encode([ 'identifier' => 'testIdentifier', 'cardinality' => 'single', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', 'type' => 'testType', ]), json_encode($subject)); } /** * @dataProvider provideInvalidVariableArrayRepresentation */ public function testItThrowsExceptionIfVariableCannotBeReconstructedDueToMissingKeys( string $expectedExceptionMessage, array $variableAsArray ): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage($expectedExceptionMessage); \taoResultServer_models_classes_Variable::fromData($variableAsArray); } public function testIfOutComeVariableCanBeReconstructedFromArray(): void { $variableAsArray = [ 'identifier' => 'testIdentifier', 'cardinality' => 'multiple', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', 'type' => \taoResultServer_models_classes_OutcomeVariable::TYPE, 'normalMinimum' => 0.0, 'normalMaximum' => 10.0, 'value' => 'testValue', ]; $result = \taoResultServer_models_classes_Variable::fromData($variableAsArray); $this->assertInstanceOf(\taoResultServer_models_classes_OutcomeVariable::class, $result); $expectedVariableData = [ 'identifier' => 'testIdentifier', 'cardinality' => 'multiple', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', 'type' => \taoResultServer_models_classes_OutcomeVariable::TYPE, 'normalMinimum' => 0.0, 'normalMaximum' => 10.0, 'value' => 'testValue', ]; $this->assertSame($expectedVariableData, $result->jsonSerialize()); } public function testIfResponseVariableCanBeConstructedFromArray(): void { $variableAsArray = [ 'identifier' => 'testIdentifier', 'cardinality' => 'multiple', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', 'type' => \taoResultServer_models_classes_ResponseVariable::TYPE, 'correctResponse' => 'testCorrectResponse', 'candidateResponse' => 'testCandidateResponse', ]; $result = \taoResultServer_models_classes_Variable::fromData($variableAsArray); $this->assertInstanceOf(\taoResultServer_models_classes_ResponseVariable::class, $result); $expectedVariableData = [ 'identifier' => 'testIdentifier', 'cardinality' => 'multiple', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', 'type' => \taoResultServer_models_classes_ResponseVariable::TYPE, 'correctResponse' => 'testCorrectResponse', 'candidateResponse' => 'testCandidateResponse', ]; $this->assertSame($expectedVariableData, $result->jsonSerialize()); } public function testIfTraceVariableCanBeConstructedFromArray(): void { $variableAsArray = [ 'identifier' => 'testIdentifier', 'cardinality' => 'multiple', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', 'type' => \taoResultServer_models_classes_TraceVariable::TYPE, 'trace' => 'test', ]; $result = \taoResultServer_models_classes_Variable::fromData($variableAsArray); $this->assertInstanceOf(\taoResultServer_models_classes_TraceVariable::class, $result); $expectedVariableData = [ 'identifier' => 'testIdentifier', 'cardinality' => 'multiple', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', 'type' => \taoResultServer_models_classes_TraceVariable::TYPE, 'trace' => 'test', ]; $this->assertSame($expectedVariableData, $result->jsonSerialize()); } public function testItThrowsExceptionIfInvalidVariableTypeIsProvided(): void { $variableAsArray = [ 'type' => 'invalid', 'identifier' => 'testIdentifier', 'cardinality' => 'multiple', 'baseType' => 'testBaseType', 'epoch' => 'testEpoch', ]; $this->expectExceptionMessage('Unsupported variable type: invalid'); \taoResultServer_models_classes_Variable::fromData($variableAsArray); } public function provideInvalidVariableArrayRepresentation(): array { return [ 'anyVariableWithMissingIdentifierKey' => [ 'expectedExceptionMessage' => 'Key "identifier" is not defined in variable data.', 'variableAsArray' => [ 'type' => 'test', ], ], 'anyVariableWithMissingCardinalityKey' => [ 'expectedExceptionMessage' => 'Key "cardinality" is not defined in variable data.', 'variableAsArray' => [ 'type' => 'test', 'identifier' => 'test', ], ], 'anyVariableWithMissingbaseTypeKey' => [ 'expectedExceptionMessage' => 'Key "baseType" is not defined in variable data.', 'variableAsArray' => [ 'type' => 'test', 'identifier' => 'test', 'cardinality' => 'single', ], ], 'anyVariableWithMissingEpochKey' => [ 'expectedExceptionMessage' => 'Key "epoch" is not defined in variable data.', 'variableAsArray' => [ 'type' => 'test', 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', ], ], 'missingVariableType' => [ 'expectedExceptionMessage' => 'Key "type" is not defined in variable data.', 'variableAsArray' => [ 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', 'epoch' => 'test', ], ], 'outcomeVariableWithMissingNormalMinimumKey' => [ 'expectedExceptionMessage' => 'Key "normalMinimum" is not defined in variable data.', 'variableAsArray' => [ 'type' => \taoResultServer_models_classes_OutcomeVariable::TYPE, 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', 'epoch' => 'test', ], ], 'outcomeVariableWithMissingNormalMaximumKey' => [ 'expectedExceptionMessage' => 'Key "normalMaximum" is not defined in variable data.', 'variableAsArray' => [ 'type' => \taoResultServer_models_classes_OutcomeVariable::TYPE, 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', 'epoch' => 'test', 'normalMinimum' => 1.00, ], ], 'outcomeVariableWithMissingValueKey' => [ 'expectedExceptionMessage' => 'Key "value" is not defined in variable data.', 'variableAsArray' => [ 'type' => \taoResultServer_models_classes_OutcomeVariable::TYPE, 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', 'epoch' => 'test', 'normalMinimum' => 1.00, 'normalMaximum' => 2.00, ], ], 'responseVariableWithMissingCorrectResponseKey' => [ 'expectedExceptionMessage' => 'Key "correctResponse" is not defined in variable data.', 'variableAsArray' => [ 'type' => \taoResultServer_models_classes_ResponseVariable::TYPE, 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', 'epoch' => 'test', ], ], 'responseVariableWithMissingCandidateResponseKey' => [ 'expectedExceptionMessage' => 'Key "candidateResponse" is not defined in variable data.', 'variableAsArray' => [ 'type' => \taoResultServer_models_classes_ResponseVariable::TYPE, 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', 'epoch' => 'test', 'correctResponse' => 'test', ], ], 'traceVariableWithMissingTraceKey' => [ 'expectedExceptionMessage' => 'Key "trace" is not defined in variable data.', 'variableAsArray' => [ 'type' => \taoResultServer_models_classes_TraceVariable::TYPE, 'identifier' => 'test', 'cardinality' => 'single', 'baseType' => 'test', 'epoch' => 'test', ], ], ]; } }