Completed
Push — master ( fa2c24...0b15ad )
by Dmitri
131:14 queued 125:30
created

GenemuFormExtensionTest::makeMock()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Devmachine\Bundle\FormBundle\Tests\Twig;
4
5
use Devmachine\Bundle\FormBundle\Twig\GenemuFormExtension;
6
use Symfony\Component\Form\FormView;
7
8
class GenemuFormExtensionTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @test
12
     */
13
    public function it_registers_functions()
14
    {
15
        $twig = new \Twig_Environment(new \Twig_Loader_Array());
16
        $twig->addExtension(new GenemuFormExtension($this->makeMock('Symfony\Component\Form\FormRendererInterface')));
17
18
        $f1 = $twig->getFunction('form_javascript');
19
        $f2 = $twig->getFunction('form_stylesheet');
20
21
        $this->assertInstanceOf('Twig_SimpleFunction', $f1);
22
        $this->assertInstanceOf('Twig_SimpleFunction', $f2);
23
    }
24
25
    /**
26
     * @test
27
     */
28
    public function it_proxies_to_form_renderer()
29
    {
30
        $view = new FormView();
31
32
        $renderer = $this->makeMock('Symfony\Component\Form\FormRendererInterface');
33
        $renderer
34
            ->expects($this->exactly(3))
35
            ->method('searchAndRenderBlock')
36
            ->withConsecutive(
37
                [$this->equalTo($view), 'javascript'],
38
                [$this->equalTo($view), 'javascript_prototype'],
39
                [$this->equalTo($view), 'stylesheet']
40
            )
41
        ;
42
43
        $twig = new \Twig_Environment(new \Twig_Loader_Array());
44
        $twig->addExtension(new GenemuFormExtension($renderer));
45
46
        call_user_func($twig->getFunction('form_javascript')->getCallable(), $view);
47
        call_user_func($twig->getFunction('form_javascript')->getCallable(), $view, true);
48
        call_user_func($twig->getFunction('form_stylesheet')->getCallable(), $view);
49
    }
50
51
    private function makeMock($originalClassName)
52
    {
53
        if (method_exists($this, 'createMock')) {
54
            return $this->createMock($originalClassName);
55
        }
56
57
        return $this->getMock($originalClassName);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::getMock() has been deprecated: Method deprecated since Release 5.4.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

57
        return /** @scrutinizer ignore-deprecated */ $this->getMock($originalClassName);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
    }
59
}
60