Skip to content

Commit

Permalink
test: Tweak the SpecFormatter
Browse files Browse the repository at this point in the history
- Rename it to `SpecPrinter`
- Passes the `SpecScenario` object for simplicitation
- Add tests
  • Loading branch information
theofidry committed Apr 14, 2024
1 parent 60cef8c commit 5e23347
Show file tree
Hide file tree
Showing 3 changed files with 472 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@

namespace Humbug\PhpScoper\Scoper\Spec;

use Humbug\PhpScoper\Configuration\SymbolsConfiguration;
use Humbug\PhpScoper\NotInstantiable;
use Humbug\PhpScoper\Symbol\NamespaceRegistry;
use Humbug\PhpScoper\Symbol\SymbolRegistry;
use Humbug\PhpScoper\Symbol\SymbolsRegistry;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use function array_map;
use function count;
Expand All @@ -34,26 +32,23 @@
/**
* @internal
*/
#[Group('integration')]
class SpecFormatter extends TestCase
final class SpecPrinter extends TestCase
{
use NotInstantiable;

/**
* @param string[][] $expectedRegisteredClasses
* @param string[][] $expectedRegisteredFunctions
*/
public static function createSpecMessage(
string $file,
string $spec,
string $contents,
SymbolsConfiguration $symbolsConfiguration,
SpecScenario $scenario,
SymbolsRegistry $symbolsRegistry,
?string $expected,
?string $actual,
array $expectedRegisteredClasses,
array $expectedRegisteredFunctions
?string $actualCode,
): string {
$file = $scenario->file;
$title = $scenario->title;
$inputCode = $scenario->inputCode;
$symbolsConfiguration = $scenario->symbolsConfiguration;
$expectedCode = $scenario->expectedCode;
$expectedRegisteredClasses = $scenario->expectedRegisteredClasses;
$expectedRegisteredFunctions = $scenario->expectedRegisteredFunctions;

$formattedExposeGlobalClasses = self::convertBoolToString($symbolsConfiguration->shouldExposeGlobalClasses());
$formattedExposeGlobalConstants = self::convertBoolToString($symbolsConfiguration->shouldExposeGlobalConstants());
$formattedExposeGlobalFunctions = self::convertBoolToString($symbolsConfiguration->shouldExposeGlobalFunctions());
Expand All @@ -78,7 +73,7 @@ public static function createSpecMessage(
$titleSeparator = str_repeat(
'=',
min(
strlen($spec),
strlen($title),
80,
),
);
Expand All @@ -87,7 +82,7 @@ public static function createSpecMessage(
{$titleSeparator}
SPECIFICATION
{$titleSeparator}
{$spec}
{$title}
{$file}
{$titleSeparator}
Expand All @@ -107,20 +102,20 @@ public static function createSpecMessage(
(raw) internal functions: {$formattedInternalFunctions}
(raw) internal constants: {$formattedInternalConstants}
{$titleSeparator}
{$contents}
{$inputCode}
{$titleSeparator}
EXPECTED
{$titleSeparator}
{$expected}
{$expectedCode}
----------------
recorded functions: {$formattedExpectedRegisteredFunctions}
recorded classes: {$formattedExpectedRegisteredClasses}
{$titleSeparator}
ACTUAL
{$titleSeparator}
{$actual}
{$actualCode}
----------------
recorded functions: {$formattedActualRegisteredFunctions}
recorded classes: {$formattedActualRegisteredClasses}
Expand Down
Loading

0 comments on commit 5e23347

Please sign in to comment.