Skip to content

Commit

Permalink
Fix #5: Adjust exception type (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Nov 18, 2021
1 parent 2284a40 commit afe907f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 90 deletions.
4 changes: 2 additions & 2 deletions src/Contract/DefinitionInterface.php
Expand Up @@ -5,9 +5,9 @@
namespace Yiisoft\Definitions\Contract;

use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotFoundException;
use Yiisoft\Definitions\Exception\NotInstantiableException;

/**
Expand All @@ -21,7 +21,7 @@ interface DefinitionInterface
* @throws InvalidConfigException If an object of incorrect type was created.
* @throws CircularReferenceException If there is a circular reference detected
* when resolving the definition.
* @throws NotFoundException If container does not know how to resolve
* @throws NotFoundExceptionInterface If container does not know how to resolve
* the definition.
* @throws NotInstantiableException If an object can not be instantiated.
*
Expand Down
39 changes: 0 additions & 39 deletions src/Exception/NotFoundException.php

This file was deleted.

4 changes: 1 addition & 3 deletions src/Infrastructure/DefinitionExtractor.php
Expand Up @@ -8,7 +8,6 @@
use ReflectionException;
use ReflectionFunctionAbstract;
use ReflectionParameter;
use Yiisoft\Definitions\Exception\NotFoundException;
use Yiisoft\Definitions\Exception\NotInstantiableClassException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
use Yiisoft\Definitions\ParameterDefinition;
Expand Down Expand Up @@ -51,7 +50,6 @@ public static function getInstance(): self
*
* @psalm-param class-string $class
*
* @throws NotFoundException
* @throws NotInstantiableException
*
* @return ParameterDefinition[]
Expand All @@ -66,7 +64,7 @@ public function fromClassName(string $class): array
try {
$reflectionClass = new ReflectionClass($class);
} catch (ReflectionException $e) {
throw new NotFoundException($class);
throw new NotInstantiableClassException($class);
}

if (!$reflectionClass->isInstantiable()) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Php8/ParameterDefinitionTest.php
Expand Up @@ -6,6 +6,7 @@

use PHPUnit\Framework\TestCase;
use Closure;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionClass;
use ReflectionFunction;
use ReflectionParameter;
Expand All @@ -14,7 +15,6 @@
use Yiisoft\Definitions\ParameterDefinition;
use Yiisoft\Definitions\Tests\Objects\GearBox;
use Yiisoft\Definitions\Tests\Objects\UnionCar;
use Yiisoft\Test\Support\Container\Exception\NotFoundException;
use Yiisoft\Test\Support\Container\SimpleContainer;

final class ParameterDefinitionTest extends TestCase
Expand All @@ -26,7 +26,7 @@ public function testNotInstantiable(): void
);
$container = new SimpleContainer();

$this->expectException(NotFoundException::class);
$this->expectException(NotFoundExceptionInterface::class);
$definition->resolve($container);
}

Expand Down
35 changes: 0 additions & 35 deletions tests/Unit/Exception/NotFoundExceptionTest.php

This file was deleted.

12 changes: 6 additions & 6 deletions tests/Unit/Infrastructure/DefinitionExtractorTest.php
Expand Up @@ -6,8 +6,8 @@

use DateTime;
use PHPUnit\Framework\TestCase;
use Psr\Container\NotFoundExceptionInterface;
use Yiisoft\Definitions\Contract\DefinitionInterface;
use Yiisoft\Definitions\Exception\NotFoundException;
use Yiisoft\Definitions\Exception\NotInstantiableClassException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
use Yiisoft\Definitions\Infrastructure\DefinitionExtractor;
Expand Down Expand Up @@ -58,7 +58,7 @@ public function testResolveCarConstructor(): void
$this->assertInstanceOf(ParameterDefinition::class, $dependencies['engine']);
$this->assertInstanceOf(ParameterDefinition::class, $dependencies['moreEngines']);

$this->expectException(\Yiisoft\Test\Support\Container\Exception\NotFoundException::class);
$this->expectException(NotFoundExceptionInterface::class);
$dependencies['engine']->resolve($container);
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public function testNullableInterfaceDependency(): void
/** @var DefinitionInterface[] $dependencies */
$dependencies = $resolver->fromClassName(NullableInterfaceDependency::class);
$this->assertCount(1, $dependencies);
$this->expectException(\Yiisoft\Test\Support\Container\Exception\NotFoundException::class);
$this->expectException(NotFoundExceptionInterface::class);
$dependencies['engine']->resolve($container);
}

Expand All @@ -110,7 +110,7 @@ public function testNullableConcreteDependency(): void
/** @var DefinitionInterface[] $dependencies */
$dependencies = $resolver->fromClassName(NullableConcreteDependency::class);
$this->assertCount(1, $dependencies);
$this->expectException(\Yiisoft\Test\Support\Container\Exception\NotFoundException::class);
$this->expectException(NotFoundExceptionInterface::class);
$dependencies['car']->resolve($container);
}

Expand Down Expand Up @@ -138,8 +138,8 @@ public function testFromNonExistingClass(): void
{
$extractor = DefinitionExtractor::getInstance();

$this->expectException(NotFoundException::class);
$this->expectExceptionMessage('No definition or class found or resolvable for NonExistingClass.');
$this->expectException(NotInstantiableClassException::class);
$this->expectExceptionMessage('Can not instantiate NonExistingClass.');
$extractor->fromClassName('NonExistingClass');
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/ParameterDefinitionTest.php
Expand Up @@ -6,6 +6,7 @@

use Closure;
use PHPUnit\Framework\TestCase;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionClass;
use ReflectionFunction;
use ReflectionParameter;
Expand All @@ -15,7 +16,6 @@
use Yiisoft\Definitions\ParameterDefinition;
use Yiisoft\Definitions\Tests\Objects\Car;
use Yiisoft\Definitions\Tests\Objects\NullableConcreteDependency;
use Yiisoft\Test\Support\Container\Exception\NotFoundException;
use Yiisoft\Test\Support\Container\SimpleContainer;

final class ParameterDefinitionTest extends TestCase
Expand Down Expand Up @@ -119,7 +119,7 @@ public function testNullableParameterNotInstantiable(): void
);
$container = new SimpleContainer();

$this->expectException(NotFoundException::class);
$this->expectException(NotFoundExceptionInterface::class);
$definition->resolve($container);
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public function testNotInstantiable(): void
);
$container = new SimpleContainer();

$this->expectException(NotFoundException::class);
$this->expectException(NotFoundExceptionInterface::class);
$definition->resolve($container);
}

Expand Down

0 comments on commit afe907f

Please sign in to comment.