Completed
Pull Request — master (#1131)
by Karel
17:34 queued 08:59
created

testSetGroupsWorksWithValidSerializer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace FOS\ElasticaBundle\Tests\Serializer;
4
5
use FOS\ElasticaBundle\Serializer\Callback;
6
7
class CallbackTest extends PHPUnit_Framework_TestCase
8
{
9
    public function testSerializerMustHaveSerializeMethod()
10
    {
11
        $callback = new Callback();
12
        $this->setExpectedException('RuntimeException', 'The serializer must have a "serialize" method.');
13
        $callback->setSerializer(new \stdClass());
14
    }
15
16
    public function testSetGroupsWorksWithValidSerializer()
17
    {
18
        $callback = new Callback();
19
        $serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer')->disableOriginalConstructor()->getMock();
20
        $callback->setSerializer($serializer);
21
22
        $callback->setGroups(array('foo'));
23
    }
24
25
    public function testSetGroupsFailsWithInvalidSerializer()
26
    {
27
        $callback = new Callback();
28
        $serializer = $this->getMockBuilder('FakeSerializer')->setMethods(array('serialize'))->getMock();
29
        $callback->setSerializer($serializer);
30
31
        $this->setExpectedException(
32
            'RuntimeException',
33
            'Setting serialization groups requires using "JMS\Serializer\Serializer" or '
34
                . '"Symfony\Component\Serializer\Serializer"'
35
        );
36
37
        $callback->setGroups(array('foo'));
38
    }
39
}
40