diff --git a/app/User.php b/app/User.php index 5cf5b62..fb18e7a 100644 --- a/app/User.php +++ b/app/User.php @@ -232,27 +232,27 @@ class User extends Authenticatable return $this->hasMany(Couple::class, 'manager_id'); } - public function getAgeAttribute() + public function getAgeDetailAttribute() { - $age = null; + $ageDetail = null; $yearOnlySuffix = Carbon::now()->format('-m-d'); if ($this->dob && !$this->dod) { - $age = Carbon::parse($this->dob)->timespan(); + $ageDetail = Carbon::parse($this->dob)->timespan(); } if (!$this->dob && $this->yob) { - $age = Carbon::parse($this->yob.$yearOnlySuffix)->timespan(); + $ageDetail = Carbon::parse($this->yob.$yearOnlySuffix)->timespan(); } if ($this->dob && $this->dod) { - $age = Carbon::parse($this->dob)->timespan($this->dod); + $ageDetail = Carbon::parse($this->dob)->timespan($this->dod); } if (!$this->dob && $this->yob && !$this->dod && $this->yod) { - $age = Carbon::parse($this->yob.$yearOnlySuffix)->timespan($this->yod.$yearOnlySuffix); + $ageDetail = Carbon::parse($this->yob.$yearOnlySuffix)->timespan($this->yod.$yearOnlySuffix); } if ($this->dob && $this->yob && $this->dod && $this->yod) { - $age = Carbon::parse($this->dob)->timespan($this->dod); + $ageDetail = Carbon::parse($this->dob)->timespan($this->dod); } - return $age; + return $ageDetail; } } diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index 212bb7b..34b3e07 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -149,27 +149,27 @@ class UserTest extends TestCase /** * @test - * @dataProvider userAgeDataProvider + * @dataProvider userAgeDetailDataProvider */ - public function user_has_age_attribute($today, $dob, $yob, $dod, $yod, $age) + public function user_has_age_detail_attribute($today, $dob, $yob, $dod, $yod, $age) { Carbon::setTestNow($today); $user = factory(User::class)->make([ 'dob' => $dob, 'yob' => $yob, 'dod' => $dod, 'yod' => $yod, ]); - $this->assertEquals($age, $user->age); + $this->assertEquals($age, $user->age_detail); Carbon::setTestNow(); } /** - * Provide data for calculating user age. + * Provide data for calculating user age detail. * Returning array of today, dob, yob, dod, yod, and age. * * @return array */ - public function userAgeDataProvider() + public function userAgeDetailDataProvider() { return [ ['2018-02-02', '1997-01-01', '1997', null, null, '21 tahun, 1 bulan, 1 hari'],