From e903e6bae5de09bbf6109cf7a772d96c25e8df0b Mon Sep 17 00:00:00 2001 From: Korvin Szanto Date: Mon, 6 Mar 2017 11:55:38 -0800 Subject: [PATCH 1/2] Speed up tests even more --- tests/tests/ConcreteDatabaseTestCase.php | 48 +++++++++++------- tests/tests/Core/File/FileListTest.php | 15 ++++-- tests/tests/Core/File/ImporterTest.php | 14 ++--- .../File/StorageLocation/fixtures/tiny.png | Bin 0 -> 82 bytes tests/tests/bootstrap.php | 1 + 5 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 tests/tests/Core/File/StorageLocation/fixtures/tiny.png diff --git a/tests/tests/ConcreteDatabaseTestCase.php b/tests/tests/ConcreteDatabaseTestCase.php index 7ea3374bbd0..dd7a8e7dca7 100755 --- a/tests/tests/ConcreteDatabaseTestCase.php +++ b/tests/tests/ConcreteDatabaseTestCase.php @@ -17,6 +17,9 @@ class ConcreteDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase /** @var bool[] Keys are tables that currently exist */ public static $existingTables = []; + /** @var bool[] Keys are entites that currently exist */ + public static $existingEntites = []; + /** @var array[] Table data cache */ public static $tableData = []; @@ -94,7 +97,6 @@ public static function tearDownAfterClass() // Make sure tables are removed $testCase = new Static(); $testCase->removeTables(); - $testCase->removeMetadatas(); // Call parent teardown parent::tearDownAfterClass(); @@ -138,9 +140,7 @@ protected function removeTables() // Get all existing tables $tables = $connection->query('show tables')->fetchAll(); - $tables = array_map(function ($table) { - return array_shift($table); - }, $tables); + $tables = array_map('array_shift', $tables); // Turn off foreign key checks $connection->exec('SET FOREIGN_KEY_CHECKS = 0'); @@ -153,7 +153,9 @@ protected function removeTables() // Reset foreign key checks on $connection->exec('SET FOREIGN_KEY_CHECKS = 1'); + // Clear exists cache static::$existingTables = []; + static::$existingEntites = []; } /** @@ -181,15 +183,21 @@ protected function extractTableData(array $tables) $name = (string)$table['name']; // If this table is being requested - if (isset(static::$existingTables[$name]) || in_array($name, $tables, false)) { + if (in_array($name, $tables, false)) { $this->appendXML($partial, $table); - // Store the fact that this table should exist now - static::$existingTables[$name] = true; + // Remove the table from our list of tables + $tables = array_filter($tables, function($name) use ($table) { + return $name !== $table; + }); // Track that we actually have tables to e $importedTables[] = $name; } + + if (!$tables) { + break; + } } // Return the partial only if there are tables to import @@ -244,15 +252,6 @@ protected function importMetadatas() } } - protected function removeMetadatas() - { - $sm = Application::make(DatabaseStructureManager::class); - - if ($metadatas = $this->getMetadatas()) { - $sm->uninstallDatabaseFor($metadatas); - } - } - /** * Gets the metadatas to import * @return array @@ -260,6 +259,7 @@ protected function removeMetadatas() protected function getMetadatas() { $metadatas = []; + $install = $this->metadatas; // If there are metadatas to import if ($this->metadatas && is_array($this->metadatas)) { @@ -269,8 +269,21 @@ protected function getMetadatas() // Loop through all metadata foreach ($factory->getAllMetadata() as $meta) { - if (in_array($meta->getName(), $this->metadatas, false)) { + if (!isset(self::$existingEntites[$meta->getName()]) && in_array($meta->getName(), $install, false)) { $metadatas[] = $meta; + + // Remove this from the list of entities to install + $install = array_filter($install, function($name) use ($meta) { + return $name !== $meta->getName(); + }); + + // Track that we've created this metadata + self::$existingEntites[$meta->getName()] = true; + } + + // If no more entities to install, lets break + if (!$install) { + break; } } } @@ -281,7 +294,6 @@ protected function getMetadatas() public function tearDown() { parent::tearDown(); - ; \ORM::entityManager('core')->clear(); \CacheLocal::flush(); } diff --git a/tests/tests/Core/File/FileListTest.php b/tests/tests/Core/File/FileListTest.php index 8e593a45305..f84713a9531 100755 --- a/tests/tests/Core/File/FileListTest.php +++ b/tests/tests/Core/File/FileListTest.php @@ -42,9 +42,9 @@ public function __construct($name = null, array $data = array(), $dataName = '') )); } - protected function setUp() + public static function setUpBeforeClass() { - parent::setUp(); + parent::setUpBeforeClass(); // TODO: Change the autogenerated stub $files = \Core::make(Filesystem::class); $files->create(); @@ -57,8 +57,9 @@ protected function setUp() FileKey::add($number, array('akHandle' => 'width', 'akName' => 'Width')); FileKey::add($number, array('akHandle' => 'height', 'akName' => 'Height')); - mkdir($this->getStorageDirectory()); - $this->getStorageLocation(); + $self = new static(); + mkdir($self->getStorageDirectory()); + $self->getStorageLocation(); $sample = dirname(__FILE__) . '/StorageLocation/fixtures/sample.txt'; $image = DIR_BASE . '/concrete/images/logo.png'; @@ -81,6 +82,11 @@ protected function setUp() foreach ($files as $filename => $pointer) { $fi->import($pointer, $filename); } + } + + protected function setUp() + { + parent::setUp(); $this->list = new \Concrete\Core\File\FileList(); $this->list->ignorePermissions(); @@ -96,7 +102,6 @@ protected function cleanup() unlink(dirname(__FILE__) . '/test.invalid'); } - $this->truncateTables(); } public function testGetPaginationObject() diff --git a/tests/tests/Core/File/ImporterTest.php b/tests/tests/Core/File/ImporterTest.php index 9b05efccfaf..919f732c970 100755 --- a/tests/tests/Core/File/ImporterTest.php +++ b/tests/tests/Core/File/ImporterTest.php @@ -237,12 +237,12 @@ public function testImporterMimeType() $fi = new Importer(); $fo1 = $fi->import($sample, 'sample.txt'); - $sample = dirname(__FILE__) . '/StorageLocation/fixtures/gummies.jpg'; + $sample = dirname(__FILE__) . '/StorageLocation/fixtures/tiny.png'; $fi = new Importer(); - $fo2 = $fi->import($sample, 'gummies.jpg'); + $fo2 = $fi->import($sample, 'tiny.png'); $this->assertEquals('text/plain', $fo1->getMimeType()); - $this->assertEquals('image/jpeg', $fo2->getMimeType()); + $this->assertEquals('image/png', $fo2->getMimeType()); } public function testFileDuplicate() @@ -269,16 +269,16 @@ public function testFileAttributesDuplicate() mkdir($this->getStorageDirectory()); $this->getStorageLocation(); - $sample = dirname(__FILE__) . '/StorageLocation/fixtures/gummies.jpg'; + $sample = dirname(__FILE__) . '/StorageLocation/fixtures/tiny.png'; $fi = new Importer(); - $f = $fi->import($sample, 'gummies.jpg'); + $f = $fi->import($sample, 'tiny.png'); $f2 = $f->duplicate(); $attributes = $f->getAttributes(); $attributesNew = $f2->getAttributes(); - $this->assertEquals(2, count($attributes)); - $this->assertEquals(2, count($attributesNew)); + $this->assertCount(2, $attributes); + $this->assertCount(2, $attributesNew); } public function testFileVersionDuplicate() diff --git a/tests/tests/Core/File/StorageLocation/fixtures/tiny.png b/tests/tests/Core/File/StorageLocation/fixtures/tiny.png new file mode 100644 index 0000000000000000000000000000000000000000..6c9a1d9f373b1327bb696de17783997e3a3a5eb4 GIT binary patch literal 82 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga%mF?juK#@*VoWXSfm|+67srr_ bImt;tHX8%8nR(3$AdA7%)z4*}Q$iB}P&yD{ literal 0 HcmV?d00001 diff --git a/tests/tests/bootstrap.php b/tests/tests/bootstrap.php index 59ff3952d5e..90adcb65994 100755 --- a/tests/tests/bootstrap.php +++ b/tests/tests/bootstrap.php @@ -71,6 +71,7 @@ $config->set('concrete.cache.blocks', false); $config->set('concrete.cache.pages', false); $config->set('concrete.cache.enabled', false); +$config->set('concrete.user.password.hash_cost_log2', 1); /** @var Concrete\Core\Database\Connection\Connection $cn */ $cn = $cms->make('database')->connection('travisWithoutDB'); From bc66f62b7da65c81fef8858f6ca3f466ad2317fe Mon Sep 17 00:00:00 2001 From: Korvin Szanto Date: Mon, 6 Mar 2017 12:24:49 -0800 Subject: [PATCH 2/2] Still track existing tables --- tests/tests/ConcreteDatabaseTestCase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/tests/ConcreteDatabaseTestCase.php b/tests/tests/ConcreteDatabaseTestCase.php index dd7a8e7dca7..62451ca80ff 100755 --- a/tests/tests/ConcreteDatabaseTestCase.php +++ b/tests/tests/ConcreteDatabaseTestCase.php @@ -191,8 +191,10 @@ protected function extractTableData(array $tables) return $name !== $table; }); - // Track that we actually have tables to e + // Track that we actually have tables to import $importedTables[] = $name; + + static::$existingTables[$name] = true; } if (!$tables) {