-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CustomDumpTrait. Позволяет задать собственный дамп БД для тестов.
- Loading branch information
Showing
3 changed files
with
107 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Prokl\BitrixTestingTools; | ||
|
||
use InvalidArgumentException; | ||
use Sheerockoff\BitrixCi\SqlDump; | ||
|
||
/** | ||
* Class Migrator | ||
* Декоратор к мигратору дампов (позволяет загружать свои). | ||
* @package Prokl\BitrixTestingTools | ||
* | ||
* @since 24.04.2021 | ||
*/ | ||
class Migrator | ||
{ | ||
/** | ||
* @param string $pathDump Путь к дампу базы. | ||
* | ||
* @return void | ||
*/ | ||
public static function migrate(string $pathDump) : void | ||
{ | ||
$db = mysqli_connect( | ||
getenv('MYSQL_HOST', true) ?: getenv('MYSQL_HOST'), | ||
getenv('MYSQL_USER', true) ?: getenv('MYSQL_USER'), | ||
getenv('MYSQL_PASSWORD', true) ?: getenv('MYSQL_PASSWORD'), | ||
getenv('MYSQL_DATABASE', true) ?: getenv('MYSQL_DATABASE') | ||
); | ||
|
||
if (!$db) { | ||
throw new InvalidArgumentException('Mysql connection error.'); | ||
} | ||
|
||
$sqlDump = new SqlDump($pathDump); | ||
foreach ($sqlDump->parse() as $query) { | ||
mysqli_query($db, $query); | ||
} | ||
|
||
mysqli_close($db); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Prokl\BitrixTestingTools\Traits; | ||
|
||
/** | ||
* Trait CustomDumpTrait | ||
* Использовать свой дамп базы для тестов. Применяется в сочетании с трэйтом ResetDatabaseTrait. | ||
* @package Prokl\BitrixTestingTools\Traits | ||
* | ||
* @since 24.04.2021 | ||
*/ | ||
trait CustomDumpTrait | ||
{ | ||
/** | ||
* Путь к кастомному дампу БД. | ||
* @return string | ||
*/ | ||
protected function getDumpPath() : string | ||
{ | ||
return ''; | ||
} | ||
} |