diff --git a/src/Invoice/Hydrator/InvoiceModelActivityHydrator.php b/src/Invoice/Hydrator/InvoiceModelActivityHydrator.php
index cbc20c18..97d8194c 100644
--- a/src/Invoice/Hydrator/InvoiceModelActivityHydrator.php
+++ b/src/Invoice/Hydrator/InvoiceModelActivityHydrator.php
@@ -9,12 +9,20 @@
namespace App\Invoice\Hydrator;
+use App\Activity\ActivityStatisticService;
use App\Entity\Activity;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
class InvoiceModelActivityHydrator implements InvoiceModelHydrator
{
+ private $activityStatistic;
+
+ public function __construct(ActivityStatisticService $activityStatistic)
+ {
+ $this->activityStatistic = $activityStatistic;
+ }
+
public function hydrate(InvoiceModel $model): array
{
if (!$model->getQuery()->hasActivities()) {
@@ -24,19 +32,23 @@ class InvoiceModelActivityHydrator implements InvoiceModelHydrator
$values = [];
$i = 0;
+ if (\count($model->getQuery()->getActivities()) === 1) {
+ $values['activity'] = $model->getQuery()->getActivities()[0]->getName();
+ }
+
foreach ($model->getQuery()->getActivities() as $activity) {
$prefix = '';
if ($i > 0) {
$prefix = $i . '.';
}
- $values = array_merge($values, $this->getValuesFromActivity($activity, $prefix));
+ $values = array_merge($values, $this->getValuesFromActivity($model, $activity, $prefix));
$i++;
}
return $values;
}
- private function getValuesFromActivity(Activity $activity, string $prefix): array
+ private function getValuesFromActivity(InvoiceModel $model, Activity $activity, string $prefix): array
{
$prefix = 'activity.' . $prefix;
@@ -46,6 +58,23 @@ class InvoiceModelActivityHydrator implements InvoiceModelHydrator
$prefix . 'comment' => $activity->getComment(),
];
+ $statistic = $this->activityStatistic->getBudgetStatisticModel($activity, $model->getQuery()->getEnd());
+ $formatter = $model->getFormatter();
+ $currency = $model->getCurrency();
+
+ if ($model->getTemplate()->isDecimalDuration()) {
+ $budgetOpenDuration = $formatter->getFormattedDecimalDuration($statistic->getTimeBudgetOpen());
+ } else {
+ $budgetOpenDuration = $formatter->getFormattedDuration($statistic->getTimeBudgetOpen());
+ }
+
+ $values = array_merge($values, [
+ $prefix . 'budget_open' => $formatter->getFormattedMoney($statistic->getBudgetOpen(), $currency),
+ $prefix . 'budget_open_plain' => $statistic->getBudgetOpen(),
+ $prefix . 'time_budget_open' => $budgetOpenDuration,
+ $prefix . 'time_budget_open_plain' => $statistic->getTimeBudgetOpen(),
+ ]);
+
foreach ($activity->getVisibleMetaFields() as $metaField) {
$values = array_merge($values, [
$prefix . 'meta.' . $metaField->getName() => $metaField->getValue(),
diff --git a/src/Invoice/Hydrator/InvoiceModelCustomerHydrator.php b/src/Invoice/Hydrator/InvoiceModelCustomerHydrator.php
index 44c17db7..d9c49293 100644
--- a/src/Invoice/Hydrator/InvoiceModelCustomerHydrator.php
+++ b/src/Invoice/Hydrator/InvoiceModelCustomerHydrator.php
@@ -9,11 +9,19 @@
namespace App\Invoice\Hydrator;
+use App\Customer\CustomerStatisticService;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
{
+ private $customerStatistic;
+
+ public function __construct(CustomerStatisticService $customerStatistic)
+ {
+ $this->customerStatistic = $customerStatistic;
+ }
+
public function hydrate(InvoiceModel $model): array
{
$customer = $model->getCustomer();
@@ -22,9 +30,6 @@ class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
return [];
}
- $formatter = $model->getFormatter();
- $currency = $model->getCurrency();
-
$values = [
'customer.id' => $customer->getId(),
'customer.address' => $customer->getAddress(),
@@ -40,12 +45,25 @@ class InvoiceModelCustomerHydrator implements InvoiceModelHydrator
'customer.fax' => $customer->getFax(),
'customer.phone' => $customer->getPhone(),
'customer.mobile' => $customer->getMobile(),
- // budget
- // remaining budget?
- // time-budget
- // remaining time-budget?
];
+ $statistic = $this->customerStatistic->getBudgetStatisticModel($customer, $model->getQuery()->getEnd());
+ $currency = $model->getCurrency();
+ $formatter = $model->getFormatter();
+
+ if ($model->getTemplate()->isDecimalDuration()) {
+ $budgetOpenDuration = $formatter->getFormattedDecimalDuration($statistic->getTimeBudgetOpen());
+ } else {
+ $budgetOpenDuration = $formatter->getFormattedDuration($statistic->getTimeBudgetOpen());
+ }
+
+ $values = array_merge($values, [
+ 'customer.budget_open' => $formatter->getFormattedMoney($statistic->getBudgetOpen(), $currency),
+ 'customer.budget_open_plain' => $statistic->getBudgetOpen(),
+ 'customer.time_budget_open' => $budgetOpenDuration,
+ 'customer.time_budget_open_plain' => $statistic->getTimeBudgetOpen(),
+ ]);
+
foreach ($customer->getMetaFields() as $metaField) {
$values = array_merge($values, [
'customer.meta.' . $metaField->getName() => $metaField->getValue(),
diff --git a/src/Invoice/Hydrator/InvoiceModelProjectHydrator.php b/src/Invoice/Hydrator/InvoiceModelProjectHydrator.php
index c5b2a3ab..2e18a367 100644
--- a/src/Invoice/Hydrator/InvoiceModelProjectHydrator.php
+++ b/src/Invoice/Hydrator/InvoiceModelProjectHydrator.php
@@ -10,40 +10,51 @@
namespace App\Invoice\Hydrator;
use App\Entity\Project;
-use App\Invoice\InvoiceFormatter;
use App\Invoice\InvoiceModel;
use App\Invoice\InvoiceModelHydrator;
+use App\Project\ProjectStatisticService;
class InvoiceModelProjectHydrator implements InvoiceModelHydrator
{
+ private $projectStatistic;
+
+ public function __construct(ProjectStatisticService $projectStatistic)
+ {
+ $this->projectStatistic = $projectStatistic;
+ }
+
public function hydrate(InvoiceModel $model): array
{
if (!$model->getQuery()->hasProjects()) {
return [];
}
- $formatter = $model->getFormatter();
- $currency = $model->getCurrency();
-
$values = [];
$i = 0;
+ if (\count($model->getQuery()->getProjects()) === 1) {
+ $values['project'] = $model->getQuery()->getProjects()[0]->getName();
+ }
+
foreach ($model->getQuery()->getProjects() as $project) {
$prefix = '';
if ($i > 0) {
$prefix = $i . '.';
}
- $values = array_merge($values, $this->getValuesFromProject($project, $formatter, $currency, $prefix));
+ $values = array_merge($values, $this->getValuesFromProject($model, $project, $prefix));
$i++;
}
return $values;
}
- private function getValuesFromProject(Project $project, InvoiceFormatter $formatter, string $currency, string $prefix): array
+ private function getValuesFromProject(InvoiceModel $model, Project $project, string $prefix): array
{
$prefix = 'project.' . $prefix;
+ $formatter = $model->getFormatter();
+ $currency = $model->getCurrency();
+
$values = [
$prefix . 'id' => $project->getId(),
$prefix . 'name' => $project->getName(),
@@ -60,6 +71,21 @@ class InvoiceModelProjectHydrator implements InvoiceModelHydrator
$prefix . 'budget_time_minutes' => (int) ($project->getTimeBudget() / 60),
];
+ $statistic = $this->projectStatistic->getBudgetStatisticModel($project, $model->getQuery()->getEnd());
+
+ if ($model->getTemplate()->isDecimalDuration()) {
+ $budgetOpenDuration = $formatter->getFormattedDecimalDuration($statistic->getTimeBudgetOpen());
+ } else {
+ $budgetOpenDuration = $formatter->getFormattedDuration($statistic->getTimeBudgetOpen());
+ }
+
+ $values = array_merge($values, [
+ $prefix . 'budget_open' => $formatter->getFormattedMoney($statistic->getBudgetOpen(), $currency),
+ $prefix . 'budget_open_plain' => $statistic->getBudgetOpen(),
+ $prefix . 'time_budget_open' => $budgetOpenDuration,
+ $prefix . 'time_budget_open_plain' => $statistic->getTimeBudgetOpen(),
+ ]);
+
foreach ($project->getVisibleMetaFields() as $metaField) {
$values = array_merge($values, [
$prefix . 'meta.' . $metaField->getName() => $metaField->getValue(),
diff --git a/src/Invoice/InvoiceModel.php b/src/Invoice/InvoiceModel.php
index 7f5eac58..769c7176 100644
--- a/src/Invoice/InvoiceModel.php
+++ b/src/Invoice/InvoiceModel.php
@@ -9,6 +9,8 @@
namespace App\Invoice;
+use App\Activity\ActivityStatisticService;
+use App\Customer\CustomerStatisticService;
use App\Entity\Customer;
use App\Entity\InvoiceTemplate;
use App\Entity\User;
@@ -18,6 +20,7 @@ use App\Invoice\Hydrator\InvoiceModelCustomerHydrator;
use App\Invoice\Hydrator\InvoiceModelDefaultHydrator;
use App\Invoice\Hydrator\InvoiceModelProjectHydrator;
use App\Invoice\Hydrator\InvoiceModelUserHydrator;
+use App\Project\ProjectStatisticService;
use App\Repository\Query\InvoiceQuery;
/**
@@ -75,14 +78,14 @@ final class InvoiceModel
*/
private $invoiceNumber;
- public function __construct(InvoiceFormatter $formatter)
+ public function __construct(InvoiceFormatter $formatter, CustomerStatisticService $customerStatistic, ProjectStatisticService $projectStatistic, ActivityStatisticService $activityStatistic)
{
$this->invoiceDate = new \DateTime();
$this->formatter = $formatter;
$this->addModelHydrator(new InvoiceModelDefaultHydrator());
- $this->addModelHydrator(new InvoiceModelCustomerHydrator());
- $this->addModelHydrator(new InvoiceModelProjectHydrator());
- $this->addModelHydrator(new InvoiceModelActivityHydrator());
+ $this->addModelHydrator(new InvoiceModelCustomerHydrator($customerStatistic));
+ $this->addModelHydrator(new InvoiceModelProjectHydrator($projectStatistic));
+ $this->addModelHydrator(new InvoiceModelActivityHydrator($activityStatistic));
$this->addModelHydrator(new InvoiceModelUserHydrator());
$this->addItemHydrator(new InvoiceItemDefaultHydrator());
}
diff --git a/src/Invoice/InvoiceModelFactory.php b/src/Invoice/InvoiceModelFactory.php
new file mode 100644
index 00000000..5531021c
--- /dev/null
+++ b/src/Invoice/InvoiceModelFactory.php
@@ -0,0 +1,33 @@
+customerStatisticService = $customerStatistic;
+ $this->projectStatisticService = $projectStatistic;
+ $this->activityStatisticService = $activityStatistic;
+ }
+
+ public function createModel(InvoiceFormatter $formatter): InvoiceModel
+ {
+ return new InvoiceModel($formatter, $this->customerStatisticService, $this->projectStatisticService, $this->activityStatisticService);
+ }
+}
diff --git a/src/Invoice/Renderer/AbstractTwigRenderer.php b/src/Invoice/Renderer/AbstractTwigRenderer.php
index 4f65c365..4ceaf909 100644
--- a/src/Invoice/Renderer/AbstractTwigRenderer.php
+++ b/src/Invoice/Renderer/AbstractTwigRenderer.php
@@ -37,7 +37,10 @@ abstract class AbstractTwigRenderer implements RendererInterface
$previousLocale = $this->changeTwigLocale($this->twig, $model->getTemplate()->getLanguage());
$content = $this->twig->render('@invoice/' . basename($document->getFilename()), [
- 'model' => $model
+ // model should not be used in the future, but we can likely not remove it
+ 'model' => $model,
+ // new since 1.16.7 - templates should only use the pre-generated values
+ 'invoice' => $model->toArray(),
]);
$this->changeTwigLocale($this->twig, $previousLocale);
diff --git a/src/Invoice/ServiceInvoice.php b/src/Invoice/ServiceInvoice.php
index 8dbd7e07..7ba092b3 100644
--- a/src/Invoice/ServiceInvoice.php
+++ b/src/Invoice/ServiceInvoice.php
@@ -46,29 +46,19 @@ final class ServiceInvoice
* @var array InvoiceItemRepositoryInterface[]
*/
private $invoiceItemRepositories = [];
- /**
- * @var InvoiceDocumentRepository
- */
private $documents;
- /**
- * @var FileHelper
- */
private $fileHelper;
- /**
- * @var LanguageFormattings
- */
private $formatter;
- /**
- * @var InvoiceRepository
- */
private $invoiceRepository;
+ private $invoiceModelFactory;
- public function __construct(InvoiceDocumentRepository $repository, FileHelper $fileHelper, InvoiceRepository $invoiceRepository, LanguageFormattings $formatter)
+ public function __construct(InvoiceDocumentRepository $repository, FileHelper $fileHelper, InvoiceRepository $invoiceRepository, LanguageFormattings $formatter, InvoiceModelFactory $invoiceModelFactory)
{
$this->documents = $repository;
$this->fileHelper = $fileHelper;
$this->invoiceRepository = $invoiceRepository;
$this->formatter = $formatter;
+ $this->invoiceModelFactory = $invoiceModelFactory;
}
public function addNumberGenerator(NumberGeneratorInterface $generator): ServiceInvoice
@@ -469,7 +459,9 @@ final class ServiceInvoice
@trigger_error('Using invoice templates without a language is is deprecated and trigger and will throw an exception with 2.0', E_USER_DEPRECATED);
}
- $model = new InvoiceModel(new DefaultInvoiceFormatter($this->formatter, $template->getLanguage()));
+ $formatter = new DefaultInvoiceFormatter($this->formatter, $template->getLanguage());
+
+ $model = $this->invoiceModelFactory->createModel($formatter);
$model
->setTemplate($template)
->setInvoiceDate($this->getDateTimeFactory($query)->createDateTime())
diff --git a/templates/invoice/renderer/timesheet.html.twig b/templates/invoice/renderer/timesheet.html.twig
index 62f9952c..ca226bfd 100644
--- a/templates/invoice/renderer/timesheet.html.twig
+++ b/templates/invoice/renderer/timesheet.html.twig
@@ -2,124 +2,135 @@
{% extends 'invoice/layout.html.twig' %}
{% block invoice %}
-{% set isDecimal = model.template.decimalDuration|default(false) %}
-
-
-
+ {% set isDecimal = model.template.decimalDuration|default(false) %}
+
-
-
-
-
-
- | {{ 'invoice.from'|trans }} |
-
- {% if model.query.user is not empty %}
- {{ widgets.username(model.query.user) }}
- {% else %}
- {{ model.template.company }}
- {% endif %}
- |
-
-
- | {{ 'label.date'|trans }} |
-
- {% if model.query.begin|date('m') != model.query.end|date('m') or model.query.begin|date('Y') != model.query.end|date('Y') %}
- {{ model.query.begin|date_short }} - {{ model.query.end|date_short }}
- {% else %}
- {{ model.query.end|month_name }} {{ model.query.end|date('Y') }}
- {% endif %}
- |
-
-
- | {{ 'label.customer'|trans }} |
-
- {% if model.customer.number is not empty %}[{{ model.customer.number }}]{% endif %}
- {{ model.customer.name }}{% if model.customer.contact is not empty %} / {{ model.customer.contact }}{% endif %}
- |
-
- {% if model.query.project is not empty and model.query.project.orderNumber is not empty %}
+
+
+
- | {{ 'label.orderNumber'|trans }} |
+ {{ 'invoice.from'|trans }} |
- {{ model.query.project.orderNumber }}
+ {% if model.query.user is not empty %}
+ {{ widgets.username(model.query.user) }}
+ {% else %}
+ {{ model.template.company }}
+ {% endif %}
|
- {% endif %}
-
-
-
-
-
-
-
-
-
- | {{ 'label.date'|trans }} |
- {% if model.query.user is empty %}
- {{ 'label.user'|trans }} |
- {% endif %}
- {{ 'label.activity'|trans }} |
- {{ 'label.hours'|trans }} |
-
-
-
- {% for entry in model.calculator.entries %}
-
- | {{ entry.begin|date_short }} |
- {% if model.query.user is empty %}
- {{ widgets.username(entry.user) }} |
- {% endif %}
-
- {% if entry.description is not empty %}
- {{ entry.description|nl2br }}
- {% else %}
- {% if entry.activity is not null %}{{ entry.activity.name }} / {% endif %}{{ entry.project.name }}
- {% endif %}
- |
- {{ entry.duration|duration(isDecimal) }} |
-
- {% endfor %}
-
-
-
- |
- {% if model.query.user is empty %}
- |
- {% endif %}
- {{ 'invoice.total_working_time'|trans }} |
- {{ model.calculator.timeWorked|duration(isDecimal) }} |
-
-
-
-
-
-
-
-
- {% if model.template.paymentTerms is not empty %}
-
{{ 'label.payment_terms'|trans }}
-
-
- {{ model.template.paymentTerms|trim|nl2br }}
-
- {% endif %}
-
-
-
-
- | {{ 'invoice.signature_user'|trans }} |
+ {{ 'label.date'|trans }} |
+
+ {% if model.query.begin|date('m') != model.query.end|date('m') or model.query.begin|date('Y') != model.query.end|date('Y') %}
+ {{ model.query.begin|date_short }} - {{ model.query.end|date_short }}
+ {% else %}
+ {{ model.query.end|month_name }} {{ model.query.end|date('Y') }}
+ {% endif %}
+ |
- | {{ 'invoice.signature_customer'|trans }} |
+ {{ 'label.customer'|trans }} |
+
+ {% if model.customer.number is not empty %}[{{ model.customer.number }}]{% endif %}
+ {{ model.customer.name }}{% if model.customer.contact is not empty %} / {{ model.customer.contact }}{% endif %}
+ |
-
+ {% if model.query.project is not empty %}
+
+ | {{ 'label.project'|trans }} |
+
+ {{ model.query.project.name }}
+ {% if model.query.project.orderNumber is not empty %}
+ ({{ 'label.orderNumber'|trans }}: {{ model.query.project.orderNumber }})
+ {% endif %}
+ |
+
+ {% endif %}
+ {% if model.query.activity is not empty %}
+
+ | {{ 'label.activity'|trans }} |
+
+ {{ model.query.activity.name }}
+ |
+
+ {% endif %}
-
+
+
+
+
+
+
+ | {{ 'label.date'|trans }} |
+ {% if model.query.user is empty %}
+ {{ 'label.user'|trans }} |
+ {% endif %}
+ {{ 'label.activity'|trans }} |
+ {{ 'label.hours'|trans }} |
+
+
+
+ {% for entry in model.calculator.entries %}
+
+ | {{ entry.begin|date_short }} |
+ {% if model.query.user is empty %}
+ {{ widgets.username(entry.user) }} |
+ {% endif %}
+
+ {% if entry.description is not empty %}
+ {{ entry.description|nl2br }}
+ {% else %}
+ {% if entry.activity is not null %}{{ entry.activity.name }} / {% endif %}{{ entry.project.name }}
+ {% endif %}
+ |
+ {{ entry.duration|duration(isDecimal) }} |
+
+ {% endfor %}
+
+
+
+ |
+ {% if model.query.user is empty %}
+ |
+ {% endif %}
+ {{ 'invoice.total_working_time'|trans }} |
+ {{ model.calculator.timeWorked|duration(isDecimal) }} |
+
+
+
+
+
+
+
+
+ {% if model.template.paymentTerms is not empty %}
+
{{ 'label.payment_terms'|trans }}
+
+
+ {{ model.template.paymentTerms|trim|nl2br }}
+
+ {% endif %}
+
+
+
+
+
+ | {{ 'invoice.signature_user'|trans }} |
+
+
+ | {{ 'invoice.signature_customer'|trans }} |
+
+
+
+
+
+
{% endblock %}
\ No newline at end of file
diff --git a/tests/Entity/InvoiceTest.php b/tests/Entity/InvoiceTest.php
index c6654ffb..8d58f0ac 100644
--- a/tests/Entity/InvoiceTest.php
+++ b/tests/Entity/InvoiceTest.php
@@ -26,6 +26,7 @@ use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
/**
@@ -158,7 +159,7 @@ class InvoiceTest extends TestCase
$query->setBegin(new \DateTime());
$query->setEnd(new \DateTime());
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Event/InvoicePostRenderEventTest.php b/tests/Event/InvoicePostRenderEventTest.php
index 7f911e47..1e6c1490 100644
--- a/tests/Event/InvoicePostRenderEventTest.php
+++ b/tests/Event/InvoicePostRenderEventTest.php
@@ -11,9 +11,9 @@ namespace App\Tests\Event;
use App\Entity\InvoiceDocument;
use App\Event\InvoicePostRenderEvent;
-use App\Invoice\InvoiceModel;
use App\Tests\Invoice\DebugFormatter;
use App\Tests\Invoice\Renderer\DebugRenderer;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
@@ -24,7 +24,7 @@ class InvoicePostRenderEventTest extends TestCase
{
public function testDefaultValues()
{
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$document = new InvoiceDocument(new \SplFileInfo(__FILE__));
$renderer = new DebugRenderer();
$response = new Response();
diff --git a/tests/Event/InvoicePreRenderEventTest.php b/tests/Event/InvoicePreRenderEventTest.php
index 6fe95965..9006b0e8 100644
--- a/tests/Event/InvoicePreRenderEventTest.php
+++ b/tests/Event/InvoicePreRenderEventTest.php
@@ -11,9 +11,9 @@ namespace App\Tests\Event;
use App\Entity\InvoiceDocument;
use App\Event\InvoicePreRenderEvent;
-use App\Invoice\InvoiceModel;
use App\Tests\Invoice\DebugFormatter;
use App\Tests\Invoice\Renderer\DebugRenderer;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
/**
@@ -23,7 +23,7 @@ class InvoicePreRenderEventTest extends TestCase
{
public function testDefaultValues()
{
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$document = new InvoiceDocument(new \SplFileInfo(__FILE__));
$renderer = new DebugRenderer();
diff --git a/tests/Invoice/Calculator/AbstractCalculatorTest.php b/tests/Invoice/Calculator/AbstractCalculatorTest.php
index 0ff02372..f01a760a 100644
--- a/tests/Invoice/Calculator/AbstractCalculatorTest.php
+++ b/tests/Invoice/Calculator/AbstractCalculatorTest.php
@@ -16,9 +16,9 @@ use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Invoice\CalculatorInterface;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
abstract class AbstractCalculatorTest extends TestCase
@@ -44,7 +44,7 @@ abstract class AbstractCalculatorTest extends TestCase
$template = new InvoiceTemplate();
$query = new InvoiceQuery();
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setQuery($query);
@@ -88,7 +88,7 @@ abstract class AbstractCalculatorTest extends TestCase
->setActivity($activity)
->setProject($project);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries([$timesheet]);
diff --git a/tests/Invoice/Calculator/ActivityInvoiceCalculatorTest.php b/tests/Invoice/Calculator/ActivityInvoiceCalculatorTest.php
index f44d7b9f..2db2a202 100644
--- a/tests/Invoice/Calculator/ActivityInvoiceCalculatorTest.php
+++ b/tests/Invoice/Calculator/ActivityInvoiceCalculatorTest.php
@@ -16,9 +16,9 @@ use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Invoice\Calculator\ActivityInvoiceCalculator;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
/**
* @covers \App\Invoice\Calculator\ActivityInvoiceCalculator
@@ -134,7 +134,7 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setActivity($activity1);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Calculator/DateInvoiceCalculatorTest.php b/tests/Invoice/Calculator/DateInvoiceCalculatorTest.php
index 3db1045d..000aa2c0 100644
--- a/tests/Invoice/Calculator/DateInvoiceCalculatorTest.php
+++ b/tests/Invoice/Calculator/DateInvoiceCalculatorTest.php
@@ -16,9 +16,9 @@ use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Invoice\Calculator\DateInvoiceCalculator;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use DateTime;
/**
@@ -107,7 +107,7 @@ class DateInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setProjects([$project1]);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Calculator/DefaultCalculatorTest.php b/tests/Invoice/Calculator/DefaultCalculatorTest.php
index 3e5103ee..d4d0ff10 100644
--- a/tests/Invoice/Calculator/DefaultCalculatorTest.php
+++ b/tests/Invoice/Calculator/DefaultCalculatorTest.php
@@ -15,9 +15,9 @@ use App\Entity\InvoiceTemplate;
use App\Entity\Tag;
use App\Entity\Timesheet;
use App\Invoice\Calculator\DefaultCalculator;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
/**
* @covers \App\Invoice\Calculator\DefaultCalculator
@@ -63,7 +63,7 @@ class DefaultCalculatorTest extends AbstractCalculatorTest
$entries = [$timesheet, $timesheet2, $timesheet3];
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Calculator/ProjectInvoiceCalculatorTest.php b/tests/Invoice/Calculator/ProjectInvoiceCalculatorTest.php
index a5ec506c..1f2b2fac 100644
--- a/tests/Invoice/Calculator/ProjectInvoiceCalculatorTest.php
+++ b/tests/Invoice/Calculator/ProjectInvoiceCalculatorTest.php
@@ -16,9 +16,9 @@ use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Invoice\Calculator\ProjectInvoiceCalculator;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use DateTime;
/**
@@ -107,7 +107,7 @@ class ProjectInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setProjects([$project1]);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Calculator/ShortInvoiceCalculatorTest.php b/tests/Invoice/Calculator/ShortInvoiceCalculatorTest.php
index 31a690ac..e98a8fc9 100644
--- a/tests/Invoice/Calculator/ShortInvoiceCalculatorTest.php
+++ b/tests/Invoice/Calculator/ShortInvoiceCalculatorTest.php
@@ -18,9 +18,9 @@ use App\Entity\Timesheet;
use App\Entity\User;
use App\Invoice\Calculator\ShortInvoiceCalculator;
use App\Invoice\InvoiceItem;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
/**
* @covers \App\Invoice\Calculator\ShortInvoiceCalculator
@@ -91,7 +91,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setActivity($activity);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
@@ -173,7 +173,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setActivity($activity);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
@@ -252,7 +252,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setActivity($activity);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Calculator/UserInvoiceCalculatorTest.php b/tests/Invoice/Calculator/UserInvoiceCalculatorTest.php
index f74f4c1a..5b5e481c 100644
--- a/tests/Invoice/Calculator/UserInvoiceCalculatorTest.php
+++ b/tests/Invoice/Calculator/UserInvoiceCalculatorTest.php
@@ -16,9 +16,9 @@ use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Invoice\Calculator\UserInvoiceCalculator;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
/**
* @covers \App\Invoice\Calculator\UserInvoiceCalculator
@@ -105,7 +105,7 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setActivity($activity);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Calculator/WeeklyInvoiceCalculatorTest.php b/tests/Invoice/Calculator/WeeklyInvoiceCalculatorTest.php
index 497e1433..d79cd6ee 100644
--- a/tests/Invoice/Calculator/WeeklyInvoiceCalculatorTest.php
+++ b/tests/Invoice/Calculator/WeeklyInvoiceCalculatorTest.php
@@ -16,9 +16,9 @@ use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Invoice\Calculator\WeeklyInvoiceCalculator;
-use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use DateTime;
/**
@@ -110,7 +110,7 @@ class WeeklyInvoiceCalculatorTest extends AbstractCalculatorTest
$query = new InvoiceQuery();
$query->setProjects([$project1]);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Hydrator/InvoiceModelActivityHydratorTest.php b/tests/Invoice/Hydrator/InvoiceModelActivityHydratorTest.php
index 47672abf..e11bd3d2 100644
--- a/tests/Invoice/Hydrator/InvoiceModelActivityHydratorTest.php
+++ b/tests/Invoice/Hydrator/InvoiceModelActivityHydratorTest.php
@@ -9,6 +9,7 @@
namespace App\Tests\Invoice\Hydrator;
+use App\Activity\ActivityStatisticService;
use App\Invoice\Hydrator\InvoiceModelActivityHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
@@ -24,7 +25,7 @@ class InvoiceModelActivityHydratorTest extends TestCase
{
$model = $this->getInvoiceModel();
- $sut = new InvoiceModelActivityHydrator();
+ $sut = new InvoiceModelActivityHydrator($this->createMock(ActivityStatisticService::class));
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
@@ -41,10 +42,18 @@ class InvoiceModelActivityHydratorTest extends TestCase
'activity.name',
'activity.comment',
'activity.meta.foo-activity',
+ 'activity.budget_open',
+ 'activity.budget_open_plain',
+ 'activity.time_budget_open',
+ 'activity.time_budget_open_plain',
'activity.1.id',
'activity.1.name',
'activity.1.comment',
'activity.1.meta.foo-activity',
+ 'activity.1.budget_open',
+ 'activity.1.budget_open_plain',
+ 'activity.1.time_budget_open',
+ 'activity.1.time_budget_open_plain',
];
$givenKeys = array_keys($model);
diff --git a/tests/Invoice/Hydrator/InvoiceModelCustomerHydratorTest.php b/tests/Invoice/Hydrator/InvoiceModelCustomerHydratorTest.php
index 241e902a..39a4c72c 100644
--- a/tests/Invoice/Hydrator/InvoiceModelCustomerHydratorTest.php
+++ b/tests/Invoice/Hydrator/InvoiceModelCustomerHydratorTest.php
@@ -9,6 +9,7 @@
namespace App\Tests\Invoice\Hydrator;
+use App\Customer\CustomerStatisticService;
use App\Invoice\Hydrator\InvoiceModelCustomerHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
@@ -24,7 +25,7 @@ class InvoiceModelCustomerHydratorTest extends TestCase
{
$model = $this->getInvoiceModel();
- $sut = new InvoiceModelCustomerHydrator();
+ $sut = new InvoiceModelCustomerHydrator($this->createMock(CustomerStatisticService::class));
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
@@ -52,6 +53,10 @@ class InvoiceModelCustomerHydratorTest extends TestCase
'customer.phone',
'customer.mobile',
'customer.meta.foo-customer',
+ 'customer.budget_open',
+ 'customer.budget_open_plain',
+ 'customer.time_budget_open',
+ 'customer.time_budget_open_plain',
];
$givenKeys = array_keys($model);
diff --git a/tests/Invoice/Hydrator/InvoiceModelProjectHydratorTest.php b/tests/Invoice/Hydrator/InvoiceModelProjectHydratorTest.php
index cdd1f550..d0649572 100644
--- a/tests/Invoice/Hydrator/InvoiceModelProjectHydratorTest.php
+++ b/tests/Invoice/Hydrator/InvoiceModelProjectHydratorTest.php
@@ -10,6 +10,7 @@
namespace App\Tests\Invoice\Hydrator;
use App\Invoice\Hydrator\InvoiceModelProjectHydrator;
+use App\Project\ProjectStatisticService;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
@@ -24,7 +25,7 @@ class InvoiceModelProjectHydratorTest extends TestCase
{
$model = $this->getInvoiceModel();
- $sut = new InvoiceModelProjectHydrator();
+ $sut = new InvoiceModelProjectHydrator($this->createMock(ProjectStatisticService::class));
$result = $sut->hydrate($model);
$this->assertModelStructure($result);
@@ -51,6 +52,10 @@ class InvoiceModelProjectHydratorTest extends TestCase
'project.budget_time',
'project.budget_time_decimal',
'project.budget_time_minutes',
+ 'project.budget_open',
+ 'project.budget_open_plain',
+ 'project.time_budget_open',
+ 'project.time_budget_open_plain',
'project.1.id',
'project.1.name',
'project.1.comment',
@@ -65,6 +70,10 @@ class InvoiceModelProjectHydratorTest extends TestCase
'project.1.budget_time',
'project.1.budget_time_decimal',
'project.1.budget_time_minutes',
+ 'project.1.budget_open',
+ 'project.1.budget_open_plain',
+ 'project.1.time_budget_open',
+ 'project.1.time_budget_open_plain',
];
$givenKeys = array_keys($model);
diff --git a/tests/Invoice/InvoiceFilenameTest.php b/tests/Invoice/InvoiceFilenameTest.php
index f0d1e379..07e8c260 100644
--- a/tests/Invoice/InvoiceFilenameTest.php
+++ b/tests/Invoice/InvoiceFilenameTest.php
@@ -13,10 +13,10 @@ use App\Entity\Customer;
use App\Entity\InvoiceTemplate;
use App\Entity\Project;
use App\Invoice\InvoiceFilename;
-use App\Invoice\InvoiceModel;
use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
/**
@@ -29,7 +29,7 @@ class InvoiceFilenameTest extends TestCase
$customer = new Customer();
$template = new InvoiceTemplate();
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setNumberGenerator($this->getNumberGeneratorSut());
$model->setTemplate($template);
$model->setCustomer($customer);
diff --git a/tests/Invoice/InvoiceModelTest.php b/tests/Invoice/InvoiceModelTest.php
index e5fc93e2..293da023 100644
--- a/tests/Invoice/InvoiceModelTest.php
+++ b/tests/Invoice/InvoiceModelTest.php
@@ -16,6 +16,7 @@ use App\Invoice\Calculator\DefaultCalculator;
use App\Invoice\InvoiceModel;
use App\Repository\Query\InvoiceQuery;
use App\Tests\Invoice\NumberGenerator\IncrementingNumberGenerator;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
/**
@@ -26,7 +27,7 @@ class InvoiceModelTest extends TestCase
public function testEmptyObject()
{
$formatter = new DebugFormatter();
- $sut = new InvoiceModel($formatter);
+ $sut = (new InvoiceModelFactoryFactory($this))->create()->createModel($formatter);
self::assertNull($sut->getQuery());
self::assertNull($sut->getCustomer());
@@ -51,7 +52,7 @@ class InvoiceModelTest extends TestCase
public function testEmptyObjectThrowsExceptionOnNumberGenerator()
{
$formatter = new DebugFormatter();
- $sut = new InvoiceModel($formatter);
+ $sut = (new InvoiceModelFactoryFactory($this))->create()->createModel($formatter);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('InvoiceModel::getInvoiceNumber() cannot be called before calling setNumberGenerator()');
@@ -60,7 +61,7 @@ class InvoiceModelTest extends TestCase
public function testSetter()
{
- $sut = new InvoiceModel(new DebugFormatter());
+ $sut = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$query = new InvoiceQuery();
self::assertInstanceOf(InvoiceModel::class, $sut->setQuery($query));
@@ -95,7 +96,7 @@ class InvoiceModelTest extends TestCase
*/
public function testDeprecations()
{
- $sut = new InvoiceModel(new DebugFormatter());
+ $sut = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$entries = [new Timesheet()];
self::assertInstanceOf(InvoiceModel::class, $sut->setEntries($entries));
diff --git a/tests/Invoice/NumberGenerator/ConfigurableNumberGeneratorTest.php b/tests/Invoice/NumberGenerator/ConfigurableNumberGeneratorTest.php
index fe91b7af..96c85db5 100644
--- a/tests/Invoice/NumberGenerator/ConfigurableNumberGeneratorTest.php
+++ b/tests/Invoice/NumberGenerator/ConfigurableNumberGeneratorTest.php
@@ -12,10 +12,10 @@ namespace App\Tests\Invoice\NumberGenerator;
use App\Configuration\SystemConfiguration;
use App\Entity\Customer;
use App\Entity\User;
-use App\Invoice\InvoiceModel;
use App\Invoice\NumberGenerator\ConfigurableNumberGenerator;
use App\Repository\InvoiceRepository;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
/**
@@ -156,7 +156,7 @@ class ConfigurableNumberGeneratorTest extends TestCase
$user->method('getAccountNumber')->willReturn('0815');
$sut = $this->getSut($format, $counter);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setInvoiceDate($invoiceDate);
$model->setCustomer($customer);
$model->setUser($user);
@@ -197,7 +197,7 @@ class ConfigurableNumberGeneratorTest extends TestCase
$this->expectExceptionMessage(sprintf('Unknown %s found', $brokenPart));
$sut = $this->getSut($format);
- $model = new InvoiceModel(new DebugFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter());
$model->setInvoiceDate($invoiceDate);
$model->setCustomer(new Customer());
$sut->setModel($model);
diff --git a/tests/Invoice/NumberGenerator/DateNumberGeneratorTest.php b/tests/Invoice/NumberGenerator/DateNumberGeneratorTest.php
index 6b0855b9..fba420ff 100644
--- a/tests/Invoice/NumberGenerator/DateNumberGeneratorTest.php
+++ b/tests/Invoice/NumberGenerator/DateNumberGeneratorTest.php
@@ -9,10 +9,10 @@
namespace App\Tests\Invoice\NumberGenerator;
-use App\Invoice\InvoiceModel;
use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Repository\InvoiceRepository;
use App\Tests\Invoice\DebugFormatter;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use PHPUnit\Framework\TestCase;
/**
@@ -40,7 +40,7 @@ class DateNumberGeneratorTest extends TestCase
public function testGetInvoiceNumber()
{
$sut = $this->getSut(false, false);
- $sut->setModel(new InvoiceModel(new DebugFormatter()));
+ $sut->setModel((new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter()));
$this->assertEquals(date('ymd'), $sut->getInvoiceNumber());
$this->assertEquals('date', $sut->getId());
@@ -49,7 +49,7 @@ class DateNumberGeneratorTest extends TestCase
public function testGetInvoiceNumberWithExisting()
{
$sut = $this->getSut(true, false);
- $sut->setModel(new InvoiceModel(new DebugFormatter()));
+ $sut->setModel((new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter()));
$this->assertEquals(date('ymd-01'), $sut->getInvoiceNumber());
$this->assertEquals('date', $sut->getId());
@@ -58,7 +58,7 @@ class DateNumberGeneratorTest extends TestCase
public function testGetInvoiceNumberWithManyExisting()
{
$sut = $this->getSut(true, true);
- $sut->setModel(new InvoiceModel(new DebugFormatter()));
+ $sut->setModel((new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter()));
$this->assertEquals(date('ymd-99'), $sut->getInvoiceNumber());
$this->assertEquals('date', $sut->getId());
diff --git a/tests/Invoice/Renderer/DebugRendererTest.php b/tests/Invoice/Renderer/DebugRendererTest.php
index 0e56869b..4365dfd3 100644
--- a/tests/Invoice/Renderer/DebugRendererTest.php
+++ b/tests/Invoice/Renderer/DebugRendererTest.php
@@ -131,12 +131,20 @@ class DebugRendererTest extends TestCase
'customer.email',
'customer.fax',
'customer.phone',
+ 'customer.budget_open',
+ 'customer.budget_open_plain',
+ 'customer.time_budget_open',
+ 'customer.time_budget_open_plain',
'customer.mobile',
'customer.meta.foo-customer',
'activity.id',
'activity.name',
'activity.comment',
'activity.meta.foo-activity',
+ 'activity.budget_open',
+ 'activity.budget_open_plain',
+ 'activity.time_budget_open',
+ 'activity.time_budget_open_plain',
'user.alias',
'user.email',
'user.name',
@@ -146,8 +154,18 @@ class DebugRendererTest extends TestCase
'testFromModelHydrator',
];
+ if ($activityCounter === 1) {
+ $keys = array_merge($keys, [
+ 'activity',
+ ]);
+ }
+
if ($activityCounter > 1) {
$keys = array_merge($keys, [
+ 'activity.1.budget_open',
+ 'activity.1.budget_open_plain',
+ 'activity.1.time_budget_open',
+ 'activity.1.time_budget_open_plain',
'activity.1.id',
'activity.1.name',
'activity.1.comment',
@@ -171,7 +189,16 @@ class DebugRendererTest extends TestCase
'project.budget_time',
'project.budget_time_decimal',
'project.budget_time_minutes',
+ 'project.budget_open',
+ 'project.budget_open_plain',
+ 'project.time_budget_open',
+ 'project.time_budget_open_plain',
]);
+ if ($projectCounter === 1) {
+ $keys = array_merge($keys, [
+ 'project',
+ ]);
+ }
if ($projectCounter > 1) {
$keys = array_merge($keys, [
'project.1.id',
@@ -188,6 +215,10 @@ class DebugRendererTest extends TestCase
'project.1.budget_time',
'project.1.budget_time_decimal',
'project.1.budget_time_minutes',
+ 'project.1.budget_open',
+ 'project.1.budget_open_plain',
+ 'project.1.time_budget_open',
+ 'project.1.time_budget_open_plain',
]);
}
}
diff --git a/tests/Invoice/Renderer/RendererTestTrait.php b/tests/Invoice/Renderer/RendererTestTrait.php
index f2b29660..5718bca2 100644
--- a/tests/Invoice/Renderer/RendererTestTrait.php
+++ b/tests/Invoice/Renderer/RendererTestTrait.php
@@ -30,6 +30,7 @@ use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Invoice\Renderer\AbstractRenderer;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
trait RendererTestTrait
{
@@ -217,7 +218,7 @@ trait RendererTestTrait
$query->setEnd(new \DateTime());
$query->setProjects([$project, $project2]);
- $model = new InvoiceModel($this->getFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel($this->getFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
@@ -301,7 +302,7 @@ trait RendererTestTrait
$query->setBegin(new \DateTime());
$query->setEnd(new \DateTime());
- $model = new InvoiceModel($this->getFormatter());
+ $model = (new InvoiceModelFactoryFactory($this))->create()->createModel($this->getFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->addEntries($entries);
diff --git a/tests/Invoice/Renderer/TwigRendererTest.php b/tests/Invoice/Renderer/TwigRendererTest.php
index 7012d968..e2086c10 100644
--- a/tests/Invoice/Renderer/TwigRendererTest.php
+++ b/tests/Invoice/Renderer/TwigRendererTest.php
@@ -66,10 +66,8 @@ class TwigRendererTest extends KernelTestCase
$filename = $model->getInvoiceNumber() . '-customer_with_special_name';
$this->assertStringContainsString('' . $filename . '', $content);
- $this->assertStringContainsString('', $content);
- $this->assertEquals(2, substr_count($content, 'activity description'));
+ $this->assertStringContainsString('a very *long* test invoice / template title with [ßpecial] chäracter', $content);
+ $this->assertEquals(3, substr_count($content, 'activity description'));
$this->assertStringContainsString(nl2br("foo\n" .
"foo\r\n" .
'foo' . PHP_EOL .
diff --git a/tests/Invoice/ServiceInvoiceTest.php b/tests/Invoice/ServiceInvoiceTest.php
index 46163403..65b29e00 100644
--- a/tests/Invoice/ServiceInvoiceTest.php
+++ b/tests/Invoice/ServiceInvoiceTest.php
@@ -24,6 +24,7 @@ use App\Invoice\ServiceInvoice;
use App\Repository\InvoiceDocumentRepository;
use App\Repository\InvoiceRepository;
use App\Repository\Query\InvoiceQuery;
+use App\Tests\Mocks\InvoiceModelFactoryFactory;
use App\Utils\FileHelper;
use PHPUnit\Framework\TestCase;
use Twig\Environment;
@@ -48,7 +49,7 @@ class ServiceInvoiceTest extends TestCase
$repo = new InvoiceDocumentRepository($paths);
$invoiceRepo = $this->createMock(InvoiceRepository::class);
- return new ServiceInvoice($repo, new FileHelper(realpath(__DIR__ . '/../../var/data/')), $invoiceRepo, $formattings);
+ return new ServiceInvoice($repo, new FileHelper(realpath(__DIR__ . '/../../var/data/')), $invoiceRepo, $formattings, (new InvoiceModelFactoryFactory($this))->create());
}
public function testInvalidExceptionOnChangeState()
diff --git a/tests/Mocks/InvoiceModelFactoryFactory.php b/tests/Mocks/InvoiceModelFactoryFactory.php
new file mode 100644
index 00000000..ffb4b322
--- /dev/null
+++ b/tests/Mocks/InvoiceModelFactoryFactory.php
@@ -0,0 +1,30 @@
+getMockBuilder(CustomerStatisticService::class)->disableOriginalConstructor()->getMock();
+ /** @var ProjectStatisticService $projectStatistic */
+ $projectStatistic = $this->getMockBuilder(ProjectStatisticService::class)->disableOriginalConstructor()->getMock();
+ /** @var ActivityStatisticService $activityStatistic */
+ $activityStatistic = $this->getMockBuilder(ActivityStatisticService::class)->disableOriginalConstructor()->getMock();
+
+ return new InvoiceModelFactory($customerStatistic, $projectStatistic, $activityStatistic);
+ }
+}