Skip to content

Commit

Permalink
Merge pull request #570 from ergebnis/fix/prophesize
Browse files Browse the repository at this point in the history
Fix: Do not use `phpspec/prophecy`
  • Loading branch information
localheinz authored Dec 28, 2021
2 parents 74e251c + 9974dd0 commit f54a4bc
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 114 deletions.
23 changes: 12 additions & 11 deletions test/Unit/AutoFormatNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Ergebnis\Json\Normalizer\Format;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Normalizer\NormalizerInterface;
use Prophecy\Argument;

/**
* @internal
Expand Down Expand Up @@ -58,26 +57,28 @@ public function testNormalizeNormalizesAndFormatsUsingJsonFormat(): void
JSON
);

$composedNormalizer = $this->prophesize(NormalizerInterface::class);
$composedNormalizer = $this->createMock(NormalizerInterface::class);

$composedNormalizer
->normalize(Argument::is($json))
->shouldBeCalled()
->expects(self::once())
->method('normalize')
->with(self::identicalTo($json))
->willReturn($normalized);

$formatter = $this->prophesize(Format\FormatterInterface::class);
$formatter = $this->createMock(Format\FormatterInterface::class);

$formatter
->format(
Argument::is($normalized),
Argument::is($json->format()),
->expects(self::once())
->method('format')
->with(
self::identicalTo($normalized),
self::identicalTo($json->format()),
)
->shouldBeCalled()
->willReturn($formatted);

$normalizer = new AutoFormatNormalizer(
$composedNormalizer->reveal(),
$formatter->reveal(),
$composedNormalizer,
$formatter,
);

self::assertSame($formatted, $normalizer->normalize($json));
Expand Down
10 changes: 5 additions & 5 deletions test/Unit/ChainNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Ergebnis\Json\Normalizer\ChainNormalizer;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Normalizer\NormalizerInterface;
use Prophecy\Argument;

/**
* @internal
Expand Down Expand Up @@ -56,16 +55,17 @@ public function testNormalizePassesJsonThroughNormalizers(): void
$previous = $json;
}

$normalizer = $this->prophesize(NormalizerInterface::class);
$normalizer = $this->createMock(NormalizerInterface::class);

$normalizer
->normalize(Argument::is($previous))
->shouldBeCalled()
->expects(self::once())
->method('normalize')
->with(self::identicalTo($previous))
->willReturn($result);

$previous = $result;

return $normalizer->reveal();
return $normalizer;
}, $results);

$normalizer = new ChainNormalizer(...$normalizers);
Expand Down
23 changes: 12 additions & 11 deletions test/Unit/FixedFormatNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Ergebnis\Json\Normalizer\Format;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Normalizer\NormalizerInterface;
use Prophecy\Argument;

/**
* @internal
Expand Down Expand Up @@ -67,27 +66,29 @@ public function testNormalizeNormalizesAndFormatsUsingFormat(): void
JSON
);

$composedNormalizer = $this->prophesize(NormalizerInterface::class);
$composedNormalizer = $this->createMock(NormalizerInterface::class);

$composedNormalizer
->normalize(Argument::is($json))
->shouldBeCalled()
->expects(self::once())
->method('normalize')
->with(self::identicalTo($json))
->willReturn($normalized);

$formatter = $this->prophesize(Format\FormatterInterface::class);
$formatter = $this->createMock(Format\FormatterInterface::class);

$formatter
->format(
Argument::is($normalized),
Argument::is($format),
->expects(self::once())
->method('format')
->with(
self::identicalTo($normalized),
self::identicalTo($format),
)
->shouldBeCalled()
->willReturn($formatted);

$normalizer = new FixedFormatNormalizer(
$composedNormalizer->reveal(),
$composedNormalizer,
$format,
$formatter->reveal(),
$formatter,
);

self::assertSame($formatted, $normalizer->normalize($json));
Expand Down
16 changes: 8 additions & 8 deletions test/Unit/Format/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Ergebnis\Json\Printer;
use Ergebnis\Test\Util\Helper;
use PHPUnit\Framework;
use Prophecy\Argument;

/**
* @internal
Expand Down Expand Up @@ -91,18 +90,19 @@ public function testFormatEncodesWithJsonEncodeOptionsIndentsAndPossiblySuffixes
$hasFinalNewLine,
);

$printer = $this->prophesize(Printer\PrinterInterface::class);
$printer = $this->createMock(Printer\PrinterInterface::class);

$printer
->print(
Argument::is($encodedWithJsonEncodeOptions),
Argument::is($format->indent()->__toString()),
Argument::is($format->newLine()->__toString()),
->expects(self::once())
->method('print')
->with(
self::identicalTo($encodedWithJsonEncodeOptions),
self::identicalTo($format->indent()->__toString()),
self::identicalTo($format->newLine()->__toString()),
)
->shouldBeCalled()
->willReturn($printedWithIndentAndNewLine);

$formatter = new Formatter($printer->reveal());
$formatter = new Formatter($printer);

$formatted = $formatter->format(
$json,
Expand Down
14 changes: 7 additions & 7 deletions test/Unit/IndentNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Ergebnis\Json\Normalizer\IndentNormalizer;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Printer\PrinterInterface;
use Prophecy\Argument;

/**
* @internal
Expand Down Expand Up @@ -48,19 +47,20 @@ public function testNormalizeUsesPrinterToNormalizeJsonWithIndent(): void
}
JSON;

$printer = $this->prophesize(PrinterInterface::class);
$printer = $this->createMock(PrinterInterface::class);

$printer
->print(
Argument::is($json->encoded()),
Argument::is($indent->__toString()),
->expects(self::once())
->method('print')
->with(
self::identicalTo($json->encoded()),
self::identicalTo($indent->__toString()),
)
->shouldBeCalled()
->willReturn($indented);

$normalizer = new IndentNormalizer(
$indent,
$printer->reveal(),
$printer,
);

$normalized = $normalizer->normalize($json);
Expand Down
Loading

0 comments on commit f54a4bc

Please sign in to comment.