public function testApplySqlPatchReturnsPatchWithErrorStatusOnExceptionInSql() { vfsStream::setup('test', null, array('name.sql' => 'SELE')); $patchFile = DBPatcher\PatchFile::createFromFS('name.sql', vfsStream::url('test')); /** @var \Doctrine\DBAL\SQLParserUtils Connection $c */ $connection = m::mock(); $connection->shouldReceive('beginTransaction')->once(); $connection->shouldReceive('exec')->with('SELE')->once()->andThrow('\\Doctrine\\DBAL\\DBALException', 'Error test'); $connection->shouldReceive('rollBack')->once(); list($patch, $errorMsg) = applySqlPatch($patchFile, $connection); $this->assertSame('Error test', $errorMsg); $this->assertInstanceOf('\\DBPatcher\\PatchFile', $patch); $this->assertSame(DBPatcher\PatchFile::STATUS_ERROR, $patch->status); }
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)); }