Skip to content

Commit a64a81c

Browse files
committed
All query exceptions have getSource() method now
1 parent 77143f3 commit a64a81c

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Fixed
9+
- All query exceptions have `getSource()` method now.
10+
711
## [0.6.0] - 2019-11-05
812
### Added
913
- Implementation totally refactored.

src/Query/Exception/LastReferenceNotFoundException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public function __construct(string $source, Throwable $previous = null)
1616
$this->source = $source;
1717
parent::__construct("Query '{$this->source}' selected no last reference", 0, $previous);
1818
}
19+
20+
public function getSource(): string
21+
{
22+
return $this->source;
23+
}
1924
}

src/Query/Exception/ParentNotFoundException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public function __construct(string $source, Throwable $previous = null)
1616
$this->source = $source;
1717
parent::__construct("Query '{$this->source}' selected no parent node", 0, $previous);
1818
}
19+
20+
public function getSource(): string
21+
{
22+
return $this->source;
23+
}
1924
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Remorhaz\JSON\Pointer\Test\Query\Exception;
5+
6+
use Exception;
7+
use PHPUnit\Framework\TestCase;
8+
use Remorhaz\JSON\Pointer\Query\Exception\LastReferenceNotFoundException;
9+
10+
/**
11+
* @covers \Remorhaz\JSON\Pointer\Query\Exception\LastReferenceNotFoundException
12+
*/
13+
class LastReferenceNotFoundExceptionTest extends TestCase
14+
{
15+
16+
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
17+
{
18+
$exception = new LastReferenceNotFoundException('a');
19+
self::assertSame('Query \'a\' selected no last reference', $exception->getMessage());
20+
}
21+
22+
public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void
23+
{
24+
$exception = new LastReferenceNotFoundException('a');
25+
self::assertSame('a', $exception->getSource());
26+
}
27+
28+
public function testGetCode_Always_ReturnsZero(): void
29+
{
30+
$exception = new LastReferenceNotFoundException('a');
31+
self::assertSame(0, $exception->getCode());
32+
}
33+
34+
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
35+
{
36+
$exception = new LastReferenceNotFoundException('a');
37+
self::assertNull($exception->getPrevious());
38+
}
39+
40+
public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): void
41+
{
42+
$previous = new Exception;
43+
$exception = new LastReferenceNotFoundException('a', $previous);
44+
self::assertSame($previous, $exception->getPrevious());
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Remorhaz\JSON\Pointer\Test\Query\Exception;
5+
6+
use Exception;
7+
use PHPUnit\Framework\TestCase;
8+
use Remorhaz\JSON\Pointer\Query\Exception\ParentNotFoundException;
9+
10+
/**
11+
* @covers \Remorhaz\JSON\Pointer\Query\Exception\ParentNotFoundException
12+
*/
13+
class ParentNotFoundExceptionTest extends TestCase
14+
{
15+
16+
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
17+
{
18+
$exception = new ParentNotFoundException('a');
19+
self::assertSame('Query \'a\' selected no parent node', $exception->getMessage());
20+
}
21+
22+
public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void
23+
{
24+
$exception = new ParentNotFoundException('a');
25+
self::assertSame('a', $exception->getSource());
26+
}
27+
28+
public function testGetCode_Always_ReturnsZero(): void
29+
{
30+
$exception = new ParentNotFoundException('a');
31+
self::assertSame(0, $exception->getCode());
32+
}
33+
34+
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
35+
{
36+
$exception = new ParentNotFoundException('a');
37+
self::assertNull($exception->getPrevious());
38+
}
39+
40+
public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): void
41+
{
42+
$previous = new Exception;
43+
$exception = new ParentNotFoundException('a', $previous);
44+
self::assertSame($previous, $exception->getPrevious());
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Remorhaz\JSON\Pointer\Test\Query\Exception;
5+
6+
use Exception;
7+
use PHPUnit\Framework\TestCase;
8+
use Remorhaz\JSON\Pointer\Query\Exception\SelectionNotFoundException;
9+
10+
/**
11+
* @covers \Remorhaz\JSON\Pointer\Query\Exception\SelectionNotFoundException
12+
*/
13+
class SelectionNotFoundExceptionTest extends TestCase
14+
{
15+
16+
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
17+
{
18+
$exception = new SelectionNotFoundException('a');
19+
self::assertSame('Query \'a\' produced no selection', $exception->getMessage());
20+
}
21+
22+
public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void
23+
{
24+
$exception = new SelectionNotFoundException('a');
25+
self::assertSame('a', $exception->getSource());
26+
}
27+
28+
public function testGetCode_Always_ReturnsZero(): void
29+
{
30+
$exception = new SelectionNotFoundException('a');
31+
self::assertSame(0, $exception->getCode());
32+
}
33+
34+
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
35+
{
36+
$exception = new SelectionNotFoundException('a');
37+
self::assertNull($exception->getPrevious());
38+
}
39+
40+
public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): void
41+
{
42+
$previous = new Exception;
43+
$exception = new SelectionNotFoundException('a', $previous);
44+
self::assertSame($previous, $exception->getPrevious());
45+
}
46+
}

0 commit comments

Comments
 (0)