Completed
Push — master ( eb83f4...bb238e )
by Maximilian
14s
created

FilterTypeGuesserTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGuessType() 0 48 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Unit\Guesser;
13
14
use Sonata\DoctrinePHPCRAdminBundle\Guesser\FilterTypeGuesser;
15
use Symfony\Component\Form\Guess\Guess;
16
17
class FilterTypeGuesserTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function testGuessType()
20
    {
21
        $managerRegistry = $this->createMock('Doctrine\Bundle\PHPCRBundle\ManagerRegistry');
22
23
        $documentRepository = $this->createMock('Doctrine\ODM\PHPCR\DocumentRepository');
24
25
        $documentRepository->expects($this->once())
26
            ->method('getClassMetadata')
27
            ->with($this->equalTo($class = 'Whatever'))
28
            ->will($this->returnValue($this->createMock(
29
                'Doctrine\Common\Persistence\Mapping\ClassMetadata'
30
            )));
31
32
        $managerRegistry->expects($this->once())
33
            ->method('getManagers')
34
            ->will($this->returnValue(array($documentRepository)));
35
36
        $guesser = new FilterTypeGuesser(
37
            $managerRegistry
38
        );
39
40
        $typeGuess = $guesser->guessType($class, $fieldname = 'whatever', $this->createMock(
41
            'Sonata\AdminBundle\Model\ModelManagerInterface'
42
        ));
43
44
        $this->assertInstanceof(
45
            'Symfony\Component\Form\Guess\TypeGuess',
46
            $typeGuess
47
        );
48
        $this->assertSame(
49
            'doctrine_phpcr_string',
50
            $typeGuess->getType()
51
        );
52
        $this->assertSame(
53
            array(
54
                'field_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
55
                'field_options' => array(),
56
                'options' => array(),
57
                'field_name' => $fieldname,
58
            ),
59
            $typeGuess->getOptions()
60
        );
61
62
        $this->assertEquals(
63
            Guess::LOW_CONFIDENCE,
64
            $typeGuess->getConfidence()
65
        );
66
    }
67
}
68