public function testToArray()
 {
     $array = array('key' => 'key', 'value' => 'value', 'ttl' => 1);
     $item = new MCacheItem();
     $item->setValue('value')->setTtl(1)->setKey('key');
     $t = ItemTransformer::toArray($item);
     unset($t['endValidation']);
     $this->assertEquals($array, $t);
 }
 /**
  * @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;
 }