Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bridge/symfony-console/src/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
* # Runs tests in Unit directory that match testImportant* AND are in Critical suite
* ./bin/testo run --path="tests/Unit/*" --filter=testImportant --suite=Critical
*
* # Hide the per-test progress; failures and the final report are still printed
* ./bin/testo run --no-progress
*
* # Run tests with custom config
* ./bin/testo run --config=./testo.php
* ```
Expand Down Expand Up @@ -94,6 +97,13 @@ public function configure(): void
'Write the minimalistic JSON report (run summary + failed tests) to the given path. '
. 'Unlike --json this keeps the human-readable terminal output; mirrors --log-junit.',
);
$this->addOption(
'no-progress',
null,
InputOption::VALUE_NONE,
'Print nothing per suite, case or test while the run goes; the failures and the final '
. 'report still come out at the end. Affects the terminal output only.',
);
$this->addOption(
'filter',
null,
Expand Down
41 changes: 37 additions & 4 deletions bridge/symfony-console/tests/Acceptance/RunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
use Testo\Lifecycle\BeforeTest;
use Testo\Output\Html\HtmlPlugin;
use Testo\Test;
use Tests\Bridge\SymfonyConsole\Stub\CapturedConsoleStreams;
use Tests\Bridge\SymfonyConsole\Stub\DiscardConsoleStreams;
use Tests\Bridge\SymfonyConsole\Testo\Sandbox;

/**
* Acceptance tests for the `--log-html` flag of `testo run`.
* Acceptance tests for the `--log-html` and `--no-progress` flags of `testo run`.
*
* Each test drives the real command end-to-end — Symfony parses the flags, {@see Run::initialize()}
* normalizes them and a whole nested run happens in-process — inside a fresh {@see Sandbox} holding a
Expand Down Expand Up @@ -94,6 +96,36 @@ public function withoutTheFlagNothingIsResolvedAndNoReportIsWritten(): void
);
}

public function noProgressLeavesOnlyTheFinalReport(): void
{
$this->sandbox->writeFile('testo.php', self::configPointingAtTheStubSuite(CapturedConsoleStreams::class));

$tester = $this->run(['--no-progress' => true]);
$output = CapturedConsoleStreams::output();

Assert::same($tester->getStatusCode(), Command::SUCCESS, $output);
Assert::string($output)->ignoringAnsi()
->notContains('Suite: Stub')
->notContains('PassingCase')
->notContains('itPasses')
->contains('Summary')
->contains('1 passed');
}

public function withoutNoProgressTheTestsAreListedAsTheyRun(): void
{
$this->sandbox->writeFile('testo.php', self::configPointingAtTheStubSuite(CapturedConsoleStreams::class));

$tester = $this->run();
$output = CapturedConsoleStreams::output();

Assert::same($tester->getStatusCode(), Command::SUCCESS, $output);
Assert::string($output)->ignoringAnsi()
->contains('Suite: Stub')
->contains('itPasses')
->contains('Summary');
}

#[BeforeTest]
public function setUp(): void
{
Expand All @@ -111,8 +143,10 @@ public function tearDown(): void
* The smallest config a nested run needs: no sources, one suite pointing at this module's stub case,
* and a fresh inert reporter in place of the process-wide default (see the class docblock).
* The stub directory is embedded as an absolute path — the sandbox CWD is elsewhere.
*
* @param class-string $streams Plugin that binds the run's console streams.
*/
private static function configPointingAtTheStubSuite(): string
private static function configPointingAtTheStubSuite(string $streams = DiscardConsoleStreams::class): string
{
$stub = \var_export(\dirname(__DIR__) . '/Stub/Run', true);

Expand All @@ -126,7 +160,6 @@ private static function configPointingAtTheStubSuite(): string
use Testo\\Application\\Config\\Plugin\\ApplicationPlugins;
use Testo\\Application\\Config\\SuiteConfig;
use Testo\\Output\\Html\\HtmlPlugin;
use Tests\\Bridge\\SymfonyConsole\\Stub\\DiscardConsoleStreams;

return new ApplicationConfig(
src: [],
Expand All @@ -137,7 +170,7 @@ private static function configPointingAtTheStubSuite(): string
),
],
plugins: ApplicationPlugins::without(HtmlPlugin::class)
->with(HtmlPlugin::inert(), new DiscardConsoleStreams()),
->with(HtmlPlugin::inert(), new \\{$streams}()),
);
PHP;
}
Expand Down
43 changes: 43 additions & 0 deletions bridge/symfony-console/tests/Stub/CapturedConsoleStreams.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Tests\Bridge\SymfonyConsole\Stub;

use Internal\Container\Container;
use Testo\Common\PluginConfigurator;
use Testo\Output\ConsoleStreams;

/**
* Points the reporters of a nested in-process run at a memory stream the test reads back.
*
* The run builds this plugin from its config file, so the test has no handle on the instance; the
* stream is reachable through {@see self::output()} instead.
*/
final class CapturedConsoleStreams implements PluginConfigurator
{
/** @var resource|null */
private static $sink = null;

/**
* Everything the last configured run wrote to its console.
*/
public static function output(): string
{
if (self::$sink === null) {
return '';
}

\rewind(self::$sink);
return (string) \stream_get_contents(self::$sink);
}

#[\Override]
public function configure(Container $container): void
{
$sink = \fopen('php://memory', 'w+b');
\assert($sink !== false);
self::$sink = $sink;
$container->set(new ConsoleStreams($sink, $sink), ConsoleStreams::class);
}
}
25 changes: 25 additions & 0 deletions core/Output/Terminal/Internal/TerminalInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Testo\Output\Terminal\Internal;

use Testo\Application\Config\Internal\Attribute\InflectableConfig;
use Testo\Application\Config\Internal\Attribute\InputOption;

/**
* CLI input for the terminal reporter.
*
* @internal
* @psalm-internal Testo\Output\Terminal
*/
#[InflectableConfig]
final class TerminalInput
{
/**
* `--no-progress` — print nothing per suite, case or test while the run goes; the failures and the
* final report still come out at the end.
*/
#[InputOption('no-progress')]
public bool $noProgress = false;
}
Loading
Loading