Beispiel #1
0
 public function testInteractiveStrategyShouldAskSuperStrategyAndThenReturnConfirmResult()
 {
     $inputs = m::mock()->shouldIgnoreMissing();
     $inputs->shouldReceive('confirm')->andReturn(false)->once();
     $falseStrategy = m::mock();
     $falseStrategy->shouldReceive('call')->andReturn(false)->once();
     $this->assertFalse(interactiveStrategy(p\PatchFile::_createForTest('n1', 'f1', 'm1', 'e1'), array($falseStrategy, 'call'), $inputs));
 }
Beispiel #2
0
 public function testSavePatchFileCallsDbInsertIfUpdateAffectedNoRows()
 {
     $patchFile = DBPatcher\PatchFile::_createForTest('n1', 'f1', 'm1', 'e1', DBPatcher\PatchFile::STATUS_INSTALLED);
     $connection = m::mock();
     $connection->shouldReceive('quote')->andReturnUsing(function ($a) {
         return $a;
     });
     $connection->shouldReceive('update')->andReturn(0)->once();
     $connection->shouldReceive('insert')->with('db_patcher', array('status' => DBPatcher\PatchFile::STATUS_INSTALLED, 'md5' => 'm1', 'name' => 'n1'))->once();
     savePatchFile($connection, $patchFile);
 }
Beispiel #3
0
/**
 * @param DBPatcher\PatchFile $patchFile
 * @param \Doctrine\DBAL\Connection $connection
 * @return DBPatcher\PatchFile
 */
function applySqlPatch($patchFile, $connection)
{
    if ($patchFile->extension === 'sql') {
        $sqlCommands = file_get_contents($patchFile->filename);
        $connection->beginTransaction();
        try {
            $connection->exec($sqlCommands);
        } catch (\Doctrine\DBAL\DBALException $e) {
            $connection->rollBack();
            return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR), $e->getMessage());
        }
        $connection->commit();
        return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_INSTALLED));
    }
    return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR));
}
Beispiel #4
0
        $actionLabel = $previewStrategy($patchFile) ? 'install' : 'skip';
    } catch (\DBPatcher\InputPreview\Exception $e) {
        $actionLabel = 'interactive';
    }
    $output->out(\DBPatcher\patchText($patchFile) . " - {$actionLabel}");
    return $actionLabel !== 'skip';
};
$runPatch = function ($patchFile) use($inputs, $output, $dbConnection, $applyStrategy) {
    $output->out("==================================");
    $output->out(\DBPatcher\patchText($patchFile));
    if (!$applyStrategy($patchFile)) {
        $output->out('Skipping');
        return true;
    }
    if (\DBPatcher\Cli\getMarkPatchesOption($inputs)) {
        $patchFile = \DBPatcher\PatchFile::copyWithNewStatus($patchFile, \DBPatcher\PatchFile::STATUS_INSTALLED);
    } else {
        list($patchFile, $errorMsg) = array_merge(\DBPatcher\Apply\applyPatch($patchFile, $dbConnection, new \Symfony\Component\Process\Process(''), STDOUT, STDERR), array(null));
        if ($patchFile->status === \DBPatcher\PatchFile::STATUS_ERROR) {
            $output->out("Error!", 'bold_red');
            $output->out($errorMsg);
        }
    }
    \DBPatcher\Storage\savePatchFile($dbConnection, $patchFile);
    if ($patchFile->status === \DBPatcher\PatchFile::STATUS_ERROR) {
        return false;
    }
    $output->out("Success", 'bold_green');
    return true;
};
// --------------------------------------------------------------------------------------------------------------------
Beispiel #5
0
 private static function setupPatchFile($dir = 'testDir', $name = 'test-patch.sql', $content = 'DROP TABLE some')
 {
     vfsStream::setup($dir, null, array($name => $content));
     return PatchFile::createFromFS($name, vfsStream::url($dir));
 }
Beispiel #6
0
 public function testPrintPatchPrintsCorrectText()
 {
     $this->assertSame('* n1 [new]', patchText(PatchFile::_createForTest('n1', 'f1', 'm1', 'e1')));
 }
Beispiel #7
0
 public function testApplyPhpPatchUnsetsProcessTimeouts()
 {
     $process = m::mock()->shouldIgnoreMissing();
     $process->shouldReceive('setTimeout')->with(null)->once();
     $process->shouldReceive('setIdleTimeout')->with(null)->once();
     applyPhpPatch(DBPatcher\PatchFile::_createForTest('n1', 'f1', 'm1', 'php'), $process);
 }