Completed
Push — master ( 451f62...fe985e )
by Anton
06:19
created

EntityFactoryTest::testJsonDecodeError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\QueueBundle\Tests\Unit\Factory;
6
7
use JMS\Serializer\SerializerInterface;
8
use Lamoda\QueueBundle\Entity\QueueEntityInterface;
9
use Lamoda\QueueBundle\Exception\UnexpectedValueException;
10
use Lamoda\QueueBundle\Factory\EntityFactory;
11
use Lamoda\QueueBundle\Job\AbstractJob;
12
use Lamoda\QueueBundle\Tests\Unit\Job\StubJob;
13
use Lamoda\QueueBundle\Tests\Unit\QueueEntity;
14
use Lamoda\QueueBundle\Tests\Unit\SymfonyMockTrait;
15
use PHPUnit_Framework_TestCase;
16
17
class EntityFactoryTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Bug introduced by
There is one abstract method getMockBuilder in this class; you could implement it, or declare this class as abstract.
Loading history...
18
{
19
    use SymfonyMockTrait;
20
21
    /**
22
     * @param AbstractJob          $job
23
     * @param QueueEntityInterface $expected
24
     *
25
     * @dataProvider dataCreateQueue()
26
     */
27
    public function testCreateQueue(AbstractJob $job, QueueEntityInterface $expected): void
28
    {
29
        $serializer = $this->getJMSSerializer(['serialize']);
30
        $serializer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JMS\Serializer\Serializer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
            ->method('serialize')
32
            ->willReturn('{"id":1}');
33
34
        $factory = $this->createFactory($serializer);
35
36
        $this->assertEquals($expected, $factory->createQueue($job));
37
    }
38
39
    public function dataCreateQueue(): array
40
    {
41
        return [
42
            [
43
                new StubJob(1),
44
                new QueueEntity('queue', 'exchange', StubJob::class, ['id' => 1]),
45
            ],
46
            [
47
                (function () {
48
                    $job = new StubJob(1);
49
                    $job->setScheduleAt(new \DateTime('25.01.10'));
50
51
                    return $job;
52
                })(),
53
                (function () {
54
                    $queue = new QueueEntity('queue', 'exchange', StubJob::class, ['id' => 1]);
55
                    $queue->setScheduled(new \DateTime('25.01.10'));
56
57
                    return $queue;
58
                })(),
59
            ],
60
        ];
61
    }
62
63
    public function testJsonDecodeError(): void
64
    {
65
        $this->expectException(UnexpectedValueException::class);
66
        $this->expectExceptionCode(4);
67
        $this->expectExceptionMessage('json_decode error: Syntax error');
68
69
        $serializer = $this->getJMSSerializer(['serialize']);
70
        $serializer->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<JMS\Serializer\Serializer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
            ->method('serialize')
72
            ->willReturn('abrakadabra');
73
74
        $factory = $this->createFactory($serializer);
75
        $factory->createQueue(new StubJob(1));
76
    }
77
78
    private function createFactory(SerializerInterface $serializer): EntityFactory
79
    {
80
        return new EntityFactory($serializer, QueueEntity::class);
81
    }
82
}
83