コード例 #1
0
ファイル: NanbandoTest.php プロジェクト: nanbando/core
 public function setUp()
 {
     $this->storage = $this->prophesize(StorageInterface::class);
     $this->databaseFactory = $this->prophesize(DatabaseFactory::class);
     $this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
     $this->databaseFactory->create(Argument::any())->will(function ($data) {
         return new Database(isset($data[0]) ? $data[0] : []);
     });
     $this->databaseFactory->createReadonly(Argument::any())->will(function ($data) {
         return new ReadonlyDatabase(isset($data[0]) ? $data[0] : []);
     });
 }
コード例 #2
0
ファイル: Nanbando.php プロジェクト: nanbando/core
 /**
  * Backup process.
  *
  * @param string $label
  * @param string $message
  *
  * @return int
  */
 public function backup($label = '', $message = '')
 {
     $destination = $this->storage->start();
     $source = new Filesystem(new ReadonlyAdapter(new Local(realpath('.'))));
     $source->addPlugin(new ListFiles());
     $source->addPlugin(new HashPlugin());
     $systemDatabase = $this->databaseFactory->create();
     $systemDatabase->set('label', $label);
     $systemDatabase->set('message', $message);
     $systemDatabase->set('started', (new \DateTime())->format(\DateTime::RFC3339));
     $event = new PreBackupEvent($this->backup, $systemDatabase, $source, $destination);
     $this->eventDispatcher->dispatch(Events::PRE_BACKUP_EVENT, $event);
     if ($event->isCanceled()) {
         $this->storage->cancel($destination);
         return BackupStatus::STATE_FAILED;
     }
     $status = BackupStatus::STATE_SUCCESS;
     $backupConfig = $event->getBackup();
     foreach ($backupConfig as $backupName => $backup) {
         $backupDestination = new Filesystem(new PrefixAdapter('backup/' . $backupName, $destination->getAdapter()));
         $backupDestination->addPlugin(new ListFiles());
         $backupDestination->addPlugin(new HashPlugin());
         $database = $this->databaseFactory->create();
         $event = new BackupEvent($systemDatabase, $database, $source, $backupDestination, $backupName, $backup);
         $this->eventDispatcher->dispatch(Events::BACKUP_EVENT, $event);
         if ($event->isCanceled()) {
             $this->storage->cancel($destination);
             return BackupStatus::STATE_FAILED;
         }
         if ($event->getStatus() === BackupStatus::STATE_FAILED) {
             $status = BackupStatus::STATE_PARTIALLY;
         }
         $encodedData = json_encode($database->getAll(), JSON_PRETTY_PRINT);
         $destination->put(sprintf('database/backup/%s.json', $event->getName()), $encodedData);
     }
     $systemDatabase->set('finished', (new \DateTime())->format(\DateTime::RFC3339));
     $systemDatabase->set('state', $status);
     $encodedSystemData = json_encode($systemDatabase->getAll(), JSON_PRETTY_PRINT);
     $destination->put('database/system.json', $encodedSystemData);
     $name = $this->storage->close($destination);
     $this->eventDispatcher->dispatch(Events::POST_BACKUP_EVENT, new PostBackupEvent($name, $status));
     return $status;
 }
コード例 #3
0
ファイル: DatabaseFactoryTest.php プロジェクト: nanbando/core
 public function testCreateWithData()
 {
     $factory = new DatabaseFactory();
     $this->assertEquals(['test' => 1], $factory->create(['test' => 1])->getAll());
 }