Esempio n. 1
0
 public static function setupBeforeClass()
 {
     // this a minor speed optimisation
     // don't rely on this because of phpunit's 'run in separate processes thing'
     if (self::$pgProvided) {
         return;
     }
     $container = static::getContainerFromAnnotations()->getcontainer();
     $settingsDb = $container->get('connectionSettingsRW');
     $databaseBuilder = new DatabaseBuilder();
     try {
         $settingsDb = $databaseBuilder->create($settingsDb, '-');
     } catch (DatabaseAlreadyExistsException $e) {
         $databaseBuilder->truncateDb($settingsDb);
         //            $databaseBuilder->emptyDb( $settingsDb );
     }
     // make a connection to the new database
     $db = new Pg(new Resource($settingsDb));
     try {
         $assets = $databaseBuilder->getSqlAssetsFromDirs($db, [__DIR__ . '/../../../../database/assets', __DIR__ . '/assets'], $assetsResolved);
         // cleanup
     } catch (AssetChangedException $e) {
         // empty the existing database
         $databaseBuilder->emptyDb($settingsDb);
         unset($assetsResolved);
         $assets = $databaseBuilder->getSqlAssetsFromDirs($db, [__DIR__ . '/../../../../database/assets', __DIR__ . '/assets'], $assetsResolved);
         // work around a phpunit bug with serialization
         // don't get me wrong - this is totally stupid and is a duplication of work
         // https://github.com/sebastianbergmann/phpunit/issues/451
         // $newException = new \Exception( $e->getMessage() );
         // $db->resource->terminate();
         // throw $newException;
     }
     $databaseBuilder->resolveByDirs([__DIR__ . '/assets'], $assets, $assetsResolved);
     $db->resource->terminate();
     self::$pgProvided = true;
     return $container;
 }
Esempio n. 2
0
use Bond\Normality\DatabaseBuilder;
use Bond\Normality\Exception\AssetChangedException;
use Bond\Pg;
use Bond\Pg\Resource;
if (count($argv) != 2) {
    print "takes argument of asset directory/file\n";
    die(1);
}
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$configurator = new \Bond\Di\Configurator($container);
$configurator->load(__DIR__ . "/Di/ConnectionFactoryConfigurable.yml");
$container->compile();
$settingsDb = $container->get('connectionSettingsRW');
$databaseBuilder = new DatabaseBuilder();
try {
    $settingsDb = $databaseBuilder->create($settingsDb, '-');
} catch (DatabaseAlreadyExistsException $e) {
    $databaseBuilder->emptyDb($settingsDb);
}
// make a connection to the new database
$db = new Pg(new Resource($settingsDb));
try {
    $assets = $databaseBuilder->getSqlAssetsFromDirs($db, [$argv[1], __DIR__ . "/../../../../database/assets"], $assetsResolved);
    $databaseBuilder->resolveByDirs([$argv[1]], $assets, $assetsResolved);
    // cleanup
} catch (AssetChangedException $e) {
    // work around a phpunit bug with serialization
    // don't get me wrong - this is totally stupid and is a duplication of work
    // https://github.com/sebastianbergmann/phpunit/issues/451
    $newException = new \Exception($e->getMessage());
    $db->resource->terminate();