Skip to content

Commit 804565d

Browse files
committed
feat: implement add removals to json diff action test
1 parent 20d7288 commit 804565d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jet\Tests\Unit\Actions;
6+
7+
use Illuminate\Container\Container;
8+
use Jet\JsonDiff\Actions\AddRemovalsToJsonDiffAction;
9+
use Jet\JsonDiff\Actions\GetUnmappedOriginalIndexesAction;
10+
use Jet\JsonDiff\JsonDiff;
11+
use Jet\JsonDiff\ValueRemoved;
12+
use Jet\Tests\Traits\InteractsWithContainer;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class AddRemovalsToJsonDiffActionTest extends TestCase
16+
{
17+
use InteractsWithContainer;
18+
19+
public function test_it_adds_removals_to_a_json_diff(): void
20+
{
21+
$originalArray = [
22+
0 => 'mapped',
23+
1 => 'unmapped',
24+
];
25+
26+
$this
27+
->stub(GetUnmappedOriginalIndexesAction::class)
28+
->method('execute')
29+
->willReturn(
30+
collect([1])
31+
);
32+
33+
$jsonDiff = new JsonDiff([], []);
34+
35+
/** @var AddRemovalsToJsonDiffAction $action */
36+
$action = Container::getInstance()->make(AddRemovalsToJsonDiffAction::class);
37+
38+
$action
39+
->execute(
40+
collect(),
41+
$originalArray,
42+
$jsonDiff,
43+
''
44+
);
45+
46+
$this->assertCount(1, $jsonDiff->getValuesRemoved());
47+
48+
/** @var ValueRemoved $valueRemoved */
49+
$valueRemoved = $jsonDiff->getValuesRemoved()->first();
50+
51+
$this->assertSame(
52+
'1',
53+
$valueRemoved->getPath()
54+
);
55+
$this->assertSame(
56+
'unmapped',
57+
$valueRemoved->getValue()
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)