diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 3a9e665be916..5bb2fa2346d8 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1186,16 +1186,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/MigrationRunner.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\ModelFactory\\:\\:injectMock\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/ModelFactory.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\ModelFactory\\:\\:reset\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/ModelFactory.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 1, diff --git a/system/Database/ModelFactory.php b/system/Database/ModelFactory.php deleted file mode 100644 index 76a30e6c1d30..000000000000 --- a/system/Database/ModelFactory.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace CodeIgniter\Database; - -use CodeIgniter\Config\Factories; - -/** - * Returns new or shared Model instances - * - * @deprecated Use CodeIgniter\Config\Factories::models() - * - * @codeCoverageIgnore - * @see \CodeIgniter\Database\ModelFactoryTest - */ -class ModelFactory -{ - /** - * Creates new Model instances or returns a shared instance - * - * @return mixed - */ - public static function get(string $name, bool $getShared = true, ?ConnectionInterface $connection = null) - { - return Factories::models($name, ['getShared' => $getShared], $connection); - } - - /** - * Helper method for injecting mock instances while testing. - * - * @param object $instance - */ - public static function injectMock(string $name, $instance) - { - Factories::injectMock('models', $name, $instance); - } - - /** - * Resets the static arrays - */ - public static function reset() - { - Factories::reset('models'); - } -} diff --git a/tests/system/Database/ModelFactoryTest.php b/tests/system/Database/ModelFactoryTest.php deleted file mode 100644 index d8857d5ad5cf..000000000000 --- a/tests/system/Database/ModelFactoryTest.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace CodeIgniter\Database; - -use CodeIgniter\Test\CIUnitTestCase; -use CodeIgniter\Test\DatabaseTestTrait; -use Tests\Support\Models\JobModel; -use Tests\Support\Models\UserModel; - -/** - * @group DatabaseLive - * - * @internal - */ -final class ModelFactoryTest extends CIUnitTestCase -{ - use DatabaseTestTrait; - - protected function setUp(): void - { - parent::setUp(); - - ModelFactory::reset(); - } - - public function testCreateSeparateInstances(): void - { - $basenameModel = ModelFactory::get('JobModel', false); - $namespaceModel = ModelFactory::get(JobModel::class, false); - - $this->assertInstanceOf(JobModel::class, $basenameModel); - $this->assertInstanceOf(JobModel::class, $namespaceModel); - $this->assertNotSame($basenameModel, $namespaceModel); - } - - public function testCreateSharedInstance(): void - { - $basenameModel = ModelFactory::get('JobModel', true); - $namespaceModel = ModelFactory::get(JobModel::class, true); - - $this->assertSame($basenameModel, $namespaceModel); - } - - public function testInjection(): void - { - ModelFactory::injectMock('Banana', new JobModel()); - - $this->assertInstanceOf(JobModel::class, ModelFactory::get('Banana')); - } - - public function testReset(): void - { - ModelFactory::injectMock('Banana', new JobModel()); - - ModelFactory::reset(); - - $this->assertNull(ModelFactory::get('Banana')); - } - - public function testBasenameDoesNotReturnExistingNamespaceInstance(): void - { - ModelFactory::injectMock(UserModel::class, new JobModel()); - - $basenameModel = ModelFactory::get('UserModel'); - - $this->assertInstanceOf(UserModel::class, $basenameModel); - } -} diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index 044e0f6d8cca..1241895560cf 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -128,6 +128,11 @@ Filters - ``Router::$filterInfo`` - ``Router::getFilter()`` +Database +-------- + +- ``ModelFactory`` + Model -----