Completed
Pull Request — master (#1131)
by Karel
05:49
created

CallbackTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 1
cbo 3
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSerializerMustHaveSerializeMethod() 0 6 1
A testSetGroupsWorksWithValidSerializer() 0 8 1
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.');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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('FOS\ElasticaBundle\Serializer\FakeSerializer')->setMethods(array('serialize'))->getMock();
29
        $callback->setSerializer($serializer);
30
31
        $this->setExpectedException(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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