Esempio n. 1
0
 public function testGetSetRuntime()
 {
     $defaultTimeZoneBackup = date_default_timezone_get();
     $interval = '1 day';
     $timezone = new DateTimeZone('Europe/Berlin');
     $event1 = new CM_Clockwork_Event('foo', $interval);
     $event2 = new CM_Clockwork_Event('bar', $interval);
     $date1 = new DateTime('2014-10-31 08:00:00', $timezone);
     $date2 = new DateTime('2014-10-31 08:02:03', $timezone);
     $context = 'persistence-test';
     $storage = new CM_Clockwork_Storage_FileSystem($context);
     $serviceManager = CM_Service_Manager::getInstance();
     $storage->setServiceManager($serviceManager);
     $filepath = 'clockwork/' . md5($context) . '.json';
     $file = new CM_File($filepath, $serviceManager->getFilesystems()->getData());
     $this->assertFalse($file->exists());
     $this->assertFalse($file->getParentDirectory()->exists());
     $storage->setRuntime($event1, $date1);
     $this->assertTrue($file->getParentDirectory()->exists());
     $this->assertTrue($file->exists());
     $storage->setRuntime($event2, $date2);
     date_default_timezone_set('Antarctica/Vostok');
     $storage = new CM_Clockwork_Storage_FileSystem($context);
     $storage->setServiceManager($serviceManager);
     $this->assertEquals($date1, $storage->getLastRuntime($event1));
     $this->assertEquals($date2, $storage->getLastRuntime($event2));
     date_default_timezone_set($defaultTimeZoneBackup);
 }
Esempio n. 2
0
 /**
  * @param CM_File     $file
  * @param string|null $content
  * @param bool|null   $overwrite
  */
 public function createFile(CM_File $file, $content = null, $overwrite = null)
 {
     $parentDirectory = $file->getParentDirectory();
     if (!$parentDirectory->exists()) {
         $this->createDirectory($parentDirectory);
     }
     if ($file->exists()) {
         if (!$overwrite) {
             $this->notify('skip', $file->getPath());
         } else {
             $this->notify('modify', $file->getPath());
             $file->write($content);
         }
     } else {
         $this->notify('create', $file->getPath());
         $file->write($content);
     }
 }
Esempio n. 3
0
 public function testDeleteByPrefix()
 {
     $filesystem = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
     $dirTmp = CM_Bootloader::getInstance()->getDirTmp();
     $pathList = array('foo/foobar/bar', 'foo/bar2', 'foo/bar');
     /** @var CM_File[] $fileList */
     $fileList = array();
     foreach ($pathList as $path) {
         $file = new CM_File($dirTmp . $path, $filesystem);
         $file->ensureParentDirectory();
         $file->write('hello');
         $fileList[] = $file;
         $fileList[] = $file->getParentDirectory();
     }
     foreach ($fileList as $file) {
         $this->assertTrue($file->exists());
     }
     $filesystem->deleteByPrefix($dirTmp);
     foreach ($fileList as $file) {
         $this->assertFalse($file->exists());
     }
     $this->assertTrue((new CM_File($dirTmp))->exists());
 }