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 ( 48aa34...e9e817 )
by Mario
29:19 queued 01:50
created

FieldDataFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testGetLegacyValueWithoutCustomHandler() 0 20 1
B testGetLegacyValueWithCustomHandler() 0 30 1
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
        $data = $this->factory->getLegacyValue($value, $definition);
50
51
        $this->assertInstanceOf(LegacyData::class, $data);
52
        $this->assertEquals(123, $data->getContentClassAttributeId());
53
        $this->assertEquals(0.0, $data->getDataFloat());
54
        $this->assertEquals(0, $data->getDataInt());
55
        $this->assertEquals((string) $value, $data->getDataText());
56
    }
57
58
    public function testGetLegacyValueWithCustomHandler()
59
    {
60
        $value = new TextValue('some value');
61
        $definition = new FieldDefinition(array(
62
            'id' => 123,
63
        ));
64
65
        $handler = $this->getMockBuilder(CustomFieldHandlerInterface::class)
66
            ->disableOriginalConstructor()
67
            ->setMethods(array('toString', 'supports'))
68
            ->getMock();
69
70
        $handler->expects($this->once())
71
            ->method('toString')
72
            ->with($value, $definition)
73
            ->willReturn((string) $value);
74
75
        $this->registry->expects($this->once())
76
            ->method('handle')
77
            ->with($value)
78
            ->willReturn($handler);
79
80
        $data = $this->factory->getLegacyValue($value, $definition);
81
82
        $this->assertInstanceOf(LegacyData::class, $data);
83
        $this->assertEquals(123, $data->getContentClassAttributeId());
84
        $this->assertEquals(0.0, $data->getDataFloat());
85
        $this->assertEquals(0, $data->getDataInt());
86
        $this->assertEquals((string) $value, $data->getDataText());
87
    }
88
}
89