mirror of
https://github.com/Karaka-Management/oms-HumanResourceManagement.git
synced 2026-01-24 01:48:39 +00:00
add unit tests
This commit is contained in:
parent
a5bfe2fd67
commit
d0e973cb26
|
|
@ -269,13 +269,13 @@ final class ApiController extends Controller
|
|||
private function createEmployeeHistoryFromRequest(RequestAbstract $request) : EmployeeHistory
|
||||
{
|
||||
$history = new EmployeeHistory((int) ($request->getData('employee') ?? 0));
|
||||
$history->setUnit((int) ($request->getData('unit') ?? 0));
|
||||
$history->setDepartment((int) ($request->getData('department') ?? 0));
|
||||
$history->setPosition((int) ($request->getData('position') ?? 0));
|
||||
$history->setStart(new \DateTime($request->getData('start') ?? 'now'));
|
||||
$history->unit = (int) ($request->getData('unit') ?? 0);
|
||||
$history->department = (int) ($request->getData('department') ?? 0);
|
||||
$history->position = (int) ($request->getData('position') ?? 0);
|
||||
$history->start = new \DateTime($request->getData('start') ?? 'now');
|
||||
|
||||
if (!empty($request->getData('end'))) {
|
||||
$history->setEnd(new \DateTime($request->getData('end')));
|
||||
$history->end = new \DateTime($request->getData('end'));
|
||||
}
|
||||
|
||||
return $history;
|
||||
|
|
@ -343,7 +343,7 @@ final class ApiController extends Controller
|
|||
private function createEmployeeWorkHistoryFromRequest(RequestAbstract $request) : EmployeeWorkHistory
|
||||
{
|
||||
$history = new EmployeeWorkHistory((int) ($request->getData('employee') ?? 0));
|
||||
$history->setStart(new \DateTime($request->getData('start') ?? 'now'));
|
||||
$history->start = new \DateTime($request->getData('start') ?? 'now');
|
||||
$history->jobTitle = $request->getData('title');
|
||||
$history->address->name = $request->getData('name');
|
||||
$history->address->address = $request->getData('address') ?? '';
|
||||
|
|
@ -354,7 +354,7 @@ final class ApiController extends Controller
|
|||
$history->address->setType(AddressType::WORK);
|
||||
|
||||
if (!empty($request->getData('end'))) {
|
||||
$history->setEnd(new \DateTime($request->getData('end')));
|
||||
$history->end = new \DateTime($request->getData('end'));
|
||||
}
|
||||
|
||||
return $history;
|
||||
|
|
@ -422,7 +422,7 @@ final class ApiController extends Controller
|
|||
private function createEmployeeEducationHistoryFromRequest(RequestAbstract $request) : EmployeeEducationHistory
|
||||
{
|
||||
$history = new EmployeeEducationHistory((int) ($request->getData('employee') ?? 0));
|
||||
$history->setStart(new \DateTime($request->getData('start') ?? 'now'));
|
||||
$history->start = new \DateTime($request->getData('start') ?? 'now');
|
||||
$history->educationTitle = $request->getData('title');
|
||||
$history->score = $request->getData('score') ?? '';
|
||||
$history->passed = (bool) ($request->getData('passed') ?? true);
|
||||
|
|
@ -435,7 +435,7 @@ final class ApiController extends Controller
|
|||
$history->address->setType(AddressType::EDUCATION);
|
||||
|
||||
if (!empty($request->getData('end'))) {
|
||||
$history->setEnd(new \DateTime($request->getData('end')));
|
||||
$history->end = new \DateTime($request->getData('end'));
|
||||
}
|
||||
|
||||
return $history;
|
||||
|
|
|
|||
|
|
@ -202,6 +202,20 @@ class Employee implements \JsonSerializable, ArrayableInterface
|
|||
return empty($this->companyHistory) ? new NullEmployeeHistory() : \end($this->companyHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add company history to employee
|
||||
*
|
||||
* @param mixed $history Company history
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addEducationHistory($history) : void
|
||||
{
|
||||
$this->educationHistory[] = $history;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get employee company education history.
|
||||
*
|
||||
|
|
@ -226,6 +240,20 @@ class Employee implements \JsonSerializable, ArrayableInterface
|
|||
return empty($this->educationHistory) ? new NullEmployeeEducationHistory() : \end($this->educationHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add company history to employee
|
||||
*
|
||||
* @param mixed $history Company history
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addWorkHistory($history) : void
|
||||
{
|
||||
$this->workHistory[] = $history;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get employee company work.
|
||||
*
|
||||
|
|
@ -258,17 +286,12 @@ class Employee implements \JsonSerializable, ArrayableInterface
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'profile' => $this->profile,
|
||||
'history' => $this->companyHistory,
|
||||
'workHistory' => $this->workHistory,
|
||||
'educationHistory' => $this->educationHistory,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) \json_encode($this->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class EmployeeEducationHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var int|Employee
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $employee = 0;
|
||||
public $employee = 0;
|
||||
|
||||
public Address $address;
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ class EmployeeEducationHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var \DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private \DateTime $start;
|
||||
public \DateTime $start;
|
||||
|
||||
/**
|
||||
* End date
|
||||
|
|
@ -74,7 +74,7 @@ class EmployeeEducationHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var null|\DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?\DateTime $end = null;
|
||||
public ?\DateTime $end = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -102,70 +102,6 @@ class EmployeeEducationHistory implements \JsonSerializable, ArrayableInterface
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the employee this history belongs to
|
||||
*
|
||||
* @return int|Employee
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEmployee()
|
||||
{
|
||||
return empty($this->employee) ? new NullEmployee() : $this->employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start date
|
||||
*
|
||||
* @return \DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getStart() : \DateTime
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set start date
|
||||
*
|
||||
* @param \DateTime $start Start date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setStart(\DateTime $start) : void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get end date
|
||||
*
|
||||
* @return null|\DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEnd() : ?\DateTime
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set end date
|
||||
*
|
||||
* @param \DateTime $end End date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setEnd(\DateTime $end) : void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -174,19 +110,14 @@ class EmployeeEducationHistory implements \JsonSerializable, ArrayableInterface
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'employee' => !\is_int($this->employee) ? $this->employee->getId() : $this->employee,
|
||||
'educationTitle' => $this->educationTitle,
|
||||
'passed' => $this->passed,
|
||||
'score' => $this->score,
|
||||
'start' => $this->start,
|
||||
'end' => $this->end,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) \json_encode($this->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class EmployeeHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var \DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private \DateTime $start;
|
||||
public \DateTime $start;
|
||||
|
||||
/**
|
||||
* End date
|
||||
|
|
@ -95,7 +95,7 @@ class EmployeeHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var null|\DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?\DateTime $end = null;
|
||||
public ?\DateTime $end = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -122,148 +122,6 @@ class EmployeeHistory implements \JsonSerializable, ArrayableInterface
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the employee this history belongs to
|
||||
*
|
||||
* @return int|Employee
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEmployee()
|
||||
{
|
||||
return empty($this->employee) ? new NullEmployee() : $this->employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position
|
||||
*
|
||||
* @return int|Position
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return empty($this->position) ? new NullPosition() : $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position
|
||||
*
|
||||
* @param int|Position $position Position
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setPosition($position) : void
|
||||
{
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unit
|
||||
*
|
||||
* @return int|Unit
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getUnit()
|
||||
{
|
||||
return empty($this->unit) ? new NullUnit() : $this->unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the unit
|
||||
*
|
||||
* @param int|Unit $unit Unit
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setUnit($unit) : void
|
||||
{
|
||||
$this->unit = $unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the department
|
||||
*
|
||||
* @return int|Department
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getDepartment()
|
||||
{
|
||||
return empty($this->department) ? new NullDepartment() : $this->department;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the department
|
||||
*
|
||||
* @param int|Department $department Department
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setDepartment($department) : void
|
||||
{
|
||||
$this->department = $department;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start date
|
||||
*
|
||||
* @return \DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getStart() : \DateTime
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set start date
|
||||
*
|
||||
* @param \DateTime $start Start date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setStart(\DateTime $start) : void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get end date
|
||||
*
|
||||
* @return null|\DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEnd() : ?\DateTime
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set end date
|
||||
*
|
||||
* @param \DateTime $end End date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setEnd(\DateTime $end) : void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -280,14 +138,6 @@ class EmployeeHistory implements \JsonSerializable, ArrayableInterface
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) \json_encode($this->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class EmployeeWorkHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var int|Employee
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $employee = 0;
|
||||
public $employee = 0;
|
||||
|
||||
public Address $address;
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ class EmployeeWorkHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var \DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private \DateTime $start;
|
||||
public \DateTime $start;
|
||||
|
||||
/**
|
||||
* End date
|
||||
|
|
@ -70,7 +70,7 @@ class EmployeeWorkHistory implements \JsonSerializable, ArrayableInterface
|
|||
* @var null|\DateTime
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?\DateTime $end = null;
|
||||
public ?\DateTime $end = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -98,70 +98,6 @@ class EmployeeWorkHistory implements \JsonSerializable, ArrayableInterface
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the employee this history belongs to
|
||||
*
|
||||
* @return int|Employee
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEmployee()
|
||||
{
|
||||
return empty($this->employee) ? new NullEmployee() : $this->employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start date
|
||||
*
|
||||
* @return \DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getStart() : \DateTime
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set start date
|
||||
*
|
||||
* @param \DateTime $start Start date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setStart(\DateTime $start) : void
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get end date
|
||||
*
|
||||
* @return null|\DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEnd() : ?\DateTime
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set end date
|
||||
*
|
||||
* @param \DateTime $end End date
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setEnd(\DateTime $end) : void
|
||||
{
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -170,19 +106,12 @@ class EmployeeWorkHistory implements \JsonSerializable, ArrayableInterface
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'employee' => !\is_int($this->employee) ? $this->employee->getId() : $this->employee,
|
||||
'jobTitle' => $this->jobTitle,
|
||||
'start' => $this->start,
|
||||
'end' => $this->end,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) \json_encode($this->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,4 +24,16 @@ namespace Modules\HumanResourceManagement\Models;
|
|||
*/
|
||||
final class NullEmployeeEducationHistory extends EmployeeEducationHistory
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,16 @@ namespace Modules\HumanResourceManagement\Models;
|
|||
*/
|
||||
final class NullEmployeeHistory extends EmployeeHistory
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,16 @@ namespace Modules\HumanResourceManagement\Models;
|
|||
*/
|
||||
final class NullEmployeeWorkHistory extends EmployeeWorkHistory
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\HumanResourceManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
|
||||
/**
|
||||
* Staff list class.
|
||||
*
|
||||
* @package Modules\HumanResourceManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class StaffList
|
||||
{
|
||||
/**
|
||||
* Database instance.
|
||||
*
|
||||
* @var DatabasePool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private DatabasePool $dbPool;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param DatabasePool $dbPool Database pool instance
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(DatabasePool $dbPool)
|
||||
{
|
||||
$this->dbPool = $dbPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all staff members.
|
||||
*
|
||||
* This function gets all accounts in a range
|
||||
*
|
||||
* @param array $filter Filter for search results
|
||||
* @param int $offset Offset for first account
|
||||
* @param int $limit Limit for results
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getList($filter = null, $offset = 0, $limit = 100) : array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task stats.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getStats() : array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
374
tests/Controller/ApiControllerTest.php
Normal file
374
tests/Controller/ApiControllerTest.php
Normal file
|
|
@ -0,0 +1,374 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\tests\Controller;
|
||||
|
||||
use Model\CoreSettings;
|
||||
use Modules\Admin\Models\AccountPermission;
|
||||
use phpOMS\Account\Account;
|
||||
use phpOMS\Account\AccountManager;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
use phpOMS\Dispatcher\Dispatcher;
|
||||
use phpOMS\Event\EventManager;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\Module\ModuleManager;
|
||||
use phpOMS\Router\WebRouter;
|
||||
use phpOMS\Uri\HttpUri;
|
||||
use phpOMS\Utils\TestUtils;
|
||||
use phpOMS\Utils\RnG\DateTime;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use Modules\Organization\Models\Department;
|
||||
use Modules\Organization\Models\DepartmentMapper;
|
||||
use Modules\Organization\Models\NullDepartment;
|
||||
use Modules\Organization\Models\NullUnit;
|
||||
use Modules\Organization\Models\NullPosition;
|
||||
use Modules\Organization\Models\Position;
|
||||
use Modules\Organization\Models\PositionMapper;
|
||||
|
||||
/**
|
||||
* @testdox Modules\HumanResourceManagement\tests\Controller\ApiControllerTest: HumanResourceManagement api controller
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected ApplicationAbstract $app;
|
||||
|
||||
/**
|
||||
* @var \Modules\HumanResourceManagement\Controller\ApiController
|
||||
*/
|
||||
protected ModuleAbstract $module;
|
||||
|
||||
protected static int $employee = 0;
|
||||
|
||||
public static function setUpBeforeClass() : void
|
||||
{
|
||||
$department = new Department();
|
||||
$department->name = 'HRMgmtDepartmentTest';
|
||||
$department->description = 'Description';
|
||||
$department->unit = new NullUnit(1);
|
||||
DepartmentMapper::create($department);
|
||||
|
||||
$position = new Position();
|
||||
$position->name = 'HRMgmtPositionTest';
|
||||
$position->description = 'Description';
|
||||
PositionMapper::create($position);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->app = new class() extends ApplicationAbstract
|
||||
{
|
||||
protected string $appName = 'Api';
|
||||
};
|
||||
|
||||
$this->app->dbPool = $GLOBALS['dbpool'];
|
||||
$this->app->orgId = 1;
|
||||
$this->app->accountManager = new AccountManager($GLOBALS['session']);
|
||||
$this->app->appSettings = new CoreSettings();
|
||||
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
|
||||
$this->app->dispatcher = new Dispatcher($this->app);
|
||||
$this->app->eventManager = new EventManager($this->app->dispatcher);
|
||||
$this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php');
|
||||
$this->app->sessionManager = new HttpSession(36000);
|
||||
|
||||
$account = new Account();
|
||||
TestUtils::setMember($account, 'id', 1);
|
||||
|
||||
$permission = new AccountPermission();
|
||||
$permission->setUnit(1);
|
||||
$permission->setApp('api');
|
||||
$permission->setPermission(
|
||||
PermissionType::READ
|
||||
| PermissionType::CREATE
|
||||
| PermissionType::MODIFY
|
||||
| PermissionType::DELETE
|
||||
| PermissionType::PERMISSION
|
||||
);
|
||||
|
||||
$account->addPermission($permission);
|
||||
|
||||
$this->app->accountManager->add($account);
|
||||
$this->app->router = new WebRouter();
|
||||
|
||||
$this->module = $this->app->moduleManager->get('HumanResourceManagement');
|
||||
|
||||
TestUtils::setMember($this->module, 'app', $this->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeFromAccountCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('profiles', '1');
|
||||
|
||||
// can create multiple accounts if profiles is a list of ids e.g. 1,2,3
|
||||
$this->module->apiEmployeeCreate($request, $response);
|
||||
self::assertGreaterThan(0, self::$employee = $response->get('')['response'][0]->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testNewEmployeeCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('name1', 'NewEmployee');
|
||||
|
||||
$this->module->apiEmployeeCreate($request, $response);
|
||||
self::assertGreaterThan(0, self::$employee = $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiEmployeeCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiEmployeeCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeCreateFromAccountInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiEmployeeFromAccountCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testNewEmployeeCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiEmployeeNewCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEmployeeFromAccountCreate
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeHistoryCreate() : void
|
||||
{
|
||||
$start = DateTime::generateDateTime(
|
||||
(new \DateTime())->setTimestamp(\time() - \mt_rand(31622400 * 5, 31622400 * 10)),
|
||||
(new \DateTime())->setTimestamp(\time() - \mt_rand(31622400 * 1, 31622400 * 4))
|
||||
);
|
||||
|
||||
$end = DateTime::generateDateTime(
|
||||
$start,
|
||||
(new \DateTime())->setTimestamp($start->getTimestamp() + \mt_rand(1, 31622400))
|
||||
);
|
||||
|
||||
for ($i = 0; $i < 3; ++$i) {
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('employee', self::$employee);
|
||||
$request->setData('start', $start->format('Y-m-d'));
|
||||
$request->setData('end', $i + 1 < 3 ? $end->format('Y-m-d') : null);
|
||||
$request->setData('unit', 1);
|
||||
$request->setData('department', 1);
|
||||
$request->setData('position', 1);
|
||||
$this->module->apiEmployeeHistoryCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
|
||||
$start = clone $end;
|
||||
$end = DateTime::generateDateTime(
|
||||
$start,
|
||||
(new \DateTime())->setTimestamp($start->getTimestamp() + \mt_rand(1, 31622400))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeHistoryCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiEmployeeHistoryCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEmployeeFromAccountCreate
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeWorkHistoryCreate() : void
|
||||
{
|
||||
$start = DateTime::generateDateTime(
|
||||
(new \DateTime())->setTimestamp(\time() - \mt_rand(31622400 * 5, 31622400 * 10)),
|
||||
(new \DateTime())->setTimestamp(\time() - \mt_rand(31622400 * 1, 31622400 * 4))
|
||||
);
|
||||
|
||||
$end = DateTime::generateDateTime(
|
||||
$start,
|
||||
(new \DateTime())->setTimestamp($start->getTimestamp() + \mt_rand(1, 31622400))
|
||||
);
|
||||
|
||||
for ($i = 0; $i < 3; ++$i) {
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('employee', self::$employee);
|
||||
$request->setData('start', $start->format('Y-m-d'));
|
||||
$request->setData('end', $i + 1 < 3 ? $end->format('Y-m-d') : null);
|
||||
$request->setData('title', 'Title: ' . $i);
|
||||
$request->setData('name', 'Address Name');
|
||||
$request->setData('address', 'Some test address');
|
||||
$request->setData('postal', \str_pad((string) \mt_rand(1000, 99999), 5, '0', \STR_PAD_LEFT));
|
||||
$request->setData('city', 'TestCity');
|
||||
$request->setData('country', ISO3166TwoEnum::getRandom());
|
||||
$request->setData('state', '');
|
||||
|
||||
$this->module->apiEmployeeWorkHistoryCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
|
||||
$start = clone $end;
|
||||
$end = DateTime::generateDateTime(
|
||||
$start,
|
||||
(new \DateTime())->setTimestamp($start->getTimestamp() + \mt_rand(1, 31622400))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeWorkHistoryCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiEmployeeWorkHistoryCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEmployeeFromAccountCreate
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeEducationHistoryCreate() : void
|
||||
{
|
||||
$start = DateTime::generateDateTime(
|
||||
(new \DateTime())->setTimestamp(\time() - \mt_rand(31622400 * 5, 31622400 * 10)),
|
||||
(new \DateTime())->setTimestamp(\time() - \mt_rand(31622400 * 1, 31622400 * 4))
|
||||
);
|
||||
|
||||
$end = DateTime::generateDateTime(
|
||||
$start,
|
||||
(new \DateTime())->setTimestamp($start->getTimestamp() + \mt_rand(1, 31622400))
|
||||
);
|
||||
|
||||
for ($i = 0; $i < 3; ++$i) {
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('employee', self::$employee);
|
||||
$request->setData('start', $start->format('Y-m-d'));
|
||||
$request->setData('end', $i + 1 < 3 ? $end->format('Y-m-d') : null);
|
||||
$request->setData('title', 'Title: ' . $i);
|
||||
$request->setData('score', (string) \mt_rand(0, 100));
|
||||
$request->setData('name', 'Address Name');
|
||||
$request->setData('address', 'Some test address');
|
||||
$request->setData('postal', \str_pad((string) \mt_rand(1000, 99999), 5, '0', \STR_PAD_LEFT));
|
||||
$request->setData('city', 'TestCity');
|
||||
$request->setData('country', ISO3166TwoEnum::getRandom());
|
||||
$request->setData('state', '');
|
||||
|
||||
$this->module->apiEmployeeEducationHistoryCreate($request, $response);
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
|
||||
$start = clone $end;
|
||||
$end = DateTime::generateDateTime(
|
||||
$start,
|
||||
(new \DateTime())->setTimestamp($start->getTimestamp() + \mt_rand(1, 31622400))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testEmployeeEducationHistoryCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiEmployeeEducationHistoryCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
}
|
||||
75
tests/Models/EmployeeEducationHistoryTest.php
Normal file
75
tests/Models/EmployeeEducationHistoryTest.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\tests\Models;
|
||||
|
||||
use Modules\HumanResourceManagement\Models\EmployeeEducationHistory;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EmployeeEducationHistoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private EmployeeEducationHistory $history;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->history = new EmployeeEducationHistory();
|
||||
}
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\EmployeeEducationHistory
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->history->getId());
|
||||
self::assertNull($this->history->end);
|
||||
self::assertEquals(0, $this->history->employee);
|
||||
self::assertEquals('', $this->history->educationTitle);
|
||||
self::assertTrue($this->history->passed);
|
||||
self::assertEquals('', $this->history->score);
|
||||
self::assertInstanceOf('\DateTime', $this->history->start);
|
||||
self::assertInstanceOf('\Modules\Admin\Models\Address', $this->history->address);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\EmployeeEducationHistory
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->history->employee = 2;
|
||||
$this->history->educationTitle = 'title';
|
||||
$this->history->score = '69';
|
||||
$this->history->passed = false;
|
||||
|
||||
$serialized = $this->history->jsonSerialize();
|
||||
unset($serialized['start']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'employee' => 2,
|
||||
'educationTitle' => 'title',
|
||||
'passed' => false,
|
||||
'score' => '69',
|
||||
'end' => null,
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,6 @@ final class EmployeeHistoryMapperTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($id, $history->getId());
|
||||
|
||||
$historyR = EmployeeHistoryMapper::get($history->getId());
|
||||
self::assertEquals($history->getEmployee()->getId(), $historyR->getEmployee()->getId());
|
||||
self::assertEquals($history->employee->getId(), $historyR->employee->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,5 +48,6 @@ final class EmployeeMapperTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$employeeR = EmployeeMapper::get($employee->getId());
|
||||
self::assertEquals($employee->profile->getId(), $employeeR->profile->getId());
|
||||
self::assertGreaterThan(0, EmployeeMapper::getFromAccount(1)->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,28 +14,109 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\HumanResourceManagement\tests\Models;
|
||||
|
||||
use Modules\Profile\Models\Profile;
|
||||
use Modules\Profile\Models\NullProfile;
|
||||
use Modules\HumanResourceManagement\Models\Employee;
|
||||
use Modules\HumanResourceManagement\Models\EmployeeHistory;
|
||||
use Modules\HumanResourceManagement\Models\EmployeeWorkHistory;
|
||||
use Modules\HumanResourceManagement\Models\EmployeeEducationHistory;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EmployeeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private Employee $employee;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->employee = new Employee();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\Employee
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$employee = new Employee();
|
||||
self::assertEquals(0, $this->employee->getId());
|
||||
self::assertGreaterThan(0, \strlen($this->employee->getSemiPrivateHash()));
|
||||
self::assertFalse($this->employee->compareSemiPrivateHash('123'));
|
||||
self::assertInstanceOf('\Modules\Media\Models\NullMedia', $this->employee->image);
|
||||
self::assertInstanceOf('\Modules\HumanResourceManagement\Models\NullEmployeeHistory', $this->employee->getNewestHistory());
|
||||
self::assertEquals([], $this->employee->getHistory());
|
||||
self::assertEquals([], $this->employee->getEducationHistory());
|
||||
self::assertEquals([], $this->employee->getWorkHistory());
|
||||
}
|
||||
|
||||
self::assertEquals(0, $employee->getId());
|
||||
self::assertGreaterThan(0, \strlen($employee->getSemiPrivateHash()));
|
||||
self::assertFalse($employee->compareSemiPrivateHash('123'));
|
||||
self::assertInstanceOf('\Modules\Media\Models\NullMedia', $employee->image);
|
||||
self::assertInstanceOf('\Modules\HumanResourceManagement\Models\NullEmployeeHistory', $employee->getNewestHistory());
|
||||
self::assertEquals([], $employee->getHistory());
|
||||
self::assertEquals([], $employee->getEducationHistory());
|
||||
self::assertEquals([], $employee->getWorkHistory());
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\Employee
|
||||
* @group module
|
||||
*/
|
||||
public function testPrivateHashInputOutput() : void
|
||||
{
|
||||
$temp = $this->employee->getSemiPrivateHash();
|
||||
self::assertTrue($this->employee->compareSemiPrivateHash($temp));
|
||||
$this->employee->updateSemiPrivateHash();
|
||||
self::assertFalse($this->employee->compareSemiPrivateHash($temp));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\Employee
|
||||
* @group module
|
||||
*/
|
||||
public function testHistoryInputOutput() : void
|
||||
{
|
||||
$this->employee->addHistory($a = new EmployeeHistory());
|
||||
$this->employee->addHistory($b = new EmployeeHistory());
|
||||
self::assertCount(2, $this->employee->getHistory());
|
||||
self::assertEquals($b, $this->employee->getNewestHistory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\Employee
|
||||
* @group module
|
||||
*/
|
||||
public function testWorkHistoryInputOutput() : void
|
||||
{
|
||||
$this->employee->addWorkHistory($a = new EmployeeWorkHistory());
|
||||
$this->employee->addWorkHistory($b = new EmployeeWorkHistory());
|
||||
self::assertCount(2, $this->employee->getWorkHistory());
|
||||
self::assertEquals($b, $this->employee->getNewestWorkHistory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\Employee
|
||||
* @group module
|
||||
*/
|
||||
public function testEducationHistoryInputOutput() : void
|
||||
{
|
||||
$this->employee->addEducationHistory($a = new EmployeeEducationHistory());
|
||||
$this->employee->addEducationHistory($b = new EmployeeEducationHistory());
|
||||
self::assertCount(2, $this->employee->getEducationHistory());
|
||||
self::assertEquals($b, $this->employee->getNewestEducationHistory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\Employee
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$serialized = $this->employee->jsonSerialize();
|
||||
unset($serialized['profile']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'history' => [],
|
||||
'workHistory' => [],
|
||||
'educationHistory' => [],
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
69
tests/Models/EmployeeWorkHistoryTest.php
Normal file
69
tests/Models/EmployeeWorkHistoryTest.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\tests\Models;
|
||||
|
||||
use Modules\HumanResourceManagement\Models\EmployeeWorkHistory;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EmployeeWorkHistoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private EmployeeWorkHistory $history;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->history = new EmployeeWorkHistory();
|
||||
}
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\EmployeeWorkHistory
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals(0, $this->history->getId());
|
||||
self::assertNull($this->history->end);
|
||||
self::assertEquals(0, $this->history->employee);
|
||||
self::assertEquals('', $this->history->jobTitle);
|
||||
self::assertInstanceOf('\DateTime', $this->history->start);
|
||||
self::assertInstanceOf('\Modules\Admin\Models\Address', $this->history->address);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\EmployeeWorkHistory
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->history->employee = 2;
|
||||
$this->history->jobTitle = 'title';
|
||||
|
||||
$serialized = $this->history->jsonSerialize();
|
||||
unset($serialized['start']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'employee' => 2,
|
||||
'jobTitle' => 'title',
|
||||
'end' => null,
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -21,20 +21,51 @@ use Modules\HumanResourceManagement\Models\EmployeeHistory;
|
|||
*/
|
||||
final class EmployeeHistoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private EmployeeHistory $history;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->history = new EmployeeHistory();
|
||||
}
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\EmployeeHistory
|
||||
* @group module
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$history = new EmployeeHistory();
|
||||
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('\DateTime', $this->history->start);
|
||||
}
|
||||
|
||||
self::assertEquals(0, $history->getId());
|
||||
self::assertNull($history->getEnd());
|
||||
self::assertInstanceOf('\Modules\HumanResourceManagement\Models\NullEmployee', $history->getEmployee());
|
||||
self::assertInstanceOf('\Modules\Organization\Models\NullPosition', $history->getPosition());
|
||||
self::assertInstanceOf('\Modules\Organization\Models\NullUnit', $history->getUnit());
|
||||
self::assertInstanceOf('\Modules\Organization\Models\NullDepartment', $history->getDepartment());
|
||||
self::assertInstanceOf('\DateTime', $history->getStart());
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\EmployeeHistory
|
||||
* @group module
|
||||
*/
|
||||
public function testSerialize() : void
|
||||
{
|
||||
$this->history->employee = 2;
|
||||
|
||||
$serialized = $this->history->jsonSerialize();
|
||||
unset($serialized['start']);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
'id' => 0,
|
||||
'employee' => 2,
|
||||
'unit' => null,
|
||||
'department' => null,
|
||||
'position' => null,
|
||||
'end' => null,
|
||||
],
|
||||
$serialized
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
tests/Models/NullEmployeeEducationHistoryTest.php
Normal file
42
tests/Models/NullEmployeeEducationHistoryTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\tests\Models;
|
||||
|
||||
use Modules\HumanResourceManagement\Models\NullEmployeeEducationHistory;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullEmployeeEducationHistoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployeeEducationHistory
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\HumanResourceManagement\Models\EmployeeEducationHistory', new NullEmployeeEducationHistory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployeeEducationHistory
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullEmployeeEducationHistory(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullEmployeeHistoryTest.php
Normal file
42
tests/Models/NullEmployeeHistoryTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\tests\Models;
|
||||
|
||||
use Modules\HumanResourceManagement\Models\NullEmployeeHistory;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullEmployeeHistoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployeeHistory
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\HumanResourceManagement\Models\EmployeeHistory', new NullEmployeeHistory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployeeHistory
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullEmployeeHistory(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullEmployeeTest.php
Normal file
42
tests/Models/NullEmployeeTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\tests\Models;
|
||||
|
||||
use Modules\HumanResourceManagement\Models\NullEmployee;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullEmployeeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployee
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\HumanResourceManagement\Models\Employee', new NullEmployee());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployee
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullEmployee(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/NullEmployeeWorkHistoryTest.php
Normal file
42
tests/Models/NullEmployeeWorkHistoryTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\HumanResourceManagement\tests\Models;
|
||||
|
||||
use Modules\HumanResourceManagement\Models\NullEmployeeWorkHistory;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class NullEmployeeWorkHistoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployeeWorkHistory
|
||||
* @group framework
|
||||
*/
|
||||
public function testNull() : void
|
||||
{
|
||||
self::assertInstanceOf('\Modules\HumanResourceManagement\Models\EmployeeWorkHistory', new NullEmployeeWorkHistory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\HumanResourceManagement\Models\NullEmployeeWorkHistory
|
||||
* @group framework
|
||||
*/
|
||||
public function testId() : void
|
||||
{
|
||||
$null = new NullEmployeeWorkHistory(2);
|
||||
self::assertEquals(2, $null->getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" stopOnError="true" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="Bootstrap.php" colors="true" columns="120" stopOnError="true" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage includeUncoveredFiles="true" processUncoveredFiles="false">
|
||||
<exclude>
|
||||
<directory>*vendor*</directory>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user