diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8a86fe46..ff71c648 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -108,7 +108,7 @@ jobs:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
- name: sonarcloud.io
- uses: sonarsource/sonarqube-scan-action@v4.2.1
+ uses: sonarsource/sonarqube-scan-action@v5.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
diff --git a/composer.json b/composer.json
index 6b0a6738..8d6227d0 100644
--- a/composer.json
+++ b/composer.json
@@ -34,12 +34,13 @@
},
"require-dev": {
"chubbyphp/chubbyphp-dev-helper": "dev-master",
- "chubbyphp/chubbyphp-mock": "^1.8",
- "infection/infection": "^0.29.10",
+ "chubbyphp/chubbyphp-mock": "^2.0@dev",
+ "dg/bypass-finals": "^1.9",
+ "infection/infection": "^0.29.13",
"php-coveralls/php-coveralls": "^2.7",
"phpstan/extension-installer": "^1.4.3",
- "phpstan/phpstan": "^2.1.3",
- "phpunit/phpunit": "^11.5.7"
+ "phpstan/phpstan": "^2.1.6",
+ "phpunit/phpunit": "^11.5.10"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index c8265dbe..9d03d7c6 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -15,4 +15,9 @@
./src/web.php
+
+
+
+
+
diff --git a/src/RequestHandler/PingRequestHandler.php b/src/RequestHandler/PingRequestHandler.php
index 3f3e1040..68010157 100644
--- a/src/RequestHandler/PingRequestHandler.php
+++ b/src/RequestHandler/PingRequestHandler.php
@@ -25,7 +25,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
;
/** @var non-empty-string $json */
- $json = json_encode(['date' => date('c')]);
+ $json = json_encode(['datetime' => date('c')]);
$response->getBody()->write($json);
diff --git a/tests/Integration/PingRequestHandlerTest.php b/tests/Integration/PingRequestHandlerTest.php
index c81257cc..01f5257d 100644
--- a/tests/Integration/PingRequestHandlerTest.php
+++ b/tests/Integration/PingRequestHandlerTest.php
@@ -32,9 +32,9 @@ public function testPing(): void
$ping = json_decode($response['body'], true, 512, JSON_THROW_ON_ERROR);
- self::assertArrayHasKey('date', $ping);
+ self::assertArrayHasKey('datetime', $ping);
- $date = new \DateTimeImmutable($ping['date']);
+ $date = new \DateTimeImmutable($ping['datetime']);
self::assertGreaterThanOrEqual($now, $date);
}
diff --git a/tests/Unit/Collection/CollectionTest.php b/tests/Unit/Collection/CollectionTest.php
index 16905574..5d565e06 100644
--- a/tests/Unit/Collection/CollectionTest.php
+++ b/tests/Unit/Collection/CollectionTest.php
@@ -7,8 +7,8 @@
use App\Collection\AbstractCollection;
use App\Collection\CollectionInterface;
use App\Model\ModelInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -19,8 +19,6 @@
*/
class CollectionTest extends TestCase
{
- use MockByCallsTrait;
-
public function testGetSet(): void
{
$collection = $this->getCollection();
@@ -32,9 +30,15 @@ public function testGetSet(): void
self::assertSame(0, $collection->getCount());
self::assertSame([], $collection->getItems());
+ $builder = new MockObjectBuilder();
+
/** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class, [
- Call::create('jsonSerialize')->with()->willReturn(['id' => '111d1691-8486-4447-997c-d10ce35d1fea']),
+ $model = $builder->create(ModelInterface::class, [
+ new WithReturn(
+ 'jsonSerialize',
+ [],
+ ['id' => '111d1691-8486-4447-997c-d10ce35d1fea']
+ ),
]);
$collection->setOffset(5);
diff --git a/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php b/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php
index 8f41165a..02a2f5c7 100644
--- a/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php
+++ b/tests/Unit/Middleware/ApiExceptionMiddlewareTest.php
@@ -7,9 +7,11 @@
use App\Middleware\ApiExceptionMiddleware;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
use Chubbyphp\HttpException\HttpException;
-use Chubbyphp\Mock\Argument\ArgumentCallback;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithCallback;
+use Chubbyphp\Mock\MockMethod\WithException;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -26,29 +28,29 @@
*/
final class ApiExceptionMiddlewareTest extends TestCase
{
- use MockByCallsTrait;
-
public function testWithDebugAndLoggerWithoutException(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class);
+ $request = $builder->create(ServerRequestInterface::class, []);
/** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class);
+ $response = $builder->create(ResponseInterface::class, []);
/** @var MockObject|RequestHandlerInterface $handler */
- $handler = $this->getMockByCalls(RequestHandlerInterface::class, [
- Call::create('handle')->with($request)->willReturn($response),
+ $handler = $builder->create(RequestHandlerInterface::class, [
+ new WithReturn('handle', [$request], $response),
]);
/** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ $encoder = $builder->create(EncoderInterface::class, []);
/** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var LoggerInterface|MockObject $logger */
- $logger = $this->getMockByCalls(LoggerInterface::class);
+ $logger = $builder->create(LoggerInterface::class, []);
$apiExceptionMiddleware = new ApiExceptionMiddleware($encoder, $responseFactory, true, $logger);
@@ -57,50 +59,55 @@ public function testWithDebugAndLoggerWithoutException(): void
public function testWithDebugAndLoggerWithExceptionAndWithoutAccept(): void
{
+ $builder = new MockObjectBuilder();
$previousException = new \RuntimeException('previous', 3);
$exception = new \LogicException('current', 5, $previousException);
/** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn(null),
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], null),
]);
/** @var MockObject|RequestHandlerInterface $handler */
- $handler = $this->getMockByCalls(RequestHandlerInterface::class, [
- Call::create('handle')->with($request)->willThrowException($exception),
+ $handler = $builder->create(RequestHandlerInterface::class, [
+ new WithException('handle', [$request], $exception),
]);
/** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ $encoder = $builder->create(EncoderInterface::class, []);
/** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var LoggerInterface|MockObject $logger */
- $logger = $this->getMockByCalls(LoggerInterface::class, [
- Call::create('error')->with('Http Exception', new ArgumentCallback(static function (array $context): void {
- self::assertArrayHasKey('backtrace', $context);
-
- self::assertCount(2, $context['backtrace']);
-
- $trace1 = array_shift($context['backtrace']);
-
- self::assertSame(\LogicException::class, $trace1['class']);
- self::assertSame('current', $trace1['message']);
- self::assertSame(5, $trace1['code']);
- self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace1['file']);
- self::assertIsInt($trace1['line']);
- self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest/', $trace1['trace']);
-
- $trace2 = array_shift($context['backtrace']);
-
- self::assertSame(\RuntimeException::class, $trace2['class']);
- self::assertSame('previous', $trace2['message']);
- self::assertSame(3, $trace2['code']);
- self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace2['file']);
- self::assertIsInt($trace2['line']);
- self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest/', $trace2['trace']);
- })),
+ $logger = $builder->create(LoggerInterface::class, [
+ new WithCallback(
+ 'error',
+ static function (string $message, array $context): void {
+ self::assertSame('Http Exception', $message);
+ self::assertArrayHasKey('backtrace', $context);
+
+ self::assertCount(2, $context['backtrace']);
+
+ $trace1 = array_shift($context['backtrace']);
+
+ self::assertSame(\LogicException::class, $trace1['class']);
+ self::assertSame('current', $trace1['message']);
+ self::assertSame(5, $trace1['code']);
+ self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace1['file']);
+ self::assertIsInt($trace1['line']);
+ self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest/', $trace1['trace']);
+
+ $trace2 = array_shift($context['backtrace']);
+
+ self::assertSame(\RuntimeException::class, $trace2['class']);
+ self::assertSame('previous', $trace2['message']);
+ self::assertSame(3, $trace2['code']);
+ self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace2['file']);
+ self::assertIsInt($trace2['line']);
+ self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest/', $trace2['trace']);
+ }
+ ),
]);
$apiExceptionMiddleware = new ApiExceptionMiddleware($encoder, $responseFactory, true, $logger);
@@ -116,68 +123,82 @@ public function testWithDebugAndLoggerWithExceptionAndWithoutAccept(): void
public function testWithDebugAndLoggerWithExceptionAndWithAccept(): void
{
+ $builder = new MockObjectBuilder();
$previousException = new \RuntimeException('previous', 3);
$exception = new \LogicException('current', 5, $previousException);
/** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
/** @var MockObject|StreamInterface $responseBody */
- $responseBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with('encoded')->willReturn(\strlen('encoded')),
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithReturn('write', ['encoded'], \strlen('encoded')),
]);
/** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/problem+json')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($responseBody),
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf(
+ 'withHeader',
+ ['Content-Type', 'application/problem+json']
+ ),
+ new WithReturn('getBody', [], $responseBody),
]);
/** @var MockObject|RequestHandlerInterface $handler */
- $handler = $this->getMockByCalls(RequestHandlerInterface::class, [
- Call::create('handle')->with($request)->willThrowException($exception),
+ $handler = $builder->create(RequestHandlerInterface::class, [
+ new WithException('handle', [$request], $exception),
]);
/** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('encode')->with(new ArgumentCallback(static function (array $data): void {
- self::assertSame('https://datatracker.ietf.org/doc/html/rfc2616#section-10.5.1', $data['type']);
- self::assertSame(500, $data['status']);
- self::assertSame('Internal Server Error', $data['title']);
- self::assertSame('current', $data['detail']);
- self::assertNull($data['instance']);
- self::assertCount(2, $data['backtrace']);
- }), 'application/json')->willReturn('encoded'),
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithCallback(
+ 'encode',
+ static function (array $data, string $contentType): string {
+ self::assertSame('https://datatracker.ietf.org/doc/html/rfc2616#section-10.5.1', $data['type']);
+ self::assertSame(500, $data['status']);
+ self::assertSame('Internal Server Error', $data['title']);
+ self::assertSame('current', $data['detail']);
+ self::assertNull($data['instance']);
+ self::assertCount(2, $data['backtrace']);
+ self::assertSame('application/json', $contentType);
+
+ return 'encoded';
+ }
+ ),
]);
/** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(500, '')->willReturn($response),
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [500, ''], $response),
]);
/** @var LoggerInterface|MockObject $logger */
- $logger = $this->getMockByCalls(LoggerInterface::class, [
- Call::create('error')->with('Http Exception', new ArgumentCallback(static function (array $context): void {
- self::assertArrayHasKey('backtrace', $context);
-
- self::assertCount(2, $context['backtrace']);
-
- $trace1 = array_shift($context['backtrace']);
-
- self::assertSame(\LogicException::class, $trace1['class']);
- self::assertSame('current', $trace1['message']);
- self::assertSame(5, $trace1['code']);
- self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace1['file']);
-
- $trace2 = array_shift($context['backtrace']);
-
- self::assertSame(\RuntimeException::class, $trace2['class']);
- self::assertSame('previous', $trace2['message']);
- self::assertSame(3, $trace2['code']);
- self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace2['file']);
- })),
+ $logger = $builder->create(LoggerInterface::class, [
+ new WithCallback(
+ 'error',
+ static function (string $message, array $context): void {
+ self::assertSame('Http Exception', $message);
+ self::assertArrayHasKey('backtrace', $context);
+
+ self::assertCount(2, $context['backtrace']);
+
+ $trace1 = array_shift($context['backtrace']);
+
+ self::assertSame(\LogicException::class, $trace1['class']);
+ self::assertSame('current', $trace1['message']);
+ self::assertSame(5, $trace1['code']);
+ self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace1['file']);
+
+ $trace2 = array_shift($context['backtrace']);
+
+ self::assertSame(\RuntimeException::class, $trace2['class']);
+ self::assertSame('previous', $trace2['message']);
+ self::assertSame(3, $trace2['code']);
+ self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace2['file']);
+ }
+ ),
]);
$apiExceptionMiddleware = new ApiExceptionMiddleware($encoder, $responseFactory, true, $logger);
@@ -187,45 +208,55 @@ public function testWithDebugAndLoggerWithExceptionAndWithAccept(): void
public function testWithoutDebugAndLoggerWithExceptionAndWithAccept(): void
{
+ $builder = new MockObjectBuilder();
$previousException = new \RuntimeException('previous', 3);
$exception = new \LogicException('current', 5, $previousException);
/** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
/** @var MockObject|StreamInterface $responseBody */
- $responseBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with('encoded')->willReturn(\strlen('encoded')),
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithReturn('write', ['encoded'], \strlen('encoded')),
]);
/** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/problem+json')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($responseBody),
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf(
+ 'withHeader',
+ ['Content-Type', 'application/problem+json']
+ ),
+ new WithReturn('getBody', [], $responseBody),
]);
/** @var MockObject|RequestHandlerInterface $handler */
- $handler = $this->getMockByCalls(RequestHandlerInterface::class, [
- Call::create('handle')->with($request)->willThrowException($exception),
+ $handler = $builder->create(RequestHandlerInterface::class, [
+ new WithException('handle', [$request], $exception),
]);
/** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('encode')->with(new ArgumentCallback(static function (array $data): void {
- self::assertSame('https://datatracker.ietf.org/doc/html/rfc2616#section-10.5.1', $data['type']);
- self::assertSame(500, $data['status']);
- self::assertSame('Internal Server Error', $data['title']);
- self::assertNull($data['detail']);
- self::assertNull($data['instance']);
- self::assertArrayNotHasKey('backtrace', $data);
- }), 'application/json')->willReturn('encoded'),
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithCallback(
+ 'encode',
+ static function (array $data, string $contentType): string {
+ self::assertSame('https://datatracker.ietf.org/doc/html/rfc2616#section-10.5.1', $data['type']);
+ self::assertSame(500, $data['status']);
+ self::assertSame('Internal Server Error', $data['title']);
+ self::assertNull($data['detail']);
+ self::assertNull($data['instance']);
+ self::assertArrayNotHasKey('backtrace', $data);
+ self::assertSame('application/json', $contentType);
+
+ return 'encoded';
+ }
+ ),
]);
/** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(500, '')->willReturn($response),
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [500, ''], $response),
]);
$apiExceptionMiddleware = new ApiExceptionMiddleware($encoder, $responseFactory);
@@ -235,67 +266,81 @@ public function testWithoutDebugAndLoggerWithExceptionAndWithAccept(): void
public function testWithDebugAndLoggerWithHttpExceptionAndWithAccept(): void
{
+ $builder = new MockObjectBuilder();
$previousException = new \RuntimeException('previous', 3);
$httpException = HttpException::createBadRequest(['key' => 'value'], $previousException);
/** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
/** @var MockObject|StreamInterface $responseBody */
- $responseBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with('encoded')->willReturn(\strlen('encoded')),
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithReturn('write', ['encoded'], \strlen('encoded')),
]);
/** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/problem+json')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($responseBody),
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf(
+ 'withHeader',
+ ['Content-Type', 'application/problem+json']
+ ),
+ new WithReturn('getBody', [], $responseBody),
]);
/** @var MockObject|RequestHandlerInterface $handler */
- $handler = $this->getMockByCalls(RequestHandlerInterface::class, [
- Call::create('handle')->with($request)->willThrowException($httpException),
+ $handler = $builder->create(RequestHandlerInterface::class, [
+ new WithException('handle', [$request], $httpException),
]);
/** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('encode')->with(new ArgumentCallback(static function (array $data): void {
- self::assertSame('https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.1', $data['type']);
- self::assertSame(400, $data['status']);
- self::assertSame('Bad Request', $data['title']);
- self::assertNull($data['detail']);
- self::assertNull($data['instance']);
- }), 'application/json')->willReturn('encoded'),
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithCallback(
+ 'encode',
+ static function (array $data, string $contentType): string {
+ self::assertSame('https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.1', $data['type']);
+ self::assertSame(400, $data['status']);
+ self::assertSame('Bad Request', $data['title']);
+ self::assertNull($data['detail']);
+ self::assertNull($data['instance']);
+ self::assertSame('application/json', $contentType);
+
+ return 'encoded';
+ }
+ ),
]);
/** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(400, '')->willReturn($response),
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [400, ''], $response),
]);
/** @var LoggerInterface|MockObject $logger */
- $logger = $this->getMockByCalls(LoggerInterface::class, [
- Call::create('info')->with('Http Exception', new ArgumentCallback(static function (array $context): void {
- self::assertArrayHasKey('backtrace', $context);
-
- self::assertCount(2, $context['backtrace']);
-
- $trace1 = array_shift($context['backtrace']);
-
- self::assertSame(HttpException::class, $trace1['class']);
- self::assertSame('Bad Request', $trace1['message']);
- self::assertSame(400, $trace1['code']);
- self::assertMatchesRegularExpression('/HttpException\.php/', $trace1['file']);
-
- $trace2 = array_shift($context['backtrace']);
-
- self::assertSame(\RuntimeException::class, $trace2['class']);
- self::assertSame('previous', $trace2['message']);
- self::assertSame(3, $trace2['code']);
- self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace2['file']);
- })),
+ $logger = $builder->create(LoggerInterface::class, [
+ new WithCallback(
+ 'info',
+ static function (string $message, array $context): void {
+ self::assertSame('Http Exception', $message);
+ self::assertArrayHasKey('backtrace', $context);
+
+ self::assertCount(2, $context['backtrace']);
+
+ $trace1 = array_shift($context['backtrace']);
+
+ self::assertSame(HttpException::class, $trace1['class']);
+ self::assertSame('Bad Request', $trace1['message']);
+ self::assertSame(400, $trace1['code']);
+ self::assertMatchesRegularExpression('/HttpException\.php/', $trace1['file']);
+
+ $trace2 = array_shift($context['backtrace']);
+
+ self::assertSame(\RuntimeException::class, $trace2['class']);
+ self::assertSame('previous', $trace2['message']);
+ self::assertSame(3, $trace2['code']);
+ self::assertMatchesRegularExpression('/ApiExceptionMiddlewareTest\.php/', $trace2['file']);
+ }
+ ),
]);
$apiExceptionMiddleware = new ApiExceptionMiddleware($encoder, $responseFactory, true, $logger);
diff --git a/tests/Unit/Orm/PetMappingTest.php b/tests/Unit/Orm/PetMappingTest.php
index b55ab594..ab4930c6 100644
--- a/tests/Unit/Orm/PetMappingTest.php
+++ b/tests/Unit/Orm/PetMappingTest.php
@@ -6,9 +6,10 @@
use App\Model\Vaccination;
use App\Orm\PetMapping;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithoutReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use Doctrine\ORM\Mapping\ClassMetadata;
+use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\TestCase;
/**
@@ -18,43 +19,44 @@
*/
final class PetMappingTest extends TestCase
{
- use MockByCallsTrait;
-
+ #[DoesNotPerformAssertions]
public function testGetClass(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ClassMetadata $classMetadata */
- $classMetadata = $this->getMockByCalls(ClassMetadata::class, [
- Call::create('setPrimaryTable')->with(['name' => 'pet']),
- Call::create('mapField')->with([
+ $classMetadata = $builder->create(ClassMetadata::class, [
+ new WithoutReturn('setPrimaryTable', [['name' => 'pet']]),
+ new WithoutReturn('mapField', [[
'fieldName' => 'id',
'type' => 'guid',
'id' => true,
- ]),
- Call::create('mapField')->with([
+ ]]),
+ new WithoutReturn('mapField', [[
'fieldName' => 'createdAt',
'type' => 'datetime_immutable',
- ]),
- Call::create('mapField')->with([
+ ]]),
+ new WithoutReturn('mapField', [[
'nullable' => true,
'fieldName' => 'updatedAt',
'type' => 'datetime_immutable',
- ]),
- Call::create('mapField')->with([
+ ]]),
+ new WithoutReturn('mapField', [[
'fieldName' => 'name',
'type' => 'string',
- ]),
- Call::create('mapField')->with([
+ ]]),
+ new WithoutReturn('mapField', [[
'nullable' => true,
'fieldName' => 'tag',
'type' => 'string',
- ]),
- Call::create('mapOneToMany')->with([
+ ]]),
+ new WithoutReturn('mapOneToMany', [[
'fieldName' => 'vaccinations',
'targetEntity' => Vaccination::class,
'mappedBy' => 'pet',
'cascade' => ['ALL'],
'orphanRemoval' => true,
- ]),
+ ]]),
]);
$mapping = new PetMapping();
diff --git a/tests/Unit/Orm/VaccinationMappingTest.php b/tests/Unit/Orm/VaccinationMappingTest.php
index 563ea8ec..189b9e31 100644
--- a/tests/Unit/Orm/VaccinationMappingTest.php
+++ b/tests/Unit/Orm/VaccinationMappingTest.php
@@ -6,9 +6,10 @@
use App\Model\Pet;
use App\Orm\VaccinationMapping;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithoutReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use Doctrine\ORM\Mapping\ClassMetadata;
+use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\TestCase;
/**
@@ -18,37 +19,36 @@
*/
final class VaccinationMappingTest extends TestCase
{
- use MockByCallsTrait;
-
+ #[DoesNotPerformAssertions]
public function testGetClass(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ClassMetadata $classMetadata */
- $classMetadata = $this->getMockByCalls(ClassMetadata::class, [
- Call::create('setPrimaryTable')->with(['name' => 'vaccination']),
- Call::create('mapField')->with([
+ $classMetadata = $builder->create(ClassMetadata::class, [
+ new WithoutReturn('setPrimaryTable', [['name' => 'vaccination']]),
+ new WithoutReturn('mapField', [[
'fieldName' => 'id',
'type' => 'guid',
'id' => true,
- ]),
- Call::create('mapField')->with([
+ ]]),
+ new WithoutReturn('mapField', [[
'fieldName' => 'name',
'type' => 'string',
- ]),
- Call::create('mapManyToOne')->with([
+ ]]),
+ new WithoutReturn('mapManyToOne', [[
'fieldName' => 'pet',
'targetEntity' => Pet::class,
'inversedBy' => 'vaccinations',
- 'joinColumns' => [
- [
- 'name' => 'pet_id',
- 'referencedColumnName' => 'id',
- 'nullable' => false,
- 'unique' => false,
- 'onDelete' => 'CASCADE',
- 'columnDefinition' => null,
- ],
- ],
- ]),
+ 'joinColumns' => [[
+ 'name' => 'pet_id',
+ 'referencedColumnName' => 'id',
+ 'nullable' => false,
+ 'unique' => false,
+ 'onDelete' => 'CASCADE',
+ 'columnDefinition' => null,
+ ]],
+ ]]),
]);
$mapping = new VaccinationMapping();
diff --git a/tests/Unit/Parsing/PetParsingTest.php b/tests/Unit/Parsing/PetParsingTest.php
index f37587bd..1ea5aa2b 100644
--- a/tests/Unit/Parsing/PetParsingTest.php
+++ b/tests/Unit/Parsing/PetParsingTest.php
@@ -8,11 +8,10 @@
use App\Dto\Model\PetRequest;
use App\Parsing\PetParsing;
use Chubbyphp\Framework\Router\UrlGeneratorInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\Parsing\Parser;
use Chubbyphp\Parsing\ParserErrorException;
-use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
@@ -23,17 +22,17 @@
*/
final class PetParsingTest extends TestCase
{
- use MockByCallsTrait;
-
public function testGetCollectionRequestSchema(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, []);
$parser = new Parser();
- /** @var MockObject|UrlGeneratorInterface $urlGenerator */
- $urlGenerator = $this->getMockByCalls(UrlGeneratorInterface::class);
+ /** @var UrlGeneratorInterface $urlGenerator */
+ $urlGenerator = $builder->create(UrlGeneratorInterface::class, []);
$petParsing = new PetParsing($parser, $urlGenerator);
@@ -71,37 +70,65 @@ public function testGetCollectionRequestSchema(): void
public function testGetCollectionResponseSchema(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, []);
$parser = new Parser();
- /** @var MockObject|UrlGeneratorInterface $urlGenerator */
- $urlGenerator = $this->getMockByCalls(UrlGeneratorInterface::class, [
- Call::create('generatePath')
- ->with('pet_read', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')
- ->with('pet_update', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')
- ->with('pet_delete', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')->with('pet_list', [], ['offset' => 10, 'limit' => 10, 'filters' => ['name' => null], 'sort' => ['name' => null]])
- ->willReturn('/api/pets?offset=10&limit=10'),
- Call::create('generatePath')->with('pet_create', [], [])->willReturn('/api/pets'),
- Call::create('generatePath')
- ->with('pet_read', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')
- ->with('pet_update', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')
- ->with('pet_delete', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')->with('pet_list', [], ['offset' => 10, 'limit' => 10, 'filters' => ['name' => 'jerry'], 'sort' => ['name' => 'asc']])
- ->willReturn('/api/pets?offset=10&limit=10&filters[name]=jerry&sort[name]=asc'),
- Call::create('generatePath')->with('pet_create', [], [])->willReturn('/api/pets'),
+ /** @var UrlGeneratorInterface $urlGenerator */
+ $urlGenerator = $builder->create(UrlGeneratorInterface::class, [
+ new WithReturn(
+ 'generatePath',
+ ['pet_read', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_update', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_delete', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_list', [], ['offset' => 10, 'limit' => 10, 'filters' => ['name' => null], 'sort' => ['name' => null]]],
+ '/api/pets?offset=10&limit=10'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_create', [], []],
+ '/api/pets'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_read', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_update', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_delete', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_list', [], ['offset' => 10, 'limit' => 10, 'filters' => ['name' => 'jerry'], 'sort' => ['name' => 'asc']]],
+ '/api/pets?offset=10&limit=10&filters[name]=jerry&sort[name]=asc'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_create', [], []],
+ '/api/pets'
+ ),
]);
$petParsing = new PetParsing($parser, $urlGenerator);
@@ -281,13 +308,15 @@ public function testGetCollectionResponseSchema(): void
public function testGetModelRequestSchema(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, []);
$parser = new Parser();
- /** @var MockObject|UrlGeneratorInterface $urlGenerator */
- $urlGenerator = $this->getMockByCalls(UrlGeneratorInterface::class);
+ /** @var UrlGeneratorInterface $urlGenerator */
+ $urlGenerator = $builder->create(UrlGeneratorInterface::class, []);
$petParsing = new PetParsing($parser, $urlGenerator);
@@ -375,22 +404,30 @@ public function testGetModelRequestSchema(): void
public function testGetModelResponseSchema(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, []);
$parser = new Parser();
- /** @var MockObject|UrlGeneratorInterface $urlGenerator */
- $urlGenerator = $this->getMockByCalls(UrlGeneratorInterface::class, [
- Call::create('generatePath')
- ->with('pet_read', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')
- ->with('pet_update', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
- Call::create('generatePath')
- ->with('pet_delete', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], [])
- ->willReturn('/api/pets/f8b51629-d105-401e-8872-bebd9911709a'),
+ /** @var UrlGeneratorInterface $urlGenerator */
+ $urlGenerator = $builder->create(UrlGeneratorInterface::class, [
+ new WithReturn(
+ 'generatePath',
+ ['pet_read', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_update', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
+ new WithReturn(
+ 'generatePath',
+ ['pet_delete', ['id' => 'f8b51629-d105-401e-8872-bebd9911709a'], []],
+ '/api/pets/f8b51629-d105-401e-8872-bebd9911709a'
+ ),
]);
$petParsing = new PetParsing($parser, $urlGenerator);
diff --git a/tests/Unit/Repository/PetRepositoryTest.php b/tests/Unit/Repository/PetRepositoryTest.php
index e24a43e0..b643d7b0 100644
--- a/tests/Unit/Repository/PetRepositoryTest.php
+++ b/tests/Unit/Repository/PetRepositoryTest.php
@@ -9,8 +9,10 @@
use App\Model\ModelInterface;
use App\Model\Pet;
use App\Repository\PetRepository;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithoutReturn;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
@@ -19,7 +21,7 @@
use Doctrine\ORM\Query\Expr\Comparison;
use Doctrine\ORM\Query\Expr\Func;
use Doctrine\ORM\QueryBuilder;
-use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\TestCase;
/**
@@ -29,12 +31,12 @@
*/
final class PetRepositoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testResolveCollectionWithWrongCollection(): void
{
- /** @var CollectionInterface|MockObject $collection */
- $collection = $this->getMockByCalls(CollectionInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var CollectionInterface $collection */
+ $collection = $builder->create(CollectionInterface::class, []);
$collectionClass = $collection::class;
@@ -47,13 +49,14 @@ public function testResolveCollectionWithWrongCollection(): void
)
);
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class);
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, []);
$repository = new PetRepository($entityManager);
$repository->resolveCollection($collection);
}
+ #[DoesNotPerformAssertions]
public function testResolveCollection(): void
{
$pet = new Pet();
@@ -66,50 +69,54 @@ public function testResolveCollection(): void
$collection->setFilters(['name' => 'sample']);
$collection->setSort(['name' => 'asc']);
- /** @var Comparison|MockObject $likeNameFunc */
- $likeNameFunc = $this->getMockByCalls(Comparison::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var Comparison $likeNameFunc */
+ $likeNameFunc = $builder->create(Comparison::class, []);
- /** @var Func|MockObject $countIdFunc */
- $countIdFunc = $this->getMockByCalls(Func::class);
+ /** @var Func $countIdFunc */
+ $countIdFunc = $builder->create(Func::class, []);
- /** @var Expr|MockObject $expr */
- $expr = $this->getMockByCalls(Expr::class, [
- Call::create('like')->with('p.name', ':name')->willReturn($likeNameFunc),
- Call::create('count')->with('p.id')->willReturn($countIdFunc),
+ /** @var Expr $expr */
+ $expr = $builder->create(Expr::class, [
+ new WithReturn('like', ['p.name', ':name'], $likeNameFunc),
+ new WithReturn('count', ['p.id'], $countIdFunc),
]);
- /** @var MockObject|Query $countQuery */
- $countQuery = $this->getMockByCalls(Query::class, [
- Call::create('getSingleScalarResult')->with()->willReturn((string) \count($items)),
+ /** @var Query $countQuery */
+ $countQuery = $builder->create(Query::class, [
+ new WithReturn('getSingleScalarResult', [], (string) \count($items)),
]);
- /** @var MockObject|Query $itemsQuery */
- $itemsQuery = $this->getMockByCalls(Query::class, [
- Call::create('getResult')->with(AbstractQuery::HYDRATE_OBJECT)->willReturn($items),
+ /** @var Query $itemsQuery */
+ $itemsQuery = $builder->create(Query::class, [
+ new WithReturn('getResult', [AbstractQuery::HYDRATE_OBJECT], $items),
]);
- /** @var MockObject|QueryBuilder $queryBuilder */
- $queryBuilder = $this->getMockByCalls(QueryBuilder::class, [
- Call::create('expr')->with()->willReturn($expr),
- Call::create('andWhere')->with($likeNameFunc)->willReturnSelf(),
- Call::create('setParameter')->with('name', '%sample%', null)->willReturnSelf(),
- Call::create('expr')->with()->willReturn($expr),
- Call::create('select')->with($countIdFunc)->willReturnSelf(),
- Call::create('getQuery')->with()->willReturn($countQuery),
- Call::create('addOrderBy')->with('p.name', 'asc')->willReturnSelf(),
- Call::create('setFirstResult')->with(0)->willReturnSelf(),
- Call::create('setMaxResults')->with(20)->willReturnSelf(),
- Call::create('getQuery')->with()->willReturn($itemsQuery),
+ /** @var QueryBuilder $queryBuilder */
+ $queryBuilder = $builder->create(QueryBuilder::class, [
+ new WithReturn('expr', [], $expr),
+ new WithReturnSelf('andWhere', [[$likeNameFunc]]),
+ new WithReturnSelf('setParameter', ['name', '%sample%', null]),
+ new WithReturnSelf('__clone', []),
+ new WithReturn('expr', [], $expr),
+ new WithReturnSelf('select', [[$countIdFunc]]),
+ new WithReturn('getQuery', [], $countQuery),
+ new WithReturnSelf('__clone', []),
+ new WithReturnSelf('addOrderBy', ['p.name', 'asc']),
+ new WithReturnSelf('setFirstResult', [0]),
+ new WithReturnSelf('setMaxResults', [20]),
+ new WithReturn('getQuery', [], $itemsQuery),
]);
- /** @var EntityRepository|MockObject $repository */
- $repository = $this->getMockByCalls(EntityRepository::class, [
- Call::create('createQueryBuilder')->with('p', null)->willReturn($queryBuilder),
+ /** @var EntityRepository $repository */
+ $repositoryMock = $builder->create(EntityRepository::class, [
+ new WithReturn('createQueryBuilder', ['p', null], $queryBuilder),
]);
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class, [
- Call::create('getRepository')->with(Pet::class)->willReturn($repository),
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, [
+ new WithReturn('getRepository', [Pet::class], $repositoryMock),
]);
$repository = new PetRepository($entityManager);
@@ -120,11 +127,11 @@ public function testFindById(): void
{
$pet = new Pet();
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class, [
- Call::create('find')
- ->with(Pet::class, '86c78085-edaf-4df9-95d0-563e45acf618', null, null)
- ->willReturn($pet),
+ $builder = new MockObjectBuilder();
+
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, [
+ new WithReturn('find', [Pet::class, '86c78085-edaf-4df9-95d0-563e45acf618', null, null], $pet),
]);
$repository = new PetRepository($entityManager);
@@ -134,8 +141,10 @@ public function testFindById(): void
public function testPersistWithWrongModel(): void
{
- /** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var ModelInterface $model */
+ $model = $builder->create(ModelInterface::class, []);
$modelClass = $model::class;
@@ -147,20 +156,23 @@ public function testPersistWithWrongModel(): void
)
);
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class);
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, []);
$repository = new PetRepository($entityManager);
$repository->persist($model);
}
+ #[DoesNotPerformAssertions]
public function testPersist(): void
{
$pet = new Pet();
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class, [
- Call::create('persist')->with($pet),
+ $builder = new MockObjectBuilder();
+
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, [
+ new WithoutReturn('persist', [$pet]),
]);
$repository = new PetRepository($entityManager);
@@ -169,8 +181,10 @@ public function testPersist(): void
public function testRemoveWithWrongModel(): void
{
- /** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var ModelInterface $model */
+ $model = $builder->create(ModelInterface::class, []);
$modelClass = $model::class;
@@ -182,31 +196,37 @@ public function testRemoveWithWrongModel(): void
)
);
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class);
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, []);
$repository = new PetRepository($entityManager);
$repository->remove($model);
}
+ #[DoesNotPerformAssertions]
public function testRemove(): void
{
$pet = new Pet();
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class, [
- Call::create('remove')->with($pet),
+ $builder = new MockObjectBuilder();
+
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, [
+ new WithoutReturn('remove', [$pet]),
]);
$repository = new PetRepository($entityManager);
$repository->remove($pet);
}
+ #[DoesNotPerformAssertions]
public function testFlush(): void
{
- /** @var EntityManager|MockObject $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class, [
- Call::create('flush')->with(),
+ $builder = new MockObjectBuilder();
+
+ /** @var EntityManager $entityManager */
+ $entityManager = $builder->create(EntityManager::class, [
+ new WithoutReturn('flush', []),
]);
$repository = new PetRepository($entityManager);
diff --git a/tests/Unit/RequestHandler/Api/Crud/CreateRequestHandlerTest.php b/tests/Unit/RequestHandler/Api/Crud/CreateRequestHandlerTest.php
index 995f18d1..77d19224 100644
--- a/tests/Unit/RequestHandler/Api/Crud/CreateRequestHandlerTest.php
+++ b/tests/Unit/RequestHandler/Api/Crud/CreateRequestHandlerTest.php
@@ -12,8 +12,10 @@
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
use Chubbyphp\HttpException\HttpExceptionInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithException;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\Parsing\ParserErrorException;
use Chubbyphp\Parsing\Schema\ObjectSchemaInterface;
use PHPUnit\Framework\TestCase;
@@ -29,8 +31,6 @@
*/
final class CreateRequestHandlerTest extends TestCase
{
- use MockByCallsTrait;
-
public function testWithParsingError(): void
{
$parserErrorException = new ParserErrorException();
@@ -40,41 +40,43 @@ public function testWithParsingError(): void
$inputAsArray = (array) $inputAsStdClass;
$inputAsJson = json_encode($inputAsArray);
- /** @var MockObject|StreamInterface $requestBody */
- $requestBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('__toString')->with()->willReturn($inputAsJson),
+ $builder = new MockObjectBuilder();
+
+ /** @var StreamInterface $requestBody */
+ $requestBody = $builder->create(StreamInterface::class, [
+ new WithReturn('__toString', [], $inputAsJson),
]);
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getAttribute')->with('contentType', null)->willReturn('application/json'),
- Call::create('getBody')->with()->willReturn($requestBody),
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getAttribute', ['contentType', null], 'application/json'),
+ new WithReturn('getBody', [], $requestBody),
]);
- /** @var DecoderInterface|MockObject $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class, [
- Call::create('decode')->with($inputAsJson, 'application/json')->willReturn($inputAsArray),
+ /** @var DecoderInterface $decoder */
+ $decoder = $builder->create(DecoderInterface::class, [
+ new WithReturn('decode', [$inputAsJson, 'application/json'], $inputAsArray),
]);
- /** @var MockObject|ObjectSchemaInterface $modelRequestSchema */
- $modelRequestSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($inputAsArray)->willThrowException($parserErrorException),
+ /** @var ObjectSchemaInterface $modelRequestSchema */
+ $modelRequestSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithException('parse', [$inputAsArray], $parserErrorException),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class, [
- Call::create('getModelRequestSchema')->with($request)->willReturn($modelRequestSchema),
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, [
+ new WithReturn('getModelRequestSchema', [$request], $modelRequestSchema),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class);
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, []);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new CreateRequestHandler(
$decoder,
@@ -87,8 +89,7 @@ public function testWithParsingError(): void
try {
$requestHandler->handle($request);
self::fail('Expected Exception');
- } catch (\Throwable $e) {
- self::assertInstanceOf(HttpExceptionInterface::class, $e);
+ } catch (HttpExceptionInterface $e) {
self::assertSame([
'type' => 'https://datatracker.ietf.org/doc/html/rfc4918#section-11.2',
'status' => 422,
@@ -107,72 +108,74 @@ public function testSuccessful(): void
$inputAsArray = (array) $inputAsStdClass;
$inputAsJson = json_encode($inputAsArray);
- /** @var MockObject|StreamInterface $requestBody */
- $requestBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('__toString')->with()->willReturn($inputAsJson),
+ $builder = new MockObjectBuilder();
+
+ /** @var StreamInterface $requestBody */
+ $requestBody = $builder->create(StreamInterface::class, [
+ new WithReturn('__toString', [], $inputAsJson),
]);
- /** @var MockObject|StreamInterface $responseBody */
- $responseBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with($inputAsJson)->willReturn(\strlen($inputAsJson)),
+ /** @var StreamInterface $responseBody */
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithReturn('write', [$inputAsJson], \strlen($inputAsJson)),
]);
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getAttribute')->with('contentType', null)->willReturn('application/json'),
- Call::create('getBody')->with()->willReturn($requestBody),
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getAttribute', ['contentType', null], 'application/json'),
+ new WithReturn('getBody', [], $requestBody),
]);
- /** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/json')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($responseBody),
+ /** @var ResponseInterface $response */
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),
+ new WithReturn('getBody', [], $responseBody),
]);
- /** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class);
+ /** @var ModelInterface $model */
+ $model = $builder->create(ModelInterface::class, []);
- /** @var DecoderInterface|MockObject $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class, [
- Call::create('decode')->with($inputAsJson, 'application/json')->willReturn($inputAsArray),
+ /** @var DecoderInterface $decoder */
+ $decoder = $builder->create(DecoderInterface::class, [
+ new WithReturn('decode', [$inputAsJson, 'application/json'], $inputAsArray),
]);
- /** @var MockObject|ModelRequestInterface $modelRequest */
- $modelRequest = $this->getMockByCalls(ModelRequestInterface::class, [
- Call::create('createModel')->with()->willReturn($model),
+ /** @var ModelRequestInterface $modelRequest */
+ $modelRequest = $builder->create(ModelRequestInterface::class, [
+ new WithReturn('createModel', [], $model),
]);
- /** @var MockObject|ObjectSchemaInterface $modelRequestSchema */
- $modelRequestSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($inputAsArray)->willReturn($modelRequest),
+ /** @var ObjectSchemaInterface $modelRequestSchema */
+ $modelRequestSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithReturn('parse', [$inputAsArray], $modelRequest),
]);
- /** @var MockObject|ObjectSchemaInterface $modelResponseSchema */
- $modelResponseSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($model)->willReturn($inputAsArray),
+ /** @var ObjectSchemaInterface $modelResponseSchema */
+ $modelResponseSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithReturn('parse', [$model], $inputAsArray),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class, [
- Call::create('getModelRequestSchema')->with($request)->willReturn($modelRequestSchema),
- Call::create('getModelResponseSchema')->with($request)->willReturn($modelResponseSchema),
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, [
+ new WithReturn('getModelRequestSchema', [$request], $modelRequestSchema),
+ new WithReturn('getModelResponseSchema', [$request], $modelResponseSchema),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('persist')->with($model),
- Call::create('flush')->with(),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('persist', [$model], $model),
+ new WithReturn('flush', [], null),
]);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('encode')->with($inputAsArray, 'application/json')->willReturn($inputAsJson),
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithReturn('encode', [$inputAsArray, 'application/json'], $inputAsJson),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(201, '')->willReturn($response),
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [201, ''], $response),
]);
$requestHandler = new CreateRequestHandler(
diff --git a/tests/Unit/RequestHandler/Api/Crud/DeleteRequestHandlerTest.php b/tests/Unit/RequestHandler/Api/Crud/DeleteRequestHandlerTest.php
index df218f40..022460bc 100644
--- a/tests/Unit/RequestHandler/Api/Crud/DeleteRequestHandlerTest.php
+++ b/tests/Unit/RequestHandler/Api/Crud/DeleteRequestHandlerTest.php
@@ -8,8 +8,9 @@
use App\Repository\RepositoryInterface;
use App\RequestHandler\Api\Crud\DeleteRequestHandler;
use Chubbyphp\HttpException\HttpExceptionInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
@@ -22,90 +23,90 @@
*/
final class DeleteRequestHandlerTest extends TestCase
{
- use MockByCallsTrait;
-
public function testCreateResourceNotFoundInvalidUuid(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('1234'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], '1234'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class);
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new DeleteRequestHandler($repository, $responseFactory);
try {
$requestHandler->handle($request);
- self::fail('Expected Exception');
- } catch (\Throwable $e) {
- self::assertInstanceOf(HttpExceptionInterface::class, $e);
+
+ throw new \Exception('Expected Exception');
+ } catch (HttpExceptionInterface $e) {
self::assertSame(404, $e->getStatus());
}
}
public function testCreateResourceNotFoundMissingModel(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], 'cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('findById')->with('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0')->willReturn(null),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('findById', ['cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'], null),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new DeleteRequestHandler($repository, $responseFactory);
try {
$requestHandler->handle($request);
- self::fail('Expected Exception');
- } catch (\Throwable $e) {
- self::assertInstanceOf(HttpExceptionInterface::class, $e);
+
+ throw new \Exception('Expected Exception');
+ } catch (HttpExceptionInterface $e) {
self::assertSame(404, $e->getStatus());
}
}
public function testSuccessful(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], 'cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
- /** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')
- ->with('Content-Type', 'application/json')
- ->willReturnSelf(),
+ /** @var ResponseInterface $response */
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),
]);
- /** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class);
+ /** @var ModelInterface $model */
+ $model = $builder->create(ModelInterface::class, []);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('findById')->with('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0')->willReturn($model),
- Call::create('remove')->with($model),
- Call::create('flush')->with(),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('findById', ['cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'], $model),
+ new WithReturnSelf('remove', [$model]),
+ new WithReturnSelf('flush', []),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')
- ->with(204, '')
- ->willReturn($response),
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [204, ''], $response),
]);
$requestHandler = new DeleteRequestHandler($repository, $responseFactory);
diff --git a/tests/Unit/RequestHandler/Api/Crud/ListRequestHandlerTest.php b/tests/Unit/RequestHandler/Api/Crud/ListRequestHandlerTest.php
index 45f641fb..85db4496 100644
--- a/tests/Unit/RequestHandler/Api/Crud/ListRequestHandlerTest.php
+++ b/tests/Unit/RequestHandler/Api/Crud/ListRequestHandlerTest.php
@@ -11,8 +11,11 @@
use App\RequestHandler\Api\Crud\ListRequestHandler;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
use Chubbyphp\HttpException\HttpExceptionInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithException;
+use Chubbyphp\Mock\MockMethod\WithoutReturn;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\Parsing\ParserErrorException;
use Chubbyphp\Parsing\Schema\ObjectSchemaInterface;
use PHPUnit\Framework\TestCase;
@@ -28,8 +31,6 @@
*/
final class ListRequestHandlerTest extends TestCase
{
- use MockByCallsTrait;
-
public function testWithParsingError(): void
{
$parserErrorException = new ParserErrorException();
@@ -38,30 +39,31 @@ public function testWithParsingError(): void
$queryAsStdClass->name = 'test';
$queryAsArray = (array) $queryAsStdClass;
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getQueryParams')->with()->willReturn($queryAsArray),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getQueryParams', [], $queryAsArray),
]);
- /** @var MockObject|ObjectSchemaInterface $collectionRequestSchema */
- $collectionRequestSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($queryAsArray)->willThrowException($parserErrorException),
+ $collectionRequestSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithException('parse', [$queryAsArray], $parserErrorException),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class, [
- Call::create('getCollectionRequestSchema')->with($request)->willReturn($collectionRequestSchema),
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, [
+ new WithReturn('getCollectionRequestSchema', [$request], $collectionRequestSchema),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class);
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, []);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new ListRequestHandler(
$parsing,
@@ -73,8 +75,7 @@ public function testWithParsingError(): void
try {
$requestHandler->handle($request);
self::fail('Expected Exception');
- } catch (\Throwable $e) {
- self::assertInstanceOf(HttpExceptionInterface::class, $e);
+ } catch (HttpExceptionInterface $e) {
self::assertSame([
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.1',
'status' => 400,
@@ -93,60 +94,62 @@ public function testSuccessful(): void
$queryAsArray = (array) $queryAsStdClass;
$queryAsJson = json_encode($queryAsArray);
- /** @var MockObject|StreamInterface $responseBody */
- $responseBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with($queryAsJson)->willReturn(\strlen($queryAsJson)),
+ $builder = new MockObjectBuilder();
+
+ /** @var StreamInterface $responseBody */
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithReturn('write', [$queryAsJson], \strlen($queryAsJson)),
]);
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getQueryParams')->with()->willReturn($queryAsArray),
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getQueryParams', [], $queryAsArray),
]);
- /** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/json')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($responseBody),
+ /** @var ResponseInterface $response */
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),
+ new WithReturn('getBody', [], $responseBody),
]);
- /** @var CollectionInterface|MockObject $collection */
- $collection = $this->getMockByCalls(CollectionInterface::class);
+ /** @var CollectionInterface $collection */
+ $collection = $builder->create(CollectionInterface::class, []);
- /** @var CollectionRequestInterface|MockObject $collectionRequest */
- $collectionRequest = $this->getMockByCalls(CollectionRequestInterface::class, [
- Call::create('createCollection')->with()->willReturn($collection),
+ /** @var CollectionRequestInterface $collectionRequest */
+ $collectionRequest = $builder->create(CollectionRequestInterface::class, [
+ new WithReturn('createCollection', [], $collection),
]);
- /** @var MockObject|ObjectSchemaInterface $collectionRequestSchema */
- $collectionRequestSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($queryAsArray)->willReturn($collectionRequest),
+ /** @var ObjectSchemaInterface $collectionRequestSchema */
+ $collectionRequestSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithReturn('parse', [$queryAsArray], $collectionRequest),
]);
- /** @var MockObject|ObjectSchemaInterface $collectionResponseSchema */
- $collectionResponseSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($collection)->willReturn($queryAsArray),
+ /** @var ObjectSchemaInterface $collectionResponseSchema */
+ $collectionResponseSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithReturn('parse', [$collection], $queryAsArray),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class, [
- Call::create('getCollectionRequestSchema')->with($request)->willReturn($collectionRequestSchema),
- Call::create('getCollectionResponseSchema')->with($request)->willReturn($collectionResponseSchema),
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, [
+ new WithReturn('getCollectionRequestSchema', [$request], $collectionRequestSchema),
+ new WithReturn('getCollectionResponseSchema', [$request], $collectionResponseSchema),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('resolveCollection')->with($collection),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithoutReturn('resolveCollection', [$collection]),
]);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('encode')->with($queryAsArray, 'application/json')->willReturn($queryAsJson),
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithReturn('encode', [$queryAsArray, 'application/json'], $queryAsJson),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(200, '')->willReturn($response),
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [200, ''], $response),
]);
$requestHandler = new ListRequestHandler(
diff --git a/tests/Unit/RequestHandler/Api/Crud/ReadRequestHandlerTest.php b/tests/Unit/RequestHandler/Api/Crud/ReadRequestHandlerTest.php
index 4b37142b..def0077e 100644
--- a/tests/Unit/RequestHandler/Api/Crud/ReadRequestHandlerTest.php
+++ b/tests/Unit/RequestHandler/Api/Crud/ReadRequestHandlerTest.php
@@ -10,8 +10,9 @@
use App\RequestHandler\Api\Crud\ReadRequestHandler;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
use Chubbyphp\HttpException\HttpExceptionInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\Parsing\Schema\ObjectSchemaInterface;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -26,27 +27,27 @@
*/
final class ReadRequestHandlerTest extends TestCase
{
- use MockByCallsTrait;
-
public function testResourceNotFoundInvalidUuid(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('1234'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], '1234'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class);
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, []);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class);
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, []);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new ReadRequestHandler(
$parsing,
@@ -57,8 +58,9 @@ public function testResourceNotFoundInvalidUuid(): void
try {
$requestHandler->handle($request);
- self::fail('Expected Exception');
- } catch (\Throwable $e) {
+
+ throw new \Exception('Expected Exception');
+ } catch (HttpExceptionInterface $e) {
self::assertInstanceOf(HttpExceptionInterface::class, $e);
self::assertSame(404, $e->getStatus());
}
@@ -66,25 +68,27 @@ public function testResourceNotFoundInvalidUuid(): void
public function testResourceNotFoundMissingModel(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], 'cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class);
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, []);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('findById')->with('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0')->willReturn(null),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('findById', ['cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'], null),
]);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new ReadRequestHandler(
$parsing,
@@ -95,8 +99,9 @@ public function testResourceNotFoundMissingModel(): void
try {
$requestHandler->handle($request);
- self::fail('Expected Exception');
- } catch (\Throwable $e) {
+
+ throw new \Exception('Expected Exception');
+ } catch (HttpExceptionInterface $e) {
self::assertInstanceOf(HttpExceptionInterface::class, $e);
self::assertSame(404, $e->getStatus());
}
@@ -109,49 +114,51 @@ public function testSuccessful(): void
$inputAsArray = (array) $inputAsStdClass;
$inputAsJson = json_encode($inputAsArray);
- /** @var MockObject|StreamInterface $responseBody */
- $responseBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with($inputAsJson)->willReturn(\strlen($inputAsJson)),
+ $builder = new MockObjectBuilder();
+
+ /** @var StreamInterface $responseBody */
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithReturn('write', [$inputAsJson], \strlen($inputAsJson)),
]);
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], 'cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
]);
- /** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/json')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($responseBody),
+ /** @var ResponseInterface $response */
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),
+ new WithReturn('getBody', [], $responseBody),
]);
- /** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class);
+ /** @var ModelInterface $model */
+ $model = $builder->create(ModelInterface::class, []);
- /** @var MockObject|ObjectSchemaInterface $modelResponseSchema */
- $modelResponseSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($model)->willReturn($inputAsArray),
+ /** @var ObjectSchemaInterface $modelResponseSchema */
+ $modelResponseSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithReturn('parse', [$model], $inputAsArray),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class, [
- Call::create('getModelResponseSchema')->with($request)->willReturn($modelResponseSchema),
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, [
+ new WithReturn('getModelResponseSchema', [$request], $modelResponseSchema),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('findById')->with('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0')->willReturn($model),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('findById', ['cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'], $model),
]);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('encode')->with($inputAsArray, 'application/json')->willReturn($inputAsJson),
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithReturn('encode', [$inputAsArray, 'application/json'], $inputAsJson),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(200, '')->willReturn($response),
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [200, ''], $response),
]);
$requestHandler = new ReadRequestHandler(
diff --git a/tests/Unit/RequestHandler/Api/Crud/UpdateRequestHandlerTest.php b/tests/Unit/RequestHandler/Api/Crud/UpdateRequestHandlerTest.php
index 783ba2ac..56b6fb18 100644
--- a/tests/Unit/RequestHandler/Api/Crud/UpdateRequestHandlerTest.php
+++ b/tests/Unit/RequestHandler/Api/Crud/UpdateRequestHandlerTest.php
@@ -12,8 +12,10 @@
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
use Chubbyphp\HttpException\HttpExceptionInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithException;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\Parsing\ParserErrorException;
use Chubbyphp\Parsing\Schema\ObjectSchemaInterface;
use PHPUnit\Framework\TestCase;
@@ -29,31 +31,31 @@
*/
final class UpdateRequestHandlerTest extends TestCase
{
- use MockByCallsTrait;
-
public function testResourceNotFoundInvalidUuid(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('1234'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getAttribute')->with('contentType', null)->willReturn('application/json'),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], '1234'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getAttribute', ['contentType', null], 'application/json'),
]);
- /** @var DecoderInterface|MockObject $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class);
+ /** @var DecoderInterface $decoder */
+ $decoder = $builder->create(DecoderInterface::class, []);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class);
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, []);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class);
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, []);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new UpdateRequestHandler(
$decoder,
@@ -65,38 +67,40 @@ public function testResourceNotFoundInvalidUuid(): void
try {
$requestHandler->handle($request);
- self::fail('Expected Exception');
- } catch (\Throwable $e) {
- self::assertInstanceOf(HttpExceptionInterface::class, $e);
+
+ throw new \Exception('Expected Exception');
+ } catch (HttpExceptionInterface $e) {
self::assertSame(404, $e->getStatus());
}
}
public function testResourceNotFoundMissingModel(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getAttribute')->with('contentType', null)->willReturn('application/json'),
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], 'cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getAttribute', ['contentType', null], 'application/json'),
]);
- /** @var DecoderInterface|MockObject $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class);
+ /** @var DecoderInterface $decoder */
+ $decoder = $builder->create(DecoderInterface::class, []);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class);
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, []);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('findById')->with('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0')->willReturn(null),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('findById', ['cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'], null),
]);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new UpdateRequestHandler(
$decoder,
@@ -108,8 +112,9 @@ public function testResourceNotFoundMissingModel(): void
try {
$requestHandler->handle($request);
- self::fail('Expected Exception');
- } catch (\Throwable $e) {
+
+ throw new \Exception('Expected Exception');
+ } catch (HttpExceptionInterface $e) {
self::assertInstanceOf(HttpExceptionInterface::class, $e);
self::assertSame(404, $e->getStatus());
}
@@ -124,47 +129,49 @@ public function testWithParsingError(): void
$inputAsArray = (array) $inputAsStdClass;
$inputAsJson = json_encode($inputAsArray);
- /** @var MockObject|StreamInterface $requestBody */
- $requestBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('__toString')->with()->willReturn($inputAsJson),
+ $builder = new MockObjectBuilder();
+
+ /** @var StreamInterface $requestBody */
+ $requestBody = $builder->create(StreamInterface::class, [
+ new WithReturn('__toString', [], $inputAsJson),
]);
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getAttribute')->with('contentType', null)->willReturn('application/json'),
- Call::create('getBody')->with()->willReturn($requestBody),
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], 'cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getAttribute', ['contentType', null], 'application/json'),
+ new WithReturn('getBody', [], $requestBody),
]);
- /** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class, []);
+ /** @var ModelInterface $model */
+ $model = $builder->create(ModelInterface::class, []);
- /** @var DecoderInterface|MockObject $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class, [
- Call::create('decode')->with($inputAsJson, 'application/json')->willReturn($inputAsArray),
+ /** @var DecoderInterface $decoder */
+ $decoder = $builder->create(DecoderInterface::class, [
+ new WithReturn('decode', [$inputAsJson, 'application/json'], $inputAsArray),
]);
- /** @var MockObject|ObjectSchemaInterface $modelRequestSchema */
- $modelRequestSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($inputAsArray)->willThrowException($parserErrorException),
+ /** @var ObjectSchemaInterface $modelRequestSchema */
+ $modelRequestSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithException('parse', [$inputAsArray], $parserErrorException),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class, [
- Call::create('getModelRequestSchema')->with($request)->willReturn($modelRequestSchema),
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, [
+ new WithReturn('getModelRequestSchema', [$request], $modelRequestSchema),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('findById')->with('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0')->willReturn($model),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('findById', ['cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'], $model),
]);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, []);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
$requestHandler = new UpdateRequestHandler(
$decoder,
@@ -176,9 +183,9 @@ public function testWithParsingError(): void
try {
$requestHandler->handle($request);
- self::fail('Expected Exception');
- } catch (\Throwable $e) {
- self::assertInstanceOf(HttpExceptionInterface::class, $e);
+
+ throw new \Exception('Expected Exception');
+ } catch (HttpExceptionInterface $e) {
self::assertSame([
'type' => 'https://datatracker.ietf.org/doc/html/rfc4918#section-11.2',
'status' => 422,
@@ -197,74 +204,76 @@ public function testSuccessful(): void
$inputAsArray = (array) $inputAsStdClass;
$inputAsJson = json_encode($inputAsArray);
- /** @var MockObject|StreamInterface $requestBody */
- $requestBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('__toString')->with()->willReturn($inputAsJson),
+ $builder = new MockObjectBuilder();
+
+ /** @var StreamInterface $requestBody */
+ $requestBody = $builder->create(StreamInterface::class, [
+ new WithReturn('__toString', [], $inputAsJson),
]);
- /** @var MockObject|StreamInterface $responseBody */
- $responseBody = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with($inputAsJson)->willReturn(\strlen($inputAsJson)),
+ /** @var StreamInterface $responseBody */
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithReturn('write', [$inputAsJson], \strlen($inputAsJson)),
]);
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class, [
- Call::create('getAttribute')->with('id', null)->willReturn('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
- Call::create('getAttribute')->with('accept', null)->willReturn('application/json'),
- Call::create('getAttribute')->with('contentType', null)->willReturn('application/json'),
- Call::create('getBody')->with()->willReturn($requestBody),
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, [
+ new WithReturn('getAttribute', ['id', null], 'cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'),
+ new WithReturn('getAttribute', ['accept', null], 'application/json'),
+ new WithReturn('getAttribute', ['contentType', null], 'application/json'),
+ new WithReturn('getBody', [], $requestBody),
]);
- /** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/json')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($responseBody),
+ /** @var ResponseInterface $response */
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),
+ new WithReturn('getBody', [], $responseBody),
]);
- /** @var MockObject|ModelInterface $model */
- $model = $this->getMockByCalls(ModelInterface::class);
+ /** @var ModelInterface $model */
+ $model = $builder->create(ModelInterface::class, []);
- /** @var DecoderInterface|MockObject $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class, [
- Call::create('decode')->with($inputAsJson, 'application/json')->willReturn($inputAsArray),
+ /** @var DecoderInterface $decoder */
+ $decoder = $builder->create(DecoderInterface::class, [
+ new WithReturn('decode', [$inputAsJson, 'application/json'], $inputAsArray),
]);
- /** @var MockObject|ModelRequestInterface $modelRequest */
- $modelRequest = $this->getMockByCalls(ModelRequestInterface::class, [
- Call::create('updateModel')->with($model)->willReturn($model),
+ /** @var ModelRequestInterface $modelRequest */
+ $modelRequest = $builder->create(ModelRequestInterface::class, [
+ new WithReturn('updateModel', [$model], $model),
]);
- /** @var MockObject|ObjectSchemaInterface $modelRequestSchema */
- $modelRequestSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($inputAsArray)->willReturn($modelRequest),
+ /** @var ObjectSchemaInterface $modelRequestSchema */
+ $modelRequestSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithReturn('parse', [$inputAsArray], $modelRequest),
]);
- /** @var MockObject|ObjectSchemaInterface $modelResponseSchema */
- $modelResponseSchema = $this->getMockByCalls(ObjectSchemaInterface::class, [
- Call::create('parse')->with($model)->willReturn($inputAsArray),
+ /** @var ObjectSchemaInterface $modelResponseSchema */
+ $modelResponseSchema = $builder->create(ObjectSchemaInterface::class, [
+ new WithReturn('parse', [$model], $inputAsArray),
]);
- /** @var MockObject|ParsingInterface $parsing */
- $parsing = $this->getMockByCalls(ParsingInterface::class, [
- Call::create('getModelRequestSchema')->with($request)->willReturn($modelRequestSchema),
- Call::create('getModelResponseSchema')->with($request)->willReturn($modelResponseSchema),
+ /** @var ParsingInterface $parsing */
+ $parsing = $builder->create(ParsingInterface::class, [
+ new WithReturn('getModelRequestSchema', [$request], $modelRequestSchema),
+ new WithReturn('getModelResponseSchema', [$request], $modelResponseSchema),
]);
- /** @var MockObject|RepositoryInterface $repository */
- $repository = $this->getMockByCalls(RepositoryInterface::class, [
- Call::create('findById')->with('cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0')->willReturn($model),
- Call::create('persist')->with($model),
- Call::create('flush')->with(),
+ /** @var RepositoryInterface $repository */
+ $repository = $builder->create(RepositoryInterface::class, [
+ new WithReturn('findById', ['cbb6bd79-b6a9-4b07-9d8b-f6be0f19aaa0'], $model),
+ new WithReturnSelf('persist', [$model]),
+ new WithReturnSelf('flush', []),
]);
- /** @var EncoderInterface|MockObject $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('encode')->with($inputAsArray, 'application/json')->willReturn($inputAsJson),
+ /** @var EncoderInterface $encoder */
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithReturn('encode', [$inputAsArray, 'application/json'], $inputAsJson),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(200, '')->willReturn($response),
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [200, ''], $response),
]);
$requestHandler = new UpdateRequestHandler(
diff --git a/tests/Unit/RequestHandler/OpenapiRequestHandlerTest.php b/tests/Unit/RequestHandler/OpenapiRequestHandlerTest.php
index 474c58bc..e90ed208 100644
--- a/tests/Unit/RequestHandler/OpenapiRequestHandlerTest.php
+++ b/tests/Unit/RequestHandler/OpenapiRequestHandlerTest.php
@@ -5,10 +5,10 @@
namespace App\Tests\Unit\RequestHandler;
use App\RequestHandler\OpenapiRequestHandler;
-use Chubbyphp\Mock\Argument\ArgumentCallback;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
-use PHPUnit\Framework\MockObject\MockObject;
+use Chubbyphp\Mock\MockMethod\WithCallback;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
@@ -23,42 +23,41 @@
*/
final class OpenapiRequestHandlerTest extends TestCase
{
- use MockByCallsTrait;
-
public function testHandle(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var ServerRequestInterface $request */
+ $request = $builder->create(ServerRequestInterface::class, []);
- /** @var MockObject|StreamInterface $responseStream */
- $responseStream = $this->getMockByCalls(StreamInterface::class);
+ /** @var StreamInterface $responseStream */
+ $responseStream = $builder->create(StreamInterface::class, []);
- /** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/x-yaml')->willReturnSelf(),
- Call::create('withHeader')
- ->with('Cache-Control', 'no-cache, no-store, must-revalidate')
- ->willReturnSelf(),
- Call::create('withHeader')->with('Pragma', 'no-cache')->willReturnSelf(),
- Call::create('withHeader')->with('Expires', '0')->willReturnSelf(),
- Call::create('withBody')->with($responseStream)->willReturnSelf(),
+ /** @var ResponseInterface $response */
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf('withHeader', ['Content-Type', 'application/x-yaml']),
+ new WithReturnSelf('withHeader', ['Cache-Control', 'no-cache, no-store, must-revalidate']),
+ new WithReturnSelf('withHeader', ['Pragma', 'no-cache']),
+ new WithReturnSelf('withHeader', ['Expires', '0']),
+ new WithReturnSelf('withBody', [$responseStream]),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(200, '')->willReturn($response),
+ /** @var ResponseFactoryInterface $responseFactory */
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [200, ''], $response),
]);
- /** @var MockObject|StreamFactoryInterface $streamFactory */
- $streamFactory = $this->getMockByCalls(StreamFactoryInterface::class, [
- Call::create('createStreamFromFile')
- ->with(
- new ArgumentCallback(static function (string $path): void {
- self::assertMatchesRegularExpression('#src/RequestHandler/../../openapi\.yml$#', $path);
- }),
- 'r'
- )
- ->willReturn($responseStream),
+ /** @var StreamFactoryInterface $streamFactory */
+ $streamFactory = $builder->create(StreamFactoryInterface::class, [
+ new WithCallback(
+ 'createStreamFromFile',
+ static function (string $filename, string $mode) use ($responseStream): StreamInterface {
+ self::assertMatchesRegularExpression('#src/RequestHandler/../../openapi\.yml$#', $filename);
+ self::assertSame('r', $mode);
+
+ return $responseStream;
+ }
+ ),
]);
$requestHandler = new OpenapiRequestHandler($responseFactory, $streamFactory);
diff --git a/tests/Unit/RequestHandler/PingRequestHandlerTest.php b/tests/Unit/RequestHandler/PingRequestHandlerTest.php
index fcb6537e..b1969ec4 100644
--- a/tests/Unit/RequestHandler/PingRequestHandlerTest.php
+++ b/tests/Unit/RequestHandler/PingRequestHandlerTest.php
@@ -5,10 +5,10 @@
namespace App\Tests\Unit\RequestHandler;
use App\RequestHandler\PingRequestHandler;
-use Chubbyphp\Mock\Argument\ArgumentCallback;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
-use PHPUnit\Framework\MockObject\MockObject;
+use Chubbyphp\Mock\MockMethod\WithCallback;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockMethod\WithReturnSelf;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
@@ -22,38 +22,31 @@
*/
final class PingRequestHandlerTest extends TestCase
{
- use MockByCallsTrait;
-
public function testHandle(): void
{
- /** @var MockObject|ServerRequestInterface $request */
- $request = $this->getMockByCalls(ServerRequestInterface::class);
-
- $bodyLength = 0;
-
- /** @var MockObject|StreamInterface $body */
- $body = $this->getMockByCalls(StreamInterface::class, [
- Call::create('write')->with(new ArgumentCallback(static function (string $json) use (&$bodyLength): void {
- $data = json_decode($json, true);
- self::assertArrayHasKey('date', $data);
- $bodyLength = \strlen($json);
- }))->willReturn($bodyLength),
+ $builder = new MockObjectBuilder();
+
+ $request = $builder->create(ServerRequestInterface::class, []);
+
+ $responseBody = $builder->create(StreamInterface::class, [
+ new WithCallback('write', static function (string $string): int {
+ $data = json_decode($string, true);
+ self::assertArrayHasKey('datetime', $data);
+
+ return \strlen($string);
+ }),
]);
- /** @var MockObject|ResponseInterface $response */
- $response = $this->getMockByCalls(ResponseInterface::class, [
- Call::create('withHeader')->with('Content-Type', 'application/json')->willReturnSelf(),
- Call::create('withHeader')
- ->with('Cache-Control', 'no-cache, no-store, must-revalidate')
- ->willReturnSelf(),
- Call::create('withHeader')->with('Pragma', 'no-cache')->willReturnSelf(),
- Call::create('withHeader')->with('Expires', '0')->willReturnSelf(),
- Call::create('getBody')->with()->willReturn($body),
+ $response = $builder->create(ResponseInterface::class, [
+ new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),
+ new WithReturnSelf('withHeader', ['Cache-Control', 'no-cache, no-store, must-revalidate']),
+ new WithReturnSelf('withHeader', ['Pragma', 'no-cache']),
+ new WithReturnSelf('withHeader', ['Expires', '0']),
+ new WithReturn('getBody', [], $responseBody),
]);
- /** @var MockObject|ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
- Call::create('createResponse')->with(200, '')->willReturn($response),
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, [
+ new WithReturn('createResponse', [200, ''], $response),
]);
$requestHandler = new PingRequestHandler($responseFactory);
diff --git a/tests/Unit/ServiceFactory/Command/CommandsFactoryTest.php b/tests/Unit/ServiceFactory/Command/CommandsFactoryTest.php
index 78c4f458..25cd63e5 100644
--- a/tests/Unit/ServiceFactory/Command/CommandsFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Command/CommandsFactoryTest.php
@@ -8,8 +8,8 @@
use Chubbyphp\CleanDirectories\Command\CleanDirectoriesCommand;
use Chubbyphp\Laminas\Config\Doctrine\DBAL\Tools\Console\Command\Database\CreateCommand as DatabaseCreateCommand;
use Chubbyphp\Laminas\Config\Doctrine\DBAL\Tools\Console\Command\Database\DropCommand as DatabaseDropCommand;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand;
@@ -37,21 +37,25 @@
*/
final class CommandsFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
- /** @var ContainerInterface $connectionProvider */
- $connectionProvider = $this->getMockByCalls(ConnectionProvider::class);
+ $config = [
+ 'directories' => [],
+ ];
+
+ $builder = new MockObjectBuilder();
+
+ /** @var ConnectionProvider $connectionProvider */
+ $connectionProvider = $builder->create(ConnectionProvider::class, []);
/** @var EntityManagerProvider $entityManagerProvider */
- $entityManagerProvider = $this->getMockByCalls(EntityManagerProvider::class);
+ $entityManagerProvider = $builder->create(EntityManagerProvider::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(ConnectionProvider::class)->willReturn($connectionProvider),
- Call::create('get')->with(EntityManagerProvider::class)->willReturn($entityManagerProvider),
- Call::create('get')->with('config')->willReturn(['directories' => []]),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [ConnectionProvider::class], $connectionProvider),
+ new WithReturn('get', [EntityManagerProvider::class], $entityManagerProvider),
+ new WithReturn('get', ['config'], $config),
]);
$factory = new CommandsFactory();
diff --git a/tests/Unit/ServiceFactory/DecodeEncode/TypeDecodersFactoryTest.php b/tests/Unit/ServiceFactory/DecodeEncode/TypeDecodersFactoryTest.php
index 6ad5220d..d2b763f2 100644
--- a/tests/Unit/ServiceFactory/DecodeEncode/TypeDecodersFactoryTest.php
+++ b/tests/Unit/ServiceFactory/DecodeEncode/TypeDecodersFactoryTest.php
@@ -9,7 +9,6 @@
use Chubbyphp\DecodeEncode\Decoder\JsonxTypeDecoder;
use Chubbyphp\DecodeEncode\Decoder\UrlEncodedTypeDecoder;
use Chubbyphp\DecodeEncode\Decoder\YamlTypeDecoder;
-use Chubbyphp\Mock\MockByCallsTrait;
use PHPUnit\Framework\TestCase;
/**
@@ -19,8 +18,6 @@
*/
final class TypeDecodersFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
$factory = new TypeDecodersFactory();
diff --git a/tests/Unit/ServiceFactory/DecodeEncode/TypeEncodersFactoryTest.php b/tests/Unit/ServiceFactory/DecodeEncode/TypeEncodersFactoryTest.php
index c22f582f..7e1e44c0 100644
--- a/tests/Unit/ServiceFactory/DecodeEncode/TypeEncodersFactoryTest.php
+++ b/tests/Unit/ServiceFactory/DecodeEncode/TypeEncodersFactoryTest.php
@@ -9,8 +9,8 @@
use Chubbyphp\DecodeEncode\Encoder\JsonxTypeEncoder;
use Chubbyphp\DecodeEncode\Encoder\UrlEncodedTypeEncoder;
use Chubbyphp\DecodeEncode\Encoder\YamlTypeEncoder;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -21,13 +21,13 @@
*/
final class TypeEncodersFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with('config')->willReturn(['debug' => true]),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', ['config'], ['debug' => true]),
]);
$factory = new TypeEncodersFactory();
diff --git a/tests/Unit/ServiceFactory/Framework/ExceptionMiddlewareFactoryTest.php b/tests/Unit/ServiceFactory/Framework/ExceptionMiddlewareFactoryTest.php
index 5c27b39c..317988e9 100644
--- a/tests/Unit/ServiceFactory/Framework/ExceptionMiddlewareFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Framework/ExceptionMiddlewareFactoryTest.php
@@ -6,8 +6,8 @@
use App\ServiceFactory\Framework\ExceptionMiddlewareFactory;
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -20,21 +20,21 @@
*/
final class ExceptionMiddlewareFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var LoggerInterface $logger */
- $logger = $this->getMockByCalls(LoggerInterface::class);
+ $logger = $builder->create(LoggerInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
- Call::create('get')->with('config')->willReturn(['debug' => true]),
- Call::create('get')->with(LoggerInterface::class)->willReturn($logger),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
+ new WithReturn('get', ['config'], ['debug' => true]),
+ new WithReturn('get', [LoggerInterface::class], $logger),
]);
$factory = new ExceptionMiddlewareFactory();
diff --git a/tests/Unit/ServiceFactory/Framework/MiddlewaresFactoryTest.php b/tests/Unit/ServiceFactory/Framework/MiddlewaresFactoryTest.php
index 6a08e7cb..c90f27d7 100644
--- a/tests/Unit/ServiceFactory/Framework/MiddlewaresFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Framework/MiddlewaresFactoryTest.php
@@ -9,7 +9,7 @@
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
use Chubbyphp\Framework\Middleware\LazyMiddleware;
use Chubbyphp\Framework\Middleware\RouteMatcherMiddleware;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -20,19 +20,22 @@
*/
final class MiddlewaresFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class);
+ $container = $builder->create(ContainerInterface::class, []);
$factory = new MiddlewaresFactory();
- self::assertEquals([
- new LazyMiddleware($container, ExceptionMiddleware::class),
- new LazyMiddleware($container, CorsMiddleware::class),
- new LazyMiddleware($container, RouteMatcherMiddleware::class),
- ], $factory($container));
+ self::assertEquals(
+ [
+ new LazyMiddleware($container, ExceptionMiddleware::class),
+ new LazyMiddleware($container, CorsMiddleware::class),
+ new LazyMiddleware($container, RouteMatcherMiddleware::class),
+ ],
+ $factory($container)
+ );
}
}
diff --git a/tests/Unit/ServiceFactory/Framework/RouteMatcherFactoryTest.php b/tests/Unit/ServiceFactory/Framework/RouteMatcherFactoryTest.php
index 441505b9..7b4dcddf 100644
--- a/tests/Unit/ServiceFactory/Framework/RouteMatcherFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Framework/RouteMatcherFactoryTest.php
@@ -7,8 +7,8 @@
use App\ServiceFactory\Framework\RouteMatcherFactory;
use Chubbyphp\Framework\Router\RouteMatcherInterface;
use Chubbyphp\Framework\Router\RoutesByNameInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -19,8 +19,6 @@
*/
final class RouteMatcherFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
$config = [
@@ -29,15 +27,17 @@ public function testInvoke(): void
],
];
- /** @var ContainerInterface|MockObject $routes */
- $routes = $this->getMockByCalls(RoutesByNameInterface::class, [
- Call::create('getRoutesByName')->with()->willReturn([]),
+ $builder = new MockObjectBuilder();
+
+ /** @var RoutesByNameInterface $routes */
+ $routes = $builder->create(RoutesByNameInterface::class, [
+ new WithReturn('getRoutesByName', [], []),
]);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(RoutesByNameInterface::class)->willReturn($routes),
- Call::create('get')->with('config')->willReturn($config),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [RoutesByNameInterface::class], $routes),
+ new WithReturn('get', ['config'], $config),
]);
$factory = new RouteMatcherFactory();
diff --git a/tests/Unit/ServiceFactory/Framework/RouteMatcherMiddlewareFactoryTest.php b/tests/Unit/ServiceFactory/Framework/RouteMatcherMiddlewareFactoryTest.php
index 5596d4a7..6a049d78 100644
--- a/tests/Unit/ServiceFactory/Framework/RouteMatcherMiddlewareFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Framework/RouteMatcherMiddlewareFactoryTest.php
@@ -7,8 +7,8 @@
use App\ServiceFactory\Framework\RouteMatcherMiddlewareFactory;
use Chubbyphp\Framework\Middleware\RouteMatcherMiddleware;
use Chubbyphp\Framework\Router\RouteMatcherInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -19,16 +19,16 @@
*/
final class RouteMatcherMiddlewareFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
- /** @var MockObject|RouteMatcherInterface $routeMatcher */
- $routeMatcher = $this->getMockByCalls(RouteMatcherInterface::class);
+ $builder = new MockObjectBuilder();
+
+ /** @var RouteMatcherInterface $routeMatcher */
+ $routeMatcher = $builder->create(RouteMatcherInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(RouteMatcherInterface::class)->willReturn($routeMatcher),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [RouteMatcherInterface::class], $routeMatcher),
]);
$factory = new RouteMatcherMiddlewareFactory();
diff --git a/tests/Unit/ServiceFactory/Framework/RoutesByNameFactoryTest.php b/tests/Unit/ServiceFactory/Framework/RoutesByNameFactoryTest.php
index 463224d7..ed2c73e8 100644
--- a/tests/Unit/ServiceFactory/Framework/RoutesByNameFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Framework/RoutesByNameFactoryTest.php
@@ -17,7 +17,7 @@
use Chubbyphp\Framework\Middleware\LazyMiddleware;
use Chubbyphp\Framework\RequestHandler\LazyRequestHandler;
use Chubbyphp\Framework\Router\Route;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\Negotiation\Middleware\AcceptMiddleware;
use Chubbyphp\Negotiation\Middleware\ContentTypeMiddleware;
use PHPUnit\Framework\TestCase;
@@ -30,12 +30,12 @@
*/
final class RoutesByNameFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class);
+ $container = $builder->create(ContainerInterface::class, []);
$ping = new LazyRequestHandler($container, PingRequestHandler::class);
$openApi = new LazyRequestHandler($container, OpenapiRequestHandler::class);
diff --git a/tests/Unit/ServiceFactory/Framework/UrlGeneratorFactoryTest.php b/tests/Unit/ServiceFactory/Framework/UrlGeneratorFactoryTest.php
index 81c49c01..225a9ffd 100644
--- a/tests/Unit/ServiceFactory/Framework/UrlGeneratorFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Framework/UrlGeneratorFactoryTest.php
@@ -7,8 +7,8 @@
use App\ServiceFactory\Framework\UrlGeneratorFactory;
use Chubbyphp\Framework\Router\RoutesByNameInterface;
use Chubbyphp\Framework\Router\UrlGeneratorInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -19,18 +19,18 @@
*/
final class UrlGeneratorFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
- /** @var ContainerInterface|MockObject $routes */
- $routes = $this->getMockByCalls(RoutesByNameInterface::class, [
- Call::create('getRoutesByName')->with()->willReturn([]),
+ $builder = new MockObjectBuilder();
+
+ /** @var RoutesByNameInterface $routes */
+ $routes = $builder->create(RoutesByNameInterface::class, [
+ new WithReturn('getRoutesByName', [], []),
]);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(RoutesByNameInterface::class)->willReturn($routes),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [RoutesByNameInterface::class], $routes),
]);
$factory = new UrlGeneratorFactory();
diff --git a/tests/Unit/ServiceFactory/Http/ResponseFactoryFactoryTest.php b/tests/Unit/ServiceFactory/Http/ResponseFactoryFactoryTest.php
index e9b0d461..c40f1011 100644
--- a/tests/Unit/ServiceFactory/Http/ResponseFactoryFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Http/ResponseFactoryFactoryTest.php
@@ -5,7 +5,7 @@
namespace App\Tests\Unit\ServiceFactory\Http;
use App\ServiceFactory\Http\ResponseFactoryFactory;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Slim\Psr7\Factory\ResponseFactory;
@@ -17,12 +17,12 @@
*/
final class ResponseFactoryFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class);
+ $container = $builder->create(ContainerInterface::class, []);
$factory = new ResponseFactoryFactory();
diff --git a/tests/Unit/ServiceFactory/Http/StreamFactoryFactoryTest.php b/tests/Unit/ServiceFactory/Http/StreamFactoryFactoryTest.php
index e9f63c7e..fc576744 100644
--- a/tests/Unit/ServiceFactory/Http/StreamFactoryFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Http/StreamFactoryFactoryTest.php
@@ -5,7 +5,7 @@
namespace App\Tests\Unit\ServiceFactory\Http;
use App\ServiceFactory\Http\StreamFactoryFactory;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Slim\Psr7\Factory\StreamFactory;
@@ -17,12 +17,12 @@
*/
final class StreamFactoryFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class);
+ $container = $builder->create(ContainerInterface::class, []);
$factory = new StreamFactoryFactory();
diff --git a/tests/Unit/ServiceFactory/Logger/LoggerFactoryTest.php b/tests/Unit/ServiceFactory/Logger/LoggerFactoryTest.php
index 6aedf3d2..cafaa7f8 100644
--- a/tests/Unit/ServiceFactory/Logger/LoggerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Logger/LoggerFactoryTest.php
@@ -6,8 +6,8 @@
use App\ServiceFactory\Logger\LoggerFactory;
use App\Tests\Helper\AssertHelper;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use Monolog\Formatter\LogstashFormatter;
use Monolog\Handler\BufferHandler;
use Monolog\Handler\StreamHandler;
@@ -25,8 +25,6 @@
*/
final class LoggerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
$path = sys_get_temp_dir().'/'.uniqid('logger-factory-').'.log';
@@ -39,9 +37,11 @@ public function testInvoke(): void
],
];
+ $builder = new MockObjectBuilder();
+
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with('config')->willReturn($config),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', ['config'], $config),
]);
$factory = new LoggerFactory();
diff --git a/tests/Unit/ServiceFactory/Middleware/ApiExceptionMiddlewareFactoryTest.php b/tests/Unit/ServiceFactory/Middleware/ApiExceptionMiddlewareFactoryTest.php
index 145844df..910097fd 100644
--- a/tests/Unit/ServiceFactory/Middleware/ApiExceptionMiddlewareFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Middleware/ApiExceptionMiddlewareFactoryTest.php
@@ -7,8 +7,8 @@
use App\Middleware\ApiExceptionMiddleware;
use App\ServiceFactory\Middleware\ApiExceptionMiddlewareFactory;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -21,25 +21,25 @@
*/
final class ApiExceptionMiddlewareFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var EncoderInterface $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ $encoder = $builder->create(EncoderInterface::class, []);
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var LoggerInterface $logger */
- $logger = $this->getMockByCalls(LoggerInterface::class);
+ $logger = $builder->create(LoggerInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(EncoderInterface::class)->willReturn($encoder),
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
- Call::create('get')->with('config')->willReturn(['debug' => true]),
- Call::create('get')->with(LoggerInterface::class)->willReturn($logger),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [EncoderInterface::class], $encoder),
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
+ new WithReturn('get', ['config'], ['debug' => true]),
+ new WithReturn('get', [LoggerInterface::class], $logger),
]);
$factory = new ApiExceptionMiddlewareFactory();
diff --git a/tests/Unit/ServiceFactory/Negotiation/AcceptNegotiatorSupportedMediaTypesFactoryTest.php b/tests/Unit/ServiceFactory/Negotiation/AcceptNegotiatorSupportedMediaTypesFactoryTest.php
index 98c1aa05..c7c7da88 100644
--- a/tests/Unit/ServiceFactory/Negotiation/AcceptNegotiatorSupportedMediaTypesFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Negotiation/AcceptNegotiatorSupportedMediaTypesFactoryTest.php
@@ -6,8 +6,8 @@
use App\ServiceFactory\Negotiation\AcceptNegotiatorSupportedMediaTypesFactory;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -18,18 +18,18 @@
*/
final class AcceptNegotiatorSupportedMediaTypesFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var EncoderInterface $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class, [
- Call::create('getContentTypes')->with()->willReturn(['application/json']),
+ $encoder = $builder->create(EncoderInterface::class, [
+ new WithReturn('getContentTypes', [], ['application/json']),
]);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(EncoderInterface::class)->willReturn($encoder),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [EncoderInterface::class], $encoder),
]);
$factory = new AcceptNegotiatorSupportedMediaTypesFactory();
diff --git a/tests/Unit/ServiceFactory/Negotiation/ContentTypeNegotiatorSupportedMediaTypesFactoryTest.php b/tests/Unit/ServiceFactory/Negotiation/ContentTypeNegotiatorSupportedMediaTypesFactoryTest.php
index 4912019d..48994f2f 100644
--- a/tests/Unit/ServiceFactory/Negotiation/ContentTypeNegotiatorSupportedMediaTypesFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Negotiation/ContentTypeNegotiatorSupportedMediaTypesFactoryTest.php
@@ -6,8 +6,8 @@
use App\ServiceFactory\Negotiation\ContentTypeNegotiatorSupportedMediaTypesFactory;
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -18,18 +18,18 @@
*/
final class ContentTypeNegotiatorSupportedMediaTypesFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var DecoderInterface $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class, [
- Call::create('getContentTypes')->with()->willReturn(['application/json']),
+ $decoder = $builder->create(DecoderInterface::class, [
+ new WithReturn('getContentTypes', [], ['application/json']),
]);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(DecoderInterface::class)->willReturn($decoder),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [DecoderInterface::class], $decoder),
]);
$factory = new ContentTypeNegotiatorSupportedMediaTypesFactory();
diff --git a/tests/Unit/ServiceFactory/Parsing/PetParsingFactoryTest.php b/tests/Unit/ServiceFactory/Parsing/PetParsingFactoryTest.php
index 4b03491a..7f883dd1 100644
--- a/tests/Unit/ServiceFactory/Parsing/PetParsingFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Parsing/PetParsingFactoryTest.php
@@ -7,8 +7,8 @@
use App\Parsing\PetParsing;
use App\ServiceFactory\Parsing\PetParsingFactory;
use Chubbyphp\Framework\Router\UrlGeneratorInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use Chubbyphp\Parsing\ParserInterface;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -20,20 +20,20 @@
*/
final class PetParsingFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ParserInterface $parser */
- $parser = $this->getMockByCalls(ParserInterface::class);
+ $parser = $builder->create(ParserInterface::class, []);
- /** @var ParserInterface $urlGenerator */
- $urlGenerator = $this->getMockByCalls(UrlGeneratorInterface::class);
+ /** @var UrlGeneratorInterface $urlGenerator */
+ $urlGenerator = $builder->create(UrlGeneratorInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(ParserInterface::class)->willReturn($parser),
- Call::create('get')->with(UrlGeneratorInterface::class)->willReturn($urlGenerator),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [ParserInterface::class], $parser),
+ new WithReturn('get', [UrlGeneratorInterface::class], $urlGenerator),
]);
$factory = new PetParsingFactory();
diff --git a/tests/Unit/ServiceFactory/Repository/PetRepositoryFactoryTest.php b/tests/Unit/ServiceFactory/Repository/PetRepositoryFactoryTest.php
index 7f534222..4027a829 100644
--- a/tests/Unit/ServiceFactory/Repository/PetRepositoryFactoryTest.php
+++ b/tests/Unit/ServiceFactory/Repository/PetRepositoryFactoryTest.php
@@ -6,8 +6,8 @@
use App\Repository\PetRepository;
use App\ServiceFactory\Repository\PetRepositoryFactory;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use Doctrine\ORM\EntityManager;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
@@ -19,16 +19,16 @@
*/
final class PetRepositoryFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var EntityManager $entityManager */
- $entityManager = $this->getMockByCalls(EntityManager::class);
+ $entityManager = $builder->create(EntityManager::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(EntityManager::class)->willReturn($entityManager),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [EntityManager::class], $entityManager),
]);
$factory = new PetRepositoryFactory();
diff --git a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactoryTest.php b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactoryTest.php
index 74d73e32..9dae7894 100644
--- a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetCreateRequestHandlerFactoryTest.php
@@ -12,8 +12,8 @@
use App\ServiceFactory\RequestHandler\Api\Crud\PetCreateRequestHandlerFactory;
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -25,32 +25,32 @@
*/
final class PetCreateRequestHandlerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var DecoderInterface $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class);
+ $decoder = $builder->create(DecoderInterface::class, []);
/** @var ParsingInterface $petParsing */
- $petParsing = $this->getMockByCalls(ParsingInterface::class);
+ $petParsing = $builder->create(ParsingInterface::class, []);
/** @var RepositoryInterface $petRepository */
- $petRepository = $this->getMockByCalls(RepositoryInterface::class);
+ $petRepository = $builder->create(RepositoryInterface::class, []);
/** @var EncoderInterface $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ $encoder = $builder->create(EncoderInterface::class, []);
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(DecoderInterface::class)->willReturn($decoder),
- Call::create('get')->with(PetParsing::class)->willReturn($petParsing),
- Call::create('get')->with(PetRepository::class)->willReturn($petRepository),
- Call::create('get')->with(EncoderInterface::class)->willReturn($encoder),
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [DecoderInterface::class], $decoder),
+ new WithReturn('get', [PetParsing::class], $petParsing),
+ new WithReturn('get', [PetRepository::class], $petRepository),
+ new WithReturn('get', [EncoderInterface::class], $encoder),
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
]);
$factory = new PetCreateRequestHandlerFactory();
diff --git a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetDeleteRequestHandlerFactoryTest.php b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetDeleteRequestHandlerFactoryTest.php
index fe10f8eb..8df27fdb 100644
--- a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetDeleteRequestHandlerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetDeleteRequestHandlerFactoryTest.php
@@ -8,8 +8,8 @@
use App\Repository\RepositoryInterface;
use App\RequestHandler\Api\Crud\DeleteRequestHandler;
use App\ServiceFactory\RequestHandler\Api\Crud\PetDeleteRequestHandlerFactory;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -21,20 +21,20 @@
*/
final class PetDeleteRequestHandlerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var RepositoryInterface $petRepository */
- $petRepository = $this->getMockByCalls(RepositoryInterface::class);
+ $petRepository = $builder->create(RepositoryInterface::class, []);
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(PetRepository::class)->willReturn($petRepository),
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [PetRepository::class], $petRepository),
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
]);
$factory = new PetDeleteRequestHandlerFactory();
diff --git a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetListRequestHandlerFactoryTest.php b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetListRequestHandlerFactoryTest.php
index cf180c14..587f3b42 100644
--- a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetListRequestHandlerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetListRequestHandlerFactoryTest.php
@@ -11,8 +11,8 @@
use App\RequestHandler\Api\Crud\ListRequestHandler;
use App\ServiceFactory\RequestHandler\Api\Crud\PetListRequestHandlerFactory;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -24,28 +24,28 @@
*/
final class PetListRequestHandlerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ParsingInterface $petParsing */
- $petParsing = $this->getMockByCalls(ParsingInterface::class);
+ $petParsing = $builder->create(ParsingInterface::class, []);
/** @var RepositoryInterface $petRepository */
- $petRepository = $this->getMockByCalls(RepositoryInterface::class);
+ $petRepository = $builder->create(RepositoryInterface::class, []);
/** @var EncoderInterface $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ $encoder = $builder->create(EncoderInterface::class, []);
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(PetParsing::class)->willReturn($petParsing),
- Call::create('get')->with(PetRepository::class)->willReturn($petRepository),
- Call::create('get')->with(EncoderInterface::class)->willReturn($encoder),
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [PetParsing::class], $petParsing),
+ new WithReturn('get', [PetRepository::class], $petRepository),
+ new WithReturn('get', [EncoderInterface::class], $encoder),
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
]);
$factory = new PetListRequestHandlerFactory();
diff --git a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactoryTest.php b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactoryTest.php
index 9bf4dc77..3c6b276a 100644
--- a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetReadRequestHandlerFactoryTest.php
@@ -11,8 +11,8 @@
use App\RequestHandler\Api\Crud\ReadRequestHandler;
use App\ServiceFactory\RequestHandler\Api\Crud\PetReadRequestHandlerFactory;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -24,28 +24,28 @@
*/
final class PetReadRequestHandlerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ParsingInterface $petParsing */
- $petParsing = $this->getMockByCalls(ParsingInterface::class);
+ $petParsing = $builder->create(ParsingInterface::class, []);
/** @var RepositoryInterface $petRepository */
- $petRepository = $this->getMockByCalls(RepositoryInterface::class);
+ $petRepository = $builder->create(RepositoryInterface::class, []);
/** @var EncoderInterface $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ $encoder = $builder->create(EncoderInterface::class, []);
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(PetParsing::class)->willReturn($petParsing),
- Call::create('get')->with(PetRepository::class)->willReturn($petRepository),
- Call::create('get')->with(EncoderInterface::class)->willReturn($encoder),
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [PetParsing::class], $petParsing),
+ new WithReturn('get', [PetRepository::class], $petRepository),
+ new WithReturn('get', [EncoderInterface::class], $encoder),
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
]);
$factory = new PetReadRequestHandlerFactory();
diff --git a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactoryTest.php b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactoryTest.php
index cc6fa03c..d3c48bad 100644
--- a/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/RequestHandler/Api/Crud/PetUpdateRequestHandlerFactoryTest.php
@@ -12,8 +12,8 @@
use App\ServiceFactory\RequestHandler\Api\Crud\PetUpdateRequestHandlerFactory;
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -25,32 +25,32 @@
*/
final class PetUpdateRequestHandlerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var DecoderInterface $decoder */
- $decoder = $this->getMockByCalls(DecoderInterface::class);
+ $decoder = $builder->create(DecoderInterface::class, []);
/** @var ParsingInterface $petParsing */
- $petParsing = $this->getMockByCalls(ParsingInterface::class);
+ $petParsing = $builder->create(ParsingInterface::class, []);
/** @var RepositoryInterface $petRepository */
- $petRepository = $this->getMockByCalls(RepositoryInterface::class);
+ $petRepository = $builder->create(RepositoryInterface::class, []);
/** @var EncoderInterface $encoder */
- $encoder = $this->getMockByCalls(EncoderInterface::class);
+ $encoder = $builder->create(EncoderInterface::class, []);
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(DecoderInterface::class)->willReturn($decoder),
- Call::create('get')->with(PetParsing::class)->willReturn($petParsing),
- Call::create('get')->with(PetRepository::class)->willReturn($petRepository),
- Call::create('get')->with(EncoderInterface::class)->willReturn($encoder),
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [DecoderInterface::class], $decoder),
+ new WithReturn('get', [PetParsing::class], $petParsing),
+ new WithReturn('get', [PetRepository::class], $petRepository),
+ new WithReturn('get', [EncoderInterface::class], $encoder),
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
]);
$factory = new PetUpdateRequestHandlerFactory();
diff --git a/tests/Unit/ServiceFactory/RequestHandler/OpenapiRequestHandlerFactoryTest.php b/tests/Unit/ServiceFactory/RequestHandler/OpenapiRequestHandlerFactoryTest.php
index 44fdb153..6d455c22 100644
--- a/tests/Unit/ServiceFactory/RequestHandler/OpenapiRequestHandlerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/RequestHandler/OpenapiRequestHandlerFactoryTest.php
@@ -6,8 +6,8 @@
use App\RequestHandler\OpenapiRequestHandler;
use App\ServiceFactory\RequestHandler\OpenapiRequestHandlerFactory;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -20,20 +20,20 @@
*/
final class OpenapiRequestHandlerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var StreamFactoryInterface $stream */
- $stream = $this->getMockByCalls(StreamFactoryInterface::class);
+ $stream = $builder->create(StreamFactoryInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
- Call::create('get')->with(StreamFactoryInterface::class)->willReturn($stream),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
+ new WithReturn('get', [StreamFactoryInterface::class], $stream),
]);
$factory = new OpenapiRequestHandlerFactory();
diff --git a/tests/Unit/ServiceFactory/RequestHandler/PingRequestHandlerFactoryTest.php b/tests/Unit/ServiceFactory/RequestHandler/PingRequestHandlerFactoryTest.php
index 7a3864ed..ac0ccca6 100644
--- a/tests/Unit/ServiceFactory/RequestHandler/PingRequestHandlerFactoryTest.php
+++ b/tests/Unit/ServiceFactory/RequestHandler/PingRequestHandlerFactoryTest.php
@@ -6,8 +6,8 @@
use App\RequestHandler\PingRequestHandler;
use App\ServiceFactory\RequestHandler\PingRequestHandlerFactory;
-use Chubbyphp\Mock\Call;
-use Chubbyphp\Mock\MockByCallsTrait;
+use Chubbyphp\Mock\MockMethod\WithReturn;
+use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
@@ -19,16 +19,16 @@
*/
final class PingRequestHandlerFactoryTest extends TestCase
{
- use MockByCallsTrait;
-
public function testInvoke(): void
{
+ $builder = new MockObjectBuilder();
+
/** @var ResponseFactoryInterface $responseFactory */
- $responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
+ $responseFactory = $builder->create(ResponseFactoryInterface::class, []);
/** @var ContainerInterface $container */
- $container = $this->getMockByCalls(ContainerInterface::class, [
- Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
+ $container = $builder->create(ContainerInterface::class, [
+ new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
]);
$factory = new PingRequestHandlerFactory();