mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-13 19:51:30 +00:00
Build modified streamline images
The official image from streamline does not currently work for the arm64 platform. As a temporary measure, the source code and docker build scripts have been lifted from the official images and are used to build locally. Some additional modifications are made to reduce overall image size, these are documented in docker/README.md
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function is_array;
|
||||
use function sort;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function trim;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
/**
|
||||
* Arrays are equal if they contain the same key-value pairs.
|
||||
* The order of the keys does not matter.
|
||||
* The types of key-value pairs do not matter.
|
||||
*/
|
||||
class ArrayComparator extends Comparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return is_array($expected) && is_array($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false, array &$processed = []): void
|
||||
{
|
||||
assert(is_array($expected));
|
||||
assert(is_array($actual));
|
||||
|
||||
if ($canonicalize) {
|
||||
sort($expected);
|
||||
sort($actual);
|
||||
}
|
||||
|
||||
$remaining = $actual;
|
||||
$actualAsString = "Array (\n";
|
||||
$expectedAsString = "Array (\n";
|
||||
$equal = true;
|
||||
$exporter = new Exporter;
|
||||
|
||||
foreach ($expected as $key => $value) {
|
||||
unset($remaining[$key]);
|
||||
|
||||
if (!array_key_exists($key, $actual)) {
|
||||
$expectedAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$exporter->export($key),
|
||||
$exporter->shortenedExport($value)
|
||||
);
|
||||
|
||||
$equal = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$comparator = $this->factory()->getComparatorFor($value, $actual[$key]);
|
||||
$comparator->assertEquals($value, $actual[$key], $delta, $canonicalize, $ignoreCase, $processed);
|
||||
|
||||
$expectedAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$exporter->export($key),
|
||||
$exporter->shortenedExport($value)
|
||||
);
|
||||
|
||||
$actualAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$exporter->export($key),
|
||||
$exporter->shortenedExport($actual[$key])
|
||||
);
|
||||
} catch (ComparisonFailure $e) {
|
||||
$expectedAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$exporter->export($key),
|
||||
$e->getExpectedAsString() ? $this->indent($e->getExpectedAsString()) : $exporter->shortenedExport($e->getExpected())
|
||||
);
|
||||
|
||||
$actualAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$exporter->export($key),
|
||||
$e->getActualAsString() ? $this->indent($e->getActualAsString()) : $exporter->shortenedExport($e->getActual())
|
||||
);
|
||||
|
||||
$equal = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($remaining as $key => $value) {
|
||||
$actualAsString .= sprintf(
|
||||
" %s => %s\n",
|
||||
$exporter->export($key),
|
||||
$exporter->shortenedExport($value)
|
||||
);
|
||||
|
||||
$equal = false;
|
||||
}
|
||||
|
||||
$expectedAsString .= ')';
|
||||
$actualAsString .= ')';
|
||||
|
||||
if (!$equal) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$expectedAsString,
|
||||
$actualAsString,
|
||||
'Failed asserting that two arrays are equal.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function indent(string $lines): string
|
||||
{
|
||||
return trim(str_replace("\n", "\n ", $lines));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
abstract class Comparator
|
||||
{
|
||||
private Factory $factory;
|
||||
|
||||
public function setFactory(Factory $factory): void
|
||||
{
|
||||
$this->factory = $factory;
|
||||
}
|
||||
|
||||
abstract public function accepts(mixed $expected, mixed $actual): bool;
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
abstract public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void;
|
||||
|
||||
protected function factory(): Factory
|
||||
{
|
||||
return $this->factory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use RuntimeException;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
|
||||
|
||||
final class ComparisonFailure extends RuntimeException
|
||||
{
|
||||
private mixed $expected;
|
||||
private mixed $actual;
|
||||
private string $expectedAsString;
|
||||
private string $actualAsString;
|
||||
|
||||
public function __construct(mixed $expected, mixed $actual, string $expectedAsString, string $actualAsString, string $message = '')
|
||||
{
|
||||
parent::__construct($message);
|
||||
|
||||
$this->expected = $expected;
|
||||
$this->actual = $actual;
|
||||
$this->expectedAsString = $expectedAsString;
|
||||
$this->actualAsString = $actualAsString;
|
||||
}
|
||||
|
||||
public function getActual(): mixed
|
||||
{
|
||||
return $this->actual;
|
||||
}
|
||||
|
||||
public function getExpected(): mixed
|
||||
{
|
||||
return $this->expected;
|
||||
}
|
||||
|
||||
public function getActualAsString(): string
|
||||
{
|
||||
return $this->actualAsString;
|
||||
}
|
||||
|
||||
public function getExpectedAsString(): string
|
||||
{
|
||||
return $this->expectedAsString;
|
||||
}
|
||||
|
||||
public function getDiff(): string
|
||||
{
|
||||
if (!$this->actualAsString && !$this->expectedAsString) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$differ = new Differ(new UnifiedDiffOutputBuilder("\n--- Expected\n+++ Actual\n"));
|
||||
|
||||
return $differ->diff($this->expectedAsString, $this->actualAsString);
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return $this->getMessage() . $this->getDiff();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function assert;
|
||||
use function mb_strtolower;
|
||||
use function sprintf;
|
||||
use DOMDocument;
|
||||
use DOMNode;
|
||||
use ValueError;
|
||||
|
||||
final class DOMNodeComparator extends ObjectComparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return $expected instanceof DOMNode && $actual instanceof DOMNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false, array &$processed = []): void
|
||||
{
|
||||
assert($expected instanceof DOMNode);
|
||||
assert($actual instanceof DOMNode);
|
||||
|
||||
$expectedAsString = $this->nodeToText($expected, true, $ignoreCase);
|
||||
$actualAsString = $this->nodeToText($actual, true, $ignoreCase);
|
||||
|
||||
if ($expectedAsString !== $actualAsString) {
|
||||
$type = $expected instanceof DOMDocument ? 'documents' : 'nodes';
|
||||
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$expectedAsString,
|
||||
$actualAsString,
|
||||
sprintf("Failed asserting that two DOM %s are equal.\n", $type)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the normalized, whitespace-cleaned, and indented textual
|
||||
* representation of a DOMNode.
|
||||
*/
|
||||
private function nodeToText(DOMNode $node, bool $canonicalize, bool $ignoreCase): string
|
||||
{
|
||||
if ($canonicalize) {
|
||||
$document = new DOMDocument;
|
||||
|
||||
try {
|
||||
$c14n = $node->C14N();
|
||||
|
||||
assert(!empty($c14n));
|
||||
|
||||
@$document->loadXML($c14n);
|
||||
} catch (ValueError) {
|
||||
}
|
||||
|
||||
$node = $document;
|
||||
}
|
||||
|
||||
$document = $node instanceof DOMDocument ? $node : $node->ownerDocument;
|
||||
|
||||
$document->formatOutput = true;
|
||||
$document->normalizeDocument();
|
||||
|
||||
$text = $node instanceof DOMDocument ? $node->saveXML() : $document->saveXML($node);
|
||||
|
||||
return $ignoreCase ? mb_strtolower($text, 'UTF-8') : $text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function abs;
|
||||
use function assert;
|
||||
use function floor;
|
||||
use function sprintf;
|
||||
use DateInterval;
|
||||
use DateTimeInterface;
|
||||
use DateTimeZone;
|
||||
|
||||
final class DateTimeComparator extends ObjectComparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return ($expected instanceof DateTimeInterface) &&
|
||||
($actual instanceof DateTimeInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false, array &$processed = []): void
|
||||
{
|
||||
assert($expected instanceof DateTimeInterface);
|
||||
assert($actual instanceof DateTimeInterface);
|
||||
|
||||
$absDelta = abs($delta);
|
||||
$delta = new DateInterval(sprintf('PT%dS', $absDelta));
|
||||
$delta->f = $absDelta - floor($absDelta);
|
||||
|
||||
$actualClone = (clone $actual)
|
||||
->setTimezone(new DateTimeZone('UTC'));
|
||||
|
||||
$expectedLower = (clone $expected)
|
||||
->setTimezone(new DateTimeZone('UTC'))
|
||||
->sub($delta);
|
||||
|
||||
$expectedUpper = (clone $expected)
|
||||
->setTimezone(new DateTimeZone('UTC'))
|
||||
->add($delta);
|
||||
|
||||
if ($actualClone < $expectedLower || $actualClone > $expectedUpper) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$this->dateTimeToString($expected),
|
||||
$this->dateTimeToString($actual),
|
||||
'Failed asserting that two DateTime objects are equal.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ISO 8601 formatted string representation of a datetime or
|
||||
* 'Invalid DateTimeInterface object' if the provided DateTimeInterface was not properly
|
||||
* initialized.
|
||||
*/
|
||||
private function dateTimeToString(DateTimeInterface $datetime): string
|
||||
{
|
||||
$string = $datetime->format('Y-m-d\TH:i:s.uO');
|
||||
|
||||
return $string ?: 'Invalid DateTimeInterface object';
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function assert;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Compares Exception instances for equality.
|
||||
*/
|
||||
final class ExceptionComparator extends ObjectComparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return $expected instanceof Exception && $actual instanceof Exception;
|
||||
}
|
||||
|
||||
protected function toArray(object $object): array
|
||||
{
|
||||
assert($object instanceof Exception);
|
||||
|
||||
$array = parent::toArray($object);
|
||||
|
||||
unset(
|
||||
$array['file'],
|
||||
$array['line'],
|
||||
$array['trace'],
|
||||
$array['string'],
|
||||
$array['xdebug_message']
|
||||
);
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function array_unshift;
|
||||
|
||||
final class Factory
|
||||
{
|
||||
private static ?Factory $instance = null;
|
||||
|
||||
/**
|
||||
* @psalm-var list<Comparator>
|
||||
*/
|
||||
private array $customComparators = [];
|
||||
|
||||
/**
|
||||
* @psalm-var list<Comparator>
|
||||
*/
|
||||
private array $defaultComparators = [];
|
||||
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->registerDefaultComparators();
|
||||
}
|
||||
|
||||
public function getComparatorFor(mixed $expected, mixed $actual): Comparator
|
||||
{
|
||||
foreach ($this->customComparators as $comparator) {
|
||||
if ($comparator->accepts($expected, $actual)) {
|
||||
return $comparator;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->defaultComparators as $comparator) {
|
||||
if ($comparator->accepts($expected, $actual)) {
|
||||
return $comparator;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException('No suitable Comparator implementation found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new comparator.
|
||||
*
|
||||
* This comparator will be returned by getComparatorFor() if its accept() method
|
||||
* returns TRUE for the compared values. It has higher priority than the
|
||||
* existing comparators, meaning that its accept() method will be invoked
|
||||
* before those of the other comparators.
|
||||
*/
|
||||
public function register(Comparator $comparator): void
|
||||
{
|
||||
array_unshift($this->customComparators, $comparator);
|
||||
|
||||
$comparator->setFactory($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a comparator.
|
||||
*
|
||||
* This comparator will no longer be considered by getComparatorFor().
|
||||
*/
|
||||
public function unregister(Comparator $comparator): void
|
||||
{
|
||||
foreach ($this->customComparators as $key => $_comparator) {
|
||||
if ($comparator === $_comparator) {
|
||||
unset($this->customComparators[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
$this->customComparators = [];
|
||||
}
|
||||
|
||||
private function registerDefaultComparators(): void
|
||||
{
|
||||
$this->registerDefaultComparator(new MockObjectComparator);
|
||||
$this->registerDefaultComparator(new DateTimeComparator);
|
||||
$this->registerDefaultComparator(new DOMNodeComparator);
|
||||
$this->registerDefaultComparator(new SplObjectStorageComparator);
|
||||
$this->registerDefaultComparator(new ExceptionComparator);
|
||||
$this->registerDefaultComparator(new ObjectComparator);
|
||||
$this->registerDefaultComparator(new ResourceComparator);
|
||||
$this->registerDefaultComparator(new ArrayComparator);
|
||||
$this->registerDefaultComparator(new NumericComparator);
|
||||
$this->registerDefaultComparator(new ScalarComparator);
|
||||
$this->registerDefaultComparator(new TypeComparator);
|
||||
}
|
||||
|
||||
private function registerDefaultComparator(Comparator $comparator): void
|
||||
{
|
||||
$this->defaultComparators[] = $comparator;
|
||||
|
||||
$comparator->setFactory($this);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function array_keys;
|
||||
use function assert;
|
||||
use function str_starts_with;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
|
||||
/**
|
||||
* Compares PHPUnit\Framework\MockObject\MockObject instances for equality.
|
||||
*/
|
||||
final class MockObjectComparator extends ObjectComparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return $expected instanceof Stub && $actual instanceof Stub;
|
||||
}
|
||||
|
||||
protected function toArray(object $object): array
|
||||
{
|
||||
assert($object instanceof Stub);
|
||||
|
||||
$array = parent::toArray($object);
|
||||
|
||||
foreach (array_keys($array) as $key) {
|
||||
if (!str_starts_with($key, '__phpunit_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($array[$key]);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function abs;
|
||||
use function is_float;
|
||||
use function is_infinite;
|
||||
use function is_nan;
|
||||
use function is_numeric;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
final class NumericComparator extends ScalarComparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
// all numerical values, but not if both of them are strings
|
||||
return is_numeric($expected) && is_numeric($actual) &&
|
||||
!(is_string($expected) && is_string($actual));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void
|
||||
{
|
||||
if ($this->isInfinite($actual) && $this->isInfinite($expected)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($this->isInfinite($actual) xor $this->isInfinite($expected)) ||
|
||||
($this->isNan($actual) || $this->isNan($expected)) ||
|
||||
abs($actual - $expected) > $delta) {
|
||||
$exporter = new Exporter;
|
||||
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
'',
|
||||
'',
|
||||
sprintf(
|
||||
'Failed asserting that %s matches expected %s.',
|
||||
$exporter->export($actual),
|
||||
$exporter->export($expected)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function isInfinite(mixed $value): bool
|
||||
{
|
||||
return is_float($value) && is_infinite($value);
|
||||
}
|
||||
|
||||
private function isNan(mixed $value): bool
|
||||
{
|
||||
return is_float($value) && is_nan($value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function assert;
|
||||
use function in_array;
|
||||
use function is_object;
|
||||
use function sprintf;
|
||||
use function substr_replace;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
class ObjectComparator extends ArrayComparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return is_object($expected) && is_object($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false, array &$processed = []): void
|
||||
{
|
||||
assert(is_object($expected));
|
||||
assert(is_object($actual));
|
||||
|
||||
if ($actual::class !== $expected::class) {
|
||||
$exporter = new Exporter;
|
||||
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$exporter->export($expected),
|
||||
$exporter->export($actual),
|
||||
sprintf(
|
||||
'%s is not instance of expected class "%s".',
|
||||
$exporter->export($actual),
|
||||
$expected::class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// don't compare twice to allow for cyclic dependencies
|
||||
if (in_array([$actual, $expected], $processed, true) ||
|
||||
in_array([$expected, $actual], $processed, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$processed[] = [$actual, $expected];
|
||||
|
||||
// don't compare objects if they are identical
|
||||
// this helps to avoid the error "maximum function nesting level reached"
|
||||
// CAUTION: this conditional clause is not tested
|
||||
if ($actual !== $expected) {
|
||||
try {
|
||||
parent::assertEquals(
|
||||
$this->toArray($expected),
|
||||
$this->toArray($actual),
|
||||
$delta,
|
||||
$canonicalize,
|
||||
$ignoreCase,
|
||||
$processed
|
||||
);
|
||||
} catch (ComparisonFailure $e) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
// replace "Array" with "MyClass object"
|
||||
substr_replace($e->getExpectedAsString(), $expected::class . ' Object', 0, 5),
|
||||
substr_replace($e->getActualAsString(), $actual::class . ' Object', 0, 5),
|
||||
'Failed asserting that two objects are equal.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function toArray(object $object): array
|
||||
{
|
||||
return (new Exporter)->toArray($object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function assert;
|
||||
use function is_resource;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
final class ResourceComparator extends Comparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return is_resource($expected) && is_resource($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void
|
||||
{
|
||||
assert(is_resource($expected));
|
||||
assert(is_resource($actual));
|
||||
|
||||
$exporter = new Exporter;
|
||||
|
||||
if ($actual != $expected) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$exporter->export($expected),
|
||||
$exporter->export($actual)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function is_bool;
|
||||
use function is_object;
|
||||
use function is_scalar;
|
||||
use function is_string;
|
||||
use function mb_strtolower;
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
/**
|
||||
* Compares scalar or NULL values for equality.
|
||||
*/
|
||||
class ScalarComparator extends Comparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return ((is_scalar($expected) xor null === $expected) &&
|
||||
(is_scalar($actual) xor null === $actual)) ||
|
||||
// allow comparison between strings and objects featuring __toString()
|
||||
(is_string($expected) && is_object($actual) && method_exists($actual, '__toString')) ||
|
||||
(is_object($expected) && method_exists($expected, '__toString') && is_string($actual));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void
|
||||
{
|
||||
$expectedToCompare = $expected;
|
||||
$actualToCompare = $actual;
|
||||
$exporter = new Exporter;
|
||||
|
||||
// always compare as strings to avoid strange behaviour
|
||||
// otherwise 0 == 'Foobar'
|
||||
if ((is_string($expected) && !is_bool($actual)) || (is_string($actual) && !is_bool($expected))) {
|
||||
$expectedToCompare = (string) $expectedToCompare;
|
||||
$actualToCompare = (string) $actualToCompare;
|
||||
|
||||
if ($ignoreCase) {
|
||||
$expectedToCompare = mb_strtolower($expectedToCompare, 'UTF-8');
|
||||
$actualToCompare = mb_strtolower($actualToCompare, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
if ($expectedToCompare !== $actualToCompare && is_string($expected) && is_string($actual)) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$exporter->export($expected),
|
||||
$exporter->export($actual),
|
||||
'Failed asserting that two strings are equal.'
|
||||
);
|
||||
}
|
||||
|
||||
if ($expectedToCompare != $actualToCompare) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
// no diff is required
|
||||
'',
|
||||
'',
|
||||
sprintf(
|
||||
'Failed asserting that %s matches expected %s.',
|
||||
$exporter->export($actual),
|
||||
$exporter->export($expected)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function assert;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
use SplObjectStorage;
|
||||
|
||||
final class SplObjectStorageComparator extends Comparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return $expected instanceof SplObjectStorage && $actual instanceof SplObjectStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void
|
||||
{
|
||||
assert($expected instanceof SplObjectStorage);
|
||||
assert($actual instanceof SplObjectStorage);
|
||||
|
||||
$exporter = new Exporter;
|
||||
|
||||
foreach ($actual as $object) {
|
||||
if (!$expected->contains($object)) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$exporter->export($expected),
|
||||
$exporter->export($actual),
|
||||
'Failed asserting that two objects are equal.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($expected as $object) {
|
||||
if (!$actual->contains($object)) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
$exporter->export($expected),
|
||||
$exporter->export($actual),
|
||||
'Failed asserting that two objects are equal.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use function gettype;
|
||||
use function sprintf;
|
||||
use SebastianBergmann\Exporter\Exporter;
|
||||
|
||||
final class TypeComparator extends Comparator
|
||||
{
|
||||
public function accepts(mixed $expected, mixed $actual): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ComparisonFailure
|
||||
*/
|
||||
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void
|
||||
{
|
||||
if (gettype($expected) != gettype($actual)) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
// we don't need a diff
|
||||
'',
|
||||
'',
|
||||
sprintf(
|
||||
'%s does not match expected type "%s".',
|
||||
(new Exporter)->shortenedExport($actual),
|
||||
gettype($expected)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
use Throwable;
|
||||
|
||||
interface Exception extends Throwable
|
||||
{
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/comparator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Comparator;
|
||||
|
||||
final class RuntimeException extends \RuntimeException implements Exception
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user