diff --git a/README.md b/README.md index 06d0cdf..0443dad 100644 --- a/README.md +++ b/README.md @@ -146,4 +146,4 @@ Licensed under The MIT License Redistributions of files must retain the above co ## Authors * Juan Pablo Ramirez -* Nicolas Masson \ No newline at end of file +* Nicolas Masson diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f245feb..7669369 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,6 +12,10 @@ + + + ./tests/TestCase/FixtureInjectorTest.php + ./tests/TestCase/ diff --git a/src/FixtureInjector.php b/src/FixtureInjector.php index c41f765..a372d54 100644 --- a/src/FixtureInjector.php +++ b/src/FixtureInjector.php @@ -49,7 +49,9 @@ public function __construct(FixtureManager $manager, bool $withStatistics = fals * @param TestSuite $suite */ public function startTestSuite(TestSuite $suite) - {} + { + $this->_fixtureManager->aliasConnections(); + } /** * Cleanup before test starts diff --git a/src/FixtureManager.php b/src/FixtureManager.php index d010547..09ec1f1 100644 --- a/src/FixtureManager.php +++ b/src/FixtureManager.php @@ -30,7 +30,7 @@ class FixtureManager extends BaseFixtureManager /** * @var bool */ - private static $_configIsLoaded = false; + private static $aliasConnectionIsLoaded = false; /** * @var array|null @@ -51,7 +51,10 @@ public function getConnection($name = 'test') */ public function aliasConnections() { - $this->_aliasConnections(); + if (!self::$aliasConnectionIsLoaded) { + $this->_aliasConnections(); + self::$aliasConnectionIsLoaded = true; + } } /** diff --git a/tests/TestCase/FixtureInjectorTest.php b/tests/TestCase/FixtureInjectorTest.php index fea2292..e2338f3 100644 --- a/tests/TestCase/FixtureInjectorTest.php +++ b/tests/TestCase/FixtureInjectorTest.php @@ -14,6 +14,7 @@ namespace TestCase; +use Cake\ORM\TableRegistry; use CakephpTestSuiteLight\FixtureInjector; use CakephpTestSuiteLight\FixtureManager; use PHPUnit\Framework\TestCase; @@ -37,7 +38,8 @@ public function testStartTestWithPhpunitTestCase() { $test = $this->createMock(TestCase::class); $this->FixtureInjector->startTest($test); - $this->assertTrue(true); + $configName = TableRegistry::getTableLocator()->get('Countries')->getConnection()->configName(); + $this->assertSame('test', $configName); } /** @@ -48,7 +50,8 @@ public function testStartTestWithCakeTestCase() $test = $this->createMock(\Cake\TestSuite\TestCase::class); $test->fixtures = null; $this->FixtureInjector->startTest($test); - $this->assertTrue(true); + $configName = TableRegistry::getTableLocator()->get('Countries')->getConnection()->configName(); + $this->assertSame('test', $configName); } /** @@ -71,4 +74,4 @@ public function testEndTestWithCakeTestCase() $this->FixtureInjector->endTest($test, 0); $this->assertTrue(true); } -} \ No newline at end of file +}