expectException(InvalidArgumentException::class); $this->expectExceptionMessage($errorMessage); new DeliveryExecutionContext($executionId, $executionContextId, $type, $label); } /** * @param string $executionId * * @dataProvider dataProviderSetInvalidExecutionId */ public function testSetExecutionIdThrowsException($executionId) { $contextData = $this->getValidContextData(); $contextObject = DeliveryExecutionContext::createFromArray($contextData); $this->expectException(InvalidArgumentException::class); $contextObject->setExecutionId($executionId); } public function testSetExecutionContextIdThrowsException() { $contextData = $this->getValidContextData(); $contextObject = DeliveryExecutionContext::createFromArray($contextData); $this->expectException(InvalidArgumentException::class); $contextObject->setExecutionContextId(''); } /** * @param array $contextData * @dataProvider dataProviderTestCreateFromArray */ public function testCreateFromArray(array $contextData) { $contextObject = DeliveryExecutionContext::createFromArray($contextData); $this->assertInstanceOf( DeliveryExecutionContextInterface::class, $contextObject, 'Method must return an object of DeliveryExecutionContextInterface' ); } public function testJsonSerialize() { $contextData = $this->getValidContextData(); $contextObject = new DeliveryExecutionContext( $contextData['execution_id'], $contextData['context_id'], $contextData['type'], $contextData['label'], $contextData['extra_data'] ); $result = $contextObject->jsonSerialize(); $this->assertEquals($contextData, $result, 'jsonSerialize method must return array with correct data'); } /** * Returns valid delivery execution context data * * @return array */ public function getValidContextData() { return [ 'execution_id' => 'http://test-execution-uri.dev', 'context_id' => 'TEST CONTEXT ID', 'type' => 'TEST EXEC TYPE', 'label' => 'TEST LABEL', 'extra_data' => ['key' => 'value'], ]; } /** * @return array */ public function dataProviderConstructInvalidValues() { return [ 'Empty execution and context IDs' => [ 'executionId' => '', 'executionContextId' => '', 'type' => '', 'label' => '', 'errorMessage' => 'Execution ID value must be not empty string.' ], 'Empty execution ID' => [ 'executionId' => '', 'executionContextId' => 'TEST_CONTEXT_ID', 'type' => '', 'label' => '', 'errorMessage' => 'Execution ID value must be not empty string.' ], 'Empty context ID' => [ 'executionId' => 'http://test-execution-uri.dev', 'executionContextId' => '', 'type' => '', 'label' => '', 'errorMessage' => 'Execution context ID value must be not empty string.' ], ]; } /** * @return array */ public function dataProviderSetInvalidExecutionId() { return [ 'Empty execution ID' => [ 'executionId' => '', ], ]; } /** * @return array */ public function dataProviderTestCreateFromArray() { return [ 'Empty optional parameters' => [ 'contextData' => [ 'execution_id' => 'http://test-execution-uri.dev', 'context_id' => 'TEST CONTEXT ID', ] ], 'Correct values' => [ 'contextData' => [ 'execution_id' => 'http://test-execution-uri.dev', 'context_id' => 'TEST CONTEXT ID', 'type' => 'TEST EXEC TYPE', 'label' => 'TEST LABEL' ] ] ]; } }