Skip to content

Commit

Permalink
Merge pull request #301 from gacela-project/test-DocBlockServiceNotFo…
Browse files Browse the repository at this point in the history
…undException

Add tests for DocBlockServiceNotFoundException
  • Loading branch information
Chemaclass authored Jul 24, 2023
2 parents 9c2dfc4 + 73e3acb commit b768a13
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
*
* @throws DocBlockServiceNotFoundException
*/
public function resolve(object|string $caller): ?object
public function resolve(object|string $caller): object
{
$resolved = $this->doResolve($caller);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace GacelaTest\Integration\Framework\DocBlockResolver;

use Gacela\Framework\Bootstrap\GacelaConfig;
use Gacela\Framework\ClassResolver\DocBlockService\DocBlockServiceNotFoundException;
use Gacela\Framework\ClassResolver\DocBlockService\DocBlockServiceResolver;
use Gacela\Framework\ClassResolver\DocBlockService\MissingClassDefinitionException;
use Gacela\Framework\DocBlockResolver\DocBlockResolvable;
use Gacela\Framework\DocBlockResolver\DocBlockResolver;
use Gacela\Framework\Gacela;
Expand All @@ -24,6 +27,22 @@ protected function setUp(): void
});
}

public function test_missing_class_definition(): void
{
$this->expectException(MissingClassDefinitionException::class);

(new FakeCommand())->getUnknown();
}

public function test_service_not_found(): void
{
$this->expectException(DocBlockServiceNotFoundException::class);

$resolver = new DocBlockServiceResolver('');
$command = new FakeCommand();
$resolver->resolve($command);
}

public function test_normalize_facade(): void
{
$resolver = DocBlockResolver::fromCaller(new FakeCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/**
* @method FakeFacade getFacade()
* @method FakeRandomService getRandom()
* @method FakeUnknown getUnknown() This does not exist and will ended up in an Error
*/
final class FakeCommand
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace GacelaTest\Unit\Framework\ClassResolver\DependencyProvider;

use Gacela\Framework\ClassResolver\DependencyProvider\DependencyProviderNotFoundException;
use PHPUnit\Framework\TestCase;

final class DependencyProviderNotFoundExceptionTest extends TestCase
{
public function test_exception_message(): void
{
$exception = new DependencyProviderNotFoundException($this);

$expected = <<<EOT
ClassResolver Exception
Cannot resolve the `DependencyProvider` for your module `DependencyProvider`
You can fix this by adding the missing `DependencyProvider` to your module.
E.g. `\GacelaTest\Unit\Framework\ClassResolver\DependencyProvider`
EOT;

self::assertSame($expected, $exception->getMessage());
}
}

0 comments on commit b768a13

Please sign in to comment.