public function testFromArray()
 {
     $array = array('key' => 'key', 'value' => 'value', 'ttl' => 1);
     $item = ItemTransformer::fromArray($array);
     $this->assertEquals('key', $item->getKey());
     $this->assertEquals('value', $item->getValue());
     $this->assertEquals(1, $item->getTtl());
 }
 /**
  * @param MCacheItem $item
  * @return bool
  */
 public function addItem(MCacheItem $item)
 {
     $inserted = new \DateTime('now');
     $endValidation = new \DateTime('now');
     $endValidation = $endValidation->add(new \DateInterval(sprintf('PT%dS', $item->getTtl())));
     $array = ItemTransformer::toArray($item);
     $array['end_validation'] = $endValidation->format(self::FILE_DATE_FORMAT);
     $array['inserted'] = $inserted->format(self::FILE_DATE_FORMAT);
     $json = json_encode($array);
     $filePath = $this->getBackupFilePath($item->getKey());
     if (file_exists($filePath)) {
         unlink($this->getBackupFilePath($item->getKey()));
     }
     return file_put_contents($filePath, $json) !== false;
 }