diff --git a/Models/EmployeeHistory.php b/Models/EmployeeHistory.php index 48dffb2..9a61cdf 100755 --- a/Models/EmployeeHistory.php +++ b/Models/EmployeeHistory.php @@ -106,11 +106,11 @@ class EmployeeHistory implements \JsonSerializable, ArrayableInterface */ public function __construct($employee = 0) { - $this->employee = $employee; - $this->start = new \DateTime('now'); - $this->unit = new NullUnit(); + $this->employee = $employee; + $this->start = new \DateTime('now'); + $this->unit = new NullUnit(); $this->department = new NullDepartment(); - $this->position = new NullPosition(); + $this->position = new NullPosition(); } /** diff --git a/Models/EmployeeMapper.php b/Models/EmployeeMapper.php index 37bc65e..fd121d5 100755 --- a/Models/EmployeeMapper.php +++ b/Models/EmployeeMapper.php @@ -76,26 +76,26 @@ final class EmployeeMapper extends DataMapperFactory */ public const HAS_MANY = [ 'files' => [ - 'mapper' => MediaMapper::class, /* mapper of the related object */ + 'mapper' => MediaMapper::class, /* mapper of the related object */ 'table' => 'hr_staff_media', /* table of the related object, null if no relation table is used (many->1) */ 'external' => 'hr_staff_media_media', 'self' => 'hr_staff_media_item', ], 'companyHistory' => [ 'mapper' => EmployeeHistoryMapper::class, - 'table' => 'hr_staff_history', // @todo: is this requried? This is stored in the mapper already. In other places I'm not using this, either use it everywhere or nowhere. Using the mapper is slower but protects us from table name changes! + 'table' => 'hr_staff_history', 'self' => 'hr_staff_history_staff', 'external' => null, ], 'workHistory' => [ 'mapper' => EmployeeWorkHistoryMapper::class, - 'table' => 'hr_staff_work_history', // @todo: is this requried? This is stored in the mapper already. In other places I'm not using this, either use it everywhere or nowhere. Using the mapper is slower but protects us from table name changes! + 'table' => 'hr_staff_work_history', 'self' => 'hr_staff_work_history_staff', 'external' => null, ], 'educationHistory' => [ 'mapper' => EmployeeEducationHistoryMapper::class, - 'table' => 'hr_staff_education_history', // @todo: is this requried? This is stored in the mapper already. In other places I'm not using this, either use it everywhere or nowhere. Using the mapper is slower but protects us from table name changes! + 'table' => 'hr_staff_education_history', 'self' => 'hr_staff_education_history_staff', 'external' => null, ], @@ -116,21 +116,4 @@ final class EmployeeMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='hr_staff_id'; - - /** - * Get the employee from an account - * - * @param int $account Account to get the employee for - * - * @return ReadMapper - * - * @since 1.0.0 - */ - public static function getFromAccount(int $account) : ReadMapper - { - return self::get() - ->with('profile') - ->with('profile/account') - ->where('profile/account', $account); - } } diff --git a/tests/Models/EmployeeMapperTest.php b/tests/Models/EmployeeMapperTest.php index 74fc18b..0b77fcf 100755 --- a/tests/Models/EmployeeMapperTest.php +++ b/tests/Models/EmployeeMapperTest.php @@ -48,6 +48,6 @@ final class EmployeeMapperTest extends \PHPUnit\Framework\TestCase $employeeR = EmployeeMapper::get()->where('id', $employee->getId())->execute(); self::assertEquals($employee->profile->getId(), $employeeR->profile->getId()); - self::assertGreaterThan(0, EmployeeMapper::getFromAccount(1)->limit(1)->execute()->getId()); + self::assertGreaterThan(0, EmployeeMapper::get()->with('profile')->where('profile/account', 1)->limit(1)->execute()->getId()); } } diff --git a/tests/Models/EmplyeeHistoryTest.php b/tests/Models/EmplyeeHistoryTest.php index 4f651cc..c53dc0f 100755 --- a/tests/Models/EmplyeeHistoryTest.php +++ b/tests/Models/EmplyeeHistoryTest.php @@ -40,9 +40,9 @@ final class EmployeeHistoryTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $this->history->getId()); self::assertNull($this->history->end); self::assertEquals(0, $this->history->employee); - self::assertNull($this->history->position); - self::assertNull($this->history->unit); - self::assertNull($this->history->department); + self::assertInstanceOf('\Modules\Organization\Models\NullPosition', $this->history->position); + self::assertInstanceOf('\Modules\Organization\Models\NullUnit', $this->history->unit); + self::assertInstanceOf('\Modules\Organization\Models\NullDepartment', $this->history->department); self::assertInstanceOf('\DateTime', $this->history->start); } @@ -56,14 +56,14 @@ final class EmployeeHistoryTest extends \PHPUnit\Framework\TestCase $serialized = $this->history->jsonSerialize(); unset($serialized['start']); + unset($serialized['unit']); + unset($serialized['department']); + unset($serialized['position']); self::assertEquals( [ 'id' => 0, 'employee' => 2, - 'unit' => null, - 'department' => null, - 'position' => null, 'end' => null, ], $serialized