/**
  * Calculates the diff to the given repository
  *
  * The method returns a Repository including all Migrations present in this
  * instance but not the given other repository.
  *
  * @param Repository $otherRepository The repository to diff to
  *
  * @throws \Bytepark\Component\Migration\Exception\UnitIsAlreadyPresentException
  *
  * @return Repository The diff
  */
 public function diff(Repository $otherRepository)
 {
     $diffRepository = new Memory();
     foreach ($this->unitOfWorkStore as $unitOfWork) {
         if (!$otherRepository->contains($unitOfWork)) {
             $diffRepository->add($unitOfWork);
         }
     }
     $diffRepository->sort();
     return $diffRepository;
 }
Beispiel #2
0
 public function testDispatchWithActiveGuard()
 {
     $this->sourceRepository->add($this->buildUnitOfWork());
     $this->historyRepository->add($this->buildUnitOfWork());
     $this->historyRepository->add($this->buildUnitOfWork('2'));
     $this->setExpectedException('\\Bytepark\\Component\\Migration\\Exception\\HistoryHasSourceUnknownUnitsOfWorkException');
     $this->manager->dispatch();
 }
Beispiel #3
0
 /**
  * Executes the given migration against the database connection
  *
  * @param UnitOfWork $unitOfWork
  *
  * @throws Exception\UnitIsAlreadyPresentException
  */
 private function executeMigration(UnitOfWork $unitOfWork)
 {
     try {
         $unitOfWork->migrate($this->connection);
         $this->historyRepository->add($unitOfWork);
     } catch (QueryNotSuccessfulException $e) {
         // for now do nothing  and leave out of history
     }
 }
Beispiel #4
0
 public function testReplace()
 {
     $filePath = TEST_FILE_FIXTURE_PATH . '/persisting-test.mig';
     $unitToReplace = $this->buildUnitOfWork();
     $replacementUnit = $this->buildUnitOfWork('replaced!');
     $this->repository->add($unitToReplace);
     $this->repository->persist();
     $this->repository->replace($replacementUnit);
     $this->repository->persist();
     static::assertEquals('replaced!', file_get_contents($filePath));
 }
 public function testReplace()
 {
     $unitToReplace = $this->buildUnitOfWork();
     $replacementUnit = $this->buildUnitOfWork('replaced!');
     $this->repository->add($unitToReplace);
     $this->repository->persist();
     $this->repository->replace($replacementUnit);
     $this->repository->persist();
     $result = $this->connection->query(sprintf('SELECT * FROM %s', $this->tableName));
     static::assertEquals($this->uidValue, $result[0]['unique_id']);
     static::assertEquals('replaced!', $result[0]['query']);
 }
Beispiel #6
0
 public function testPersisting()
 {
     $fileName = 'persisting-test.mig';
     $fileContent = 'file-contents';
     $filePath = TEST_GROUPED_FILE_FIXTURE_PATH . '/b/d/' . $fileName;
     $unitOfWorkToPersist = new UnitOfWork(new Uid($fileName), new Workload($fileContent), new \DateTime());
     $this->repository->add($unitOfWorkToPersist);
     $wasSuccess = $this->repository->persist();
     static::assertTrue($wasSuccess);
     static::assertFileExists($filePath);
     static::assertEquals($fileContent, file_get_contents($filePath));
 }
Beispiel #7
0
 public function testPersisting()
 {
     static::assertTrue($this->repository->persist());
 }