Skip to content

Commit

Permalink
Push dbi and dummyDbi members down
Browse files Browse the repository at this point in the history
The idea is to only load the DBI when needed.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jul 13, 2022
1 parent 641ba50 commit 63d57b1
Show file tree
Hide file tree
Showing 62 changed files with 804 additions and 44 deletions.
23 changes: 1 addition & 22 deletions test/classes/AbstractTestCase.php
Expand Up @@ -44,20 +44,6 @@ abstract class AbstractTestCase extends TestCase
'__PHPUNIT_BOOTSTRAP',
];

/**
* The DatabaseInterface loaded by setGlobalDbi
*
* @var DatabaseInterface
*/
protected $dbi;

/**
* The DbiDummy loaded by setGlobalDbi
*
* @var DbiDummy
*/
protected $dummyDbi;

/**
* Prepares environment for the test.
* Clean all variables
Expand Down Expand Up @@ -97,7 +83,7 @@ protected function setUp(): void
// Config before DBI
$this->setGlobalConfig();
$this->loadContainerBuilder();
$this->setGlobalDbi();
$GLOBALS['dbi'] = $this->createDatabaseInterface();
$this->setTheme();
Cache::purge();
}
Expand Down Expand Up @@ -160,13 +146,6 @@ protected function assertResponseWasSuccessfull(): void
$this->assertTrue($response->hasSuccessState(), 'expected the request not to fail');
}

protected function setGlobalDbi(): void
{
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

protected function createDatabaseInterface(?DbiExtension $extension = null): DatabaseInterface
{
return new DatabaseInterface($extension ?? $this->createDbiDummy());
Expand Down
11 changes: 11 additions & 0 deletions test/classes/BookmarkTest.php
Expand Up @@ -6,21 +6,32 @@

use PhpMyAdmin\Bookmark;
use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Dbal\TableName;
use PhpMyAdmin\Tests\Stubs\DbiDummy;

/**
* @covers \PhpMyAdmin\Bookmark
*/
class BookmarkTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
$GLOBALS['cfg']['Server']['user'] = 'root';
$GLOBALS['cfg']['Server']['pmadb'] = 'phpmyadmin';
$GLOBALS['cfg']['Server']['bookmarktable'] = 'pma_bookmark';
Expand Down
16 changes: 16 additions & 0 deletions test/classes/Controllers/CheckRelationsControllerTest.php
Expand Up @@ -6,16 +6,32 @@

use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\CheckRelationsController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;

/**
* @covers \PhpMyAdmin\Controllers\CheckRelationsController
*/
class CheckRelationsControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testCheckRelationsController(): void
{
$GLOBALS['server'] = 1;
Expand Down
Expand Up @@ -5,18 +5,28 @@
namespace PhpMyAdmin\Tests\Controllers\Database\MultiTableQuery;

use PhpMyAdmin\Controllers\Database\MultiTableQuery\TablesController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;

/**
* @covers \PhpMyAdmin\Controllers\Database\MultiTableQuery\TablesController
*/
class TablesControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
parent::setLanguage();
parent::setGlobalDbi();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
parent::loadContainerBuilder();
parent::loadDbiIntoContainerBuilder();
$GLOBALS['server'] = 1;
Expand Down
14 changes: 11 additions & 3 deletions test/classes/Controllers/Database/PrivilegesControllerTest.php
Expand Up @@ -5,9 +5,11 @@
namespace PhpMyAdmin\Tests\Controllers\Database;

use PhpMyAdmin\Controllers\Database\PrivilegesController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Url;

Expand All @@ -19,14 +21,20 @@
*/
class PrivilegesControllerTest extends AbstractTestCase
{
/**
* Configures global environment.
*/
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
parent::setLanguage();
parent::setTheme();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testIndex(): void
Expand Down
Expand Up @@ -6,9 +6,11 @@

use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Database\Structure\FavoriteTableController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\RecentFavoriteTable;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseStub;
use ReflectionClass;

Expand All @@ -19,6 +21,20 @@
*/
class FavoriteTableControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testSynchronizeFavoriteTables(): void
{
$GLOBALS['server'] = 1;
Expand Down
Expand Up @@ -5,8 +5,10 @@
namespace PhpMyAdmin\Tests\Controllers\Database\Structure;

use PhpMyAdmin\Controllers\Database\Structure\RealRowCountController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseStub;

use function json_encode;
Expand All @@ -16,6 +18,20 @@
*/
class RealRowCountControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testRealRowCount(): void
{
$GLOBALS['server'] = 1;
Expand Down
16 changes: 16 additions & 0 deletions test/classes/Controllers/Export/ExportControllerTest.php
Expand Up @@ -5,11 +5,13 @@
namespace PhpMyAdmin\Tests\Controllers\Export;

use PhpMyAdmin\Controllers\Export\ExportController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Export;
use PhpMyAdmin\FieldMetadata;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;

use function htmlspecialchars;
Expand All @@ -25,6 +27,20 @@
*/
class ExportControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testExportController(): void
{
parent::loadDbiIntoContainerBuilder();
Expand Down
16 changes: 16 additions & 0 deletions test/classes/Controllers/Export/Template/CreateControllerTest.php
Expand Up @@ -7,18 +7,34 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Controllers\Export\Template\CreateController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Export\Template as ExportTemplate;
use PhpMyAdmin\Export\TemplateModel;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;

/**
* @covers \PhpMyAdmin\Controllers\Export\Template\CreateController
*/
class CreateControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testCreate(): void
{
$GLOBALS['server'] = 1;
Expand Down
16 changes: 16 additions & 0 deletions test/classes/Controllers/Export/Template/DeleteControllerTest.php
Expand Up @@ -6,17 +6,33 @@

use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\Export\Template\DeleteController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Export\TemplateModel;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;

/**
* @covers \PhpMyAdmin\Controllers\Export\Template\DeleteController
*/
class DeleteControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testDelete(): void
{
$GLOBALS['server'] = 1;
Expand Down
16 changes: 16 additions & 0 deletions test/classes/Controllers/Export/Template/LoadControllerTest.php
Expand Up @@ -7,17 +7,33 @@
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Controllers\Export\Template\LoadController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Export\TemplateModel;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;

/**
* @covers \PhpMyAdmin\Controllers\Export\Template\LoadController
*/
class LoadControllerTest extends AbstractTestCase
{
/** @var DatabaseInterface */
protected $dbi;

/** @var DbiDummy */
protected $dummyDbi;

protected function setUp(): void
{
parent::setUp();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
}

public function testLoad(): void
{
$GLOBALS['server'] = 1;
Expand Down

0 comments on commit 63d57b1

Please sign in to comment.