diff --git a/src/Member.php b/src/Member.php index 05e9203..b0bd721 100644 --- a/src/Member.php +++ b/src/Member.php @@ -38,6 +38,10 @@ class Member extends Model { 'eintrittsdatum' => 'joined_at', ]; + protected $casts = []; + + protected $nullable = ['further_address', 'other_country', 'nickname']; + protected $guarded = []; public static function fromNami($item) { @@ -59,7 +63,11 @@ class Member extends Model { } public function getJoinedAtAttribute() { - return Carbon::parse($this->attributes['joined_at'])->format('Y-m-d'); + $date = $this->attributes['joined_at']; + + return empty($date) + ? null + : Carbon::parse($date)->format('Y-m-d'); } public function getGenderIdAttribute() { @@ -70,4 +78,14 @@ class Member extends Model { $this->attributes['gender_id'] = data_get($this->geschlechtMaps, $v, null); } + public function getAttributeValue($key) { + $original = parent::getAttributeValue($key); + + if (in_array($key, $this->nullable) && $original === '') { + return null; + } + + return $original; + } + } diff --git a/tests/Unit/PullMemberTest.php b/tests/Unit/PullMemberTest.php index c59219f..3ed575c 100644 --- a/tests/Unit/PullMemberTest.php +++ b/tests/Unit/PullMemberTest.php @@ -23,7 +23,7 @@ class PullMemberTest extends TestCase 'other_country' => ['other_country', ['deutsch', null]], 'address' => ['address', ['straße 1', 'straße 2']], 'further_address' => ['further_address', ['addrz', null]], - 'zip' => ['zip', [12345, 5555]], + 'zip' => ['zip', ['12345', '5555']], 'location' => ['location', ['SG', 'Köln']], 'main_phone' => ['main_phone', ['+49888', '+49668']], 'mobile_phone' => ['mobile_phone', ['+49176', '+49172']], @@ -35,7 +35,7 @@ class PullMemberTest extends TestCase 'nationality_id' => ['nationality_id', [1054, null]], 'confession_id' => ['confession_id', [1, null]], 'birthday' => ['birthday', ['1991-06-20', '1984-01-17']], - 'joined_at' => ['joined_at', ['2005-05-01', '2003-11-17']], + 'joined_at' => ['joined_at', ['2005-05-01', null]], ]; } @@ -53,7 +53,7 @@ class PullMemberTest extends TestCase 'email_parents' => ['email_parents', ['testp@example.com', 'test2p@example.com']], 'gender_id' => ['gender_id', [19, null]], 'birthday' => ['birthday', ['1991-06-20', '1984-01-17']], - 'joined_at' => ['joined_at', ['2005-05-01', '2003-11-17']], + 'joined_at' => ['joined_at', ['2005-05-01', null]], ]; } @@ -79,8 +79,8 @@ class PullMemberTest extends TestCase $group = Nami::group(103); - $this->assertEquals($values[0], $group->member(16)->{$key}); - $this->assertEquals($values[1], $group->member(17)->{$key}); + $this->assertSame($values[0], $group->member(16)->{$key}); + $this->assertSame($values[1], $group->member(17)->{$key}); Http::assertSentCount(5); } @@ -100,7 +100,7 @@ class PullMemberTest extends TestCase Nami::login(); - $this->assertEquals([ + $this->assertSame([ 16 => $values[0], 17 => $values[1] ], Nami::group(103)->members()->pluck($key, 'id')->toArray()); @@ -123,7 +123,7 @@ class PullMemberTest extends TestCase Nami::login(); - $this->assertEquals([ + $this->assertSame([ 16 => $values[0], 17 => $values[1] ], Nami::group(103)->members()->pluck($key, 'id')->toArray()); @@ -147,7 +147,7 @@ class PullMemberTest extends TestCase $group = Nami::group(103); - $this->assertEquals($values[0], $group->member(16)->{$key}); + $this->assertSame($values[0], $group->member(16)->{$key}); Http::assertSentCount(5); } diff --git a/tests/json/member-17.json b/tests/json/member-17.json index 1dce126..078545f 100644 --- a/tests/json/member-17.json +++ b/tests/json/member-17.json @@ -24,7 +24,7 @@ "mglTypeId": "MITGLIED", "beitragsart": "Voller Beitrag", "nachname": "Nach2", - "eintrittsdatum": "2003-11-17 00:00:00", + "eintrittsdatum": "", "rover": null, "region": "Nordrhein-Westfalen (Deutschland)", "status": "Aktiv", diff --git a/tests/json/member_overview.json b/tests/json/member_overview.json index c46ac9c..41c5e20 100644 --- a/tests/json/member_overview.json +++ b/tests/json/member_overview.json @@ -37,7 +37,7 @@ "entries_geburtsDatum":"1991-06-20 00:00:00", "entries_staatangehoerigkeitText":"deutsch", "entries_nachname":"Nach1", - "entries_eintrittsdatum":"2005-05-01 00:00:00", + "entries_eintrittsdatum":"2005-05-01", "entries_austrittsDatum":"", "entries_genericField2":"", "entries_telefax":"+55111"