Skip to content

Commit

Permalink
chore: Rename BodyResolver to ValueResolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
shulard committed Oct 6, 2022
1 parent 76365b9 commit f66162b
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 54 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ You can combine different `Resolver` and let the configured body pass through
all the methods and be enriched. This library come with a specific `Faker`
resolver to generate data easily with providers (see [Faker doc](https://fakerphp.github.io/formatters/)).

You can build your own resolvers using the `BodyResolverInterface`.
You can build your own resolvers using the `ValueResolverInterface`.

```php
<?php

use CHStudio\Raven\Http\Factory\Body\ArrayValueResolver;
use CHStudio\Raven\Http\Factory\Body\FakerValueResolver;
use CHStudio\Raven\Http\Factory\Body\PassThroughValueResolver;
use CHStudio\Raven\Http\Factory\Resolver\ArrayValueResolver;
use CHStudio\Raven\Http\Factory\Resolver\FakerValueResolver;
use CHStudio\Raven\Http\Factory\Resolver\PassThroughValueResolver;

$generator = \Faker\Factory::create();

Expand Down
8 changes: 0 additions & 8 deletions src/Http/Factory/Body/BodyResolverInterface.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Http/Factory/Body/PassThroughValueResolver.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Http/Factory/RequestBodyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace CHStudio\Raven\Http\Factory;

use CHStudio\Raven\Http\Factory\Body\BodyResolverInterface;
use CHStudio\Raven\Http\Factory\Resolver\ValueResolverInterface;
use Psr\Http\Message\RequestInterface;

class RequestBodyResolver implements RequestFactoryInterface
{
public function __construct(
private readonly BodyResolverInterface $resolver,
private readonly ValueResolverInterface $resolver,
private readonly RequestFactoryInterface $decorated
) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace CHStudio\Raven\Http\Factory\Body;
namespace CHStudio\Raven\Http\Factory\Resolver;

class ArrayValueResolver implements BodyResolverInterface
class ArrayValueResolver implements ValueResolverInterface
{
public function __construct(
private readonly BodyResolverInterface $resolver
private readonly ValueResolverInterface $resolver
) {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace CHStudio\Raven\Http\Factory\Body;
namespace CHStudio\Raven\Http\Factory\Resolver;

use Faker\Generator;
use InvalidArgumentException;
use JsonException;

class FakerValueResolver implements BodyResolverInterface
class FakerValueResolver implements ValueResolverInterface
{
public function __construct(
private readonly Generator $faker,
private readonly BodyResolverInterface $resolver
private readonly ValueResolverInterface $resolver
) {
}

Expand Down
11 changes: 11 additions & 0 deletions src/Http/Factory/Resolver/PassThroughValueResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace CHStudio\Raven\Http\Factory\Resolver;

class PassThroughValueResolver implements ValueResolverInterface
{
public function resolve(mixed $value): mixed
{
return $value;
}
}
8 changes: 8 additions & 0 deletions src/Http/Factory/Resolver/ValueResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CHStudio\Raven\Http\Factory\Resolver;

interface ValueResolverInterface
{
public function resolve(mixed $value): mixed;
}
8 changes: 4 additions & 4 deletions tests/unit/Http/Factory/RequestBodyResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CHStudio\RavenTest\Http\Factory;

use CHStudio\Raven\Http\Factory\Body\BodyResolverInterface;
use CHStudio\Raven\Http\Factory\Resolver\ValueResolverInterface;
use CHStudio\Raven\Http\Factory\RequestBodyResolver;
use CHStudio\Raven\Http\Factory\RequestFactoryInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -14,7 +14,7 @@ final class RequestBodyResolverTest extends TestCase
{
public function testItCanBeBuilt(): void
{
$bodyResolver = $this->createMock(BodyResolverInterface::class);
$bodyResolver = $this->createMock(ValueResolverInterface::class);
$decorated = $this->createMock(RequestFactoryInterface::class);

$factory = new RequestBodyResolver($bodyResolver, $decorated);
Expand All @@ -24,7 +24,7 @@ public function testItCanBeBuilt(): void

public function testItResolvesBodyWhenThereIsOne(): void
{
$bodyResolver = $this->createMock(BodyResolverInterface::class);
$bodyResolver = $this->createMock(ValueResolverInterface::class);
$decorated = $this->createMock(RequestFactoryInterface::class);

$bodyResolver
Expand All @@ -45,7 +45,7 @@ public function testItResolvesBodyWhenThereIsOne(): void

public function testItDoesntCallResolverOnEmptyBody(): void
{
$bodyResolver = $this->createMock(BodyResolverInterface::class);
$bodyResolver = $this->createMock(ValueResolverInterface::class);
$decorated = $this->createMock(RequestFactoryInterface::class);

$bodyResolver->expects(static::never())->method('resolve');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

declare(strict_types=1);

namespace CHStudio\RavenTest\Http\Factory\Body;
namespace CHStudio\RavenTest\Http\Factory\Resolver;

use CHStudio\Raven\Http\Factory\Body\ArrayValueResolver;
use CHStudio\Raven\Http\Factory\Body\BodyResolverInterface;
use CHStudio\Raven\Http\Factory\Resolver\ArrayValueResolver;
use CHStudio\Raven\Http\Factory\Resolver\ValueResolverInterface;
use PHPUnit\Framework\TestCase;

final class ArrayValueResolverTest extends TestCase
{
public function testItCanBeBuilt(): void
{
$decorated = $this->createMock(BodyResolverInterface::class);
$decorated = $this->createMock(ValueResolverInterface::class);
$arrayResolver = new ArrayValueResolver($decorated);

static::assertInstanceOf(BodyResolverInterface::class, $arrayResolver);
static::assertInstanceOf(ValueResolverInterface::class, $arrayResolver);
}

public function testItResolveEachInnerArrayRecursively(): void
Expand All @@ -30,7 +30,7 @@ public function testItResolveEachInnerArrayRecursively(): void
]
];

$decorated = $this->createMock(BodyResolverInterface::class);
$decorated = $this->createMock(ValueResolverInterface::class);
$decorated
->expects(static::exactly(3))
->method('resolve')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace CHStudio\RavenTest\Http\Factory\Body;
namespace CHStudio\RavenTest\Http\Factory\Resolver;

use CHStudio\Raven\Http\Factory\Body\BodyResolverInterface;
use CHStudio\Raven\Http\Factory\Body\FakerValueResolver;
use CHStudio\Raven\Http\Factory\Resolver\ValueResolverInterface;
use CHStudio\Raven\Http\Factory\Resolver\FakerValueResolver;
use Faker\Generator;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
Expand All @@ -16,18 +16,18 @@ public function testItCanBeBuilt(): void
{
$resolver = new FakerValueResolver(
$this->createMock(Generator::class),
$this->createMock(BodyResolverInterface::class)
$this->createMock(ValueResolverInterface::class)
);

static::assertInstanceOf(BodyResolverInterface::class, $resolver);
static::assertInstanceOf(ValueResolverInterface::class, $resolver);
}

/**
* @dataProvider giveNonResolvableValues
*/
public function testItPassTheValueToNextResolverInDifferent(mixed $parameter): void
{
$decorated = $this->createMock(BodyResolverInterface::class);
$decorated = $this->createMock(ValueResolverInterface::class);
$decorated
->expects(static::once())
->method('resolve')
Expand Down Expand Up @@ -57,7 +57,7 @@ public function giveNonResolvableValues(): \Generator
*/
public function testItResolveTheValueThroughFakerGenerator(string $parameter, string $method, array $arguments): void
{
$decorated = $this->createMock(BodyResolverInterface::class);
$decorated = $this->createMock(ValueResolverInterface::class);
$decorated
->expects(static::never())
->method('resolve');
Expand Down Expand Up @@ -85,7 +85,7 @@ public function giveResolvableValues(): \Generator

public function testItCaptureFakerInvalidArguments(): void
{
$decorated = $this->createMock(BodyResolverInterface::class);
$decorated = $this->createMock(ValueResolverInterface::class);
$decorated
->expects(static::never())
->method('resolve');
Expand All @@ -109,7 +109,7 @@ public function testItFailsOnFunctionArgumentThatCantBeJsonDecoded(): void
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/^Can\'t extract the arguments to call method/');

$decorated = $this->createMock(BodyResolverInterface::class);
$decorated = $this->createMock(ValueResolverInterface::class);
$decorated
->expects(static::never())
->method('resolve');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace CHStudio\RavenTest\Http\Factory\Body;
namespace CHStudio\RavenTest\Http\Factory\Resolver;

use CHStudio\Raven\Http\Factory\Body\BodyResolverInterface;
use CHStudio\Raven\Http\Factory\Body\PassThroughValueResolver;
use CHStudio\Raven\Http\Factory\Resolver\ValueResolverInterface;
use CHStudio\Raven\Http\Factory\Resolver\PassThroughValueResolver;
use PHPUnit\Framework\TestCase;

final class PassThroughValueResolverTest extends TestCase
Expand All @@ -14,7 +14,7 @@ public function testItCanBeBuilt(): void
{
$resolver = new PassThroughValueResolver();

static::assertInstanceOf(BodyResolverInterface::class, $resolver);
static::assertInstanceOf(ValueResolverInterface::class, $resolver);
}

public function testItReturnGivenValue(): void
Expand Down

0 comments on commit f66162b

Please sign in to comment.