/** * Test custom "constructor" when providing valid JSON data. * @covers moosend\Models\SegmentCriteria::withJSON * @group SegmentCriteriaTest */ public function test_Can_Create_SegmentCriteria_Instance_When_Providing_Valid_Json_Data_To_Custom_Constructor() { $this->assertEquals(201, $this->_segmentCriteria->getID()); $this->assertEquals(163, $this->_segmentCriteria->getSegmentID()); $this->assertEquals(99, $this->_segmentCriteria->getField()); $this->assertEquals('dd4fb545-ba00-4afe-bc39-5ed2462fd1d3', $this->_segmentCriteria->getCustomFieldID()); $this->assertEquals(0, $this->_segmentCriteria->getComparer()); $this->assertEquals('London', $this->_segmentCriteria->getValue()); $this->assertEquals(null, $this->_segmentCriteria->getDateFrom()); $this->assertEquals(null, $this->_segmentCriteria->getDateTo()); $this->assertEquals(SegmentCriteriaProperty::withJSON($this->_jsonData['Properties'][0]), $this->_segmentCriteria->getProperties()[0]); }
/** * Create a new instance and populate its properties with JSON data * @param array $jsonData * @return \moosend\Models\SegmentCriteria */ public static function withJSON(array $jsonData) { $instance = new self(); $instance->ID = $jsonData['ID']; $instance->SegmentID = $jsonData['SegmentID']; $instance->Field = $jsonData['Field']; $instance->CustomFieldID = $jsonData['CustomFieldID']; $instance->Comparer = $jsonData['Comparer']; $instance->Value = $jsonData['Value']; $instance->DateFrom = $jsonData['DateFrom']; $instance->DateTo = $jsonData['DateTo']; $instance->Properties = array(); foreach ($jsonData['Properties'] as $property) { $entry = SegmentCriteriaProperty::withJSON($property); array_push($instance->Properties, $entry); } return $instance; }
public function setUp() { $this->_jsonData = json_decode(file_get_contents(__DIR__ . '/../../tests/JsonResponses/getCampaignRawJsonResponse.html'), true)['Context']['Segment']['Criteria'][0]['Properties'][0]; $this->_segmentCriteriaProperty = SegmentCriteriaProperty::withJSON($this->_jsonData); }