Completed
Pull Request — 3.x (#587)
by Sullivan
08:36
created

DatagridBuilderTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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\DoctrineORMAdminBundle\Tests\Builder;
13
14
use Sonata\AdminBundle\Datagrid\Pager;
15
use Sonata\AdminBundle\Filter\FilterFactoryInterface;
16
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
17
use Sonata\DoctrineORMAdminBundle\Builder\DatagridBuilder;
18
use Symfony\Component\Form\FormFactoryInterface;
19
20
/**
21
 * @author Sullivan Senechal <[email protected]>
22
 */
23
final class DatagridBuilderTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var TypeGuesserInterface|\PHPUnit_Framework_MockObject_MockObject
27
     */
28
    protected $typeGuesser;
29
30
    /**
31
     * @var DatagridBuilder
32
     */
33
    protected $datagridBuilder;
34
    /**
35
     * @var FormFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
36
     */
37
    private $formFactory;
38
39
    /**
40
     * @var FilterFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
41
     */
42
    private $filterFactory;
43
44
    protected function setUp()
45
    {
46
        $this->formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
47
        $this->filterFactory = $this->getMock('Sonata\AdminBundle\Filter\FilterFactoryInterface');
48
        $this->typeGuesser = $this->getMock('Sonata\AdminBundle\Guesser\TypeGuesserInterface');
49
50
        $this->datagridBuilder = new DatagridBuilder($this->formFactory, $this->filterFactory, $this->typeGuesser);
51
    }
52
53
    public function testGetBaseDatagrid()
54
    {
55
        $admin = $this->getMockBuilder('Sonata\AdminBundle\Admin\AbstractAdmin')
56
            ->disableOriginalConstructor()->getMock();
57
        $admin->expects($this->once())->method('getPagerType')->willReturn(Pager::TYPE_SIMPLE);
58
        $admin->expects($this->once())->method('getClass')->willReturn('Foo\Bar');
59
        $admin->expects($this->once())->method('createQuery')
60
            ->willReturn($this->getMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
61
        $admin->expects($this->once())->method('getList')
62
            ->willReturn($this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionCollection'));
63
64
        $modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
65
        $modelManager->expects($this->once())->method('getIdentifierFieldNames')->willReturn(array('id'));
66
        $admin->expects($this->once())->method('getModelManager')->willReturn($modelManager);
67
68
        $this->formFactory->expects($this->once())->method('createNamedBuilder')
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormFactoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
            ->willReturn($this->getMock('Symfony\Component\Form\FormBuilderInterface'));
70
71
        $this->assertInstanceOf('Sonata\AdminBundle\Datagrid\Datagrid', $this->datagridBuilder->getBaseDatagrid($admin));
72
    }
73
}
74