Skip to content

Commit 19c1558

Browse files
authored
Merge pull request #1 from chubbyphp/chubbyphp-mock-2.x
chubbyphp-mock-2.x
2 parents 0d37d49 + d74e15e commit 19c1558

File tree

7 files changed

+65
-55
lines changed

7 files changed

+65
-55
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4141
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
4242
- name: sonarcloud.io
43-
uses: sonarsource/sonarqube-scan-action@v4.1.0
43+
uses: sonarsource/sonarqube-scan-action@v5.0.0
4444
env:
4545
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4646
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.
2626
## Requirements
2727

2828
* php: ^8.2
29-
* symfony/yaml: ^5.4.46|^6.4.14|^7.2
29+
* symfony/yaml: ^5.4.45|^6.4.18|^7.2
3030

3131
## Suggest
3232

33-
* chubbyphp/chubbyphp-container: ^2.1
33+
* chubbyphp/chubbyphp-container: ^2.2
3434
* psr/container: ^1.1.2|^2.0.2
3535

3636
## Installation

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
"ext-dom": "*",
2424
"ext-json": "*",
2525
"ext-mbstring": "*",
26-
"symfony/yaml": "^5.4.46|^6.4.14|^7.2"
26+
"symfony/yaml": "^5.4.45|^6.4.18|^7.2"
2727
},
2828
"require-dev": {
2929
"chubbyphp/chubbyphp-container": "^2.2",
3030
"chubbyphp/chubbyphp-dev-helper": "dev-master",
31-
"chubbyphp/chubbyphp-laminas-config-factory": "^1.3",
32-
"chubbyphp/chubbyphp-mock": "^1.8",
33-
"infection/infection": "^0.29.8",
31+
"chubbyphp/chubbyphp-laminas-config-factory": "^1.4",
32+
"chubbyphp/chubbyphp-mock": "^2.0@dev",
33+
"infection/infection": "^0.29.13",
3434
"php-coveralls/php-coveralls": "^2.7.0",
3535
"phpstan/extension-installer": "^1.4.3",
36-
"phpstan/phpstan": "^2.0.3",
37-
"phpunit/phpunit": "^11.5.0",
36+
"phpstan/phpstan": "^2.1.6",
37+
"phpunit/phpunit": "^11.5.10",
3838
"psr/container": "^2.0.2"
3939
},
4040
"autoload": {

tests/Unit/Decoder/DecoderTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
use Chubbyphp\DecodeEncode\Decoder\Decoder;
88
use Chubbyphp\DecodeEncode\Decoder\TypeDecoderInterface;
99
use Chubbyphp\DecodeEncode\LogicException;
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

1514
/**
@@ -19,13 +18,13 @@
1918
*/
2019
final class DecoderTest extends TestCase
2120
{
22-
use MockByCallsTrait;
23-
2421
public function testGetContentTypes(): void
2522
{
26-
/** @var MockObject|TypeDecoderInterface */
27-
$typeDecoder = $this->getMockByCalls(TypeDecoderInterface::class, [
28-
Call::create('getContentType')->with()->willReturn('application/json'),
23+
$builder = new MockObjectBuilder();
24+
25+
/** @var TypeDecoderInterface $typeDecoder */
26+
$typeDecoder = $builder->create(TypeDecoderInterface::class, [
27+
new WithReturn('getContentType', [], 'application/json'),
2928
]);
3029

3130
$decoder = new Decoder([$typeDecoder]);
@@ -35,10 +34,12 @@ public function testGetContentTypes(): void
3534

3635
public function testDecode(): void
3736
{
38-
/** @var MockObject|TypeDecoderInterface */
39-
$typeDecoder = $this->getMockByCalls(TypeDecoderInterface::class, [
40-
Call::create('getContentType')->with()->willReturn('application/json'),
41-
Call::create('decode')->with('{"key": "value"}')->willReturn(['key' => 'value']),
37+
$builder = new MockObjectBuilder();
38+
39+
/** @var TypeDecoderInterface $typeDecoder */
40+
$typeDecoder = $builder->create(TypeDecoderInterface::class, [
41+
new WithReturn('getContentType', [], 'application/json'),
42+
new WithReturn('decode', ['{"key": "value"}'], ['key' => 'value']),
4243
]);
4344

4445
$decoder = new Decoder([$typeDecoder]);
@@ -51,9 +52,11 @@ public function testDecodeWithMissingType(): void
5152
$this->expectException(LogicException::class);
5253
$this->expectExceptionMessage('There is no decoder/encoder for content-type: "application/xml"');
5354

54-
/** @var MockObject|TypeDecoderInterface */
55-
$typeDecoder = $this->getMockByCalls(TypeDecoderInterface::class, [
56-
Call::create('getContentType')->with()->willReturn('application/json'),
55+
$builder = new MockObjectBuilder();
56+
57+
/** @var TypeDecoderInterface $typeDecoder */
58+
$typeDecoder = $builder->create(TypeDecoderInterface::class, [
59+
new WithReturn('getContentType', [], 'application/json'),
5760
]);
5861

5962
$decoder = new Decoder([$typeDecoder]);

tests/Unit/Encoder/EncoderTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
use Chubbyphp\DecodeEncode\Encoder\Encoder;
88
use Chubbyphp\DecodeEncode\Encoder\TypeEncoderInterface;
99
use Chubbyphp\DecodeEncode\LogicException;
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

1514
/**
@@ -19,13 +18,13 @@
1918
*/
2019
final class EncoderTest extends TestCase
2120
{
22-
use MockByCallsTrait;
23-
2421
public function testGetContentTypes(): void
2522
{
26-
/** @var MockObject|TypeEncoderInterface $typeEncoder */
27-
$typeEncoder = $this->getMockByCalls(TypeEncoderInterface::class, [
28-
Call::create('getContentType')->with()->willReturn('application/json'),
23+
$builder = new MockObjectBuilder();
24+
25+
/** @var TypeEncoderInterface $typeEncoder */
26+
$typeEncoder = $builder->create(TypeEncoderInterface::class, [
27+
new WithReturn('getContentType', [], 'application/json'),
2928
]);
3029

3130
$encoder = new Encoder([$typeEncoder]);
@@ -35,10 +34,12 @@ public function testGetContentTypes(): void
3534

3635
public function testEncode(): void
3736
{
38-
/** @var MockObject|TypeEncoderInterface $typeEncoder */
39-
$typeEncoder = $this->getMockByCalls(TypeEncoderInterface::class, [
40-
Call::create('getContentType')->with()->willReturn('application/json'),
41-
Call::create('encode')->with(['key' => 'value'])->willReturn('{"key":"value"}'),
37+
$builder = new MockObjectBuilder();
38+
39+
/** @var TypeEncoderInterface $typeEncoder */
40+
$typeEncoder = $builder->create(TypeEncoderInterface::class, [
41+
new WithReturn('getContentType', [], 'application/json'),
42+
new WithReturn('encode', [['key' => 'value']], '{"key":"value"}'),
4243
]);
4344

4445
$encoder = new Encoder([$typeEncoder]);
@@ -51,9 +52,11 @@ public function testEncodeWithMissingType(): void
5152
$this->expectException(LogicException::class);
5253
$this->expectExceptionMessage('There is no decoder/encoder for content-type: "application/xml"');
5354

54-
/** @var MockObject|TypeEncoderInterface $typeEncoder */
55-
$typeEncoder = $this->getMockByCalls(TypeEncoderInterface::class, [
56-
Call::create('getContentType')->with()->willReturn('application/json'),
55+
$builder = new MockObjectBuilder();
56+
57+
/** @var TypeEncoderInterface $typeEncoder */
58+
$typeEncoder = $builder->create(TypeEncoderInterface::class, [
59+
new WithReturn('getContentType', [], 'application/json'),
5760
]);
5861

5962
$encoder = new Encoder([$typeEncoder]);

tests/Unit/ServiceFactory/DecoderFactoryTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
88
use Chubbyphp\DecodeEncode\Decoder\TypeDecoderInterface;
99
use Chubbyphp\DecodeEncode\ServiceFactory\DecoderFactory;
10-
use Chubbyphp\Mock\Call;
11-
use Chubbyphp\Mock\MockByCallsTrait;
10+
use Chubbyphp\Mock\MockMethod\WithReturn;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Container\ContainerInterface;
1414

@@ -19,13 +19,13 @@
1919
*/
2020
final class DecoderFactoryTest extends TestCase
2121
{
22-
use MockByCallsTrait;
23-
2422
public function testInvoke(): void
2523
{
24+
$builder = new MockObjectBuilder();
25+
2626
/** @var ContainerInterface $container */
27-
$container = $this->getMockByCalls(ContainerInterface::class, [
28-
Call::create('get')->with(TypeDecoderInterface::class.'[]')->willReturn([]),
27+
$container = $builder->create(ContainerInterface::class, [
28+
new WithReturn('get', [TypeDecoderInterface::class.'[]'], []),
2929
]);
3030

3131
$factory = new DecoderFactory();
@@ -37,9 +37,11 @@ public function testInvoke(): void
3737

3838
public function testCallStatic(): void
3939
{
40+
$builder = new MockObjectBuilder();
41+
4042
/** @var ContainerInterface $container */
41-
$container = $this->getMockByCalls(ContainerInterface::class, [
42-
Call::create('get')->with(TypeDecoderInterface::class.'[]default')->willReturn([]),
43+
$container = $builder->create(ContainerInterface::class, [
44+
new WithReturn('get', [TypeDecoderInterface::class.'[]default'], []),
4345
]);
4446

4547
$factory = [DecoderFactory::class, 'default'];

tests/Unit/ServiceFactory/EncoderFactoryTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
88
use Chubbyphp\DecodeEncode\Encoder\TypeEncoderInterface;
99
use Chubbyphp\DecodeEncode\ServiceFactory\EncoderFactory;
10-
use Chubbyphp\Mock\Call;
11-
use Chubbyphp\Mock\MockByCallsTrait;
10+
use Chubbyphp\Mock\MockMethod\WithReturn;
11+
use Chubbyphp\Mock\MockObjectBuilder;
1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Container\ContainerInterface;
1414

@@ -19,13 +19,13 @@
1919
*/
2020
final class EncoderFactoryTest extends TestCase
2121
{
22-
use MockByCallsTrait;
23-
2422
public function testInvoke(): void
2523
{
24+
$builder = new MockObjectBuilder();
25+
2626
/** @var ContainerInterface $container */
27-
$container = $this->getMockByCalls(ContainerInterface::class, [
28-
Call::create('get')->with(TypeEncoderInterface::class.'[]')->willReturn([]),
27+
$container = $builder->create(ContainerInterface::class, [
28+
new WithReturn('get', [TypeEncoderInterface::class.'[]'], []),
2929
]);
3030

3131
$factory = new EncoderFactory();
@@ -37,9 +37,11 @@ public function testInvoke(): void
3737

3838
public function testCallStatic(): void
3939
{
40+
$builder = new MockObjectBuilder();
41+
4042
/** @var ContainerInterface $container */
41-
$container = $this->getMockByCalls(ContainerInterface::class, [
42-
Call::create('get')->with(TypeEncoderInterface::class.'[]default')->willReturn([]),
43+
$container = $builder->create(ContainerInterface::class, [
44+
new WithReturn('get', [TypeEncoderInterface::class.'[]default'], []),
4345
]);
4446

4547
$factory = [EncoderFactory::class, 'default'];

0 commit comments

Comments
 (0)