From 2a88bfd1d3b3dff77dc2a2b7df878a3cc6133472 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Fri, 18 Nov 2016 15:31:51 -0600 Subject: [PATCH] Migrations should only look in setPath when one has been set. --- application/Config/Migrations.php | 12 ------------ system/Database/MigrationRunner.php | 26 +++++++++++++++++++------- system/Test/CIDatabaseTestCase.php | 20 ++++++++++---------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/application/Config/Migrations.php b/application/Config/Migrations.php index 37f5dccd4833..c746a22cba1b 100644 --- a/application/Config/Migrations.php +++ b/application/Config/Migrations.php @@ -60,16 +60,4 @@ class Migrations extends BaseConfig */ public $currentVersion = 0; - /* - |-------------------------------------------------------------------------- - | Migrations Path - |-------------------------------------------------------------------------- - | - | Path to your migrations folder. - | Typically, it will be within your application path. - | Also, writing permission is required within the migrations path. - | - */ - public $path = APPPATH.'Database/Migrations/'; - } diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index e128f35fd85d..cec922beb563 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -116,9 +116,6 @@ public function __construct(BaseConfig $config, ConnectionInterface $db = null) $this->type = $config->type ?? 'timestamp'; $this->table = $config->table ?? 'migrations'; $this->currentVersion = $config->currentVersion ?? 0; - $this->path = $config->path ?? 'Database/Migrations/'; - - $this->path = rtrim($this->path, '/').'/'; if (empty($this->table)) { @@ -285,14 +282,29 @@ public function findMigrations() { $migrations = []; - $config = new Autoload(); + // If $path has been set, ONLY do that one since + // the user has specified their will. Otherwise, + // scan all PSR4 paths. This is required so + // when tests are ran, it will only look in it's + // location. + $paths = []; + if (empty($this->path)) + { + $config = new Autoload(); + foreach ($config->psr4 as $dir) + { + $paths[] = rtrim($dir, '/').'/Database/Migrations/'; + } + } + else + { + $paths[] = $this->path; + } // Loop through all of our namespaced folders // searching for migration directories. - foreach ($config->psr4 as $namespace => $dir) + foreach ($paths as $dir) { - $dir = rtrim($dir, '/').'/'.$this->path; - if (! is_dir($dir)) { continue; diff --git a/system/Test/CIDatabaseTestCase.php b/system/Test/CIDatabaseTestCase.php index 46fc24fb265a..fdb37b8c165c 100644 --- a/system/Test/CIDatabaseTestCase.php +++ b/system/Test/CIDatabaseTestCase.php @@ -81,20 +81,20 @@ class CIDatabaseTestCase extends CIUnitTestCase /** * Our database connection. - * + * * @var BaseConnection */ protected $db; /** * Migration Runner instance. - * + * * @var MigrationRunner|mixed */ protected $migrations; /** - * Seeder instance + * Seeder instance * * @var \CodeIgniter\Database\Seeder */ @@ -125,7 +125,7 @@ public function loadDependencies() $config->enabled = true; $this->migrations = Services::migrations($config, $this->db); - $this->migrations->setSilent(true); + $this->migrations->setSilent(false); } if ($this->seeder === null) @@ -165,7 +165,7 @@ public function setUp() { $this->seeder->setPath(rtrim($this->basePath, '/').'/seeds'); } - + $this->seed($this->seed); } } @@ -225,13 +225,13 @@ public function dontSeeInDatabase(string $table, array $where) $this->assertTrue($count == 0, 'Row was found in database'); } - + //-------------------------------------------------------------------- /** * Asserts that records that match the conditions in $where DO * exist in the database. - * + * * @param string $table * @param array $where * @@ -271,7 +271,7 @@ public function grabFromDatabase(string $table, string $column, array $where) return $query->$column ?? false; } - + //-------------------------------------------------------------------- /** @@ -314,7 +314,7 @@ public function seeNumRecords(int $expected, string $table, array $where) $this->assertEquals($expected, $count, 'Wrong number of matching rows in database.'); } - + //-------------------------------------------------------------------- - + }