Skip to content

Commit b2db61d

Browse files
committedMar 2, 2025··
chubbyphp-mock-2.x
1 parent 24931b4 commit b2db61d

13 files changed

+101
-121
lines changed
 

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5555
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
5656
- name: sonarcloud.io
57-
uses: sonarsource/sonarqube-scan-action@v4.1.0
57+
uses: sonarsource/sonarqube-scan-action@v5.0.0
5858
env:
5959
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6060
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

‎composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
},
2323
"require-dev": {
2424
"chubbyphp/chubbyphp-dev-helper": "dev-master",
25-
"chubbyphp/chubbyphp-mock": "^1.8",
26-
"infection/infection": "^0.29.8",
25+
"chubbyphp/chubbyphp-mock": "^2.0@dev",
26+
"infection/infection": "^0.29.13",
2727
"php-coveralls/php-coveralls": "^2.7",
2828
"phpstan/extension-installer": "^1.4.3",
29-
"phpstan/phpstan": "^2.0.3",
30-
"phpunit/phpunit": "^11.5.0"
29+
"phpstan/phpstan": "^2.1.6",
30+
"phpunit/phpunit": "^11.5.10"
3131
},
3232
"autoload": {
3333
"psr-4": { "App\\": "src/" }

‎tests/Unit/RequestHandler/PingRequestHandlerTest.php

+21-30
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace App\Tests\Unit\RequestHandler;
66

77
use App\RequestHandler\PingRequestHandler;
8-
use Chubbyphp\Mock\Argument\ArgumentCallback;
9-
use Chubbyphp\Mock\Call;
10-
use Chubbyphp\Mock\MockByCallsTrait;
11-
use PHPUnit\Framework\MockObject\MockObject;
8+
use Chubbyphp\Mock\MockMethod\WithCallback;
9+
use Chubbyphp\Mock\MockMethod\WithReturn;
10+
use Chubbyphp\Mock\MockMethod\WithReturnSelf;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Http\Message\ResponseFactoryInterface;
1414
use Psr\Http\Message\ResponseInterface;
@@ -22,44 +22,35 @@
2222
*/
2323
final class PingRequestHandlerTest extends TestCase
2424
{
25-
use MockByCallsTrait;
26-
2725
public function testHandle(): void
2826
{
29-
/** @var MockObject|ServerRequestInterface $request */
30-
$request = $this->getMockByCalls(ServerRequestInterface::class);
31-
32-
$bodyLength = 0;
27+
$builder = new MockObjectBuilder();
3328

34-
/** @var MockObject|StreamInterface $body */
35-
$body = $this->getMockByCalls(StreamInterface::class, [
36-
Call::create('write')->with(new ArgumentCallback(static function (string $body) use (&$bodyLength): void {
37-
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
29+
$request = $builder->create(ServerRequestInterface::class, []);
3830

31+
$responseBody = $builder->create(StreamInterface::class, [
32+
new WithCallback('write', static function (string $string): int {
33+
$data = json_decode($string, true);
3934
self::assertArrayHasKey('datetime', $data);
4035

41-
$bodyLength = \strlen($body);
42-
}))->willReturn($bodyLength),
36+
return \strlen($string);
37+
}),
4338
]);
4439

45-
/** @var MockObject|ResponseInterface $response */
46-
$response = $this->getMockByCalls(ResponseInterface::class, [
47-
Call::create('withHeader')->with('Content-Type', 'application/json')->willReturnSelf(),
48-
Call::create('withHeader')
49-
->with('Cache-Control', 'no-cache, no-store, must-revalidate')
50-
->willReturnSelf(),
51-
Call::create('withHeader')->with('Pragma', 'no-cache')->willReturnSelf(),
52-
Call::create('withHeader')->with('Expires', '0')->willReturnSelf(),
53-
Call::create('getBody')->with()->willReturn($body),
40+
$response = $builder->create(ResponseInterface::class, [
41+
new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),
42+
new WithReturnSelf('withHeader', ['Cache-Control', 'no-cache, no-store, must-revalidate']),
43+
new WithReturnSelf('withHeader', ['Pragma', 'no-cache']),
44+
new WithReturnSelf('withHeader', ['Expires', '0']),
45+
new WithReturn('getBody', [], $responseBody),
5446
]);
5547

56-
/** @var MockObject|ResponseFactoryInterface $responseFactory */
57-
$responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class, [
58-
Call::create('createResponse')->with(200, '')->willReturn($response),
48+
$responseFactory = $builder->create(ResponseFactoryInterface::class, [
49+
new WithReturn('createResponse', [200, ''], $response),
5950
]);
6051

61-
$RequestHandler = new PingRequestHandler($responseFactory);
52+
$requestHandler = new PingRequestHandler($responseFactory);
6253

63-
self::assertSame($response, $RequestHandler->handle($request));
54+
self::assertSame($response, $requestHandler->handle($request));
6455
}
6556
}

‎tests/Unit/ServiceFactory/Command/CommandsFactoryTest.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
use App\ServiceFactory\Command\CommandsFactory;
88
use Chubbyphp\CleanDirectories\Command\CleanDirectoriesCommand;
9-
use Chubbyphp\Mock\Call;
10-
use Chubbyphp\Mock\MockByCallsTrait;
11-
use PHPUnit\Framework\MockObject\MockObject;
9+
use Chubbyphp\Mock\MockMethod\WithReturn;
10+
use Chubbyphp\Mock\MockObjectBuilder;
1211
use PHPUnit\Framework\TestCase;
1312
use Psr\Container\ContainerInterface;
1413

@@ -19,13 +18,13 @@
1918
*/
2019
final class CommandsFactoryTest extends TestCase
2120
{
22-
use MockByCallsTrait;
23-
2421
public function testInvoke(): void
2522
{
26-
/** @var ContainerInterface|MockObject $container */
27-
$container = $this->getMockByCalls(ContainerInterface::class, [
28-
Call::create('get')->with('config')->willReturn(['directories' => ['directoryName' => 'directoryPath']]),
23+
$builder = new MockObjectBuilder();
24+
25+
/** @var ContainerInterface $container */
26+
$container = $builder->create(ContainerInterface::class, [
27+
new WithReturn('get', ['config'], ['directories' => ['directoryName' => 'directoryPath']]),
2928
]);
3029

3130
$factory = new CommandsFactory();

‎tests/Unit/ServiceFactory/Framework/ExceptionMiddlewareFactoryTest.php

+13-14
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
use App\ServiceFactory\Framework\ExceptionMiddlewareFactory;
88
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
9-
use Chubbyphp\Mock\Call;
10-
use Chubbyphp\Mock\MockByCallsTrait;
11-
use PHPUnit\Framework\MockObject\MockObject;
9+
use Chubbyphp\Mock\MockMethod\WithReturn;
10+
use Chubbyphp\Mock\MockObjectBuilder;
1211
use PHPUnit\Framework\TestCase;
1312
use Psr\Container\ContainerInterface;
1413
use Psr\Http\Message\ResponseFactoryInterface;
@@ -21,25 +20,25 @@
2120
*/
2221
final class ExceptionMiddlewareFactoryTest extends TestCase
2322
{
24-
use MockByCallsTrait;
25-
2623
public function testInvoke(): void
2724
{
28-
/** @var MockObject|ResponseFactoryInterface $responseFactory */
29-
$responseFactory = $this->getMockByCalls(ResponseFactoryInterface::class);
25+
$builder = new MockObjectBuilder();
26+
27+
/** @var ResponseFactoryInterface $responseFactory */
28+
$responseFactory = $builder->create(ResponseFactoryInterface::class, []);
3029

31-
/** @var LoggerInterface|MockObject $logger */
32-
$logger = $this->getMockByCalls(LoggerInterface::class);
30+
/** @var LoggerInterface $logger */
31+
$logger = $builder->create(LoggerInterface::class, []);
3332

3433
$config = [
3534
'debug' => true,
3635
];
3736

38-
/** @var ContainerInterface|MockObject $container */
39-
$container = $this->getMockByCalls(ContainerInterface::class, [
40-
Call::create('get')->with(ResponseFactoryInterface::class)->willReturn($responseFactory),
41-
Call::create('get')->with('config')->willReturn($config),
42-
Call::create('get')->with(LoggerInterface::class)->willReturn($logger),
37+
/** @var ContainerInterface $container */
38+
$container = $builder->create(ContainerInterface::class, [
39+
new WithReturn('get', [ResponseFactoryInterface::class], $responseFactory),
40+
new WithReturn('get', ['config'], $config),
41+
new WithReturn('get', [LoggerInterface::class], $logger),
4342
]);
4443

4544
$factory = new ExceptionMiddlewareFactory();

‎tests/Unit/ServiceFactory/Framework/MiddlewaresFactoryTest.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
99
use Chubbyphp\Framework\Middleware\LazyMiddleware;
1010
use Chubbyphp\Framework\Middleware\RouteMatcherMiddleware;
11-
use Chubbyphp\Mock\MockByCallsTrait;
12-
use PHPUnit\Framework\MockObject\MockObject;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1312
use PHPUnit\Framework\TestCase;
1413
use Psr\Container\ContainerInterface;
1514

@@ -20,12 +19,12 @@
2019
*/
2120
final class MiddlewaresFactoryTest extends TestCase
2221
{
23-
use MockByCallsTrait;
24-
2522
public function testInvoke(): void
2623
{
27-
/** @var ContainerInterface|MockObject $container */
28-
$container = $this->getMockByCalls(ContainerInterface::class);
24+
$builder = new MockObjectBuilder();
25+
26+
/** @var ContainerInterface $container */
27+
$container = $builder->create(ContainerInterface::class, []);
2928

3029
$factory = new MiddlewaresFactory();
3130

‎tests/Unit/ServiceFactory/Framework/RouteMatcherFactoryTest.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
use App\ServiceFactory\Framework\RouteMatcherFactory;
88
use Chubbyphp\Framework\Router\RouteMatcherInterface;
99
use Chubbyphp\Framework\Router\RoutesByNameInterface;
10-
use Chubbyphp\Mock\Call;
11-
use Chubbyphp\Mock\MockByCallsTrait;
12-
use PHPUnit\Framework\MockObject\MockObject;
10+
use Chubbyphp\Mock\MockMethod\WithReturn;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1312
use PHPUnit\Framework\TestCase;
1413
use Psr\Container\ContainerInterface;
1514

@@ -20,8 +19,6 @@
2019
*/
2120
final class RouteMatcherFactoryTest extends TestCase
2221
{
23-
use MockByCallsTrait;
24-
2522
public function testInvoke(): void
2623
{
2724
$config = [
@@ -30,15 +27,17 @@ public function testInvoke(): void
3027
],
3128
];
3229

33-
/** @var ContainerInterface|MockObject $routesByName */
34-
$routesByName = $this->getMockByCalls(RoutesByNameInterface::class, [
35-
Call::create('getRoutesByName')->with()->willReturn([]),
30+
$builder = new MockObjectBuilder();
31+
32+
/** @var RoutesByNameInterface $routesByName */
33+
$routesByName = $builder->create(RoutesByNameInterface::class, [
34+
new WithReturn('getRoutesByName', [], []),
3635
]);
3736

38-
/** @var ContainerInterface|MockObject $container */
39-
$container = $this->getMockByCalls(ContainerInterface::class, [
40-
Call::create('get')->with(RoutesByNameInterface::class)->willReturn($routesByName),
41-
Call::create('get')->with('config')->willReturn($config),
37+
/** @var ContainerInterface $container */
38+
$container = $builder->create(ContainerInterface::class, [
39+
new WithReturn('get', [RoutesByNameInterface::class], $routesByName),
40+
new WithReturn('get', ['config'], $config),
4241
]);
4342

4443
$factory = new RouteMatcherFactory();

‎tests/Unit/ServiceFactory/Framework/RouteMatcherMiddlewareFactoryTest.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
use App\ServiceFactory\Framework\RouteMatcherMiddlewareFactory;
88
use Chubbyphp\Framework\Middleware\RouteMatcherMiddleware;
99
use Chubbyphp\Framework\Router\RouteMatcherInterface;
10-
use Chubbyphp\Mock\Call;
11-
use Chubbyphp\Mock\MockByCallsTrait;
12-
use PHPUnit\Framework\MockObject\MockObject;
10+
use Chubbyphp\Mock\MockMethod\WithReturn;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1312
use PHPUnit\Framework\TestCase;
1413
use Psr\Container\ContainerInterface;
1514

@@ -20,16 +19,16 @@
2019
*/
2120
final class RouteMatcherMiddlewareFactoryTest extends TestCase
2221
{
23-
use MockByCallsTrait;
24-
2522
public function testInvoke(): void
2623
{
27-
/** @var MockObject|RouteMatcherInterface $routeMatcher */
28-
$routeMatcher = $this->getMockByCalls(RouteMatcherInterface::class);
24+
$builder = new MockObjectBuilder();
25+
26+
/** @var RouteMatcherInterface $routeMatcher */
27+
$routeMatcher = $builder->create(RouteMatcherInterface::class, []);
2928

30-
/** @var ContainerInterface|MockObject $container */
31-
$container = $this->getMockByCalls(ContainerInterface::class, [
32-
Call::create('get')->with(RouteMatcherInterface::class)->willReturn($routeMatcher),
29+
/** @var ContainerInterface $container */
30+
$container = $builder->create(ContainerInterface::class, [
31+
new WithReturn('get', [RouteMatcherInterface::class], $routeMatcher),
3332
]);
3433

3534
$factory = new RouteMatcherMiddlewareFactory();

‎tests/Unit/ServiceFactory/Framework/RoutesFactoryTest.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
use App\ServiceFactory\Framework\RoutesByNameFactory;
99
use Chubbyphp\Framework\RequestHandler\LazyRequestHandler;
1010
use Chubbyphp\Framework\Router\Route;
11-
use Chubbyphp\Mock\MockByCallsTrait;
12-
use PHPUnit\Framework\MockObject\MockObject;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1312
use PHPUnit\Framework\TestCase;
1413
use Psr\Container\ContainerInterface;
1514

@@ -20,12 +19,12 @@
2019
*/
2120
final class RoutesFactoryTest extends TestCase
2221
{
23-
use MockByCallsTrait;
24-
2522
public function testInvoke(): void
2623
{
27-
/** @var ContainerInterface|MockObject $container */
28-
$container = $this->getMockByCalls(ContainerInterface::class);
24+
$builder = new MockObjectBuilder();
25+
26+
/** @var ContainerInterface $container */
27+
$container = $builder->create(ContainerInterface::class, []);
2928

3029
$r = static fn (string $name) => new LazyRequestHandler($container, $name);
3130

‎tests/Unit/ServiceFactory/Framework/UrlGeneratorFactoryTest.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
use App\ServiceFactory\Framework\UrlGeneratorFactory;
88
use Chubbyphp\Framework\Router\RoutesByNameInterface;
99
use Chubbyphp\Framework\Router\UrlGeneratorInterface;
10-
use Chubbyphp\Mock\Call;
11-
use Chubbyphp\Mock\MockByCallsTrait;
12-
use PHPUnit\Framework\MockObject\MockObject;
10+
use Chubbyphp\Mock\MockMethod\WithReturn;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1312
use PHPUnit\Framework\TestCase;
1413
use Psr\Container\ContainerInterface;
1514

@@ -20,18 +19,18 @@
2019
*/
2120
final class UrlGeneratorFactoryTest extends TestCase
2221
{
23-
use MockByCallsTrait;
24-
2522
public function testInvoke(): void
2623
{
27-
/** @var ContainerInterface|MockObject $routesByName */
28-
$routesByName = $this->getMockByCalls(RoutesByNameInterface::class, [
29-
Call::create('getRoutesByName')->with()->willReturn([]),
24+
$builder = new MockObjectBuilder();
25+
26+
/** @var RoutesByNameInterface $routesByName */
27+
$routesByName = $builder->create(RoutesByNameInterface::class, [
28+
new WithReturn('getRoutesByName', [], []),
3029
]);
3130

32-
/** @var ContainerInterface|MockObject $container */
33-
$container = $this->getMockByCalls(ContainerInterface::class, [
34-
Call::create('get')->with(RoutesByNameInterface::class)->willReturn($routesByName),
31+
/** @var ContainerInterface $container */
32+
$container = $builder->create(ContainerInterface::class, [
33+
new WithReturn('get', [RoutesByNameInterface::class], $routesByName),
3534
]);
3635

3736
$factory = new UrlGeneratorFactory();

‎tests/Unit/ServiceFactory/Http/ResponseFactoryFactoryTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace App\Tests\Unit\ServiceFactory\Http;
66

77
use App\ServiceFactory\Http\ResponseFactoryFactory;
8-
use Chubbyphp\Mock\MockByCallsTrait;
98
use PHPUnit\Framework\TestCase;
109
use Slim\Psr7\Factory\ResponseFactory;
1110

@@ -16,8 +15,6 @@
1615
*/
1716
final class ResponseFactoryFactoryTest extends TestCase
1817
{
19-
use MockByCallsTrait;
20-
2118
public function testInvoke(): void
2219
{
2320
$factory = new ResponseFactoryFactory();

0 commit comments

Comments
 (0)
Please sign in to comment.