Skip to content

Commit

Permalink
Merge pull request #291 from prooph/projection_not_found_exception
Browse files Browse the repository at this point in the history
add projection not found exception
  • Loading branch information
codeliner authored Jun 24, 2017
2 parents e551990 + 5a2558f commit 24a6015
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/Exception/ProjectionNotFound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the prooph/event-store.
* (c) 2014-2017 prooph software GmbH <[email protected]>
* (c) 2015-2017 Sascha-Oliver Prolic <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Exception;

class ProjectionNotFound extends RuntimeException
{
public static function withName(string $name): ProjectionNotFound
{
return new self('A projection with name "' . $name . '" could not be found.');
}
}
6 changes: 3 additions & 3 deletions src/Projection/InMemoryProjectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function fetchProjectionNamesRegex(string $regex, int $limit = 20, int $o
public function fetchProjectionStatus(string $name): ProjectionStatus
{
if (! isset($this->projectors[$name])) {
throw new Exception\RuntimeException('A projection with name "' . $name . '" could not be found.');
throw Exception\ProjectionNotFound::withName($name);
}

$projector = $this->projectors[$name];
Expand All @@ -179,7 +179,7 @@ public function fetchProjectionStatus(string $name): ProjectionStatus
public function fetchProjectionStreamPositions(string $name): array
{
if (! isset($this->projectors[$name])) {
throw new Exception\RuntimeException('A projection with name "' . $name . '" could not be found.');
throw Exception\ProjectionNotFound::withName($name);
}

$projector = $this->projectors[$name];
Expand All @@ -194,7 +194,7 @@ public function fetchProjectionStreamPositions(string $name): array
public function fetchProjectionState(string $name): array
{
if (! isset($this->projectors[$name])) {
throw new Exception\RuntimeException('A projection with name "' . $name . '" could not be found.');
throw Exception\ProjectionNotFound::withName($name);
}

return $this->projectors[$name]->getState();
Expand Down
8 changes: 4 additions & 4 deletions tests/Projection/AbstractProjectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use PHPUnit\Framework\TestCase;
use Prooph\EventStore\Exception\InvalidArgumentException;
use Prooph\EventStore\Exception\OutOfRangeException;
use Prooph\EventStore\Exception\RuntimeException;
use Prooph\EventStore\Exception\ProjectionNotFound;
use Prooph\EventStore\Projection\ProjectionManager;
use Prooph\EventStore\Projection\ProjectionStatus;

Expand Down Expand Up @@ -247,7 +247,7 @@ public function it_throws_exception_when_fetching_projection_names_using_invalid
*/
public function it_throws_exception_when_asked_for_unknown_projection_status(): void
{
$this->expectException(RuntimeException::class);
$this->expectException(ProjectionNotFound::class);

$this->projectionManager->fetchProjectionStatus('unkown');
}
Expand All @@ -257,7 +257,7 @@ public function it_throws_exception_when_asked_for_unknown_projection_status():
*/
public function it_throws_exception_when_asked_for_unknown_projection_stream_positions(): void
{
$this->expectException(RuntimeException::class);
$this->expectException(ProjectionNotFound::class);

$this->projectionManager->fetchProjectionStreamPositions('unkown');
}
Expand All @@ -267,7 +267,7 @@ public function it_throws_exception_when_asked_for_unknown_projection_stream_pos
*/
public function it_throws_exception_when_asked_for_unknown_projection_state(): void
{
$this->expectException(RuntimeException::class);
$this->expectException(ProjectionNotFound::class);

$this->projectionManager->fetchProjectionState('unkown');
}
Expand Down

0 comments on commit 24a6015

Please sign in to comment.