89 lines
3.3 KiB
PHP
89 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace RprtCli\Tests\Kernel;
|
|
|
|
use DI\ContainerBuilder;
|
|
use PHPUnit\Framework\TestCase;
|
|
use RprtCli\Commands\InvoiceCommand;
|
|
use RprtCli\Commands\ReportCommand;
|
|
use Symfony\Component\Console\Application;
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
use function file_exists;
|
|
use function unlink;
|
|
|
|
/**
|
|
* Report and invoice command test.
|
|
*
|
|
* Does not cover the part of talking to the api, nor does it yet cover email
|
|
* and pdf generation. @TODO
|
|
*/
|
|
class ReportCommandTest extends TestCase
|
|
{
|
|
protected const INPUT_CSV_FILE = __DIR__ . '/../data/21-03.csv';
|
|
|
|
protected const REPORT_OUTPUT_FILE = __DIR__ . '/../data/report-21-03.txt';
|
|
|
|
protected const INVOICE_OUTPUT_FILE = __DIR__ . '/../data/invoice-21-03.txt';
|
|
|
|
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');
|
|
$container = $builder->build();
|
|
|
|
$application = new Application('Command Line Tool to process Youtrack Reports', '0.1.0');
|
|
|
|
$invoiceCommand = $container->get(InvoiceCommand::class);
|
|
$application->add($invoiceCommand);
|
|
$reportCommand = $container->get(ReportCommand::class);
|
|
$application->add($reportCommand);
|
|
|
|
$reportCommand = $application->find('report');
|
|
$reportCommandTester = new CommandTester($reportCommand);
|
|
$reportCommandTester->execute([
|
|
// pass arguments to the helper
|
|
'--file' => __DIR__ . '/../data/21-03.csv',
|
|
|
|
// prefix the key with two dashes when passing options,
|
|
// e.g: '--some-option' => 'option_value',
|
|
// use brackets for testing array value,
|
|
// e.g: '--some-option' => ['option_value'],
|
|
]);
|
|
|
|
$reportCommandTester->assertCommandIsSuccessful();
|
|
|
|
// the output of the command in the console
|
|
$output = $reportCommandTester->getDisplay();
|
|
$this->assertStringContainsString('21-03.csv', $output, 'Check that report name is included in console output.');
|
|
$this->assertStringEqualsFile(self::REPORT_OUTPUT_FILE, $output, 'Check that report is still the same as it was.');
|
|
|
|
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);
|
|
$this->assertStringContainsString('21-03.csv', $invoice_output, 'Check that invoice command output contains report name.');
|
|
$this->assertStringEqualsFile(self::INVOICE_OUTPUT_FILE, $invoice_output, 'Check that invoice command output is the same as it was.');
|
|
$this->assertFileExists(self::INVOICE_OUTPUT_PDF, 'Check that pdf file was generated.');
|
|
}
|
|
}
|