Skip to content

Commit

Permalink
Try to fix travis tests (#1210)
Browse files Browse the repository at this point in the history
Get Travis tests passing again.
  • Loading branch information
isometriks authored Feb 3, 2017
1 parent 6b64245 commit de1345c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
58 changes: 35 additions & 23 deletions Tests/Form/AbstractDivLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

abstract class AbstractDivLayoutTest extends FormIntegrationTestCase
{
protected $extension;
protected $renderer;
protected $tabFactory;
protected $formTypeMap = array(
'form' => 'Symfony\Component\Form\Extension\Core\Type\FormType',
Expand All @@ -46,22 +46,7 @@ protected function setUp()

parent::setUp();

$rendererEngine = new TwigRendererEngine(array(
'form_div_layout.html.twig',
'fields.html.twig',
));

if (interface_exists('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')) {
$csrfProviderInterface = 'Symfony\Component\Security\Csrf\CsrfTokenManagerInterface';
} else {
$csrfProviderInterface = 'Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface';
}

$renderer = new TwigRenderer($rendererEngine, $this->getMock($csrfProviderInterface));

$this->extension = new FormExtension($renderer);

$reflection = new \ReflectionClass($renderer);
$reflection = new \ReflectionClass('Symfony\Bridge\Twig\Form\TwigRenderer');
$bridgeDirectory = dirname($reflection->getFileName()).'/../Resources/views/Form';

$loader = new \Twig_Loader_Filesystem(array(
Expand All @@ -76,9 +61,36 @@ protected function setUp()
$environment->addExtension(new IconExtension('fontawesome'));
$environment->addExtension(new TwigFormExtension());
$environment->addGlobal('global', '');
$environment->addExtension($this->extension);

$this->extension->initRuntime($environment);
$rendererEngine = new TwigRendererEngine(array(
'form_div_layout.html.twig',
'fields.html.twig',
), $environment);

if (interface_exists('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')) {
$csrfProviderInterface = 'Symfony\Component\Security\Csrf\CsrfTokenManagerInterface';
} else {
$csrfProviderInterface = 'Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface';
}

$csrfProvider = $this->getMockBuilder($csrfProviderInterface)->getMock();
$this->renderer = new TwigRenderer($rendererEngine, $csrfProvider);
$environment->addExtension($extension = new FormExtension($this->renderer));
$extension->initRuntime($environment);
$this->registerTwigRuntimeLoader($environment, $this->renderer);
}

protected function registerTwigRuntimeLoader(\Twig_Environment $environment, TwigRenderer $renderer)
{
if (!method_exists($environment, 'addRuntimeLoader')) {
return;
}

$loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
array('Symfony\Bridge\Twig\Form\TwigRenderer', $renderer),
)));
$environment->addRuntimeLoader($loader);
}

/**
Expand Down Expand Up @@ -290,7 +302,7 @@ protected function removeBreaks($html)
*/
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
return (string) $this->renderer->renderBlock($view, 'form', $vars);
}

/**
Expand All @@ -301,7 +313,7 @@ protected function renderForm(FormView $view, array $vars = array())
*/
protected function renderRow(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
return (string) $this->renderer->searchAndRenderBlock($view, 'row', $vars);
}

/**
Expand All @@ -312,7 +324,7 @@ protected function renderRow(FormView $view, array $vars = array())
*/
protected function renderWidget(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
return (string) $this->renderer->searchAndRenderBlock($view, 'widget', $vars);
}

/**
Expand All @@ -328,7 +340,7 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
$vars += array('label' => $label);
}

return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
}

protected function getFormType($name)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Form/TypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setUp()
{
self::bootKernel();
$this->container = self::$kernel->getContainer();
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->factory = Forms::createFormFactoryBuilder()
->addExtensions($this->getExtensions())
->getFormFactory();
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"mopa/composer-bridge": "~1.3"
},
"require-dev": {
"phpunit/phpunit": "~4.6"
"phpunit/phpunit": "~4.6",
"symfony/security-bundle": "~2.3|~3.0",
"symfony/translation": "~2.3|~3.0"
},
"conflict": {
"symfony/twig-bridge": "<2.3"
Expand Down

0 comments on commit de1345c

Please sign in to comment.