Skip to content

Commit 6522e6e

Browse files
committed
Tests added for operations
1 parent a8595a5 commit 6522e6e

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

tests/Operation/AddOperationTest.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Remorhaz\JSON\Patch\Test\Operation;
5+
6+
use PHPUnit\Framework\TestCase;
7+
use Remorhaz\JSON\Data\Value\NodeValueInterface;
8+
use Remorhaz\JSON\Patch\Operation\AddOperation;
9+
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
10+
use Remorhaz\JSON\Pointer\Processor\Result\ResultInterface as PointerResultInterface;
11+
use Remorhaz\JSON\Pointer\Query\QueryInterface as PointerQueryInterface;
12+
13+
/**
14+
* @covers \Remorhaz\JSON\Patch\Operation\AddOperation
15+
*/
16+
class AddOperationTest extends TestCase
17+
{
18+
19+
public function testApply_Constructed_PassesInputToGivenPointerProcessor(): void
20+
{
21+
$pathPointer = $this->createMock(PointerQueryInterface::class);
22+
$value = $this->createMock(NodeValueInterface::class);
23+
$operation = new AddOperation(0, $pathPointer, $value);
24+
25+
$input = $this->createMock(NodeValueInterface::class);
26+
$pointerProcessor = $this->createMock(PointerProcessorInterface::class);
27+
$pointerProcessor
28+
->expects(self::once())
29+
->method('add')
30+
->with(
31+
self::identicalTo($pathPointer),
32+
self::identicalTo($input),
33+
self::identicalTo($value)
34+
);
35+
$operation->apply($input, $pointerProcessor);
36+
}
37+
38+
public function testApply_Constructed_ReturnsValueFromPointerProcessor(): void
39+
{
40+
$operation = new AddOperation(
41+
0,
42+
$this->createMock(PointerQueryInterface::class),
43+
$this->createMock(NodeValueInterface::class)
44+
);
45+
46+
$input = $this->createMock(NodeValueInterface::class);
47+
$pointerProcessor = $this->createMock(PointerProcessorInterface::class);
48+
$processedValue = $this->createMock(NodeValueInterface::class);
49+
$result = $this->createMock(PointerResultInterface::class);
50+
$result
51+
->method('get')
52+
->willReturn($processedValue);
53+
$pointerProcessor
54+
->method('add')
55+
->willReturn($result);
56+
$actualValue = $operation->apply($input, $pointerProcessor);
57+
self::assertSame($processedValue, $actualValue);
58+
}
59+
}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Remorhaz\JSON\Patch\Test\Operation;
5+
6+
use PHPUnit\Framework\TestCase;
7+
use Remorhaz\JSON\Data\Value\NodeValueInterface;
8+
use Remorhaz\JSON\Patch\Operation\RemoveOperation;
9+
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
10+
use Remorhaz\JSON\Pointer\Processor\Result\ResultInterface as PointerResultInterface;
11+
use Remorhaz\JSON\Pointer\Query\QueryInterface as PointerQueryInterface;
12+
13+
/**
14+
* @covers \Remorhaz\JSON\Patch\Operation\RemoveOperation
15+
*/
16+
class RemoveOperationTest extends TestCase
17+
{
18+
19+
public function testApply_Constructed_PassesInputToGivenPointerProcessor(): void
20+
{
21+
$pathPointer = $this->createMock(PointerQueryInterface::class);
22+
$operation = new RemoveOperation(0, $pathPointer);
23+
24+
$input = $this->createMock(NodeValueInterface::class);
25+
$pointerProcessor = $this->createMock(PointerProcessorInterface::class);
26+
$pointerProcessor
27+
->expects(self::once())
28+
->method('delete')
29+
->with(
30+
self::identicalTo($pathPointer),
31+
self::identicalTo($input)
32+
);
33+
$operation->apply($input, $pointerProcessor);
34+
}
35+
36+
public function testApply_Constructed_ReturnsValueFromPointerProcessor(): void
37+
{
38+
$operation = new RemoveOperation(
39+
0,
40+
$this->createMock(PointerQueryInterface::class)
41+
);
42+
43+
$input = $this->createMock(NodeValueInterface::class);
44+
$pointerProcessor = $this->createMock(PointerProcessorInterface::class);
45+
$processedValue = $this->createMock(NodeValueInterface::class);
46+
$result = $this->createMock(PointerResultInterface::class);
47+
$result
48+
->method('get')
49+
->willReturn($processedValue);
50+
$pointerProcessor
51+
->method('delete')
52+
->willReturn($result);
53+
$actualValue = $operation->apply($input, $pointerProcessor);
54+
self::assertSame($processedValue, $actualValue);
55+
}
56+
}
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Remorhaz\JSON\Patch\Test\Operation;
5+
6+
use PHPUnit\Framework\TestCase;
7+
use Remorhaz\JSON\Data\Value\NodeValueInterface;
8+
use Remorhaz\JSON\Patch\Operation\ReplaceOperation;
9+
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
10+
use Remorhaz\JSON\Pointer\Processor\Result\ResultInterface as PointerResultInterface;
11+
use Remorhaz\JSON\Pointer\Query\QueryInterface as PointerQueryInterface;
12+
13+
/**
14+
* @covers \Remorhaz\JSON\Patch\Operation\ReplaceOperation
15+
*/
16+
class ReplaceOperationTest extends TestCase
17+
{
18+
19+
public function testApply_Constructed_PassesInputToGivenPointerProcessor(): void
20+
{
21+
$pathPointer = $this->createMock(PointerQueryInterface::class);
22+
$value = $this->createMock(NodeValueInterface::class);
23+
$operation = new ReplaceOperation(0, $pathPointer, $value);
24+
25+
$input = $this->createMock(NodeValueInterface::class);
26+
$pointerProcessor = $this->createMock(PointerProcessorInterface::class);
27+
$pointerProcessor
28+
->expects(self::once())
29+
->method('replace')
30+
->with(
31+
self::identicalTo($pathPointer),
32+
self::identicalTo($input),
33+
self::identicalTo($value)
34+
);
35+
$operation->apply($input, $pointerProcessor);
36+
}
37+
38+
public function testApply_Constructed_ReturnsValueFromPointerProcessor(): void
39+
{
40+
$operation = new ReplaceOperation(
41+
0,
42+
$this->createMock(PointerQueryInterface::class),
43+
$this->createMock(NodeValueInterface::class)
44+
);
45+
46+
$input = $this->createMock(NodeValueInterface::class);
47+
$pointerProcessor = $this->createMock(PointerProcessorInterface::class);
48+
$processedValue = $this->createMock(NodeValueInterface::class);
49+
$result = $this->createMock(PointerResultInterface::class);
50+
$result
51+
->method('get')
52+
->willReturn($processedValue);
53+
$pointerProcessor
54+
->method('replace')
55+
->willReturn($result);
56+
$actualValue = $operation->apply($input, $pointerProcessor);
57+
self::assertSame($processedValue, $actualValue);
58+
}
59+
}

0 commit comments

Comments
 (0)