Skip to content

Commit

Permalink
Add scan test.
Browse files Browse the repository at this point in the history
  • Loading branch information
m50 committed Feb 9, 2020
1 parent 88e7fe2 commit c98fe77
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/integration/ScanTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Tests\Command;

use PHPUnit\Framework\TestCase;
use NotSoSimple\Commands\InitCommand;
use NotSoSimple\Commands\ScanCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\TesterTrait;
use Symfony\Component\Console\Tester\CommandTester;

class ScanTest extends TestCase
{
use TesterTrait;

private static ?CommandTester $commandTester = null;

private static string $outputDir = '';

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
$application = new Application();
$application->add(new ScanCommand());

$command = $application->find('scan');
static::$commandTester = new CommandTester($command);

static::$outputDir = getenv('TEST_OUTPUT_DIR') ?? __DIR__;
}

public function tearDown(): void
{
parent::tearDown();

// @unlink(static::$outputDir . '/report.json');
// @unlink(static::$outputDir . '/report.html');
// @unlink(static::$outputDir . '/report.junit.xml');
}

/** @test */
function test_execute()
{
static::$commandTester->execute(['--files' => __DIR__ . '/../../README.md', '-e' => './vendor/']);
$output = static::$commandTester->getDisplay();
$this->assertRegExp('/Scanning [\.\/a-z]+README.md.../', $output);
$this->assertRegExp('/Simple took \d\.\d+ seconds to run\./', $output);
$this->assertRegExp('/simple\(\d\)\s*in\s*[\.\/a-z]+README\.md:\d+\s*\n\s+\=\>/', $output);
}

/** @test */
function test_execute_json_report()
{
static::$commandTester->execute([
'--files' => __DIR__ . '/../../README.md',
'-e' => './vendor/',
'--report-file' => static::$outputDir . '/report.json',
]);

$this->assertFileExists(static::$outputDir . '/report.json');
}

/** @test */
function test_execute_html_report()
{
static::$commandTester->execute([
'--files' => __DIR__ . '/../../README.md',
'-e' => './vendor/',
'--report-file' => static::$outputDir . '/report.html',
]);

$this->assertFileExists(static::$outputDir . '/report.html');
}

/** @test */
function test_execute_junit_report()
{
static::$commandTester->execute([
'--files' => __DIR__ . '/../../README.md',
'-e' => './vendor/',
'--report-file' => static::$outputDir . '/report.junit.xml',
]);

$this->assertFileExists(static::$outputDir . '/report.junit.xml');
}
}

0 comments on commit c98fe77

Please sign in to comment.