monthly budget, monthly report, unified report calculation (#2684)
This commit is contained in:
@@ -20,12 +20,31 @@ abstract class AbstractTimesheetCountedStatisticTest extends TestCase
|
||||
self::assertSame(0.0, $sut->getRate());
|
||||
self::assertSame(0, $sut->getRecordDuration());
|
||||
self::assertSame(0, $sut->getDuration());
|
||||
self::assertSame(0, $sut->getRecordAmount());
|
||||
self::assertSame(0, $sut->getCounter());
|
||||
self::assertSame(0, $sut->getCounterBillable());
|
||||
self::assertSame(0.0, $sut->getRecordInternalRate());
|
||||
self::assertSame(0, $sut->getValue());
|
||||
self::assertSame(0, $sut->getDurationBillable());
|
||||
self::assertSame(0.0, $sut->getRateBillable());
|
||||
self::assertSame(0, $sut->getRecordAmountBillable());
|
||||
self::assertSame(0.0, $sut->getInternalRateBillable());
|
||||
|
||||
$json = $sut->jsonSerialize();
|
||||
|
||||
$expected = [
|
||||
'duration' => 0,
|
||||
'duration_billable' => 0,
|
||||
'rate' => 0.0,
|
||||
'rate_billable' => 0.0,
|
||||
'rate_internal' => 0.0,
|
||||
'amount' => 0,
|
||||
'amount_billable' => 0,
|
||||
];
|
||||
|
||||
foreach ($expected as $key => $value) {
|
||||
self::assertArrayHasKey($key, $json);
|
||||
self::assertSame($value, $json[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function assertSetter(TimesheetCountedStatistic $sut)
|
||||
@@ -33,23 +52,34 @@ abstract class AbstractTimesheetCountedStatisticTest extends TestCase
|
||||
self::assertInstanceOf(TimesheetCountedStatistic::class, $sut->setRecordRate(23.97));
|
||||
self::assertInstanceOf(TimesheetCountedStatistic::class, $sut->setRecordDuration(21));
|
||||
self::assertInstanceOf(TimesheetCountedStatistic::class, $sut->setRecordAmount(5));
|
||||
$sut->setRecordAmountBillable(15);
|
||||
self::assertInstanceOf(TimesheetCountedStatistic::class, $sut->setRecordInternalRate(99.09));
|
||||
|
||||
self::assertSame(23.97, $sut->getRecordRate());
|
||||
self::assertSame(23.97, $sut->getRate());
|
||||
self::assertSame(21, $sut->getRecordDuration());
|
||||
self::assertSame(21, $sut->getDuration());
|
||||
self::assertSame(21, $sut->getValue());
|
||||
self::assertSame(5, $sut->getRecordAmount());
|
||||
self::assertSame(15, $sut->getRecordAmountBillable());
|
||||
self::assertSame(99.09, $sut->getRecordInternalRate());
|
||||
|
||||
self::assertSame(21, $sut->getValue());
|
||||
|
||||
$sut->setCounter(524);
|
||||
$sut->setCounterBillable(198);
|
||||
$sut->setInternalRate(567.09);
|
||||
$sut->setRate(323.97);
|
||||
$sut->setDuration(22);
|
||||
$sut->setRateBillable(123.456);
|
||||
$sut->setDurationBillable(1234);
|
||||
$sut->setRecordAmountBillable(4321);
|
||||
$sut->setInternalRateBillable(987.12);
|
||||
|
||||
self::assertSame(524, $sut->getCounter());
|
||||
self::assertSame(198, $sut->getCounterBillable());
|
||||
self::assertSame(567.09, $sut->getInternalRate());
|
||||
self::assertSame(22, $sut->getDuration());
|
||||
self::assertSame(323.97, $sut->getRate());
|
||||
self::assertSame(123.456, $sut->getRateBillable());
|
||||
self::assertSame(1234, $sut->getDurationBillable());
|
||||
self::assertSame(4321, $sut->getRecordAmountBillable());
|
||||
self::assertSame(987.12, $sut->getInternalRateBillable());
|
||||
}
|
||||
|
||||
protected function assertJsonSerialize(TimesheetCountedStatistic $sut)
|
||||
|
||||
48
tests/Model/ActivityBudgetStatisticModelTest.php
Normal file
48
tests/Model/ActivityBudgetStatisticModelTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\EntityWithBudget;
|
||||
use App\Model\ActivityBudgetStatisticModel;
|
||||
use App\Model\BudgetStatisticModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\ActivityBudgetStatisticModel
|
||||
*/
|
||||
class ActivityBudgetStatisticModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param EntityWithBudget $entity
|
||||
* @return ActivityBudgetStatisticModel
|
||||
*/
|
||||
protected function getSut(EntityWithBudget $entity): BudgetStatisticModel
|
||||
{
|
||||
\assert($entity instanceof Activity);
|
||||
|
||||
return new ActivityBudgetStatisticModel($entity);
|
||||
}
|
||||
|
||||
protected function getEntity(): EntityWithBudget
|
||||
{
|
||||
return new Activity();
|
||||
}
|
||||
|
||||
public function testAdditionals()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$sut = $this->getSut($entity);
|
||||
|
||||
self::assertInstanceOf(Activity::class, $sut->getEntity());
|
||||
self::assertSame($entity, $sut->getEntity());
|
||||
self::assertSame($entity, $sut->getActivity());
|
||||
}
|
||||
}
|
||||
169
tests/Model/BudgetStatisticModelTest.php
Normal file
169
tests/Model/BudgetStatisticModelTest.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\EntityWithBudget;
|
||||
use App\Model\BudgetStatisticModel;
|
||||
use App\Model\Statistic\BudgetStatistic;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\BudgetStatisticModel
|
||||
*/
|
||||
class BudgetStatisticModelTest extends TestCase
|
||||
{
|
||||
protected function getSut(EntityWithBudget $entity): BudgetStatisticModel
|
||||
{
|
||||
return new BudgetStatisticModel($entity);
|
||||
}
|
||||
|
||||
protected function getEntity(): EntityWithBudget
|
||||
{
|
||||
return new Customer();
|
||||
}
|
||||
|
||||
public function testDefaults()
|
||||
{
|
||||
$this->assertDefaults();
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$this->assertSetter();
|
||||
}
|
||||
|
||||
public function testCalculation()
|
||||
{
|
||||
$this->assertCalculation();
|
||||
}
|
||||
|
||||
protected function assertCalculation()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$entity->setBudget(100.0);
|
||||
$entity->setTimeBudget(100);
|
||||
$entity->setBudgetType('month');
|
||||
$sut = $this->getSut($entity);
|
||||
|
||||
$statistic = new BudgetStatistic();
|
||||
$statistic->setInternalRate(147.95);
|
||||
$statistic->setRate(47.00);
|
||||
$statistic->setRateBillable(13.00);
|
||||
$statistic->setDuration(53);
|
||||
$statistic->setDurationBillable(23);
|
||||
$sut->setStatistic($statistic);
|
||||
|
||||
$statisticTotal = new BudgetStatistic();
|
||||
$statisticTotal->setInternalRate(247.95);
|
||||
$statisticTotal->setRate(247.00);
|
||||
$statisticTotal->setRateBillable(213.00);
|
||||
$statisticTotal->setDuration(253);
|
||||
$statisticTotal->setDurationBillable(223);
|
||||
$sut->setStatisticTotal($statisticTotal);
|
||||
|
||||
self::assertSame($entity, $sut->getEntity());
|
||||
self::assertSame(23, $sut->getDurationBillable());
|
||||
self::assertSame(53, $sut->getDuration());
|
||||
self::assertSame(13.00, $sut->getRateBillable());
|
||||
self::assertSame(47.00, $sut->getRate());
|
||||
self::assertSame(147.95, $sut->getInternalRate());
|
||||
|
||||
self::assertTrue($sut->isMonthlyBudget());
|
||||
|
||||
self::assertTrue($sut->hasTimeBudget());
|
||||
self::assertSame(100, $sut->getTimeBudget());
|
||||
self::assertSame(77, $sut->getTimeBudgetOpen());
|
||||
self::assertSame(23, $sut->getTimeBudgetSpent());
|
||||
|
||||
self::assertTrue($sut->hasBudget());
|
||||
self::assertSame(100.00, $sut->getBudget());
|
||||
self::assertSame(87.00, $sut->getBudgetOpen());
|
||||
self::assertSame(13.00, $sut->getBudgetSpent());
|
||||
|
||||
self::assertSame($statistic, $sut->getStatistic());
|
||||
self::assertSame($statisticTotal, $sut->getStatisticTotal());
|
||||
|
||||
$entity->setBudgetType(null);
|
||||
|
||||
self::assertSame(223, $sut->getDurationBillable());
|
||||
self::assertSame(253, $sut->getDuration());
|
||||
self::assertSame(213.00, $sut->getRateBillable());
|
||||
self::assertSame(247.00, $sut->getRate());
|
||||
self::assertSame(247.95, $sut->getInternalRate());
|
||||
|
||||
self::assertSame(100, $sut->getTimeBudget());
|
||||
self::assertSame(0, $sut->getTimeBudgetOpen());
|
||||
self::assertSame(223, $sut->getTimeBudgetSpent());
|
||||
|
||||
self::assertSame(100.00, $sut->getBudget());
|
||||
self::assertSame(0.00, $sut->getBudgetOpen());
|
||||
self::assertSame(213.00, $sut->getBudgetSpent());
|
||||
}
|
||||
|
||||
protected function assertSetter()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$entity->setBudget(10.0);
|
||||
$entity->setTimeBudget(10);
|
||||
$entity->setBudgetType('month');
|
||||
$sut = $this->getSut($entity);
|
||||
|
||||
self::assertSame($entity, $sut->getEntity());
|
||||
self::assertSame(0, $sut->getDurationBillable());
|
||||
self::assertSame(0, $sut->getDuration());
|
||||
self::assertSame(0.00, $sut->getRateBillable());
|
||||
self::assertSame(0.00, $sut->getRate());
|
||||
self::assertSame(0.00, $sut->getInternalRate());
|
||||
|
||||
self::assertTrue($sut->isMonthlyBudget());
|
||||
|
||||
self::assertTrue($sut->hasTimeBudget());
|
||||
self::assertSame(10, $sut->getTimeBudget());
|
||||
self::assertSame(10, $sut->getTimeBudgetOpen());
|
||||
self::assertSame(0, $sut->getTimeBudgetSpent());
|
||||
|
||||
self::assertTrue($sut->hasBudget());
|
||||
self::assertSame(10.00, $sut->getBudget());
|
||||
self::assertSame(10.00, $sut->getBudgetOpen());
|
||||
self::assertSame(0.00, $sut->getBudgetSpent());
|
||||
|
||||
self::assertNull($sut->getStatisticTotal());
|
||||
self::assertNull($sut->getStatistic());
|
||||
}
|
||||
|
||||
protected function assertDefaults()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$sut = $this->getSut($entity);
|
||||
|
||||
self::assertSame($entity, $sut->getEntity());
|
||||
self::assertSame(0, $sut->getDurationBillable());
|
||||
self::assertSame(0, $sut->getDuration());
|
||||
self::assertSame(0.00, $sut->getRateBillable());
|
||||
self::assertSame(0.00, $sut->getRate());
|
||||
self::assertSame(0.00, $sut->getInternalRate());
|
||||
|
||||
self::assertFalse($sut->isMonthlyBudget());
|
||||
|
||||
self::assertFalse($sut->hasTimeBudget());
|
||||
self::assertSame(0, $sut->getTimeBudget());
|
||||
self::assertSame(0, $sut->getTimeBudgetOpen());
|
||||
self::assertSame(0, $sut->getTimeBudgetSpent());
|
||||
|
||||
self::assertFalse($sut->hasBudget());
|
||||
self::assertSame(0.00, $sut->getBudget());
|
||||
self::assertSame(0.00, $sut->getBudgetOpen());
|
||||
self::assertSame(0.00, $sut->getBudgetSpent());
|
||||
|
||||
self::assertNull($sut->getStatisticTotal());
|
||||
self::assertNull($sut->getStatistic());
|
||||
}
|
||||
}
|
||||
48
tests/Model/CustomerBudgetStatisticModelTest.php
Normal file
48
tests/Model/CustomerBudgetStatisticModelTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\EntityWithBudget;
|
||||
use App\Model\BudgetStatisticModel;
|
||||
use App\Model\CustomerBudgetStatisticModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\CustomerBudgetStatisticModel
|
||||
*/
|
||||
class CustomerBudgetStatisticModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param EntityWithBudget $entity
|
||||
* @return CustomerBudgetStatisticModel
|
||||
*/
|
||||
protected function getSut(EntityWithBudget $entity): BudgetStatisticModel
|
||||
{
|
||||
\assert($entity instanceof Customer);
|
||||
|
||||
return new CustomerBudgetStatisticModel($entity);
|
||||
}
|
||||
|
||||
protected function getEntity(): EntityWithBudget
|
||||
{
|
||||
return new Customer();
|
||||
}
|
||||
|
||||
public function testAdditionals()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$sut = $this->getSut($entity);
|
||||
|
||||
self::assertInstanceOf(Customer::class, $sut->getEntity());
|
||||
self::assertSame($entity, $sut->getEntity());
|
||||
self::assertSame($entity, $sut->getCustomer());
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,9 @@ class CustomerStatisticTest extends AbstractTimesheetCountedStatisticTest
|
||||
$this->assertJsonSerialize(new CustomerStatistic());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testAdditionalSetter()
|
||||
{
|
||||
$sut = new CustomerStatistic();
|
||||
|
||||
69
tests/Model/DailyStatisticTest.php
Normal file
69
tests/Model/DailyStatisticTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Model\DailyStatistic;
|
||||
use App\Model\Statistic\StatisticDate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\DailyStatistic
|
||||
*/
|
||||
class DailyStatisticTest extends TestCase
|
||||
{
|
||||
public function testStatistic()
|
||||
{
|
||||
$begin = new \DateTime('2018-04-07 12:00:00');
|
||||
$end = new \DateTime('2018-04-13 18:00:00');
|
||||
$user = new User();
|
||||
$sut = new DailyStatistic($begin, $end, $user);
|
||||
|
||||
self::assertSame($user, $sut->getUser());
|
||||
$days = $sut->getDays();
|
||||
$dateTimes = $sut->getDateTimes();
|
||||
|
||||
self::assertCount(7, $days);
|
||||
self::assertCount(7, $dateTimes);
|
||||
|
||||
$expectedDateTimes = [
|
||||
new \DateTime('2018-04-07 00:00:00'),
|
||||
new \DateTime('2018-04-08 00:00:00'),
|
||||
new \DateTime('2018-04-09 00:00:00'),
|
||||
new \DateTime('2018-04-10 00:00:00'),
|
||||
new \DateTime('2018-04-11 00:00:00'),
|
||||
new \DateTime('2018-04-12 00:00:00'),
|
||||
new \DateTime('2018-04-13 00:00:00'),
|
||||
];
|
||||
|
||||
self::assertEquals($expectedDateTimes, $dateTimes);
|
||||
|
||||
foreach ($days as $day) {
|
||||
self::assertInstanceOf(StatisticDate::class, $day);
|
||||
}
|
||||
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getDayByDateTime(new \DateTime('2018-04-13 23:12:00')));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getDay('2018', '4', '13'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getDay('2018', '04', '13'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getDay('2018', '4', '7'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getDay('2018', '4', '07'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getDay('2018', '04', '7'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getDayByReportDate('2018-04-13'));
|
||||
|
||||
self::assertNull($sut->getDayByDateTime(new \DateTime('2018-04-06 23:59:59')));
|
||||
self::assertNull($sut->getDayByDateTime(new \DateTime('2018-04-14 00:00:00')));
|
||||
self::assertNull($sut->getDay('2018', '4', '06'));
|
||||
self::assertNull($sut->getDay('2018', '4', '6'));
|
||||
self::assertNull($sut->getDay('2018', '4', '14'));
|
||||
self::assertNull($sut->getDay('2018', '04', '14'));
|
||||
self::assertNull($sut->getDayByReportDate('2018-04-14'));
|
||||
self::assertNull($sut->getDayByReportDate('2018-4-14'));
|
||||
}
|
||||
}
|
||||
108
tests/Model/MonthlyStatisticTest.php
Normal file
108
tests/Model/MonthlyStatisticTest.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Model\MonthlyStatistic;
|
||||
use App\Model\Statistic\StatisticDate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\MonthlyStatistic
|
||||
*/
|
||||
class MonthlyStatisticTest extends TestCase
|
||||
{
|
||||
public function testStatistic()
|
||||
{
|
||||
$begin = new \DateTime('2017-04-07 12:00:00');
|
||||
$end = new \DateTime('2019-11-13 18:00:00');
|
||||
$user = new User();
|
||||
$sut = new MonthlyStatistic($begin, $end, $user);
|
||||
|
||||
self::assertSame($user, $sut->getUser());
|
||||
$years = $sut->getYears();
|
||||
$months = $sut->getMonths();
|
||||
$dateTimes = $sut->getDateTimes();
|
||||
|
||||
self::assertCount(32, $months);
|
||||
self::assertCount(32, $dateTimes);
|
||||
self::assertCount(3, $years);
|
||||
|
||||
$expectedDateTimes = [
|
||||
new \DateTime('2017-04-07 00:00:00'),
|
||||
new \DateTime('2017-05-07 00:00:00'),
|
||||
new \DateTime('2017-06-07 00:00:00'),
|
||||
new \DateTime('2017-07-07 00:00:00'),
|
||||
new \DateTime('2017-08-07 00:00:00'),
|
||||
new \DateTime('2017-09-07 00:00:00'),
|
||||
new \DateTime('2017-10-07 00:00:00'),
|
||||
new \DateTime('2017-11-07 00:00:00'),
|
||||
new \DateTime('2017-12-07 00:00:00'),
|
||||
new \DateTime('2018-01-07 00:00:00'),
|
||||
new \DateTime('2018-02-07 00:00:00'),
|
||||
new \DateTime('2018-03-07 00:00:00'),
|
||||
new \DateTime('2018-04-07 00:00:00'),
|
||||
new \DateTime('2018-05-07 00:00:00'),
|
||||
new \DateTime('2018-06-07 00:00:00'),
|
||||
new \DateTime('2018-07-07 00:00:00'),
|
||||
new \DateTime('2018-08-07 00:00:00'),
|
||||
new \DateTime('2018-09-07 00:00:00'),
|
||||
new \DateTime('2018-10-07 00:00:00'),
|
||||
new \DateTime('2018-11-07 00:00:00'),
|
||||
new \DateTime('2018-12-07 00:00:00'),
|
||||
new \DateTime('2019-01-07 00:00:00'),
|
||||
new \DateTime('2019-02-07 00:00:00'),
|
||||
new \DateTime('2019-03-07 00:00:00'),
|
||||
new \DateTime('2019-04-07 00:00:00'),
|
||||
new \DateTime('2019-05-07 00:00:00'),
|
||||
new \DateTime('2019-06-07 00:00:00'),
|
||||
new \DateTime('2019-07-07 00:00:00'),
|
||||
new \DateTime('2019-08-07 00:00:00'),
|
||||
new \DateTime('2019-09-07 00:00:00'),
|
||||
new \DateTime('2019-10-07 00:00:00'),
|
||||
new \DateTime('2019-11-07 00:00:00'),
|
||||
];
|
||||
|
||||
self::assertEquals($expectedDateTimes, $dateTimes);
|
||||
|
||||
$expectedYears = [
|
||||
'2017',
|
||||
'2018',
|
||||
'2019',
|
||||
];
|
||||
|
||||
self::assertEquals($expectedYears, $years);
|
||||
|
||||
foreach ($months as $month) {
|
||||
self::assertInstanceOf(StatisticDate::class, $month);
|
||||
}
|
||||
|
||||
$year = $sut->getYear('2017');
|
||||
self::assertCount(9, $year);
|
||||
foreach ($year as $month) {
|
||||
self::assertInstanceOf(StatisticDate::class, $month);
|
||||
}
|
||||
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getMonth('2017', '4'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getMonth('2019', '11'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getMonth('2018', '4'));
|
||||
self::assertInstanceOf(StatisticDate::class, $sut->getMonth('2018', '04'));
|
||||
|
||||
self::assertNull($sut->getYear('2016'));
|
||||
self::assertNull($sut->getYear('2020'));
|
||||
self::assertNull($sut->getMonth('2018', '14'));
|
||||
self::assertNull($sut->getMonth('2017', '14'));
|
||||
self::assertNull($sut->getMonth('2017', '3'));
|
||||
self::assertNull($sut->getMonth('2017', '03'));
|
||||
self::assertNull($sut->getMonth('2019', '12'));
|
||||
self::assertNull($sut->getMonth('2020', '1'));
|
||||
self::assertNull($sut->getMonth('2020', '01'));
|
||||
}
|
||||
}
|
||||
48
tests/Model/ProjectBudgetStatisticModelTest.php
Normal file
48
tests/Model/ProjectBudgetStatisticModelTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\EntityWithBudget;
|
||||
use App\Entity\Project;
|
||||
use App\Model\BudgetStatisticModel;
|
||||
use App\Model\ProjectBudgetStatisticModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\ProjectBudgetStatisticModel
|
||||
*/
|
||||
class ProjectBudgetStatisticModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param EntityWithBudget $entity
|
||||
* @return ProjectBudgetStatisticModel
|
||||
*/
|
||||
protected function getSut(EntityWithBudget $entity): BudgetStatisticModel
|
||||
{
|
||||
\assert($entity instanceof Project);
|
||||
|
||||
return new ProjectBudgetStatisticModel($entity);
|
||||
}
|
||||
|
||||
protected function getEntity(): EntityWithBudget
|
||||
{
|
||||
return new Project();
|
||||
}
|
||||
|
||||
public function testAdditionals()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$sut = $this->getSut($entity);
|
||||
|
||||
self::assertInstanceOf(Project::class, $sut->getEntity());
|
||||
self::assertSame($entity, $sut->getEntity());
|
||||
self::assertSame($entity, $sut->getProject());
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ class ProjectStatisticTest extends AbstractTimesheetCountedStatisticTest
|
||||
$this->assertJsonSerialize(new CustomerStatistic());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testAdditionalSetter()
|
||||
{
|
||||
$sut = new ProjectStatistic();
|
||||
|
||||
42
tests/Model/Statistic/AbstractTimesheetTest.php
Normal file
42
tests/Model/Statistic/AbstractTimesheetTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Timesheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class AbstractTimesheetTest extends TestCase
|
||||
{
|
||||
protected function assertDefaultValues(Timesheet $sut)
|
||||
{
|
||||
self::assertSame(0.0, $sut->getRate());
|
||||
self::assertSame(0, $sut->getDuration());
|
||||
self::assertSame(0, $sut->getValue());
|
||||
self::assertSame(0.0, $sut->getInternalRate());
|
||||
self::assertSame(0, $sut->getTotalDuration());
|
||||
self::assertSame(0.0, $sut->getTotalRate());
|
||||
self::assertSame(0.0, $sut->getTotalInternalRate());
|
||||
}
|
||||
|
||||
protected function assertSetter(Timesheet $sut)
|
||||
{
|
||||
$sut->setTotalInternalRate(5485.84);
|
||||
$sut->setTotalRate(1234.23);
|
||||
$sut->setTotalDuration(567);
|
||||
|
||||
self::assertSame(1234.23, $sut->getRate());
|
||||
self::assertSame(567, $sut->getDuration());
|
||||
self::assertSame(567, $sut->getValue());
|
||||
self::assertSame(5485.84, $sut->getInternalRate());
|
||||
self::assertSame(567, $sut->getTotalDuration());
|
||||
self::assertSame(1234.23, $sut->getTotalRate());
|
||||
self::assertSame(5485.84, $sut->getTotalInternalRate());
|
||||
}
|
||||
}
|
||||
34
tests/Model/Statistic/BudgetStatisticTest.php
Normal file
34
tests/Model/Statistic/BudgetStatisticTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\BudgetStatistic;
|
||||
use App\Tests\Model\AbstractTimesheetCountedStatisticTest;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\BudgetStatistic
|
||||
*/
|
||||
class BudgetStatisticTest extends AbstractTimesheetCountedStatisticTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$this->assertDefaultValues(new BudgetStatistic());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$this->assertSetter(new BudgetStatistic());
|
||||
}
|
||||
|
||||
public function testJsonSerialize()
|
||||
{
|
||||
$this->assertJsonSerialize(new BudgetStatistic());
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,26 @@ namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Day;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\Day
|
||||
*/
|
||||
class DayTest extends TestCase
|
||||
class DayTest extends AbstractTimesheetTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$date = new DateTime('-8 hours');
|
||||
$sut = new Day($date, 0, 0.0);
|
||||
$this->assertDefaultValues($sut);
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$date = new DateTime('-8 hours');
|
||||
$sut = new Day($date, 12340, 197.25956);
|
||||
$this->assertSetter($sut);
|
||||
}
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$date = new DateTime('-8 hours');
|
||||
|
||||
@@ -11,16 +11,17 @@ namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Month;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\Month
|
||||
*/
|
||||
class MonthTest extends TestCase
|
||||
class MonthTest extends AbstractTimesheetTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new Month('01');
|
||||
$this->assertDefaultValues($sut);
|
||||
|
||||
self::assertSame('01', $sut->getMonth());
|
||||
self::assertSame(0, $sut->getTotalDuration());
|
||||
self::assertSame(0.0, $sut->getTotalRate());
|
||||
@@ -88,6 +89,8 @@ class MonthTest extends TestCase
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new Month('01');
|
||||
$this->assertSetter($sut);
|
||||
|
||||
$sut->setTotalDuration(999);
|
||||
$sut->setTotalRate(0.123456789);
|
||||
$sut->setBillableDuration(123456);
|
||||
|
||||
49
tests/Model/Statistic/StatisticDateTest.php
Normal file
49
tests/Model/Statistic/StatisticDateTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\StatisticDate;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\StatisticDate
|
||||
*/
|
||||
class StatisticDateTest extends AbstractTimesheetTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$dateTime = new \DateTime('-8 hours');
|
||||
$sut = new StatisticDate($dateTime);
|
||||
$this->assertDefaultValues($sut);
|
||||
self::assertSame(0.0, $sut->getBillableRate());
|
||||
self::assertSame(0, $sut->getBillableDuration());
|
||||
self::assertNotSame($dateTime, $sut->getDate());
|
||||
self::assertEquals($dateTime->getTimestamp(), $sut->getDate()->getTimestamp());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$date = new DateTime('-8 hours');
|
||||
$sut = new StatisticDate($date);
|
||||
$this->assertSetter($sut);
|
||||
}
|
||||
|
||||
public function testAdditionalMethods()
|
||||
{
|
||||
$date = new DateTime('-8 hours');
|
||||
$sut = new StatisticDate($date);
|
||||
|
||||
$sut->setBillableRate(4869.38);
|
||||
self::assertSame(4869.38, $sut->getBillableRate());
|
||||
|
||||
$sut->setBillableDuration(512376);
|
||||
self::assertSame(512376, $sut->getBillableDuration());
|
||||
}
|
||||
}
|
||||
30
tests/Model/Statistic/TimesheetTest.php
Normal file
30
tests/Model/Statistic/TimesheetTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Timesheet;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\Timesheet
|
||||
*/
|
||||
class TimesheetTest extends AbstractTimesheetTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new Timesheet();
|
||||
$this->assertDefaultValues($sut);
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new Timesheet();
|
||||
$this->assertSetter($sut);
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,17 @@ namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Month;
|
||||
use App\Model\Statistic\Year;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\Year
|
||||
*/
|
||||
class YearTest extends TestCase
|
||||
class YearTest extends AbstractTimesheetTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new Year('1999');
|
||||
$this->assertDefaultValues($sut);
|
||||
|
||||
self::assertNull($sut->getMonth(1));
|
||||
self::assertEmpty($sut->getMonths());
|
||||
self::assertIsArray($sut->getMonths());
|
||||
@@ -30,6 +31,7 @@ class YearTest extends TestCase
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new Year('1999');
|
||||
$this->assertSetter($sut);
|
||||
|
||||
$sut->setMonth(new Month('01'));
|
||||
$sut->setMonth(new Month('02'));
|
||||
|
||||
@@ -10,29 +10,72 @@
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Model\ActivityStatistic;
|
||||
use App\Model\Statistic\Month;
|
||||
use App\Model\UserStatistic;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\UserStatistic
|
||||
*/
|
||||
class UserStatisticTest extends TestCase
|
||||
class UserStatisticTest extends AbstractTimesheetCountedStatisticTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
private function getSut(): UserStatistic
|
||||
{
|
||||
$user = new User();
|
||||
$sut = new UserStatistic($user);
|
||||
$this->assertEquals(0, $sut->getRecordRate());
|
||||
|
||||
return new UserStatistic($user);
|
||||
}
|
||||
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$this->assertDefaultValues($this->getSut());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new ActivityStatistic();
|
||||
$sut->setRecordAmount(7654);
|
||||
$sut->setRecordDuration(826);
|
||||
$this->assertSetter($this->getSut());
|
||||
}
|
||||
|
||||
$this->assertEquals(7654, $sut->getRecordAmount());
|
||||
$this->assertEquals(826, $sut->getRecordDuration());
|
||||
public function testJsonSerialize()
|
||||
{
|
||||
$this->assertJsonSerialize($this->getSut());
|
||||
}
|
||||
|
||||
public function testAdditionalValues()
|
||||
{
|
||||
$user = new User();
|
||||
$sut = new UserStatistic($user);
|
||||
|
||||
$this->assertSetter($sut);
|
||||
|
||||
self::assertSame(22, $sut->getDuration());
|
||||
self::assertSame(1234, $sut->getDurationBillable());
|
||||
self::assertSame(323.97, $sut->getRate());
|
||||
self::assertSame(123.456, $sut->getRateBillable());
|
||||
self::assertSame(567.09, $sut->getInternalRate());
|
||||
|
||||
$month = new Month('10');
|
||||
|
||||
$sut->addValuesFromMonth($month);
|
||||
|
||||
self::assertSame(22, $sut->getDuration());
|
||||
self::assertSame(1234, $sut->getDurationBillable());
|
||||
self::assertSame(323.97, $sut->getRate());
|
||||
self::assertSame(123.456, $sut->getRateBillable());
|
||||
self::assertSame(567.09, $sut->getInternalRate());
|
||||
|
||||
$month = new Month('10');
|
||||
$month->setTotalDuration(123);
|
||||
$month->setBillableDuration(234);
|
||||
$month->setTotalRate(345.67);
|
||||
$month->setBillableRate(456.78);
|
||||
$month->setTotalInternalRate(567.89);
|
||||
|
||||
$sut->addValuesFromMonth($month);
|
||||
|
||||
self::assertSame(145, $sut->getDuration());
|
||||
self::assertSame(1468, $sut->getDurationBillable());
|
||||
self::assertSame(669.64, $sut->getRate());
|
||||
self::assertSame(580.236, $sut->getRateBillable());
|
||||
self::assertSame(1134.98, $sut->getInternalRate());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user