mirror of
https://github.com/Karaka-Management/oms-HumanResourceTimeRecording.git
synced 2026-02-06 16:08:41 +00:00
add tests
This commit is contained in:
parent
f32340303e
commit
b17058c20d
26
tests/Admin/AdminTest.php
Normal file
26
tests/Admin/AdminTest.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\HumanResourceTimeRecording\Admin;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class AdminTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected const MODULE_NAME = 'HumanResourceTimeRecording';
|
||||
protected const URI_LOAD = '';
|
||||
|
||||
use \Modules\tests\ModuleTestTrait;
|
||||
}
|
||||
39
tests/Models/SessionElementMapperTest.php
Normal file
39
tests/Models/SessionElementMapperTest.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\HumanResourceTimeRecording\Models;
|
||||
|
||||
use Modules\HumanResourceTimeRecording\Models\Session;
|
||||
use Modules\HumanResourceTimeRecording\Models\SessionElement;
|
||||
use Modules\HumanResourceTimeRecording\Models\SessionElementMapper;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class SessionElementMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testCRUD() : void
|
||||
{
|
||||
$element = new SessionElement(new Session(1), new \DateTime('now'));
|
||||
|
||||
$id = SessionElementMapper::create($element);
|
||||
self::assertGreaterThan(0, $element->getId());
|
||||
self::assertEquals($id, $element->getId());
|
||||
|
||||
$elementR = SessionElementMapper::get($element->getId());
|
||||
self::assertEquals($element->getDatetime()->format('Y-m-d'), $elementR->getDatetime()->format('Y-m-d'));
|
||||
self::assertEquals($element->getStatus(), $elementR->getStatus());
|
||||
self::assertEquals($element->getSession()->getEmployee(), $elementR->getSession()->getEmployee()->getId());
|
||||
}
|
||||
}
|
||||
42
tests/Models/SessionElementTest.php
Normal file
42
tests/Models/SessionElementTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\HumanResourceTimeRecording\Models;
|
||||
|
||||
use Modules\HumanResourceTimeRecording\Models\ClockingStatus;
|
||||
use Modules\HumanResourceTimeRecording\Models\SessionElement;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class SessionElementTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDefault() : void
|
||||
{
|
||||
$element = new SessionElement();
|
||||
|
||||
self::assertEquals(0, $element->getId());
|
||||
self::assertEquals(0, $element->getSession());
|
||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $element->getDatetime()->format('Y-m-d'));
|
||||
self::assertEquals(ClockingStatus::START, $element->getStatus());
|
||||
}
|
||||
|
||||
public function testSetGet() : void
|
||||
{
|
||||
$element = new SessionElement();
|
||||
|
||||
$element->setStatus(ClockingStatus::END);
|
||||
self::assertEquals(ClockingStatus::END, $element->getStatus());
|
||||
}
|
||||
}
|
||||
103
tests/Models/SessionMapperTest.php
Normal file
103
tests/Models/SessionMapperTest.php
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\HumanResourceTimeRecording\Models;
|
||||
|
||||
use Modules\HumanResourceTimeRecording\Models\ClockingStatus;
|
||||
use Modules\HumanResourceTimeRecording\Models\Session;
|
||||
use Modules\HumanResourceTimeRecording\Models\SessionElement;
|
||||
use Modules\HumanResourceTimeRecording\Models\SessionMapper;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class SessionMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Modules\HumanResourceTimeRecording\Models\SessionMapper
|
||||
* @group module
|
||||
*/
|
||||
public function testCRUD() : void
|
||||
{
|
||||
$session = new Session(1);
|
||||
|
||||
$dt = new \DateTime(\date('Y-m-d', \strtotime('now')) . ' 7:55:34');
|
||||
$element = new SessionElement($session, $dt);
|
||||
$element->setStatus(ClockingStatus::START);
|
||||
$session->addSessionElement($element);
|
||||
|
||||
$id = SessionMapper::create($session);
|
||||
self::assertGreaterThan(0, $session->getId());
|
||||
self::assertEquals($id, $session->getId());
|
||||
|
||||
$sessionR = SessionMapper::get($session->getId());
|
||||
self::assertEquals($session->getType(), $sessionR->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group volume
|
||||
* @group module
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testVolume() : void
|
||||
{
|
||||
for ($i = 0; $i < 1000; ++$i) {
|
||||
$day = \date('Y-m-d', \strtotime(' -' . ($i + 1) . ' day'));
|
||||
$weekday = \date('D', \strtotime($day));
|
||||
|
||||
if ($weekday === 'Sat' || $weekday === 'Sun') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$session = new Session(1);
|
||||
|
||||
$hourStart = \mt_rand(7, 9);
|
||||
$minutesStart = \mt_rand(0, 59);
|
||||
|
||||
$hourEnd = \mt_rand(16, 18);
|
||||
$minutesEnd = \mt_rand(0, 59);
|
||||
|
||||
$hourBreakStart = \mt_rand(11, 14);
|
||||
$minutesBreakStart = \mt_rand(0, 59);
|
||||
|
||||
$breakLength = \mt_rand(5, 90);
|
||||
|
||||
// start
|
||||
$dt = new \DateTime($day . ' ' . $hourStart . ':' . $minutesStart);
|
||||
$element = new SessionElement($session, $dt);
|
||||
$element->setStatus(ClockingStatus::START);
|
||||
$session->addSessionElement($element);
|
||||
|
||||
// break start
|
||||
$dt = new \DateTime($day . ' ' . $hourBreakStart . ':' . $minutesBreakStart);
|
||||
$element = new SessionElement($session, $dt);
|
||||
$element->setStatus(ClockingStatus::PAUSE);
|
||||
$session->addSessionElement($element);
|
||||
|
||||
// work continue
|
||||
$dt = new \DateTime($day . ' ' . ($hourBreakStart + ((int) (($minutesBreakStart + $breakLength) / 60))) . ':' . (($minutesBreakStart + $breakLength) % 60));
|
||||
$element = new SessionElement($session, $dt);
|
||||
$element->setStatus(ClockingStatus::CONTINUE);
|
||||
$session->addSessionElement($element);
|
||||
|
||||
// end
|
||||
$dt = new \DateTime($day . ' ' . $hourEnd . ':' . $minutesEnd);
|
||||
$element = new SessionElement($session, $dt);
|
||||
$element->setStatus(ClockingStatus::END);
|
||||
$session->addSessionElement($element);
|
||||
|
||||
SessionMapper::create($session);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
tests/Models/SessionTest.php
Normal file
52
tests/Models/SessionTest.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @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\tests\HumanResourceTimeRecording\Models;
|
||||
|
||||
use Modules\HumanResourceTimeRecording\Models\ClockingStatus;
|
||||
use Modules\HumanResourceTimeRecording\Models\ClockingType;
|
||||
use Modules\HumanResourceTimeRecording\Models\Session;
|
||||
use Modules\HumanResourceTimeRecording\Models\SessionElement;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class SessionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDefault() : void
|
||||
{
|
||||
$session = new Session();
|
||||
|
||||
self::assertEquals(0, $session->getId());
|
||||
self::assertEquals(0, $session->getBusy());
|
||||
self::assertEquals(ClockingType::OFFICE, $session->getType());
|
||||
self::assertEquals(ClockingStatus::START, $session->getStatus());
|
||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $session->getStart()->format('Y-m-d'));
|
||||
self::assertNull($session->getEnd());
|
||||
}
|
||||
|
||||
public function testSetGet() : void
|
||||
{
|
||||
$session = new Session();
|
||||
|
||||
$session->setType(ClockingType::VACATION);
|
||||
self::assertEquals(ClockingType::VACATION, $session->getType());
|
||||
|
||||
$element = new SessionElement(0, new \DateTime('now'));
|
||||
$element->setStatus(ClockingStatus::PAUSE);
|
||||
$session->addSessionElement($element);
|
||||
|
||||
self::assertEquals(ClockingStatus::PAUSE, $session->getStatus());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user