From d07a9fe20469567f9553665ea010bbd5dee507eb Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 8 May 2024 11:55:51 -0400 Subject: [PATCH 1/2] Properly convert string based LDAP booleans --- src/Models/Concerns/HasAttributes.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Models/Concerns/HasAttributes.php b/src/Models/Concerns/HasAttributes.php index 3423c50f..a34d7dd1 100644 --- a/src/Models/Concerns/HasAttributes.php +++ b/src/Models/Concerns/HasAttributes.php @@ -578,8 +578,12 @@ protected function asBoolean(mixed $value): bool /** * Cast the value from a primitive boolean to an LDAP boolean string. */ - protected function fromBoolean(bool $value): string + protected function fromBoolean(mixed $value): string { + if (is_string($value)) { + $value = $this->asBoolean($value); + } + return $value ? 'TRUE' : 'FALSE'; } From 7b785db58847e6fd501abc6be7c6e174b4390571 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 8 May 2024 11:55:54 -0400 Subject: [PATCH 2/2] Add test --- tests/Unit/Models/ModelAttributeCastTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Unit/Models/ModelAttributeCastTest.php b/tests/Unit/Models/ModelAttributeCastTest.php index c19e1fc2..c3bd6cc4 100644 --- a/tests/Unit/Models/ModelAttributeCastTest.php +++ b/tests/Unit/Models/ModelAttributeCastTest.php @@ -28,6 +28,10 @@ public function test_boolean_attributes_are_casted() $this->assertTrue($model->booleanAttribute); $this->assertEquals($model->getRawAttribute('booleanAttribute'), ['TRUE']); + $model->booleanAttribute = 'false'; + $this->assertFalse($model->booleanAttribute); + $this->assertEquals($model->getRawAttribute('booleanAttribute'), ['FALSE']); + // Casing differences $model = (new ModelCastStub)->setRawAttributes(['boolAttribute' => ['true']]);