77use Chubbyphp \DecodeEncode \Encoder \Encoder ;
88use Chubbyphp \DecodeEncode \Encoder \TypeEncoderInterface ;
99use 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 ;
1312use PHPUnit \Framework \TestCase ;
1413
1514/**
1918 */
2019final 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 ]);
0 commit comments