Completed
Pull Request — master (#1079)
by Guillaume
07:38
created

IdentifierWithToString::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace FOS\ElasticaBundle\Tests\PropertyAccessor;
4
5
use FOS\ElasticaBundle\PropertyAccessor\CastToStringPropertyAccessor;
6
7
class IdentifierWithoutToString
8
{
9
    protected $id;
10
11
    public function __construct($id)
12
    {
13
        $this->id = $id;
14
    }
15
}
16
17
class IdentifierWithToString extends IdentifierWithoutToString
18
{
19
    public function __toString()
20
    {
21
        return (string) $this->id;
22
    }
23
}
24
25
class CastToStringPropertyAccessorTest extends \PHPUnit_Framework_TestCase
26
{
27 View Code Duplication
    public function testThatCanCastObjectToString()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $id = new IdentifierWithToString('id');
30
        $array = [
31
            'a' => $id
32
        ];
33
        $propertyAccessor = new CastToStringPropertyAccessor();
34
35
        $this->assertEquals('id', $propertyAccessor->getValue($array, '[a]'));
36
    }
37
38 View Code Duplication
    public function testThatWontCastObjectWithoutToString()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $id = new IdentifierWithoutToString('id');
41
        $array = [
42
            'a' => $id
43
        ];
44
        $propertyAccessor = new CastToStringPropertyAccessor();
45
46
        $this->assertEquals($id, $propertyAccessor->getValue($array, '[a]'));
47
    }
48
49
    public function testThatWontCastIntToString()
50
    {
51
        $array = [
52
            'a' => 1
53
        ];
54
        $propertyAccessor = new CastToStringPropertyAccessor();
55
56
        $this->assertEquals(1, $propertyAccessor->getValue($array, '[a]'));
57
    }
58
}
59