/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/TestSuite/Fixture
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/TestSuite/Fixture/SchemaLoader.php (4368B)
helper = new ConnectionHelper();
}
/**
* Load and apply schema sql file, or an array of files.
*
* @param array
|string $paths Schema files to load
* @param string $connectionName Connection name
* @param bool $dropTables Drop all tables prior to loading schema files
* @param bool $truncateTables Truncate all tables after loading schema files
* @return void
*/
public function loadSqlFiles(
$paths,
string $connectionName = 'test',
bool $dropTables = true,
bool $truncateTables = false
): void {
$files = (array)$paths;
// Don't create schema if we are in a phpunit separate process test method.
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
return;
}
if ($dropTables) {
$this->helper->dropTables($connectionName);
}
/** @var \Cake\Database\Connection $connection */
$connection = ConnectionManager::get($connectionName);
foreach ($files as $file) {
if (!file_exists($file)) {
throw new InvalidArgumentException("Unable to load SQL file `$file`.");
}
$sql = file_get_contents($file);
// Use the underlying PDO connection so we can avoid prepared statements
// which don't support multiple queries in postgres.
$driver = $connection->getDriver();
$driver->getConnection()->exec($sql);
}
if ($truncateTables) {
$this->helper->truncateTables($connectionName);
}
}
/**
* Load and apply CakePHP-specific schema file.
*
* @param string $file Schema file
* @param string $connectionName Connection name
* @return void
* @internal
*/
public function loadInternalFile(string $file, string $connectionName = 'test'): void
{
// Don't reload schema when we are in a separate process state.
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
return;
}
$this->helper->dropTables($connectionName);
$tables = include $file;
$connection = ConnectionManager::get($connectionName);
$connection->disableConstraints(function ($connection) use ($tables) {
foreach ($tables as $table) {
$schema = new TableSchema($table['table'], $table['columns']);
if (isset($table['indexes'])) {
foreach ($table['indexes'] as $key => $index) {
$schema->addIndex($key, $index);
}
}
if (isset($table['constraints'])) {
foreach ($table['constraints'] as $key => $index) {
$schema->addConstraint($key, $index);
}
}
// Generate SQL for each table.
foreach ($schema->createSql($connection) as $sql) {
$connection->execute($sql);
}
}
});
}
}