added explicit classes for widgets (#3170)

This commit is contained in:
Kevin Papst
2022-02-22 21:15:19 +01:00
committed by GitHub
parent 3d3ae97af4
commit c8b47d1033
30 changed files with 1187 additions and 94 deletions

View 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\Event;
use Symfony\Contracts\EventDispatcher\Event;
/**
* Used to display the full revenue information for a certain date-range.
*/
final class RevenueStatisticEvent extends Event
{
private $begin;
private $end;
private $revenue = 0.0;
public function __construct(?\DateTime $begin, ?\DateTime $end)
{
$this->begin = $begin;
$this->end = $end;
}
public function getBegin(): ?\DateTime
{
return $this->begin;
}
public function getEnd(): ?\DateTime
{
return $this->end;
}
public function getRevenue(): float
{
return $this->revenue;
}
public function addRevenue(float $revenue): void
{
$this->revenue += $revenue;
}
}

View File

@@ -0,0 +1,53 @@
<?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\Event;
use App\Entity\User;
use Symfony\Contracts\EventDispatcher\Event;
/**
* Used to display the full revenue information for a certain date-range and user.
*/
final class UserRevenueStatisticEvent extends Event
{
private $event;
private $user;
public function __construct(User $user, ?\DateTime $begin, ?\DateTime $end)
{
$this->user = $user;
$this->event = new RevenueStatisticEvent($begin, $end);
}
public function getBegin(): ?\DateTime
{
return $this->event->getBegin();
}
public function getEnd(): ?\DateTime
{
return $this->event->getEnd();
}
public function getRevenue(): float
{
return $this->event->getRevenue();
}
public function addRevenue(float $revenue): void
{
$this->event->addRevenue($revenue);
}
public function getUser(): User
{
return $this->user;
}
}

View File

@@ -181,44 +181,6 @@ class WidgetRepository
'color' => 'red',
'type' => Counter::class,
],
'userAmountToday' => [
'title' => 'stats.amountToday',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'user' => true,
'begin' => '00:00:00',
'end' => '23:59:59',
'icon' => 'money',
'color' => 'green',
'type' => Counter::class,
],
'userAmountWeek' => [
'title' => 'stats.amountWeek',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'user' => true,
'begin' => 'monday this week 00:00:00',
'end' => 'sunday this week 23:59:59',
'icon' => 'money',
'color' => 'blue',
'type' => Counter::class,
],
'userAmountMonth' => [
'title' => 'stats.amountMonth',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'user' => true,
'begin' => 'first day of this month 00:00:00',
'end' => 'last day of this month 23:59:59',
'icon' => 'money',
'color' => 'purple',
'type' => Counter::class,
],
'userAmountTotal' => [
'title' => 'stats.amountTotal',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'user' => true,
'icon' => 'money',
'color' => 'red',
'type' => Counter::class,
],
'durationToday' => [
'title' => 'stats.durationToday',
'query' => TimesheetRepository::STATS_QUERY_DURATION,
@@ -257,44 +219,6 @@ class WidgetRepository
'user' => false,
'type' => Counter::class,
],
'amountToday' => [
'title' => 'stats.amountToday',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'begin' => '00:00:00',
'end' => '23:59:59',
'icon' => 'money',
'color' => 'green',
'user' => false,
'type' => Counter::class,
],
'amountWeek' => [
'title' => 'stats.amountWeek',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'begin' => 'monday this week 00:00:00',
'end' => 'sunday this week 23:59:59',
'icon' => 'money',
'color' => 'blue',
'user' => false,
'type' => Counter::class,
],
'amountMonth' => [
'title' => 'stats.amountMonth',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'begin' => 'first day of this month 00:00:00',
'end' => 'last day of this month 23:59:59',
'icon' => 'money',
'color' => 'purple',
'user' => false,
'type' => Counter::class,
],
'amountTotal' => [
'title' => 'stats.amountTotal',
'query' => TimesheetRepository::STATS_QUERY_RATE,
'icon' => 'money',
'color' => 'red',
'user' => false,
'type' => Counter::class,
],
'activeUsersToday' => [
'title' => 'stats.userActiveToday',
'query' => TimesheetRepository::STATS_QUERY_USER,

View File

@@ -0,0 +1,59 @@
<?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\Widget\Type;
use App\Event\RevenueStatisticEvent;
use App\Repository\TimesheetRepository;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
abstract class AbstractAmountPeriod extends SimpleStatisticChart
{
private $dispatcher;
public function __construct(TimesheetRepository $repository, EventDispatcherInterface $dispatcher)
{
parent::__construct($repository);
$this->dispatcher = $dispatcher;
}
public function getTitle(): string
{
return 'stats.' . $this->getId();
}
public function getTemplateName(): string
{
return 'widget/widget-counter.html.twig';
}
public function getOptions(array $options = []): array
{
return array_merge([
'icon' => 'money',
'dataType' => 'money',
], parent::getOptions($options));
}
public function getData(array $options = [])
{
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
$this->setQueryWithUser(false);
$data = parent::getData($options);
$event = new RevenueStatisticEvent($this->begin, $this->end);
if ($data !== null) {
$event->addRevenue($data);
}
$this->dispatcher->dispatch($event);
return $event->getRevenue();
}
}

View File

@@ -0,0 +1,59 @@
<?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\Widget\Type;
use App\Event\UserRevenueStatisticEvent;
use App\Repository\TimesheetRepository;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
abstract class AbstractUserAmountPeriod extends SimpleStatisticChart
{
private $dispatcher;
public function __construct(TimesheetRepository $repository, EventDispatcherInterface $dispatcher)
{
parent::__construct($repository);
$this->dispatcher = $dispatcher;
}
public function getTitle(): string
{
return 'stats.' . str_replace('userA', 'a', $this->getId());
}
public function getTemplateName(): string
{
return 'widget/widget-counter.html.twig';
}
public function getOptions(array $options = []): array
{
return array_merge([
'icon' => 'money',
'dataType' => 'money',
], parent::getOptions($options));
}
public function getData(array $options = [])
{
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
$this->setQueryWithUser(true);
$data = parent::getData($options);
$event = new UserRevenueStatisticEvent($this->user, $this->begin, $this->end);
if ($data !== null) {
$event->addRevenue($data);
}
$this->dispatcher->dispatch($event);
return $event->getRevenue();
}
}

View File

@@ -0,0 +1,33 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class AmountMonth extends AbstractAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_MONTH], parent::getOptions($options));
}
public function getId(): string
{
return 'amountMonth';
}
public function getData(array $options = [])
{
$this->setBegin('first day of this month 00:00:00');
$this->setEnd('last day of this month 23:59:59');
return parent::getData($options);
}
}

View File

@@ -0,0 +1,33 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class AmountToday extends AbstractAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_TODAY], parent::getOptions($options));
}
public function getId(): string
{
return 'amountToday';
}
public function getData(array $options = [])
{
$this->setBegin('00:00:00');
$this->setEnd('23:59:59');
return parent::getData($options);
}
}

View File

@@ -0,0 +1,25 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class AmountTotal extends AbstractAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_TOTAL], parent::getOptions($options));
}
public function getId(): string
{
return 'amountTotal';
}
}

View File

@@ -0,0 +1,33 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class AmountWeek extends AbstractAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_WEEK], parent::getOptions($options));
}
public function getId(): string
{
return 'amountWeek';
}
public function getData(array $options = [])
{
$this->setBegin('monday this week 00:00:00');
$this->setEnd('sunday this week 23:59:59');
return parent::getData($options);
}
}

View File

@@ -10,17 +10,23 @@
namespace App\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Event\RevenueStatisticEvent;
use App\Repository\TimesheetRepository;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
final class AmountYear extends CounterYear
{
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
private $dispatcher;
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration, EventDispatcherInterface $dispatcher)
{
parent::__construct($repository, $systemConfiguration);
$this->dispatcher = $dispatcher;
$this->setId('amountYear');
$this->setOption('dataType', 'money');
$this->setOption('icon', 'money');
$this->setOption('color', 'yellow');
$this->setOption('color', WidgetInterface::COLOR_YEAR);
$this->setTitle('stats.amountYear');
}
@@ -30,6 +36,14 @@ final class AmountYear extends CounterYear
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
$this->setQueryWithUser(false);
return parent::getData($options);
$data = parent::getData($options);
$event = new RevenueStatisticEvent($this->begin, $this->end);
if ($data !== null) {
$event->addRevenue($data);
}
$this->dispatcher->dispatch($event);
return $event->getRevenue();
}
}

View File

@@ -34,7 +34,7 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
/**
* @var User|null
*/
private $user;
protected $user;
/**
* @var bool
*/
@@ -106,11 +106,11 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
$end = $this->end;
if (!empty($begin) && \is_string($begin)) {
$begin = new \DateTime($begin, $timezone);
$this->begin = new \DateTime($begin, $timezone);
}
if (!empty($end) && \is_string($end)) {
$end = new \DateTime($end, $timezone);
$this->end = new \DateTime($end, $timezone);
}
try {
@@ -119,7 +119,7 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
$user = $this->user;
}
return $this->repository->getStatistic($this->query, $begin, $end, $user);
return $this->repository->getStatistic($this->query, $this->begin, $this->end, $user);
} catch (\Exception $ex) {
throw new WidgetException(
'Failed loading widget data: ' . $ex->getMessage()

View File

@@ -0,0 +1,33 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class UserAmountMonth extends AbstractUserAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_MONTH], parent::getOptions($options));
}
public function getId(): string
{
return 'userAmountMonth';
}
public function getData(array $options = [])
{
$this->setBegin('first day of this month 00:00:00');
$this->setEnd('last day of this month 23:59:59');
return parent::getData($options);
}
}

View File

@@ -0,0 +1,33 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class UserAmountToday extends AbstractUserAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_TODAY], parent::getOptions($options));
}
public function getId(): string
{
return 'userAmountToday';
}
public function getData(array $options = [])
{
$this->setBegin('00:00:00');
$this->setEnd('23:59:59');
return parent::getData($options);
}
}

View File

@@ -0,0 +1,25 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class UserAmountTotal extends AbstractUserAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_TOTAL], parent::getOptions($options));
}
public function getId(): string
{
return 'userAmountTotal';
}
}

View File

@@ -0,0 +1,33 @@
<?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\Widget\Type;
use App\Widget\WidgetInterface;
final class UserAmountWeek extends AbstractUserAmountPeriod
{
public function getOptions(array $options = []): array
{
return array_merge(['color' => WidgetInterface::COLOR_WEEK], parent::getOptions($options));
}
public function getId(): string
{
return 'userAmountWeek';
}
public function getData(array $options = [])
{
$this->setBegin('monday this week 00:00:00');
$this->setEnd('sunday this week 23:59:59');
return parent::getData($options);
}
}

View File

@@ -10,17 +10,23 @@
namespace App\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Event\UserRevenueStatisticEvent;
use App\Repository\TimesheetRepository;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
final class UserAmountYear extends CounterYear
{
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
private $dispatcher;
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration, EventDispatcherInterface $dispatcher)
{
parent::__construct($repository, $systemConfiguration);
$this->dispatcher = $dispatcher;
$this->setId('userAmountYear');
$this->setOption('dataType', 'money');
$this->setOption('icon', 'money');
$this->setOption('color', 'yellow');
$this->setOption('color', WidgetInterface::COLOR_YEAR);
$this->setTitle('stats.amountYear');
}
@@ -30,6 +36,14 @@ final class UserAmountYear extends CounterYear
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
$this->setQueryWithUser(true);
return parent::getData($options);
$data = parent::getData($options);
$event = new UserRevenueStatisticEvent($this->user, $this->begin, $this->end);
if ($data !== null) {
$event->addRevenue($data);
}
$this->dispatcher->dispatch($event);
return $event->getRevenue();
}
}

View File

@@ -11,6 +11,12 @@ namespace App\Widget;
interface WidgetInterface
{
public const COLOR_TODAY = 'green';
public const COLOR_WEEK = 'blue';
public const COLOR_MONTH = 'purple';
public const COLOR_YEAR = 'yellow';
public const COLOR_TOTAL = 'red';
/**
* Returns a unique ID for this widget.
*

View File

@@ -0,0 +1,44 @@
<?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\Event;
use App\Event\RevenueStatisticEvent;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Event\RevenueStatisticEvent
*/
class RevenueStatisticEventTest extends TestCase
{
public function testDefaultValues()
{
$sut = new RevenueStatisticEvent(null, null);
self::assertNull($sut->getEnd());
self::assertNull($sut->getBegin());
self::assertSame(0.0, $sut->getRevenue());
$end = new \DateTime();
$begin = new \DateTime();
$sut = new RevenueStatisticEvent($begin, $end);
self::assertSame($begin, $sut->getBegin());
self::assertSame($end, $sut->getEnd());
self::assertSame(0.0, $sut->getRevenue());
$sut->addRevenue(13.45);
$sut->addRevenue(6.55);
$sut->addRevenue(111);
$sut->addRevenue(2222.22);
self::assertSame(2353.22, $sut->getRevenue());
}
}

View 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\Event;
use App\Entity\User;
use App\Event\UserRevenueStatisticEvent;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Event\UserRevenueStatisticEvent
*/
class UserRevenueStatisticEventTest extends TestCase
{
public function testDefaultValues()
{
$user = new User();
$sut = new UserRevenueStatisticEvent($user, null, null);
self::assertSame($user, $sut->getUser());
self::assertNull($sut->getEnd());
self::assertNull($sut->getBegin());
self::assertSame(0.0, $sut->getRevenue());
$end = new \DateTime();
$begin = new \DateTime();
$sut = new UserRevenueStatisticEvent($user, $begin, $end);
self::assertSame($user, $sut->getUser());
self::assertSame($begin, $sut->getBegin());
self::assertSame($end, $sut->getEnd());
self::assertSame(0.0, $sut->getRevenue());
$sut->addRevenue(13.45);
$sut->addRevenue(6.55);
$sut->addRevenue(111);
$sut->addRevenue(2222.22);
self::assertSame(2353.22, $sut->getRevenue());
}
}

View File

@@ -58,10 +58,6 @@ abstract class AbstractWidgetTypeTest extends TestCase
self::assertEquals('blab', $options['blub']);
self::assertEquals('money', $options['dataType']);
self::assertEquals('trääääää', $options['föööö']);
// id
$sut->setId('cvbnmyx');
self::assertEquals('cvbnmyx', $sut->getId());
}
public function testData()

View File

@@ -0,0 +1,68 @@
<?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\Widget\Type;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\AmountMonth;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\AmountMonth
* @covers \App\Widget\Type\AbstractAmountPeriod
*/
class AmountMonthTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
return new AmountMonth($repository, $dispatcher);
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_MONTH,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('amountMonth', $sut->getId());
}
}

View File

@@ -0,0 +1,68 @@
<?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\Widget\Type;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\AmountToday;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\AmountToday
* @covers \App\Widget\Type\AbstractAmountPeriod
*/
class AmountTodayTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
return new AmountToday($repository, $dispatcher);
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_TODAY,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('amountToday', $sut->getId());
}
}

View File

@@ -0,0 +1,68 @@
<?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\Widget\Type;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\AmountTotal;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\AmountTotal
* @covers \App\Widget\Type\AbstractAmountPeriod
*/
class AmountTotalTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
return new AmountTotal($repository, $dispatcher);
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_TOTAL,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('amountTotal', $sut->getId());
}
}

View File

@@ -0,0 +1,68 @@
<?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\Widget\Type;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\AmountWeek;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\AmountWeek
* @covers \App\Widget\Type\AbstractAmountPeriod
*/
class AmountWeekTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
return new AmountWeek($repository, $dispatcher);
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_WEEK,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('amountWeek', $sut->getId());
}
}

View File

@@ -15,6 +15,8 @@ use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\AmountYear;
use App\Widget\Type\CounterYear;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\AmountYear
@@ -22,6 +24,11 @@ use App\Widget\Type\SimpleStatisticChart;
*/
class AmountYearTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return CounterYear
*/
@@ -29,8 +36,9 @@ class AmountYearTest extends AbstractWidgetTypeTest
{
$repository = $this->createMock(TimesheetRepository::class);
$configuration = $this->createMock(SystemConfiguration::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
return new AmountYear($repository, $configuration);
return new AmountYear($repository, $configuration, $dispatcher);
}
public function getDefaultOptions(): array
@@ -38,7 +46,7 @@ class AmountYearTest extends AbstractWidgetTypeTest
return [
'dataType' => 'money',
'icon' => 'money',
'color' => 'yellow',
'color' => WidgetInterface::COLOR_YEAR,
];
}

View File

@@ -0,0 +1,72 @@
<?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\Widget\Type;
use App\Entity\User;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractUserAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\Type\UserAmountMonth;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\UserAmountMonth
* @covers \App\Widget\Type\AbstractUserAmountPeriod
*/
class UserAmountMonthTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractUserAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$widget = new UserAmountMonth($repository, $dispatcher);
$widget->setUser(new User());
return $widget;
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_MONTH,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('userAmountMonth', $sut->getId());
}
}

View File

@@ -0,0 +1,72 @@
<?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\Widget\Type;
use App\Entity\User;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractUserAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\Type\UserAmountToday;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\UserAmountToday
* @covers \App\Widget\Type\AbstractUserAmountPeriod
*/
class UserAmountTodayTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractUserAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$widget = new UserAmountToday($repository, $dispatcher);
$widget->setUser(new User());
return $widget;
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_TODAY,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('userAmountToday', $sut->getId());
}
}

View File

@@ -0,0 +1,72 @@
<?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\Widget\Type;
use App\Entity\User;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractUserAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\Type\UserAmountTotal;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\UserAmountTotal
* @covers \App\Widget\Type\AbstractUserAmountPeriod
*/
class UserAmountTotalTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractUserAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$widget = new UserAmountTotal($repository, $dispatcher);
$widget->setUser(new User());
return $widget;
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_TOTAL,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('userAmountTotal', $sut->getId());
}
}

View File

@@ -0,0 +1,72 @@
<?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\Widget\Type;
use App\Entity\User;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractUserAmountPeriod;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\Type\UserAmountWeek;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\UserAmountWeek
* @covers \App\Widget\Type\AbstractUserAmountPeriod
*/
class UserAmountWeekTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return AbstractUserAmountPeriod
*/
public function createSut(): AbstractWidgetType
{
$repository = $this->createMock(TimesheetRepository::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$widget = new UserAmountWeek($repository, $dispatcher);
$widget->setUser(new User());
return $widget;
}
public function getDefaultOptions(): array
{
return [
'dataType' => 'money',
'icon' => 'money',
'color' => WidgetInterface::COLOR_WEEK,
];
}
public function testData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
$sut = $this->createSut();
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
$sut->setData(10);
}
public function testSettings()
{
$sut = $this->createSut();
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
self::assertEquals('userAmountWeek', $sut->getId());
}
}

View File

@@ -10,11 +10,14 @@
namespace App\Tests\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Entity\User;
use App\Repository\TimesheetRepository;
use App\Widget\Type\AbstractWidgetType;
use App\Widget\Type\CounterYear;
use App\Widget\Type\SimpleStatisticChart;
use App\Widget\Type\UserAmountYear;
use App\Widget\WidgetInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @covers \App\Widget\Type\UserAmountYear
@@ -22,6 +25,11 @@ use App\Widget\Type\UserAmountYear;
*/
class UserAmountYearTest extends AbstractWidgetTypeTest
{
protected function assertDefaultData(AbstractWidgetType $sut)
{
self::assertEquals(0.0, $sut->getData());
}
/**
* @return CounterYear
*/
@@ -29,8 +37,12 @@ class UserAmountYearTest extends AbstractWidgetTypeTest
{
$repository = $this->createMock(TimesheetRepository::class);
$configuration = $this->createMock(SystemConfiguration::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
return new UserAmountYear($repository, $configuration);
$widget = new UserAmountYear($repository, $configuration, $dispatcher);
$widget->setUser(new User());
return $widget;
}
public function getDefaultOptions(): array
@@ -38,7 +50,7 @@ class UserAmountYearTest extends AbstractWidgetTypeTest
return [
'dataType' => 'money',
'icon' => 'money',
'color' => 'yellow',
'color' => WidgetInterface::COLOR_YEAR,
];
}