[ 'name' => 'property1', 'type' => 'string', 'available' => true], 'property2' => [ 'name' => 'property2', 'type' => 'string', 'available' => true ] ]; private $cloudProperties = [ 'cloud' => [ 'name' => 'cloud', 'type' => 'string', 'available' => true ] ]; /** * Test that a cloud response which has a null value for a property is * mapped into an AspectPropertyValue with the 'no value reason' set from * the 'nullvaluereason' in the cloud response. */ public function testPropertyInResourceNullValue() { $engine = new CloudEngine(); $engine->dataKey = 'testElement'; $cloudRequestEngine = $this->createMock(CloudRequestEngine::class); $cloudRequestEngine->method('getProperties') ->willReturn($this->cloudProperties); $cloudRequestEngine->flowElementProperties = [ 'testElement' => $this->properties ]; $cloudRequestEngine->dataKey = 'cloud'; $builder = new PipelineBuilder(); $pipeline = $builder->add($cloudRequestEngine)->add($engine)->build(); $flowData = $pipeline->createFlowData(); $this->addResponse($cloudRequestEngine, $flowData, MissingPropertyHandling::nullValueJson); $engine->aspectProperties = $this->properties; $engine->dataKey = 'testElement'; $engine->processInternal($flowData); $data = $flowData->get('testElement'); $property2 = $data->get('property2'); $this->assertTrue($property2 != null); $this->assertFalse($property2->hasValue); $this->assertEquals( MissingPropertyHandling::expectedNullReason, $property2->noValueMessage ); } /** * Test that a cloud response which has no value for a property throws a * PropertyMissingException. */ public function testPropertyNotInResource() { $engine = new CloudEngine(); $engine->dataKey = 'testElement'; $cloudRequestEngine = $this->createMock(CloudRequestEngine::class); $cloudRequestEngine->method('getProperties') ->willReturn($this->cloudProperties); $cloudRequestEngine->flowElementProperties = [ 'testElement' => $this->properties ]; $cloudRequestEngine->dataKey = 'cloud'; $builder = new PipelineBuilder(); $pipeline = $builder->add($cloudRequestEngine)->add($engine)->build(); $flowData = $pipeline->createFlowData(); $this->addResponse($cloudRequestEngine, $flowData, MissingPropertyHandling::nullValueJson); $engine->aspectProperties = $this->properties; $engine->dataKey = 'testElement'; $engine->processInternal($flowData); $data = $flowData->get('testElement'); try { $property = $data->get('property3'); $this->fail(); } catch (\Exception $ex) { $this->assertEquals( sprintf( MissingPropertyMessages::PREFIX . MissingPropertyMessages::PROPERTY_NOT_IN_CLOUD_RESOURCE, 'property3', 'testElement', 'testElement', 'property1, property2' ), $ex->getMessage() ); } } private function addResponse($cloud, $flowData, $json) { $cloudData = new AspectDataDictionary($cloud, ['cloud' => $json]); $flowData->setElementData($cloudData); } }