public function addSegmentOnCache(array $segmentData) { $segmentName = $segmentData['name']; $segmentCache = new SegmentCache(); if ($segmentCache->getChangeNumber($segmentName) != $segmentData['till']) { $segmentCache->addToSegment($segmentName, $segmentData['added']); $segmentCache->removeFromSegment($segmentName, $segmentData['removed']); $segmentCache->setChangeNumber($segmentName, $segmentData['till']); } return true; }
/** * @depends testSplitCacheInterface */ public function testSegmentCacheInterface() { $segmentChanges = file_get_contents(__DIR__ . "/../../files/segmentEmployeesChanges.json"); $this->assertJson($segmentChanges); $segmentData = json_decode($segmentChanges, true); $segmentName = $segmentData['name']; $segmentCache = new SegmentCache(); $this->assertArrayHasKey('fake_user_id_4', $segmentCache->addToSegment($segmentName, $segmentData['added'])); $removedResult = $segmentCache->removeFromSegment($segmentName, $segmentData['removed']); $this->assertArrayHasKey('fake_user_id_6', $removedResult); $this->assertTrue($segmentCache->setChangeNumber($segmentName, $segmentData['till'])); $this->assertEquals($segmentData['till'], $segmentCache->getChangeNumber($segmentName)); }