From 56fd959a24ffcffe71e3089b30895a0478d35ed9 Mon Sep 17 00:00:00 2001 From: HC Torres Date: Sat, 17 Jun 2023 21:49:16 -0300 Subject: [PATCH 1/6] Check existence of childTypes method --- src/HasChildren.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/HasChildren.php b/src/HasChildren.php index a25475e..77c8ff7 100644 --- a/src/HasChildren.php +++ b/src/HasChildren.php @@ -267,6 +267,14 @@ public function classToAlias(string $className): string */ public function getChildTypes(): array { - return property_exists($this, 'childTypes') ? $this->childTypes : []; + if (method_exists($this, 'childTypes')) { + return $this->childTypes(); + } + + if (property_exists($this, 'childTypes')) { + return $this->childTypes; + } + + return []; } } From 3ee056e236a2df7ec15126e89307ee3708335b0e Mon Sep 17 00:00:00 2001 From: Anthony Clark Date: Fri, 28 Jul 2023 15:30:59 -0700 Subject: [PATCH 2/6] Fix phpunit test --- .gitignore | 3 +- phpunit.xml | 31 +++++++------------ ....php => ParentsAreAwareOfChildrenTest.php} | 0 ...sParentModelTest.php => HasParentTest.php} | 0 4 files changed, 14 insertions(+), 20 deletions(-) rename tests/Features/{ParentsReturnChildrenTest.php => ParentsAreAwareOfChildrenTest.php} (100%) rename tests/Unit/{HasParentModelTest.php => HasParentTest.php} (100%) diff --git a/.gitignore b/.gitignore index e484b50..12a94bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor/ .idea composer.lock -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +.phpunit.cache diff --git a/phpunit.xml b/phpunit.xml index 7aef90f..34ca597 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,14 @@ - - - - ./tests - - - - - ./src - - + + + + + ./tests + + + + + ./src + + diff --git a/tests/Features/ParentsReturnChildrenTest.php b/tests/Features/ParentsAreAwareOfChildrenTest.php similarity index 100% rename from tests/Features/ParentsReturnChildrenTest.php rename to tests/Features/ParentsAreAwareOfChildrenTest.php diff --git a/tests/Unit/HasParentModelTest.php b/tests/Unit/HasParentTest.php similarity index 100% rename from tests/Unit/HasParentModelTest.php rename to tests/Unit/HasParentTest.php From 58a57bcd3a49b97571487ddfa0d191f2ace1e969 Mon Sep 17 00:00:00 2001 From: Anthony Clark Date: Fri, 28 Jul 2023 15:31:49 -0700 Subject: [PATCH 3/6] Add Enum tests --- tests/Enums/ToolNames.php | 10 ++++++++ tests/Features/TypeColumnCanBeAliasedTest.php | 22 ++++++++++++++++++ tests/Models/ClawHammer.php | 12 ++++++++++ tests/Models/Mallet.php | 12 ++++++++++ tests/Models/SledgeHammer.php | 12 ++++++++++ tests/Models/Tool.php | 23 +++++++++++++++++++ tests/TestCase.php | 6 +++++ 7 files changed, 97 insertions(+) create mode 100644 tests/Enums/ToolNames.php create mode 100644 tests/Models/ClawHammer.php create mode 100644 tests/Models/Mallet.php create mode 100644 tests/Models/SledgeHammer.php create mode 100644 tests/Models/Tool.php diff --git a/tests/Enums/ToolNames.php b/tests/Enums/ToolNames.php new file mode 100644 index 0000000..211668a --- /dev/null +++ b/tests/Enums/ToolNames.php @@ -0,0 +1,10 @@ +assertInstanceOf(ChildFromAbstractParent::class, $child[0]); } + + /** @test */ + function enums_can_be_used_as_type_alias() + { + ClawHammer::create(); + Mallet::create(); + SledgeHammer::create(); + + $tools = Tool::all(); + + $this->assertInstanceOf(ClawHammer::class, $tools[0]); + $this->assertEquals(ToolNames::ClawHammer->value, $tools[0]->type); + $this->assertInstanceOf(Mallet::class, $tools[1]); + $this->assertEquals(ToolNames::Mallet->value, $tools[1]->type); + $this->assertInstanceOf(SledgeHammer::class, $tools[2]); + $this->assertEquals(ToolNames::SledgeHammer->value, $tools[2]->type); + } } diff --git a/tests/Models/ClawHammer.php b/tests/Models/ClawHammer.php new file mode 100644 index 0000000..0e609f8 --- /dev/null +++ b/tests/Models/ClawHammer.php @@ -0,0 +1,12 @@ +value => ClawHammer::class, + ToolNames::Mallet->value => Mallet::class, + ToolNames::SledgeHammer->value => SledgeHammer::class, + ]; + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 035986c..a1b0e60 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -104,5 +104,11 @@ public function runMigrations() $table->string('type')->nullable(); $table->timestamps(); }); + + Schema::create('tools', function ($table) { + $table->increments('id'); + $table->string('type')->nullable(); + $table->timestamps(); + }); } } From 6a049da060acb22023ca8561847c5eb87327195f Mon Sep 17 00:00:00 2001 From: Anthony Clark Date: Fri, 28 Jul 2023 15:41:47 -0700 Subject: [PATCH 4/6] Skip enum test on earlier PHP versions --- tests/Features/TypeColumnCanBeAliasedTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Features/TypeColumnCanBeAliasedTest.php b/tests/Features/TypeColumnCanBeAliasedTest.php index 71f351c..ee67a3a 100644 --- a/tests/Features/TypeColumnCanBeAliasedTest.php +++ b/tests/Features/TypeColumnCanBeAliasedTest.php @@ -48,6 +48,10 @@ function type_column_values_can_accept_type_aliases_from_abstract_parent() /** @test */ function enums_can_be_used_as_type_alias() { + if (phpversion() < 8.1) { + $this->markTestSkipped('Enums are not supported in this version of PHP'); + } + ClawHammer::create(); Mallet::create(); SledgeHammer::create(); From 6f580140f287b20c7ab34fab6b516251ddc24870 Mon Sep 17 00:00:00 2001 From: Anthony Clark Date: Fri, 28 Jul 2023 15:44:09 -0700 Subject: [PATCH 5/6] Update test matrix --- .github/workflows/tests.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f4a2df8..6849250 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,12 +9,14 @@ jobs: strategy: fail-fast: true matrix: - php: [8.0] - laravel: [9.*] + php: [8.0, 8.1, 8.2] + laravel: [9.*, 10.*] dependency-version: [prefer-stable] include: - laravel: 9.* testbench: 7.* + - laravel: 10.* + testbench: 8.* name: PHP ${{ matrix.php }} - LARAVEL ${{ matrix.laravel }} - ${{ matrix.dependency-version }} @@ -41,4 +43,4 @@ jobs: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute Tests - run: ./vendor/bin/phpunit --testdox \ No newline at end of file + run: ./vendor/bin/phpunit --testdox From 791142908482b6c367da5965589036f17749fcd7 Mon Sep 17 00:00:00 2001 From: Anthony Clark Date: Fri, 28 Jul 2023 15:48:22 -0700 Subject: [PATCH 6/6] Exclude Laravel 10 from php 8 --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6849250..3dd482b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,6 +17,9 @@ jobs: testbench: 7.* - laravel: 10.* testbench: 8.* + exclude: + - php: '8.0' + laravel: 10.* name: PHP ${{ matrix.php }} - LARAVEL ${{ matrix.laravel }} - ${{ matrix.dependency-version }}