IntFieldTest::testGetDocumentValueForNotNumber()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Tests\Schema\Field\Entity;
4
5
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\IntField;
6
7
class IntFieldTest extends \PHPUnit_Framework_TestCase
8
{
9
10
    public function testGetDocumentValueForNumbers()
11
    {
12
        $int = 123;
13
        $double = 123.83;
14
        $null = null;
15
16
        $entity = new \stdClass();
17
        $field = new IntField('price', 'd_price', false, 10, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $suggester of Mdiyakov\DoctrineSolrBun...IntField::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        $field = new IntField('price', 'd_price', false, 10, /** @scrutinizer ignore-type */ false);
Loading history...
18
19
        $entity->price = $double;
20
        $fieldValue = $field->getDocumentFieldValue($entity);
21
        $this->assertEquals(123,$fieldValue);
22
23
        $entity->price = $int;
24
        $fieldValue = $field->getDocumentFieldValue($entity);
25
        $this->assertEquals(123,$fieldValue);
26
27
        $entity->price = $null;
28
        $fieldValue = $field->getDocumentFieldValue($entity);
29
        $this->assertEquals(0,$fieldValue);
30
    }
31
32
    /**
33
     * @dataProvider notNumberProvider
34
     * @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\InvalidFieldValueException
35
     */
36
    public function testGetDocumentValueForNotNumber($value)
37
    {
38
        $entity = new \stdClass();
39
        $field = new IntField('price', 'd_price', false, 10, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $suggester of Mdiyakov\DoctrineSolrBun...IntField::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $field = new IntField('price', 'd_price', false, 10, /** @scrutinizer ignore-type */ false);
Loading history...
40
41
        $entity->price = $value;
42
        $field->getDocumentFieldValue($entity);
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function notNumberProvider()
49
    {
50
        return [
51
            ['urytryry453'],
52
            [true],
53
            [new \stdClass()]
54
        ];
55
    }
56
}