|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Chubbyphp\Tests\DecodeEncode\Unit\ServiceFactory; |
| 6 | + |
| 7 | +use Chubbyphp\DecodeEncode\Encoder\JsonTypeEncoder; |
| 8 | +use Chubbyphp\DecodeEncode\Encoder\JsonxTypeEncoder; |
| 9 | +use Chubbyphp\DecodeEncode\Encoder\UrlEncodedTypeEncoder; |
| 10 | +use Chubbyphp\DecodeEncode\Encoder\YamlTypeEncoder; |
| 11 | +use Chubbyphp\DecodeEncode\ServiceFactory\TypeEncodersFactory; |
| 12 | +use Chubbyphp\Mock\MockMethod\WithReturn; |
| 13 | +use Chubbyphp\Mock\MockObjectBuilder; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Psr\Container\ContainerInterface; |
| 16 | + |
| 17 | +/** |
| 18 | + * @covers \Chubbyphp\DecodeEncode\ServiceFactory\TypeEncodersFactory |
| 19 | + * |
| 20 | + * @internal |
| 21 | + */ |
| 22 | +final class TypeEncodersFactoryTest extends TestCase |
| 23 | +{ |
| 24 | + public function testInvoke(): void |
| 25 | + { |
| 26 | + $builder = new MockObjectBuilder(); |
| 27 | + |
| 28 | + /** @var ContainerInterface $container */ |
| 29 | + $container = $builder->create(ContainerInterface::class, [ |
| 30 | + new WithReturn('get', ['config'], ['debug' => true]), |
| 31 | + ]); |
| 32 | + |
| 33 | + $factory = new TypeEncodersFactory(); |
| 34 | + |
| 35 | + $typeEncoders = $factory($container); |
| 36 | + |
| 37 | + self::assertIsArray($typeEncoders); |
| 38 | + |
| 39 | + self::assertCount(4, $typeEncoders); |
| 40 | + |
| 41 | + self::assertInstanceOf(JsonTypeEncoder::class, array_shift($typeEncoders)); |
| 42 | + |
| 43 | + /** @var JsonxTypeEncoder $jsonxTypeEncoder */ |
| 44 | + $jsonxTypeEncoder = array_shift($typeEncoders); |
| 45 | + self::assertInstanceOf(JsonxTypeEncoder::class, $jsonxTypeEncoder); |
| 46 | + |
| 47 | + self::assertSame('application/jsonx+xml', $jsonxTypeEncoder->getContentType()); |
| 48 | + |
| 49 | + self::assertInstanceOf(UrlEncodedTypeEncoder::class, array_shift($typeEncoders)); |
| 50 | + self::assertInstanceOf(YamlTypeEncoder::class, array_shift($typeEncoders)); |
| 51 | + } |
| 52 | +} |
0 commit comments