-
-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathChainableDenormalizerTestCase.php
110 lines (83 loc) · 3.31 KB
/
ChainableDenormalizerTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
* This file is part of the Alice package.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\Chainable;
use Nelmio\Alice\Definition\FlagBag;
use Nelmio\Alice\FixtureBag;
use Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\ChainableFixtureDenormalizerInterface;
use Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\FixtureDenormalizerInterface;
use Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\FixtureFactory;
use Nelmio\Alice\FixtureBuilder\Denormalizer\Fixture\ReferenceProviderTrait;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
abstract class ChainableDenormalizerTestCase extends TestCase
{
use ProphecyTrait;
use ReferenceProviderTrait;
/**
* @var ChainableFixtureDenormalizerInterface
*/
protected $denormalizer;
public function testIsABuilderMethod(): void
{
self::assertInstanceOf(ChainableFixtureDenormalizerInterface::class, $this->denormalizer);
}
abstract public function testCanBuildSimpleFixtures($name);
abstract public function testCanBuildListFixtures($name);
abstract public function testCanBuildMalformedListFixtures($name);
abstract public function testCanBuildSegmentFixtures($name);
abstract public function testCanBuildMalformedSegmentFixtures($name);
abstract public function testBuildSimpleFixtures($name, $expected);
abstract public function testBuildListFixtures($name, $expected);
abstract public function testBuildMalformedListFixtures($name, $expected);
abstract public function testBuildSegmentFixtures($name, $expected);
abstract public function testBuildMalformedSegmentFixtures($name, $expected);
public function assertCanBuild(string $fixtureId): void
{
$actual = $this->denormalizer->canDenormalize($fixtureId);
self::assertTrue($actual);
}
public function assertCannotBuild(string $fixtureId): void
{
$actual = $this->denormalizer->canDenormalize($fixtureId);
self::assertFalse($actual);
}
public function assertBuiltResultIsTheSame(string $fixtureId, array $expected): void
{
self::assertTrue($this->denormalizer->canDenormalize($fixtureId));
$actual = $this->denormalizer->denormalize(
new FixtureBag(),
'Dummy',
$fixtureId,
[],
new FlagBag(''),
);
$expectedFixtures = new FixtureBag();
foreach ($expected as $item) {
$expectedFixtures = $expectedFixtures->with($item);
}
self::assertEquals($expectedFixtures, $actual);
}
public function markAsInvalidCase(): void
{
self::assertTrue(true, 'Invalid scenario');
}
public function createDummyDenormalizer(): FixtureDenormalizerInterface
{
$decoratedDenormalizerProphecy = $this->prophesize(FixtureDenormalizerInterface::class);
$decoratedDenormalizerProphecy
->denormalize(Argument::cetera())
->will(
fn ($args) => $args[0]->with(FixtureFactory::create($args[2], '')),
);
return $decoratedDenormalizerProphecy->reveal();
}
}