added invoice model to invoice created event (#3079)

* added model to InvoiceCreatedEvent
* allow to switch formatter locale
This commit is contained in:
Kevin Papst
2022-01-20 18:41:55 +01:00
committed by GitHub
parent fd4cbb43c1
commit 49bb9980b8
8 changed files with 109 additions and 123 deletions

View File

@@ -11,6 +11,8 @@ namespace App\Tests\Event;
use App\Entity\Invoice;
use App\Event\InvoiceCreatedEvent;
use App\Tests\Invoice\DebugFormatter;
use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
/**
@@ -21,9 +23,11 @@ class InvoiceCreatedEventTest extends TestCase
public function testDefaultValues()
{
$invoice = new Invoice();
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$sut = new InvoiceCreatedEvent($invoice);
$sut = new InvoiceCreatedEvent($invoice, $model);
self::assertSame($invoice, $sut->getInvoice());
self::assertSame($model, $sut->getInvoiceModel());
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\InvoiceSubscriber;
/**
* @covers \App\EventSubscriber\Actions\InvoiceSubscriber
*/
class InvoiceSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(InvoiceSubscriber::class, 'invoice');
}
}

View File

@@ -13,31 +13,17 @@ use App\Invoice\InvoiceFormatter;
class DebugFormatter implements InvoiceFormatter
{
/**
* @param \DateTime $date
* @return mixed
*/
public function getFormattedDateTime(\DateTime $date)
public function getFormattedDateTime(\DateTime $date): string
{
return $date->format('d.m.Y');
}
/**
* @param \DateTime $date
* @return mixed
*/
public function getFormattedTime(\DateTime $date)
public function getFormattedTime(\DateTime $date): string
{
return $date->format('H:i');
}
/**
* @param int|float $amount
* @param string|null $currency
* @param bool $withCurrency
* @return string
*/
public function getFormattedMoney($amount, ?string $currency, bool $withCurrency = true)
public function getFormattedMoney(float $amount, ?string $currency, bool $withCurrency = true): string
{
if (null === $currency) {
$withCurrency = false;
@@ -50,35 +36,33 @@ class DebugFormatter implements InvoiceFormatter
return (string) $amount;
}
/**
* @param \DateTime $date
* @return mixed
*/
public function getFormattedMonthName(\DateTime $date)
public function getFormattedMonthName(\DateTime $date): string
{
return $date->format('m');
}
/**
* @param mixed $seconds
* @return mixed
*/
public function getFormattedDuration($seconds)
public function getFormattedDuration(int $seconds): string
{
return $seconds;
return (string) $seconds;
}
/**
* @param mixed $seconds
* @return mixed
*/
public function getFormattedDecimalDuration($seconds)
public function getFormattedDecimalDuration(int $seconds): string
{
return $seconds;
return (string) $seconds;
}
public function getCurrencySymbol(string $currency): string
{
return $currency;
}
public function getLocale(): string
{
return 'en';
}
public function setLocale(string $locale): void
{
// does nothing
}
}