diff --git a/app/composer.json b/app/composer.json
index 81012fc..0a7a2ef 100644
--- a/app/composer.json
+++ b/app/composer.json
@@ -36,7 +36,8 @@
},
"scripts": {
"cs": "phpcs --colors --standard=PSR12",
- "cbf": "phpcbf"
+ "cbf": "phpcbf",
+ "phpstan": "phpstan analyze -l 5 src"
},
"config": {
"allow-plugins": {
diff --git a/app/src/Commands/InvoiceCommand.php b/app/src/Commands/InvoiceCommand.php
index 43823bf..1490915 100644
--- a/app/src/Commands/InvoiceCommand.php
+++ b/app/src/Commands/InvoiceCommand.php
@@ -27,6 +27,7 @@ use function explode;
use function is_array;
use function is_null;
use function is_string;
+use function PHPUnit\Framework\throwException;
use function readline;
use function strpos;
use function strtolower;
@@ -42,13 +43,15 @@ class InvoiceCommand extends Command
{
use SelectReportTrait;
- protected $csv;
+ protected ReportCsvInterface $csv;
- protected $config;
+ protected ConfigurationInterface $config;
- protected $youtrack;
+ protected YoutrackInterface $trackingService;
- protected $pdfExport;
+ protected PdfExportInterface $pdfExport;
+
+ protected MailerInterface $mailer;
protected const TYPE_WORK = 1;
protected const TYPE_EXPENSE = 2;
@@ -185,11 +188,11 @@ class InvoiceCommand extends Command
if ($out = $input->getOption('output')) {
$this->pdfExport->setOutput($out);
}
- $output_path = $this->pdfExport->fromDefaultDataToPdf($nice_data);
+ $output_path = $this->pdfExport->fromDefaultDataToPdf($nice_data) ?: sys_get_temp_dir();
// Notify the user where the file was generated to.
$output->writeln("The file was generated at
{$cell} | "; } diff --git a/app/src/Utils/TimeTrackingServices/YoutrackInterface.php b/app/src/Utils/TimeTrackingServices/YoutrackInterface.php index 97bad20..cd790aa 100644 --- a/app/src/Utils/TimeTrackingServices/YoutrackInterface.php +++ b/app/src/Utils/TimeTrackingServices/YoutrackInterface.php @@ -40,4 +40,9 @@ interface YoutrackInterface public function setReportName(?string $report_name = null): void; public function getReportName(): ?string; + + /** + * Clears cache for youtrack report. + */ + public function clearReportCache(string $report_id): int; } diff --git a/app/tests/Kernel/ReportCommandTest.php b/app/tests/Kernel/ReportCommandTest.php index 032280c..fcedf53 100644 --- a/app/tests/Kernel/ReportCommandTest.php +++ b/app/tests/Kernel/ReportCommandTest.php @@ -27,6 +27,9 @@ class ReportCommandTest extends TestCase { protected const INVOICE_OUTPUT_PDF = __DIR__ . '/../data/output/Invoice-test.pdf'; + /** + * Run report and invoice command with file option parameter. Check if pdf was generated. + */ public function testExecute() { $builder = new ContainerBuilder(); $builder->addDefinitions(__DIR__ . '/../test-dependencies.php'); @@ -60,29 +63,25 @@ class ReportCommandTest extends TestCase { $this->assertStringContainsString('21-03.csv', $output); $this->assertStringEqualsFile(self::REPORT_OUTPUT_FILE, $output); + if (file_exists(self::INVOICE_OUTPUT_PDF)) { + unlink(self::INVOICE_OUTPUT_PDF); + } $invoiceCommand = $application->find('invoice'); $invoiceCommandTester = new CommandTester($invoiceCommand); $invoiceCommandTester->execute([ '--file' => self::INPUT_CSV_FILE, '--pdf' => TRUE, + '--output' => self::INVOICE_OUTPUT_PDF, ]); $invoiceCommandTester->assertCommandIsSuccessful(); // the output of the command in the console $invoice_output = $invoiceCommandTester->getDisplay(); - var_dump($invoice_output); + // var_dump($invoice_output); $this->assertStringContainsString('21-03.csv', $invoice_output); $this->assertStringEqualsFile(self::INVOICE_OUTPUT_FILE, $invoice_output); - - // $invoiceCommandTester->execute([ - // '--file' => self::INPUT_CSV_FILE, - // '--pdf' - // ]); - // $invoice_output = $invoiceCommandTester->getDisplay(); - // var_dump($invoice_output); - // $this->assertFileExists(); - + $this->assertFileExists(self::INVOICE_OUTPUT_PDF); } } diff --git a/app/tests/data/invoice-21-03.txt b/app/tests/data/invoice-21-03.txt index 3da3ffc..ccb8e60 100644 --- a/app/tests/data/invoice-21-03.txt +++ b/app/tests/data/invoice-21-03.txt @@ -9,3 +9,4 @@ report: /home/lio/Projects/drunomix/rprt-cli/app/tests/Kernel/../data/21-03.csv +-----------------------------+--------+-------+----------+ | Gessamt brutto | 4.505,35 | +-----------------------------+--------+-------+----------+ +The file was generated at /home/lio/Projects/drunomix/rprt-cli/app/tests/Kernel/../data/output/Invoice-test.pdf. diff --git a/todo.txt b/todo.txt index 1a5e46c..287a6cb 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,4 @@ TODO: -- nice report selection - clean up the config (default reports) - Improve readme - abstract baseCommand with some input params @@ -8,13 +7,9 @@ TODO: - in dependencies.php find subdependencies.php - Create interface for 3rd party service integration and abstract class - Create factory to add correct service of a 3rd party service to the Command -- separator constant ------------------------ - add plugin system for time tracking service -- add tests ------------------------ -- question helper: https://symfony.com/doc/current/components/console/helpers/questionhelper.html -- psr-12 code check and add phpstan https://phpstan.org/user-guide/getting-started - phing for build automation - add ddev for dockerization @@ -32,6 +27,7 @@ OPTIONAL: - youtrack - jira - kimai +- build phar without most of the fonts @@ -44,4 +40,8 @@ DONE: - upload a phar file on repo - create release - clear report cache - +- nice report selection +- separator constant +- add tests +- psr-12 code check and add phpstan https://phpstan.org/user-guide/getting-started +- question helper: https://symfony.com/doc/current/components/console/helpers/questionhelper.html
---|