diff --git a/tests/DetectsEnumVersion.php b/tests/DetectsEnumVersion.php index 5862707..c613159 100644 --- a/tests/DetectsEnumVersion.php +++ b/tests/DetectsEnumVersion.php @@ -20,6 +20,10 @@ trait DetectsEnumVersion { private function getEnumVersion(): string { + if (method_exists(Enum::class, 'hasNot')) { + return '4.0.0'; + } + return defined(Enum::class . '::__DEFAULT') ? '3.0.0' : '2.3.0'; } diff --git a/tests/EnumAccessorTest.php b/tests/EnumAccessorTest.php index 021c272..a0d981d 100644 --- a/tests/EnumAccessorTest.php +++ b/tests/EnumAccessorTest.php @@ -14,6 +14,7 @@ namespace Konekt\Enum\Eloquent\Tests; +use Konekt\Enum\Eloquent\Tests\Models\BillingRule; use Konekt\Enum\Eloquent\Tests\Models\Client; use Konekt\Enum\Eloquent\Tests\Models\Order; use Konekt\Enum\Eloquent\Tests\Models\OrderStatus; @@ -140,4 +141,22 @@ public function it_doesnt_break_related_properties() $this->assertInstanceOf(Client::class, $order->client); $this->assertEquals($client->id, $order->client->id); } + + /** @test */ + public function it_works_with_integer_database_fields() + { + $clientAny = Client::create(['name' => 'Pawel Jedrzejewsky']); + $clientInvoiceOnly = Client::create(['name' => 'Pawel Jedrzejewsky', 'billing_rule' => 1]); + $clientNoInvoice = Client::create(['name' => 'Pawel Jedrzejewsky', 'billing_rule' => 0]); + + $this->assertInstanceOf(BillingRule::class, $clientAny->billing_rule); + $this->assertNull($clientAny->billing_rule->value()); + + $this->assertInstanceOf(BillingRule::class, $clientInvoiceOnly->billing_rule); + $this->assertEquals(1, $clientInvoiceOnly->billing_rule->value()); + + $this->assertInstanceOf(BillingRule::class, $clientNoInvoice->billing_rule); + $this->assertEquals(0, $clientNoInvoice->billing_rule->value()); + + } } diff --git a/tests/Models/BillingRule.php b/tests/Models/BillingRule.php new file mode 100644 index 0000000..861538f --- /dev/null +++ b/tests/Models/BillingRule.php @@ -0,0 +1,25 @@ + BillingRule::class, + ]; } diff --git a/tests/TestCase.php b/tests/TestCase.php index 5f7278b..f402397 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -58,6 +58,7 @@ protected function setUpDatabase() $this->capsule->schema()->create('clients', function (Blueprint $table) { $table->increments('id'); $table->string('name'); + $table->integer('billing_rule')->nullable(); $table->timestamps(); });