|
|
@@ -17,6 +17,7 @@ namespace Cake\Test\TestCase\TestSuite;
|
|
|
|
|
|
use Cake\Database\Connection;
|
|
|
use Cake\Datasource\ConnectionManager;
|
|
|
+use Cake\Datasource\Exception\MissingDatasourceConfigException;
|
|
|
use Cake\TestSuite\ConnectionHelper;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
use TestApp\Database\Driver\TestDriver;
|
|
|
@@ -25,7 +26,12 @@ class ConnectionHelperTest extends TestCase
|
|
|
{
|
|
|
protected function tearDown(): void
|
|
|
{
|
|
|
+ parent::tearDown();
|
|
|
+
|
|
|
ConnectionManager::drop('query_logging');
|
|
|
+ ConnectionManager::drop('something');
|
|
|
+ ConnectionManager::drop('test_something');
|
|
|
+ ConnectionManager::dropAlias('something');
|
|
|
}
|
|
|
|
|
|
public function testAliasConnections(): void
|
|
|
@@ -42,16 +48,47 @@ class ConnectionHelperTest extends TestCase
|
|
|
public function testAliasNonDefaultConnections(): void
|
|
|
{
|
|
|
$connection = new Connection(['driver' => TestDriver::class]);
|
|
|
- ConnectionManager::setConfig('something', $connection);
|
|
|
+ ConnectionManager::setConfig('test_something', $connection);
|
|
|
|
|
|
ConnectionHelper::addTestAliases();
|
|
|
|
|
|
+ // Having a test_ alias defined will generate an alias for the unprefixed
|
|
|
+ // connection for simpler CI configuration
|
|
|
$this->assertSame(
|
|
|
ConnectionManager::get('test_something'),
|
|
|
ConnectionManager::get('something')
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public function testAliasNoTestClass(): void
|
|
|
+ {
|
|
|
+ $connection = new Connection(['driver' => TestDriver::class]);
|
|
|
+ ConnectionManager::setConfig('something', $connection);
|
|
|
+
|
|
|
+ (new ConnectionHelper())->addTestAliases();
|
|
|
+
|
|
|
+ // Should raise as no test connection was defined.
|
|
|
+ $this->expectException(MissingDatasourceConfigException::class);
|
|
|
+ ConnectionManager::get('test_something');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAliasNonDefaultConnectionWithTestConnection(): void
|
|
|
+ {
|
|
|
+ $testConnection = new Connection(['driver' => TestDriver::class]);
|
|
|
+ $connection = new Connection(['driver' => TestDriver::class]);
|
|
|
+ ConnectionManager::setConfig('something', $connection);
|
|
|
+ ConnectionManager::setConfig('test_something', $testConnection);
|
|
|
+
|
|
|
+ (new ConnectionHelper())->addTestAliases();
|
|
|
+
|
|
|
+ // Development connections that have test_ prefix connections defined
|
|
|
+ // should have an alias defined for the test_ prefixed name. This allows
|
|
|
+ // access to the development connection to resolve to the test prefixed name
|
|
|
+ // in tests.
|
|
|
+ $this->assertSame($testConnection, ConnectionManager::get('test_something'));
|
|
|
+ $this->assertSame($testConnection, ConnectionManager::get('something'));
|
|
|
+ }
|
|
|
+
|
|
|
public function testEnableQueryLogging(): void
|
|
|
{
|
|
|
$connection = new Connection(['driver' => TestDriver::class]);
|