From ca21115c979aef9459140927d04a0cfcd193721f Mon Sep 17 00:00:00 2001 From: Gocha Ossinkine Date: Tue, 11 Apr 2017 14:52:55 +0500 Subject: [PATCH] Create FixtureNotFoundException for resolver context --- .../ChildFixtureNotFoundException.php | 18 +++++++++ .../Chainable/FixtureReferenceResolver.php | 2 +- .../Resolver/FixtureNotFoundException.php | 20 ++++++++++ .../FixtureNotFoundExceptionFactory.php | 30 ++++++++++++++ .../FixtureNotFoundExceptionFactoryTest.php | 34 ++++++++++++++++ .../Resolver/FixtureNotFoundExceptionTest.php | 39 +++++++++++++++++++ 6 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 fixtures/Throwable/Exception/Generator/Resolver/ChildFixtureNotFoundException.php create mode 100644 src/Throwable/Exception/Generator/Resolver/FixtureNotFoundException.php create mode 100644 src/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactory.php create mode 100644 tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactoryTest.php create mode 100644 tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionTest.php diff --git a/fixtures/Throwable/Exception/Generator/Resolver/ChildFixtureNotFoundException.php b/fixtures/Throwable/Exception/Generator/Resolver/ChildFixtureNotFoundException.php new file mode 100644 index 000000000..af6920692 --- /dev/null +++ b/fixtures/Throwable/Exception/Generator/Resolver/ChildFixtureNotFoundException.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types = 1); + +namespace Nelmio\Alice\Throwable\Exception\Generator\Resolver; + +class ChildFixtureNotFoundException extends FixtureNotFoundException +{ +} diff --git a/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php b/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php index 7bdcbe591..d2139cb44 100644 --- a/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php +++ b/src/Generator/Resolver/Value/Chainable/FixtureReferenceResolver.php @@ -17,8 +17,8 @@ use Nelmio\Alice\Definition\Object\CompleteObject; use Nelmio\Alice\Definition\Value\FixtureReferenceValue; use Nelmio\Alice\Definition\ValueInterface; -use Nelmio\Alice\Throwable\Exception\FixtureNotFoundExceptionFactory; use Nelmio\Alice\Throwable\Exception\Generator\ObjectGenerator\ObjectGeneratorNotFoundExceptionFactory; +use Nelmio\Alice\Throwable\Exception\Generator\Resolver\FixtureNotFoundExceptionFactory; use Nelmio\Alice\Throwable\Exception\Generator\Resolver\UnresolvableValueException; use Nelmio\Alice\FixtureIdInterface; use Nelmio\Alice\FixtureInterface; diff --git a/src/Throwable/Exception/Generator/Resolver/FixtureNotFoundException.php b/src/Throwable/Exception/Generator/Resolver/FixtureNotFoundException.php new file mode 100644 index 000000000..870ca7f86 --- /dev/null +++ b/src/Throwable/Exception/Generator/Resolver/FixtureNotFoundException.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Nelmio\Alice\Throwable\Exception\Generator\Resolver; + +use Nelmio\Alice\Throwable\ResolutionThrowable; + +class FixtureNotFoundException extends \RuntimeException implements ResolutionThrowable +{ +} diff --git a/src/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactory.php b/src/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactory.php new file mode 100644 index 000000000..85aeaa4a7 --- /dev/null +++ b/src/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactory.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Nelmio\Alice\Throwable\Exception\Generator\Resolver; + +/** + * @private + */ +final class FixtureNotFoundExceptionFactory +{ + public static function create(string $id): FixtureNotFoundException + { + return new FixtureNotFoundException( + sprintf( + 'Could not find the fixture "%s".', + $id + ) + ); + } +} diff --git a/tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactoryTest.php b/tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactoryTest.php new file mode 100644 index 000000000..4705528ba --- /dev/null +++ b/tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionFactoryTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Nelmio\Alice\Throwable\Exception\Generator\Resolver; + +use PHPUnit\Framework\TestCase; + +/** + * @covers \Nelmio\Alice\Throwable\Exception\Generator\Resolver\FixtureNotFoundExceptionFactory + */ +class FixtureNotFoundExceptionFactoryTest extends TestCase +{ + public function testTestCreateNewExceptionWithFactory() + { + $exception = FixtureNotFoundExceptionFactory::create('foo'); + + $this->assertEquals( + 'Could not find the fixture "foo".', + $exception->getMessage() + ); + $this->assertEquals(0, $exception->getCode()); + $this->assertNull($exception->getPrevious()); + } +} diff --git a/tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionTest.php b/tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionTest.php new file mode 100644 index 000000000..3e65e9c2c --- /dev/null +++ b/tests/Throwable/Exception/Generator/Resolver/FixtureNotFoundExceptionTest.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Nelmio\Alice\Throwable\Exception\Generator\Resolver; + +use PHPUnit\Framework\TestCase; +use Nelmio\Alice\Throwable\ResolutionThrowable; + +/** + * @covers \Nelmio\Alice\Throwable\Exception\Generator\Resolver\FixtureNotFoundException + */ +class FixtureNotFoundExceptionTest extends TestCase +{ + public function testIsARuntimeException() + { + $this->assertTrue(is_a(FixtureNotFoundException::class, \RuntimeException::class, true)); + } + + public function testIsAResolutionThrowable() + { + $this->assertTrue(is_a(FixtureNotFoundException::class, ResolutionThrowable::class, true)); + } + + public function testIsExtensible() + { + $exception = new ChildFixtureNotFoundException(); + $this->assertInstanceOf(ChildFixtureNotFoundException::class, $exception); + } +}