Skip to content

Commit

Permalink
Issue #5: results provide node value
Browse files Browse the repository at this point in the history
  • Loading branch information
remorhaz committed Nov 19, 2019
1 parent 5162f9c commit ff69b2a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Issue #5: `ResultInterface::get()` method added.

## [0.6.3] - 2019-11-18
### Fixed
- Issue #4: replacing document root with `add()` fixed.
Expand Down
5 changes: 5 additions & 0 deletions src/Processor/Result/ExistingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public function decode()
->decoder
->exportValue($this->nodeValue);
}

public function get(): NodeValueInterface
{
return $this->nodeValue;
}
}
7 changes: 7 additions & 0 deletions src/Processor/Result/NonExistingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Remorhaz\JSON\Pointer\Processor\Result;

use Remorhaz\JSON\Data\Value\NodeValueInterface;

final class NonExistingResult implements ResultInterface
{

Expand All @@ -27,4 +29,9 @@ public function decode()
{
throw new Exception\ResultNotFoundException($this->source);
}

public function get(): NodeValueInterface
{
throw new Exception\ResultNotFoundException($this->source);
}
}
4 changes: 4 additions & 0 deletions src/Processor/Result/ResultInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Remorhaz\JSON\Pointer\Processor\Result;

use Remorhaz\JSON\Data\Value\NodeValueInterface;

interface ResultInterface
{

Expand All @@ -11,4 +13,6 @@ public function exists(): bool;
public function encode(): string;

public function decode();

public function get(): NodeValueInterface;
}
13 changes: 11 additions & 2 deletions tests/Processor/Result/ExistingResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function testEncode_EncoderExportsValue_ReturnsSameValue(): void
);

$encoder
->expects(self::once())
->method('exportValue')
->willReturn('a');
self::assertSame('a', $result->encode());
Expand Down Expand Up @@ -87,9 +86,19 @@ public function testDecode_DecoderExportsValue_ReturnsSameValue(): void
);

$decoder
->expects(self::once())
->method('exportValue')
->willReturn('a');
self::assertSame('a', $result->decode());
}

public function testGet_ConstructedWithValue_ReturnsSameInstance(): void
{
$value = $this->createMock(NodeValueInterface::class);
$result = new ExistingResult(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
$value
);
self::assertSame($value, $result->get());
}
}
10 changes: 9 additions & 1 deletion tests/Processor/Result/NonExistingResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ public function testEncode_ConstructedWithSource_ThrowsMatchingException(): void
$result->encode();
}

public function testDencode_ConstructedWithSource_ThrowsMatchingException(): void
public function testDecode_ConstructedWithSource_ThrowsMatchingException(): void
{
$result = new NonExistingResult('a');
$this->expectException(ResultNotFoundException::class);
$this->expectExceptionMessage('\'a\'');
$result->decode();
}

public function testGet_ConstructedWithSource_ThrowsMatchingException(): void
{
$result = new NonExistingResult('a');
$this->expectException(ResultNotFoundException::class);
$this->expectExceptionMessage('\'a\'');
$result->get();
}
}

0 comments on commit ff69b2a

Please sign in to comment.