GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 55e41a...4bbae3 )
by Mario
04:35
created

FieldDataFactoryTest::testGetLegacyValueWithCustomHandler()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 31
rs 8.8571
c 1
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
namespace Netgen\Bundle\InformationCollectionBundle\Tests\Factory;
4
5
use eZ\Publish\Core\FieldType\TextLine\Value as TextValue;
6
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition;
7
use Netgen\Bundle\InformationCollectionBundle\Factory\FieldDataFactory;
8
use Netgen\Bundle\InformationCollectionBundle\FieldHandler\Custom\CustomFieldHandlerInterface;
9
use Netgen\Bundle\InformationCollectionBundle\FieldHandler\FieldHandlerRegistry;
10
use Netgen\Bundle\InformationCollectionBundle\Value\LegacyData;
11
use PHPUnit\Framework\TestCase;
12
13
class FieldDataFactoryTest extends TestCase
14
{
15
    /**
16
     * @var FieldDataFactory
17
     */
18
    protected $factory;
19
20
    /**
21
     * @var \PHPUnit_Framework_MockObject_MockObject
22
     */
23
    protected $registry;
24
25
    public function setUp()
26
    {
27
        $this->registry = $this->getMockBuilder(FieldHandlerRegistry::class)
28
            ->disableOriginalConstructor()
29
            ->setMethods(array('handle'))
30
            ->getMock();
31
32
        $this->factory = new FieldDataFactory($this->registry);
33
34
        parent::setUp();
35
    }
36
37
    public function testGetLegacyValueWithoutCustomHandler()
38
    {
39
        $value = new TextValue('some value');
40
        $definition = new FieldDefinition(array(
41
            'id' => 123,
42
        ));
43
44
        $this->registry->expects($this->once())
45
            ->method('handle')
46
            ->with($value)
47
            ->willReturn(null);
48
49
        /** @var LegacyData $data */
50
        $data = $this->factory->getLegacyValue($value, $definition);
51
52
        $this->assertInstanceOf(LegacyData::class, $data);
53
        $this->assertEquals(123, $data->contentClassAttributeId);
54
        $this->assertEquals(0.0, $data->dataFloat);
55
        $this->assertEquals(0, $data->dataInt);
56
        $this->assertEquals((string) $value, $data->dataText);
57
    }
58
59
    public function testGetLegacyValueWithCustomHandler()
60
    {
61
        $value = new TextValue('some value');
62
        $definition = new FieldDefinition(array(
63
            'id' => 123,
64
        ));
65
66
        $handler = $this->getMockBuilder(CustomFieldHandlerInterface::class)
67
            ->disableOriginalConstructor()
68
            ->setMethods(array('toString', 'supports'))
69
            ->getMock();
70
71
        $handler->expects($this->once())
72
            ->method('toString')
73
            ->with($value, $definition)
74
            ->willReturn((string) $value);
75
76
        $this->registry->expects($this->once())
77
            ->method('handle')
78
            ->with($value)
79
            ->willReturn($handler);
80
81
        /** @var LegacyData $data */
82
        $data = $this->factory->getLegacyValue($value, $definition);
83
84
        $this->assertInstanceOf(LegacyData::class, $data);
85
        $this->assertEquals(123, $data->contentClassAttributeId);
86
        $this->assertEquals(0.0, $data->dataFloat);
87
        $this->assertEquals(0, $data->dataInt);
88
        $this->assertEquals((string) $value, $data->dataText);
89
    }
90
}
91