diff --git a/src/Tests/ModelTestState.php b/src/Tests/ModelTestState.php index 93c551f..5418452 100644 --- a/src/Tests/ModelTestState.php +++ b/src/Tests/ModelTestState.php @@ -7,14 +7,13 @@ class ModelTestState extends TableTestState { - public function __construct(string $modelClassName, bool $globalExportMode = false) + public function __construct(string $modelClassName) { $model = new $modelClassName(); parent::__construct( tableName: $model->getTable(), jsonFields: $this->getModelJSONFields($model), - globalExportMode: $globalExportMode, connectionName: $model->getConnectionName($model), ); } diff --git a/src/Tests/TableTestState.php b/src/Tests/TableTestState.php index 207eea2..958a376 100644 --- a/src/Tests/TableTestState.php +++ b/src/Tests/TableTestState.php @@ -13,8 +13,6 @@ class TableTestState extends Assert { use FixturesTrait; - public bool $globalExportMode; - protected string $tableName; protected array $jsonFields; protected ?string $connectionName; @@ -23,13 +21,11 @@ class TableTestState extends Assert public function __construct( string $tableName, array $jsonFields = [], - bool $globalExportMode = false, ?string $connectionName = null, ) { $this->tableName = $tableName; $this->jsonFields = $jsonFields; $this->connectionName = $connectionName ?? DB::getDefaultConnection(); - $this->globalExportMode = $globalExportMode; $this->state = $this->getDataSet($tableName); } diff --git a/src/Traits/FixturesTrait.php b/src/Traits/FixturesTrait.php index c0390db..20447d1 100644 --- a/src/Traits/FixturesTrait.php +++ b/src/Traits/FixturesTrait.php @@ -55,6 +55,15 @@ trait FixturesTrait protected string $dumpFileName = 'dump.sql'; + protected bool $globalExportMode = false; + + protected function setGlobalExportMode(bool $value = true): self + { + $this->globalExportMode = $value; + + return $this; + } + protected function loadTestDump(): void { $dump = $this->getFixture($this->dumpFileName, false); @@ -103,9 +112,7 @@ public function getJsonFixture(string $fixtureName, $assoc = true) public function assertEqualsFixture(string $fixture, $data, bool $exportMode = false): void { - $globalExportMode = $this->globalExportMode ?? false; - - if ($globalExportMode || $exportMode) { + if ($this->globalExportMode || $exportMode) { $this->exportJson($fixture, $data); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 1b07ee5..f9ada5f 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,13 +20,6 @@ abstract class TestCase extends BaseTest protected static string $startedTestSuite = ''; protected static bool $isWrappedIntoTransaction = true; - protected bool $globalExportMode = false; - - protected function setGlobalExportMode(): void - { - $this->globalExportMode = true; - } - public function setUp(): void { parent::setUp(); @@ -115,11 +108,11 @@ protected function rollbackTransaction(): void protected function prepareModelTestState(string $modelClassName): ModelTestState { - return new ModelTestState($modelClassName, $this->globalExportMode); + return (new ModelTestState($modelClassName))->setGlobalExportMode($this->globalExportMode); } protected function prepareTableTestState(string $tableName, array $jsonFields = [], ?string $connectionName = null): TableTestState { - return new TableTestState($tableName, $jsonFields, $this->globalExportMode, $connectionName); + return (new TableTestState($tableName, $jsonFields, $connectionName))->setGlobalExportMode($this->globalExportMode); } }