Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make exporter configurable #5773

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/Event/Emitter/DispatchingEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use PHPUnit\Event\TestSuite\Started as TestSuiteStarted;
use PHPUnit\Event\TestSuite\TestSuite;
use PHPUnit\TextUI\Configuration\Configuration;
use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -582,7 +582,7 @@ public function testCreatedTestProxy(string $className, array $constructorArgume
new Test\TestProxyCreated(
$this->telemetryInfo(),
$className,
(new Exporter)->export($constructorArguments),
ExporterFacade::instance()->export($constructorArguments),
),
);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Event/Value/Test/TestMethodBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use PHPUnit\Event\TestData\TestDataCollection;
use PHPUnit\Framework\TestCase;
use PHPUnit\Metadata\Parser\Registry as MetadataRegistry;
use PHPUnit\Util\ExporterFacade;
use PHPUnit\Util\Reflection;
use SebastianBergmann\Exporter\Exporter;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -60,7 +60,6 @@ public static function fromCallStack(): TestMethod

private static function dataFor(TestCase $testCase): TestDataCollection
{
$exporter = new Exporter;
$testData = [];

if ($testCase->usesDataProvider()) {
Expand All @@ -72,14 +71,14 @@ private static function dataFor(TestCase $testCase): TestDataCollection

$testData[] = DataFromDataProvider::from(
$dataSetName,
$exporter->export($testCase->providedData()),
ExporterFacade::instance()->export($testCase->providedData()),
$testCase->dataSetAsStringWithData(),
);
}

if ($testCase->hasDependencyInput()) {
$testData[] = DataFromTestDependency::from(
$exporter->export($testCase->dependencyInput()),
ExporterFacade::instance()->export($testCase->dependencyInput()),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Cardinality/GreaterThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
namespace PHPUnit\Framework\Constraint;

use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand All @@ -28,7 +28,7 @@ public function __construct(mixed $value)
*/
public function toString(): string
{
return 'is greater than ' . (new Exporter)->export($this->value);
return 'is greater than ' . ExporterFacade::instance()->export($this->value);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Cardinality/LessThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
namespace PHPUnit\Framework\Constraint;

use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand All @@ -28,7 +28,7 @@ public function __construct(mixed $value)
*/
public function toString(): string
{
return 'is less than ' . (new Exporter)->export($this->value);
return 'is less than ' . ExporterFacade::instance()->export($this->value);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Framework/Constraint/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use Countable;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\SelfDescribing;
use PHPUnit\Util\ExporterFacade;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Exporter\Exporter;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -123,7 +123,7 @@
*/
protected function failureDescription(mixed $other): string
{
return (new Exporter)->export($other) . ' ' . $this->toString();
return ExporterFacade::instance()->export($other) . ' ' . $this->toString();
}

/**
Expand Down Expand Up @@ -163,7 +163,7 @@
return '';
}

return (new Exporter)->export($other) . ' ' . $string;
return ExporterFacade::instance()->export($other) . ' ' . $string;

Check warning on line 166 in src/Framework/Constraint/Constraint.php

View check run for this annotation

Codecov / codecov/patch

src/Framework/Constraint/Constraint.php#L166

Added line #L166 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Equality/IsEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use function str_contains;
use function trim;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Util\ExporterFacade;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Comparator\Factory as ComparatorFactory;
use SebastianBergmann\Exporter\Exporter;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -97,7 +97,7 @@ public function toString(): string

return sprintf(
'is equal to %s%s',
(new Exporter)->export($this->value),
ExporterFacade::instance()->export($this->value),
$delta,
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Equality/IsEqualCanonicalizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use function str_contains;
use function trim;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Util\ExporterFacade;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Comparator\Factory as ComparatorFactory;
use SebastianBergmann\Exporter\Exporter;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -97,7 +97,7 @@ public function toString(): string

return sprintf(
'is equal to %s',
(new Exporter)->export($this->value),
ExporterFacade::instance()->export($this->value),
);
}
}
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Equality/IsEqualIgnoringCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use function str_contains;
use function trim;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Util\ExporterFacade;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Comparator\Factory as ComparatorFactory;
use SebastianBergmann\Exporter\Exporter;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -98,7 +98,7 @@ public function toString(): string

return sprintf(
'is equal to %s',
(new Exporter)->export($this->value),
ExporterFacade::instance()->export($this->value),
);
}
}
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Equality/IsEqualWithDelta.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use function sprintf;
use function trim;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Util\ExporterFacade;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Comparator\Factory as ComparatorFactory;
use SebastianBergmann\Exporter\Exporter;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -85,7 +85,7 @@ public function toString(): string
{
return sprintf(
'is equal to %s with delta <%F>',
(new Exporter)->export($this->value),
ExporterFacade::instance()->export($this->value),
$this->delta,
);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Framework/Constraint/Exception/ExceptionCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace PHPUnit\Framework\Constraint;

use function sprintf;
use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -46,12 +46,10 @@ protected function matches(mixed $other): bool
*/
protected function failureDescription(mixed $other): string
{
$exporter = new Exporter;

return sprintf(
'%s is equal to expected exception code %s',
$exporter->export($other),
$exporter->export($this->expectedCode),
ExporterFacade::instance()->export($other),
ExporterFacade::instance()->export($this->expectedCode),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use function sprintf;
use function str_contains;
use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand All @@ -31,7 +31,7 @@ public function toString(): string
return 'exception message is empty';
}

return 'exception message contains ' . (new Exporter)->export($this->expectedMessage);
return 'exception message contains ' . ExporterFacade::instance()->export($this->expectedMessage);
}

protected function matches(mixed $other): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use function preg_match;
use function sprintf;
use Exception;
use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand All @@ -28,7 +28,7 @@ public function __construct(string $regularExpression)

public function toString(): string
{
return 'exception message matches ' . (new Exporter)->export($this->regularExpression);
return 'exception message matches ' . ExporterFacade::instance()->export($this->regularExpression);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Framework/Constraint/IsIdentical.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use function is_string;
use function sprintf;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Util\ExporterFacade;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Exporter\Exporter;
use UnitEnum;

/**
Expand Down Expand Up @@ -67,13 +67,11 @@ public function evaluate(mixed $other, string $description = '', bool $returnRes

// if both values are array or enums, make sure a diff is generated
if ((is_array($this->value) && is_array($other)) || ($this->value instanceof UnitEnum && $other instanceof UnitEnum)) {
$exporter = new Exporter;

$f = new ComparisonFailure(
$this->value,
$other,
$exporter->export($this->value),
$exporter->export($other),
ExporterFacade::instance()->export($this->value),
ExporterFacade::instance()->export($other),
);
}

Expand All @@ -93,7 +91,7 @@ public function toString(): string
$this->value::class . '"';
}

return 'is identical to ' . (new Exporter)->export($this->value);
return 'is identical to ' . ExporterFacade::instance()->export($this->value);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Constraint/String/StringContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use function str_contains;
use function strlen;
use function strtr;
use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -60,7 +60,7 @@ public function toString(): string

public function failureDescription(mixed $other): string
{
$stringifiedHaystack = (new Exporter)->export($other);
$stringifiedHaystack = ExporterFacade::instance()->export($other);
$haystackEncoding = $this->getDetectedEncoding($other);
$haystackLength = $this->getHaystackLength($other);

Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Traversable/ArrayHasKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use function array_key_exists;
use function is_array;
use ArrayAccess;
use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand All @@ -31,7 +31,7 @@ public function __construct(int|string $key)
*/
public function toString(): string
{
return 'has the key ' . (new Exporter)->export($this->key);
return 'has the key ' . ExporterFacade::instance()->export($this->key);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Constraint/Traversable/TraversableContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use function is_array;
use function sprintf;
use SebastianBergmann\Exporter\Exporter;
use PHPUnit\Util\ExporterFacade;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand All @@ -30,7 +30,7 @@ public function __construct(mixed $value)
*/
public function toString(): string
{
return 'contains ' . (new Exporter)->export($this->value);
return 'contains ' . ExporterFacade::instance()->export($this->value);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
use PHPUnit\Runner\DeprecationCollector\Facade as DeprecationCollector;
use PHPUnit\TestRunner\TestResult\PassedTests;
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
use PHPUnit\Util\ExporterFacade;
use PHPUnit\Util\Test as TestUtil;
use ReflectionClass;
use ReflectionException;
Expand Down Expand Up @@ -2062,16 +2063,15 @@ private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after):
private function compareGlobalStateSnapshotPart(array $before, array $after, string $header): void
{
if ($before != $after) {
$differ = new Differ(new UnifiedDiffOutputBuilder($header));
$exporter = new Exporter;
$differ = new Differ(new UnifiedDiffOutputBuilder($header));

Event\Facade::emitter()->testConsideredRisky(
$this->valueObjectForEvents(),
'This test modified global state but was not expected to do so' . PHP_EOL .
trim(
$differ->diff(
$exporter->export($before),
$exporter->export($after),
ExporterFacade::instance()->export($before),
ExporterFacade::instance()->export($after),
),
),
);
Expand Down
1 change: 1 addition & 0 deletions src/Framework/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use function tempnam;
use function unlink;
use function var_export;
use function xdebug_is_debugger_active;
use AssertionError;
use PHPUnit\Event;
use PHPUnit\Event\NoPreviousThrowableException;
Expand Down
Loading