Completed
Push — refonte ( 64e01a...7173e3 )
by Arnaud
03:31
created

FieldFactoryTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 3
dl 0
loc 57
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testCreate() 0 54 1
1
<?php
2
3
namespace LAG\AdminBundle\Tests\AdminBundle\Field\Factory;
4
5
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Application\Configuration\ApplicationConfiguration;
7
use LAG\AdminBundle\Application\Configuration\ApplicationConfigurationStorage;
8
use LAG\AdminBundle\Field\Configuration\StringFieldConfiguration;
9
use LAG\AdminBundle\Field\Factory\ConfigurationFactory;
10
use LAG\AdminBundle\Field\Factory\FieldFactory;
11
use LAG\AdminBundle\Field\Field\StringField;
12
use LAG\AdminBundle\Tests\AdminTestBase;
13
use Symfony\Component\Translation\TranslatorInterface;
14
15
class FieldFactoryTest extends AdminTestBase
16
{
17
    public function testCreate()
18
    {
19
        $applicationConfiguration = $this->getMockWithoutConstructor(ApplicationConfiguration::class);
20
        $applicationConfiguration
21
            ->expects($this->once())
22
            ->method('getParameter')
23
            ->with('fields_mapping')
24
            ->willReturn([
25
                'string' => StringField::class,
26
                'test' => 'lol',
27
            ])
28
        ;
29
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
30
        
31
        $fieldConfiguration = $this->getMockWithoutConstructor(StringFieldConfiguration::class);
32
        $fieldConfiguration
33
            ->expects($this->once())
34
            ->method('isResolved')
35
            ->willReturn(true)
36
        ;
37
    
38
        $storage = $this->getMockWithoutConstructor(ApplicationConfigurationStorage::class);
39
    
40
        $storage
41
            ->expects($this->once())
42
            ->method('getApplicationConfiguration')
43
            ->willReturn($applicationConfiguration)
44
        ;
45
        
46
        $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class);
47
        $configurationFactory
48
            ->expects($this->once())
49
            ->method('create')
50
            ->willReturnCallback(function ($field, $configuration) use ($actionConfiguration, $fieldConfiguration) {
51
                $this->assertInstanceOf(StringField::class, $field);
52
                $this->assertEquals([
53
                    'length' => 200,
54
                ], $configuration);
55
                
56
                return $fieldConfiguration;
57
            })
58
        ;
59
        
60
        $translator = $this->getMockWithoutConstructor(TranslatorInterface::class);
61
        $twig = $this->getMockWithoutConstructor(\Twig_Environment::class);
62
        
63
        
64
        $fieldFactory = new FieldFactory($storage, $configurationFactory, $translator, $twig);
65
        $fieldFactory->create('test', [
66
            'options' => [
67
                'length' => 200,
68
            ],
69
        ], $actionConfiguration);
70
    }
71
}
72