From 5dc71fd2fa086dba28c4fcd8914e024d6738ea0c Mon Sep 17 00:00:00 2001 From: Jeremy Postlethwaite Date: Wed, 13 Mar 2024 09:54:22 -0700 Subject: [PATCH 1/2] GH-25 --- composer.json | 27 ++++++++++++--------------- tests/Feature/TestCase.php | 9 --------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 715db7b..ba4fb0a 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "laravel", "playground" ], - "homepage": "https://github.com/gammamatrix/playground/wiki", + "homepage": "https://gammamatrix-playground.readthedocs.io/", "license": "MIT", "authors": [ { @@ -16,22 +16,19 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-intl": "*", "ezyang/htmlpurifier": "^4.16", - "illuminate/auth": "^10.0", - "illuminate/console": "^10.0", - "illuminate/contracts": "^10.0", - "illuminate/database": "^10.0", - "illuminate/http": "^10.0", - "illuminate/routing": "^10.0", - "illuminate/support": "^10.0", - "illuminate/translation": "^10.0", - "illuminate/validation": "^10.0", - "illuminate/view": "^10.0" - }, - "require-dev": { - "gammamatrix/playground-test": "dev-develop|dev-master|dev-feature/*|^73.0" + "illuminate/auth": "^11.0", + "illuminate/console": "^11.0", + "illuminate/contracts": "^11.0", + "illuminate/database": "^11.0", + "illuminate/http": "^11.0", + "illuminate/routing": "^11.0", + "illuminate/support": "^11.0", + "illuminate/translation": "^11.0", + "illuminate/validation": "^11.0", + "illuminate/view": "^11.0" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 6b1d096..b06e101 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -39,14 +39,5 @@ protected function getEnvironmentSetUp($app) { $app['config']->set('auth.providers.users.model', 'Playground\\Test\\Models\\User'); $app['config']->set('playground-auth.verify', 'user'); - - $app['config']->set('playground.load.routes', true); - $app['config']->set('playground.routes.about', true); - $app['config']->set('playground.routes.bootstrap', true); - $app['config']->set('playground.routes.dashboard', true); - $app['config']->set('playground.routes.home', true); - $app['config']->set('playground.routes.sitemap', true); - $app['config']->set('playground.routes.theme', true); - $app['config']->set('playground.routes.welcome', true); } } From f932a6478e0d8fd157e04e5c502b9969d2def50e Mon Sep 17 00:00:00 2001 From: Jeremy Postlethwaite Date: Wed, 13 Mar 2024 12:47:36 -0700 Subject: [PATCH 2/2] GH-25 --- .github/workflows/ci.yml | 4 +- .php-cs-fixer.dist.php | 1 + composer.json | 3 + config/playground.php | 4 + database/factories/UserFactory.php | 2 + .../0001_01_01_000000_create_users_table.php | 51 +++++ .../0001_01_01_000001_create_cache_table.php | 37 ++++ .../0001_01_01_000002_create_jobs_table.php | 59 ++++++ .../2014_10_12_000000_create_users_table.php | 32 ---- ...000_create_password_reset_tokens_table.php | 28 --- ...01_create_personal_access_tokens_table.php | 33 ---- ... 0001_01_01_000000_create_users_table.php} | 19 ++ .../0001_01_01_000001_create_cache_table.php | 37 ++++ .../0001_01_01_000002_create_jobs_table.php | 59 ++++++ ...000_create_password_reset_tokens_table.php | 28 --- ...01_create_personal_access_tokens_table.php | 33 ---- phpunit.xml.dev | 11 +- phpunit.xml.dist | 10 +- src/Models/Concerns/Abilities.php | 2 + src/Models/Concerns/Admin.php | 2 + src/Models/Concerns/Privileges.php | 2 + src/Models/Concerns/Role.php | 2 + src/Models/Concerns/WithChildren.php | 2 + src/Models/Concerns/WithCreator.php | 2 + src/Models/Concerns/WithModifier.php | 2 + src/Models/Concerns/WithOwner.php | 2 + src/Models/Concerns/WithParent.php | 2 + src/Models/Contracts/Abilities.php | 2 + src/Models/Contracts/Admin.php | 2 + src/Models/Contracts/Privileges.php | 2 + src/Models/Contracts/Revision.php | 2 + src/Models/Contracts/Role.php | 2 + src/Models/Contracts/WithChildren.php | 2 + src/Models/Contracts/WithCreator.php | 2 + src/Models/Contracts/WithMatrix.php | 2 + src/Models/Contracts/WithModifier.php | 2 + src/Models/Contracts/WithOwner.php | 2 + src/Models/Contracts/WithParent.php | 2 + src/Models/Model.php | 2 + src/Models/Scopes/ScopeFilterColumns.php | 2 + src/Models/Scopes/ScopeFilterDates.php | 2 + src/Models/Scopes/ScopeFilterFlags.php | 2 + src/Models/Scopes/ScopeFilterIds.php | 2 + src/Models/Scopes/ScopeFilterTrash.php | 2 + src/Models/Scopes/ScopeSort.php | 2 + src/Models/User.php | 14 +- src/Models/UuidModel.php | 2 + src/ServiceProvider.php | 2 + tests/Feature/Models/User/ModelTest.php | 2 + tests/Feature/TestCase.php | 2 + tests/Unit/Models/Model/ModelTest.php | 60 ++---- .../Scopes/ScopeFilterColumns/ModelTest.php | 153 +++++---------- .../Scopes/ScopeFilterDates/ModelTest.php | 179 ++++++------------ .../Scopes/ScopeFilterFlags/ModelTest.php | 45 ++--- .../Scopes/ScopeFilterIds/ModelTest.php | 117 ++++-------- .../Scopes/ScopeFilterTrash/ModelTest.php | 45 ++--- .../Models/Scopes/ScopeSort/ModelTest.php | 119 ++++-------- tests/Unit/Models/TestModel.php | 16 ++ tests/Unit/Models/User/ModelTest.php | 2 + tests/Unit/ServiceProvider/InstanceTest.php | 27 +-- tests/Unit/TestCase.php | 2 + 61 files changed, 616 insertions(+), 676 deletions(-) create mode 100644 database/migrations-laravel/0001_01_01_000000_create_users_table.php create mode 100644 database/migrations-laravel/0001_01_01_000001_create_cache_table.php create mode 100644 database/migrations-laravel/0001_01_01_000002_create_jobs_table.php delete mode 100644 database/migrations-laravel/2014_10_12_000000_create_users_table.php delete mode 100644 database/migrations-laravel/2014_10_12_100000_create_password_reset_tokens_table.php delete mode 100644 database/migrations-laravel/2019_12_14_000001_create_personal_access_tokens_table.php rename database/migrations-playground/{2014_10_12_000000_create_users_table.php => 0001_01_01_000000_create_users_table.php} (88%) create mode 100644 database/migrations-playground/0001_01_01_000001_create_cache_table.php create mode 100644 database/migrations-playground/0001_01_01_000002_create_jobs_table.php delete mode 100644 database/migrations-playground/2014_10_12_100000_create_password_reset_tokens_table.php delete mode 100644 database/migrations-playground/2019_12_14_000001_create_personal_access_tokens_table.php create mode 100644 tests/Unit/Models/TestModel.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24a6c58..eadd82e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: 'Tests: Playground' +name: 'CI' on: push: @@ -99,7 +99,7 @@ jobs: env: XDEBUG_MODE: coverage with: - version: "10.5" + version: "11.0" php_version: "8.2" php_extensions: intl xdebug coverage_clover: clover.xml diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index cdf705b..5e16832 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -59,6 +59,7 @@ 'encoding' => true, 'full_opening_tag' => true, 'fully_qualified_strict_types' => true, + 'declare_strict_types' => true, 'function_declaration' => true, 'general_phpdoc_tag_rename' => true, 'heredoc_to_nowdoc' => true, diff --git a/composer.json b/composer.json index ba4fb0a..33a6e0a 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,9 @@ "illuminate/validation": "^11.0", "illuminate/view": "^11.0" }, + "require-dev": { + "gammamatrix/playground-test": "dev-develop|dev-master|dev-feature/*|^73.0" + }, "minimum-stability": "dev", "prefer-stable": true, "autoload": { diff --git a/config/playground.php b/config/playground.php index 78de58e..9e39758 100644 --- a/config/playground.php +++ b/config/playground.php @@ -1,5 +1,7 @@ [ diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 4960cf6..931948f 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -1,4 +1,6 @@ id(); + $table->string('name'); + $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + }); + + Schema::create('password_reset_tokens', function (Blueprint $table) { + $table->string('email')->primary(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + }); + + Schema::create('sessions', function (Blueprint $table) { + $table->string('id')->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->longText('payload'); + $table->integer('last_activity')->index(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('users'); + Schema::dropIfExists('password_reset_tokens'); + Schema::dropIfExists('sessions'); + } +}; diff --git a/database/migrations-laravel/0001_01_01_000001_create_cache_table.php b/database/migrations-laravel/0001_01_01_000001_create_cache_table.php new file mode 100644 index 0000000..960e12b --- /dev/null +++ b/database/migrations-laravel/0001_01_01_000001_create_cache_table.php @@ -0,0 +1,37 @@ +string('key')->primary(); + $table->mediumText('value'); + $table->integer('expiration'); + }); + + Schema::create('cache_locks', function (Blueprint $table) { + $table->string('key')->primary(); + $table->string('owner'); + $table->integer('expiration'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('cache'); + Schema::dropIfExists('cache_locks'); + } +}; diff --git a/database/migrations-laravel/0001_01_01_000002_create_jobs_table.php b/database/migrations-laravel/0001_01_01_000002_create_jobs_table.php new file mode 100644 index 0000000..0dcb8c4 --- /dev/null +++ b/database/migrations-laravel/0001_01_01_000002_create_jobs_table.php @@ -0,0 +1,59 @@ +id(); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + + Schema::create('job_batches', function (Blueprint $table) { + $table->string('id')->primary(); + $table->string('name'); + $table->integer('total_jobs'); + $table->integer('pending_jobs'); + $table->integer('failed_jobs'); + $table->longText('failed_job_ids'); + $table->mediumText('options')->nullable(); + $table->integer('cancelled_at')->nullable(); + $table->integer('created_at'); + $table->integer('finished_at')->nullable(); + }); + + Schema::create('failed_jobs', function (Blueprint $table) { + $table->id(); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('jobs'); + Schema::dropIfExists('job_batches'); + Schema::dropIfExists('failed_jobs'); + } +}; diff --git a/database/migrations-laravel/2014_10_12_000000_create_users_table.php b/database/migrations-laravel/2014_10_12_000000_create_users_table.php deleted file mode 100644 index 1f97419..0000000 --- a/database/migrations-laravel/2014_10_12_000000_create_users_table.php +++ /dev/null @@ -1,32 +0,0 @@ -id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('users'); - } -}; diff --git a/database/migrations-laravel/2014_10_12_100000_create_password_reset_tokens_table.php b/database/migrations-laravel/2014_10_12_100000_create_password_reset_tokens_table.php deleted file mode 100644 index 8b5b388..0000000 --- a/database/migrations-laravel/2014_10_12_100000_create_password_reset_tokens_table.php +++ /dev/null @@ -1,28 +0,0 @@ -string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('password_reset_tokens'); - } -}; diff --git a/database/migrations-laravel/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations-laravel/2019_12_14_000001_create_personal_access_tokens_table.php deleted file mode 100644 index 0fc7a63..0000000 --- a/database/migrations-laravel/2019_12_14_000001_create_personal_access_tokens_table.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - $table->morphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamp('expires_at')->nullable(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('personal_access_tokens'); - } -}; diff --git a/database/migrations-playground/2014_10_12_000000_create_users_table.php b/database/migrations-playground/0001_01_01_000000_create_users_table.php similarity index 88% rename from database/migrations-playground/2014_10_12_000000_create_users_table.php rename to database/migrations-playground/0001_01_01_000000_create_users_table.php index 1f90a54..d3ca506 100644 --- a/database/migrations-playground/2014_10_12_000000_create_users_table.php +++ b/database/migrations-playground/0001_01_01_000000_create_users_table.php @@ -1,5 +1,7 @@ comment('Encrypted array of sources'); }); + + Schema::create('password_reset_tokens', function (Blueprint $table) { + $table->string('email')->primary(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + }); + + Schema::create('sessions', function (Blueprint $table) { + $table->string('id')->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->longText('payload'); + $table->integer('last_activity')->index(); + }); } /** @@ -152,5 +169,7 @@ public function up(): void public function down(): void { Schema::dropIfExists('users'); + Schema::dropIfExists('password_reset_tokens'); + Schema::dropIfExists('sessions'); } }; diff --git a/database/migrations-playground/0001_01_01_000001_create_cache_table.php b/database/migrations-playground/0001_01_01_000001_create_cache_table.php new file mode 100644 index 0000000..960e12b --- /dev/null +++ b/database/migrations-playground/0001_01_01_000001_create_cache_table.php @@ -0,0 +1,37 @@ +string('key')->primary(); + $table->mediumText('value'); + $table->integer('expiration'); + }); + + Schema::create('cache_locks', function (Blueprint $table) { + $table->string('key')->primary(); + $table->string('owner'); + $table->integer('expiration'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('cache'); + Schema::dropIfExists('cache_locks'); + } +}; diff --git a/database/migrations-playground/0001_01_01_000002_create_jobs_table.php b/database/migrations-playground/0001_01_01_000002_create_jobs_table.php new file mode 100644 index 0000000..0dcb8c4 --- /dev/null +++ b/database/migrations-playground/0001_01_01_000002_create_jobs_table.php @@ -0,0 +1,59 @@ +id(); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + + Schema::create('job_batches', function (Blueprint $table) { + $table->string('id')->primary(); + $table->string('name'); + $table->integer('total_jobs'); + $table->integer('pending_jobs'); + $table->integer('failed_jobs'); + $table->longText('failed_job_ids'); + $table->mediumText('options')->nullable(); + $table->integer('cancelled_at')->nullable(); + $table->integer('created_at'); + $table->integer('finished_at')->nullable(); + }); + + Schema::create('failed_jobs', function (Blueprint $table) { + $table->id(); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('jobs'); + Schema::dropIfExists('job_batches'); + Schema::dropIfExists('failed_jobs'); + } +}; diff --git a/database/migrations-playground/2014_10_12_100000_create_password_reset_tokens_table.php b/database/migrations-playground/2014_10_12_100000_create_password_reset_tokens_table.php deleted file mode 100644 index 8b5b388..0000000 --- a/database/migrations-playground/2014_10_12_100000_create_password_reset_tokens_table.php +++ /dev/null @@ -1,28 +0,0 @@ -string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('password_reset_tokens'); - } -}; diff --git a/database/migrations-playground/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations-playground/2019_12_14_000001_create_personal_access_tokens_table.php deleted file mode 100644 index a297dc2..0000000 --- a/database/migrations-playground/2019_12_14_000001_create_personal_access_tokens_table.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - $table->uuidMorphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamp('expires_at')->nullable(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('personal_access_tokens'); - } -}; diff --git a/phpunit.xml.dev b/phpunit.xml.dev index 9b133b2..3cc6f35 100644 --- a/phpunit.xml.dev +++ b/phpunit.xml.dev @@ -1,7 +1,7 @@ + - - + - + - + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7f1f703..e863b8a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ + - + - + - + + diff --git a/src/Models/Concerns/Abilities.php b/src/Models/Concerns/Abilities.php index c605851..41602e1 100644 --- a/src/Models/Concerns/Abilities.php +++ b/src/Models/Concerns/Abilities.php @@ -1,4 +1,6 @@ markTestSkipped(sprintf( - 'Expecting the abstract this->mock class to exist: %1$s', - static::MODEL_CLASS - )); - } - config(['auth.providers.users.model' => \Playground\Test\Models\User::class]); - } - public function test_WithChildren_children_returns_HasMany(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; - $this->assertInstanceOf(HasMany::class, $mock->children()); + $this->assertInstanceOf(HasMany::class, $instance->children()); } public function test_WithCreator_creator_returns_HasOne(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; - $this->assertInstanceOf(HasOne::class, $mock->creator()); + $this->assertInstanceOf(HasOne::class, $instance->creator()); } public function test_WithModifier_modifier_returns_HasOne(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; - $this->assertInstanceOf(HasOne::class, $mock->modifier()); + $this->assertInstanceOf(HasOne::class, $instance->modifier()); } public function test_WithOwner_owner_returns_HasOne(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; - $this->assertInstanceOf(HasOne::class, $mock->owner()); + $this->assertInstanceOf(HasOne::class, $instance->owner()); } public function test_WithParent_parent_returns_HasOne(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; - $this->assertInstanceOf(HasOne::class, $mock->parent()); + $this->assertInstanceOf(HasOne::class, $instance->parent()); } } diff --git a/tests/Unit/Models/Scopes/ScopeFilterColumns/ModelTest.php b/tests/Unit/Models/Scopes/ScopeFilterColumns/ModelTest.php index f5f17d4..323f4c6 100644 --- a/tests/Unit/Models/Scopes/ScopeFilterColumns/ModelTest.php +++ b/tests/Unit/Models/Scopes/ScopeFilterColumns/ModelTest.php @@ -1,13 +1,15 @@ markTestSkipped(sprintf( - 'Expecting the abstract model class to exist: %1$s', - static::MODEL_CLASS - )); - } + Carbon::setTestNow(Carbon::now()); } public function test_scopeFilterColumns_returns_query_without_columns_or_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterColumns([], []); + $query = $instance->filterColumns([], []); $this->assertInstanceOf(Builder::class, $query); @@ -62,17 +51,14 @@ public function test_scopeFilterColumns_returns_query_without_columns_or_filters public function test_scopeFilterColumns_returns_query_without_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterColumns([ + $query = $instance->filterColumns([ 'title' => [], 'label' => [], ], []); @@ -88,14 +74,11 @@ public function test_scopeFilterColumns_returns_query_without_filters(): void public function test_scopeFilterColumns_returns_query_with_invalid_column(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -108,7 +91,7 @@ public function test_scopeFilterColumns_returns_query_with_invalid_column(): voi ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -121,14 +104,11 @@ public function test_scopeFilterColumns_returns_query_with_invalid_column(): voi public function test_scopeFilterColumns_returns_query_with_filters_without_meta_for_strings(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `title` LIKE ? and `label` LIKE ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -145,7 +125,7 @@ public function test_scopeFilterColumns_returns_query_with_filters_without_meta_ ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -162,14 +142,11 @@ public function test_scopeFilterColumns_returns_query_with_filters_without_meta_ public function test_scopeFilterColumns_returns_query_with_null_comparison_and_ignore(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -183,7 +160,7 @@ public function test_scopeFilterColumns_returns_query_with_null_comparison_and_i ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -196,14 +173,11 @@ public function test_scopeFilterColumns_returns_query_with_null_comparison_and_i public function test_scopeFilterColumns_returns_query_with_comparison(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `title` LIKE ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -216,7 +190,7 @@ public function test_scopeFilterColumns_returns_query_with_comparison(): void ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -231,14 +205,11 @@ public function test_scopeFilterColumns_returns_query_with_comparison(): void public function test_scopeFilterColumns_with_boolean_filter_type_and_null_value(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `active` = ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -253,7 +224,7 @@ public function test_scopeFilterColumns_with_boolean_filter_type_and_null_value( ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -268,14 +239,11 @@ public function test_scopeFilterColumns_with_boolean_filter_type_and_null_value( public function test_scopeFilterColumns_with_boolean_filter_type_and_true_value(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `active` = ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -290,7 +258,7 @@ public function test_scopeFilterColumns_with_boolean_filter_type_and_true_value( ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -305,14 +273,11 @@ public function test_scopeFilterColumns_with_boolean_filter_type_and_true_value( public function test_scopeFilterColumns_with_boolean_filter_type_and_false_value(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `active` = ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -327,7 +292,7 @@ public function test_scopeFilterColumns_with_boolean_filter_type_and_false_value ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -342,14 +307,11 @@ public function test_scopeFilterColumns_with_boolean_filter_type_and_false_value public function test_scopeFilterColumns_with_filter_operator_without_operator_and_default_to_like(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `title` LIKE ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -364,7 +326,7 @@ public function test_scopeFilterColumns_with_filter_operator_without_operator_an ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -379,10 +341,7 @@ public function test_scopeFilterColumns_with_filter_operator_without_operator_an public function test_scopeFilterColumns_with_filter_operators(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $filter_operators = [ '|' => [], @@ -443,12 +402,12 @@ public function test_scopeFilterColumns_with_filter_operators(): void $sql = sprintf( 'select * from `%1$s` where `title` %2$s%3$s and `%1$s`.`deleted_at` is null', - $mock->getTable(), + $instance->getTable(), $operator, $parameter ); - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -469,14 +428,11 @@ public function test_scopeFilterColumns_with_filter_operators(): void public function test_scopeFilterColumns_with_between_filter_operator_without_single_parameter_and_ignore_between(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -492,7 +448,7 @@ public function test_scopeFilterColumns_with_between_filter_operator_without_sin ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -505,14 +461,11 @@ public function test_scopeFilterColumns_with_between_filter_operator_without_sin public function test_scopeFilterColumns_with_between_filter_operator(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `rank` between ? and ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -528,7 +481,7 @@ public function test_scopeFilterColumns_with_between_filter_operator(): void ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -545,14 +498,11 @@ public function test_scopeFilterColumns_with_between_filter_operator(): void public function test_scopeFilterColumns_with_not_between_filter_operator_without_single_parameter_and_ignore_between(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -568,7 +518,7 @@ public function test_scopeFilterColumns_with_not_between_filter_operator_without ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -581,14 +531,11 @@ public function test_scopeFilterColumns_with_not_between_filter_operator_without public function test_scopeFilterColumns_with_not_between_filter_operator(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `rank` not between ? and ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $columns = [ @@ -604,7 +551,7 @@ public function test_scopeFilterColumns_with_not_between_filter_operator(): void ], ]; - $query = $mock->filterColumns($columns, $validated); + $query = $instance->filterColumns($columns, $validated); $this->assertInstanceOf(Builder::class, $query); diff --git a/tests/Unit/Models/Scopes/ScopeFilterDates/ModelTest.php b/tests/Unit/Models/Scopes/ScopeFilterDates/ModelTest.php index cada017..a95cb39 100644 --- a/tests/Unit/Models/Scopes/ScopeFilterDates/ModelTest.php +++ b/tests/Unit/Models/Scopes/ScopeFilterDates/ModelTest.php @@ -1,4 +1,6 @@ markTestSkipped(sprintf( - 'Expecting the abstract model class to exist: %1$s', - static::MODEL_CLASS - )); - } - $this->setUpSqlTrait(); parent::setUp(); @@ -46,17 +35,14 @@ protected function setUp(): void public function test_scopeFilterDates_returns_query_without_dates_or_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterDates([], []); + $query = $instance->filterDates([], []); $this->assertInstanceOf(Builder::class, $query); @@ -65,17 +51,14 @@ public function test_scopeFilterDates_returns_query_without_dates_or_filters(): public function test_scopeFilterDates_returns_query_without_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterDates([ + $query = $instance->filterDates([ 'created_at' => [], 'updated_at' => [], ], []); @@ -91,14 +74,11 @@ public function test_scopeFilterDates_returns_query_without_filters(): void public function test_scopeFilterDates_returns_query_with_invalid_column(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -111,7 +91,7 @@ public function test_scopeFilterDates_returns_query_with_invalid_column(): void ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -124,14 +104,11 @@ public function test_scopeFilterDates_returns_query_with_invalid_column(): void public function test_scopeFilterDates_returns_query_with_filters_without_meta_for_strings(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `updated_at` >= ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -147,7 +124,7 @@ public function test_scopeFilterDates_returns_query_with_filters_without_meta_fo ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -162,14 +139,11 @@ public function test_scopeFilterDates_returns_query_with_filters_without_meta_fo public function test_scopeFilterDates_returns_query_with_null_comparison_and_ignore(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -187,7 +161,7 @@ public function test_scopeFilterDates_returns_query_with_null_comparison_and_ign ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -200,15 +174,12 @@ public function test_scopeFilterDates_returns_query_with_null_comparison_and_ign public function test_scopeFilterDates_returns_query_with_null_comparison_and_allow(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( // 'select * from `%1$s` where `%1$s`.`closed_at` is null and `%1$s`.`deleted_at` is null', 'select * from `%1$s` where `closed_at` is null and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -225,7 +196,7 @@ public function test_scopeFilterDates_returns_query_with_null_comparison_and_all ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -238,15 +209,12 @@ public function test_scopeFilterDates_returns_query_with_null_comparison_and_all public function test_scopeFilterDates_returns_query_with_comparison(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( // 'select * from `%1$s` where `%1$s`.`updated_at` LIKE ? and `%1$s`.`deleted_at` is null', 'select * from `%1$s` where `updated_at` >= ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -259,7 +227,7 @@ public function test_scopeFilterDates_returns_query_with_comparison(): void ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -274,14 +242,11 @@ public function test_scopeFilterDates_returns_query_with_comparison(): void public function test_scopeFilterDates_returns_query_with_wildcard(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `updated_at` LIKE ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -294,7 +259,7 @@ public function test_scopeFilterDates_returns_query_with_wildcard(): void ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -309,14 +274,11 @@ public function test_scopeFilterDates_returns_query_with_wildcard(): void public function test_scopeFilterDates_returns_query_with_operator_wildcard(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `updated_at` LIKE ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -331,7 +293,7 @@ public function test_scopeFilterDates_returns_query_with_operator_wildcard(): vo ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -346,14 +308,11 @@ public function test_scopeFilterDates_returns_query_with_operator_wildcard(): vo public function test_scopeFilterDates_returns_query_with_object_value_and_ignore(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -369,7 +328,7 @@ public function test_scopeFilterDates_returns_query_with_object_value_and_ignore ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -382,14 +341,11 @@ public function test_scopeFilterDates_returns_query_with_object_value_and_ignore public function test_scopeFilterDates_returns_query_with_unnullable_value_and_ignore(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -404,7 +360,7 @@ public function test_scopeFilterDates_returns_query_with_unnullable_value_and_ig ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -417,14 +373,11 @@ public function test_scopeFilterDates_returns_query_with_unnullable_value_and_ig public function test_scopeFilterDates_returns_query_with_invalid_operator_and_use_like(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `updated_at` >= ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -440,7 +393,7 @@ public function test_scopeFilterDates_returns_query_with_invalid_operator_and_us ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -458,14 +411,11 @@ public function test_scopeFilterDates_returns_query_with_invalid_operator_and_us public function test_scopeFilterDates_returns_query_with_invalid_parsable_value_and_ignore(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -481,7 +431,7 @@ public function test_scopeFilterDates_returns_query_with_invalid_parsable_value_ ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -494,14 +444,11 @@ public function test_scopeFilterDates_returns_query_with_invalid_parsable_value_ public function test_scopeFilterDates_returns_query_with_short_date_and_gte_operator(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `updated_at` >= ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -517,7 +464,7 @@ public function test_scopeFilterDates_returns_query_with_short_date_and_gte_oper ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -532,14 +479,11 @@ public function test_scopeFilterDates_returns_query_with_short_date_and_gte_oper public function test_scopeFilterDates_returns_query_with_phrase_date_and_automatically_parse(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `updated_at` = ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -555,7 +499,7 @@ public function test_scopeFilterDates_returns_query_with_phrase_date_and_automat ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -573,14 +517,11 @@ public function test_scopeFilterDates_returns_query_with_phrase_date_and_automat public function test_scopeFilterDates_with_between_filter_operator_with_parse(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `created_at` between ? and ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -597,7 +538,7 @@ public function test_scopeFilterDates_with_between_filter_operator_with_parse(): ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -621,14 +562,11 @@ public function test_scopeFilterDates_with_between_filter_operator_with_parse(): public function test_scopeFilterDates_with_not_between_filter_operator_with_parse(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `created_at` not between ? and ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $dates = [ @@ -645,7 +583,7 @@ public function test_scopeFilterDates_with_not_between_filter_operator_with_pars ], ]; - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -669,10 +607,7 @@ public function test_scopeFilterDates_with_not_between_filter_operator_with_pars public function test_scopeFilterDates_with_filter_operators(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $filter_operators = [ '|' => [], @@ -733,12 +668,12 @@ public function test_scopeFilterDates_with_filter_operators(): void $sql = sprintf( 'select * from `%1$s` where `created_at` %2$s%3$s and `%1$s`.`deleted_at` is null', - $mock->getTable(), + $instance->getTable(), $operator, $parameter ); - $query = $mock->filterDates($dates, $validated); + $query = $instance->filterDates($dates, $validated); $this->assertInstanceOf(Builder::class, $query); diff --git a/tests/Unit/Models/Scopes/ScopeFilterFlags/ModelTest.php b/tests/Unit/Models/Scopes/ScopeFilterFlags/ModelTest.php index 9a704a0..6ebbf56 100644 --- a/tests/Unit/Models/Scopes/ScopeFilterFlags/ModelTest.php +++ b/tests/Unit/Models/Scopes/ScopeFilterFlags/ModelTest.php @@ -1,13 +1,15 @@ markTestSkipped(sprintf( - 'Expecting the abstract model class to exist: %1$s', - static::MODEL_CLASS - )); - } + Carbon::setTestNow(Carbon::now()); } public function test_scopeFilterFlags_returns_query_without_flags_or_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterFlags([], []); + $query = $instance->filterFlags([], []); $this->assertInstanceOf(Builder::class, $query); @@ -62,17 +51,14 @@ public function test_scopeFilterFlags_returns_query_without_flags_or_filters(): public function test_scopeFilterFlags_returns_query_without_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterFlags([ + $query = $instance->filterFlags([ 'active' => [], 'problem' => [], ], []); @@ -88,17 +74,14 @@ public function test_scopeFilterFlags_returns_query_without_filters(): void public function test_scopeFilterFlags_returns_query_with_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `active` = ? and `problem` = ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterFlags([ + $query = $instance->filterFlags([ 'active' => [], 'problem' => [], ], [ diff --git a/tests/Unit/Models/Scopes/ScopeFilterIds/ModelTest.php b/tests/Unit/Models/Scopes/ScopeFilterIds/ModelTest.php index 0071643..8e2dd58 100644 --- a/tests/Unit/Models/Scopes/ScopeFilterIds/ModelTest.php +++ b/tests/Unit/Models/Scopes/ScopeFilterIds/ModelTest.php @@ -1,13 +1,15 @@ markTestSkipped(sprintf( - 'Expecting the abstract model class to exist: %1$s', - static::MODEL_CLASS - )); - } + Carbon::setTestNow(Carbon::now()); } public function test_scopeFilterIds_returns_query_without_ids_or_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterIds([], []); + $query = $instance->filterIds([], []); $this->assertInstanceOf(Builder::class, $query); @@ -62,17 +51,14 @@ public function test_scopeFilterIds_returns_query_without_ids_or_filters(): void public function test_scopeFilterIds_returns_query_without_filters(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterIds([ + $query = $instance->filterIds([ 'id' => [], 'owned_by_id' => [], ], []); @@ -88,14 +74,11 @@ public function test_scopeFilterIds_returns_query_without_filters(): void public function test_scopeFilterIds_returns_query_with_invalid_column(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -108,7 +91,7 @@ public function test_scopeFilterIds_returns_query_with_invalid_column(): void ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -121,14 +104,11 @@ public function test_scopeFilterIds_returns_query_with_invalid_column(): void public function test_scopeFilterIds_returns_query_with_null_comparison(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `id` is null and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -142,7 +122,7 @@ public function test_scopeFilterIds_returns_query_with_null_comparison(): void ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -155,14 +135,11 @@ public function test_scopeFilterIds_returns_query_with_null_comparison(): void public function test_scopeFilterIds_returns_query_with_comparison(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `id` = ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -175,7 +152,7 @@ public function test_scopeFilterIds_returns_query_with_comparison(): void ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -190,14 +167,11 @@ public function test_scopeFilterIds_returns_query_with_comparison(): void public function test_scopeFilterIds_returns_query_with_filters_array(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `modified_by_id` in (?, ?, ?) and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -224,7 +198,7 @@ public function test_scopeFilterIds_returns_query_with_filters_array(): void ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -243,14 +217,11 @@ public function test_scopeFilterIds_returns_query_with_filters_array(): void public function test_scopeFilterIds_returns_query_with_filters_with_integer(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `id` = ? and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -272,7 +243,7 @@ public function test_scopeFilterIds_returns_query_with_filters_with_integer(): v ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -287,14 +258,11 @@ public function test_scopeFilterIds_returns_query_with_filters_with_integer(): v public function test_scopeFilterIds_returns_query_with_array_of_ids_without_type(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `modified_by_id` in (?, ?, ?) and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -318,7 +286,7 @@ public function test_scopeFilterIds_returns_query_with_array_of_ids_without_type ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -338,14 +306,11 @@ public function test_scopeFilterIds_returns_query_with_array_of_ids_without_type public function test_scopeFilterIds_returns_query_with_array_of_uuids_for_integer_type_ids_and_ignore(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -368,7 +333,7 @@ public function test_scopeFilterIds_returns_query_with_array_of_uuids_for_intege ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -382,14 +347,11 @@ public function test_scopeFilterIds_returns_query_with_array_of_uuids_for_intege public function test_scopeFilterIds_returns_query_with_array_of_integer_ids_ignore_duplicate_id(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `modified_by_id` in (?, ?) and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -413,7 +375,7 @@ public function test_scopeFilterIds_returns_query_with_array_of_integer_ids_igno ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); @@ -431,14 +393,11 @@ public function test_scopeFilterIds_returns_query_with_array_of_integer_ids_igno public function test_scopeFilterIds_returns_query_with_filters_with_null_and_string_and_array(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `id` = ? and `owned_by_id` is null and `modified_by_id` in (?, ?, ?) and `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); $ids = [ @@ -468,7 +427,7 @@ public function test_scopeFilterIds_returns_query_with_filters_with_null_and_str ], ]; - $query = $mock->filterIds($ids, $validated); + $query = $instance->filterIds($ids, $validated); $this->assertInstanceOf(Builder::class, $query); diff --git a/tests/Unit/Models/Scopes/ScopeFilterTrash/ModelTest.php b/tests/Unit/Models/Scopes/ScopeFilterTrash/ModelTest.php index 1858263..1d36eb8 100644 --- a/tests/Unit/Models/Scopes/ScopeFilterTrash/ModelTest.php +++ b/tests/Unit/Models/Scopes/ScopeFilterTrash/ModelTest.php @@ -1,13 +1,15 @@ markTestSkipped(sprintf( - 'Expecting the abstract model class to exist: %1$s', - static::MODEL_CLASS - )); - } + Carbon::setTestNow(Carbon::now()); } public function test_scopeFilterTrash_returns_query_with_empty_visibility(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterTrash(); + $query = $instance->filterTrash(); $this->assertInstanceOf(Builder::class, $query); @@ -62,19 +51,16 @@ public function test_scopeFilterTrash_returns_query_with_empty_visibility(): voi public function test_scopeFilterTrash_returns_query_with_trash(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $visibility = 'with'; $sql = sprintf( 'select * from `%1$s`', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterTrash($visibility); + $query = $instance->filterTrash($visibility); $this->assertInstanceOf(Builder::class, $query); @@ -83,19 +69,16 @@ public function test_scopeFilterTrash_returns_query_with_trash(): void public function test_scopeFilterTrash_returns_query_with_only_trash(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $visibility = 'only'; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is not null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->filterTrash($visibility); + $query = $instance->filterTrash($visibility); $this->assertInstanceOf(Builder::class, $query); diff --git a/tests/Unit/Models/Scopes/ScopeSort/ModelTest.php b/tests/Unit/Models/Scopes/ScopeSort/ModelTest.php index fa2dc52..1aa654a 100644 --- a/tests/Unit/Models/Scopes/ScopeSort/ModelTest.php +++ b/tests/Unit/Models/Scopes/ScopeSort/ModelTest.php @@ -1,13 +1,15 @@ markTestSkipped(sprintf( - 'Expecting the abstract model class to exist: %1$s', - static::MODEL_CLASS - )); - } + Carbon::setTestNow(Carbon::now()); } public function test_scopeSort_returns_query_with_empty_sort(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; - $this->assertInstanceOf(Builder::class, $mock->sort()); + $this->assertInstanceOf(Builder::class, $instance->sort()); $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort(); + $query = $instance->sort(); $this->assertInstanceOf(Builder::class, $query); @@ -64,10 +53,7 @@ public function test_scopeSort_returns_query_with_empty_sort(): void public function test_scopeSort_returns_query_with_array_boolean_sort_asc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = [ 'label' => true, @@ -75,10 +61,10 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_asc(): void $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `label` asc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -87,10 +73,7 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_asc(): void public function test_scopeSort_returns_query_with_array_boolean_sort_desc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = [ 'title' => false, @@ -98,10 +81,10 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_desc(): voi $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `title` desc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -110,10 +93,7 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_desc(): voi public function test_scopeSort_returns_query_with_array_boolean_sort_pair(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = [ 'label' => false, @@ -122,10 +102,10 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_pair(): voi $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `label` desc, `title` asc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -134,10 +114,7 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_pair(): voi public function test_scopeSort_returns_query_with_array_boolean_sort_triplet(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = [ 'created_at' => true, @@ -147,10 +124,10 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_triplet(): $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `created_at` asc, `label` asc, `title` desc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -159,18 +136,15 @@ public function test_scopeSort_returns_query_with_array_boolean_sort_triplet(): public function test_scopeSort_returns_query_with_csv_sort_asc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = 'label'; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `label` asc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); $this->assertSame($this->replace_quotes($sql), $query->toSql()); @@ -178,19 +152,16 @@ public function test_scopeSort_returns_query_with_csv_sort_asc(): void public function test_scopeSort_returns_query_with_csv_sort_desc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = '-created_at'; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `created_at` desc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -206,19 +177,16 @@ public function test_scopeSort_returns_query_with_csv_sort_desc(): void public function test_scopeSort_returns_query_with_simple_array_asc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = ['label']; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `label` asc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -227,19 +195,16 @@ public function test_scopeSort_returns_query_with_simple_array_asc(): void public function test_scopeSort_returns_query_with_simple_array_desc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = ['-label']; $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `label` desc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -248,10 +213,7 @@ public function test_scopeSort_returns_query_with_simple_array_desc(): void public function test_scopeSort_returns_query_with_hash_array_asc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = [ 'label' => 'aSc', @@ -259,10 +221,10 @@ public function test_scopeSort_returns_query_with_hash_array_asc(): void $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `label` asc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); @@ -271,10 +233,7 @@ public function test_scopeSort_returns_query_with_hash_array_asc(): void public function test_scopeSort_returns_query_with_hash_array_desc(): void { - /** - * @var MockObject&TestModel - */ - $mock = $this->getMockForAbstractClass(static::MODEL_CLASS); + $instance = new TestModel; $sort = [ 'label' => 'dEsC', @@ -282,10 +241,10 @@ public function test_scopeSort_returns_query_with_hash_array_desc(): void $sql = sprintf( 'select * from `%1$s` where `%1$s`.`deleted_at` is null order by `label` desc', - $mock->getTable() + $instance->getTable() ); - $query = $mock->sort($sort); + $query = $instance->sort($sort); $this->assertInstanceOf(Builder::class, $query); diff --git a/tests/Unit/Models/TestModel.php b/tests/Unit/Models/TestModel.php new file mode 100644 index 0000000..85b3977 --- /dev/null +++ b/tests/Unit/Models/TestModel.php @@ -0,0 +1,16 @@ +newInstanceWithoutConstructor(); @@ -82,14 +85,14 @@ public function test_userPrimaryKeyType_with_exception(): void // $log->dump(); - $log->assertLogged( - fn (LogEntry $log) => $log->level === 'debug' - ); - $log->assertLogged( - fn (LogEntry $log) => str_contains( - $log->message, - 'Error: Call to undefined method Exception::getIncrementing()' - ) - ); + // $log->assertLogged( + // fn (LogEntry $log) => $log->level === 'debug' + // ); + // $log->assertLogged( + // fn (LogEntry $log) => str_contains( + // $log->message, + // 'Error: Call to undefined method Exception::getIncrementing()' + // ) + // ); } } diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index af1efb4..3f260fb 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -1,4 +1,6 @@