89 lines
3.0 KiB
PHP
89 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace RprtCli\Tests\Kernel;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Console\Application;
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
use DI\ContainerBuilder;
|
|
use RprtCli\Commands\InvoiceCommand;
|
|
use RprtCli\Commands\ReportCommand;
|
|
|
|
/**
|
|
* 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';
|
|
|
|
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();
|
|
// var_dump($output);
|
|
$this->assertStringContainsString('21-03.csv', $output);
|
|
$this->assertStringEqualsFile(self::REPORT_OUTPUT_FILE, $output);
|
|
|
|
$invoiceCommand = $application->find('invoice');
|
|
$invoiceCommandTester = new CommandTester($invoiceCommand);
|
|
$invoiceCommandTester->execute([
|
|
'--file' => self::INPUT_CSV_FILE,
|
|
'--pdf' => TRUE,
|
|
]);
|
|
|
|
$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);
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|