Skip to content

Commit

Permalink
Move FakeTemplating to public test namespace (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 authored and soullivaneuh committed Jul 12, 2016
1 parent 0f1429c commit 790ce52
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 63 deletions.
1 change: 0 additions & 1 deletion Test/AbstractBlockServiceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Tests\Block\Service\FakeTemplating;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down
84 changes: 84 additions & 0 deletions Test/FakeTemplating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\BlockBundle\Test;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;

/**
* Mocking class for template usage.
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class FakeTemplating implements EngineInterface
{
/**
* @var string
*/
public $view;

/**
* @var array
*/
public $parameters;

/**
* @var Response
*/
public $response;

/**
* @var string
*/
public $name;

/**
* {@inheritdoc}
*/
public function render($name, array $parameters = array())
{
$this->name = $name;
$this->parameters = $parameters;
}

/**
* {@inheritdoc}
*/
public function renderResponse($view, array $parameters = array(), Response $response = null)
{
$this->view = $view;
$this->parameters = $parameters;
$this->response = $response;

if ($response) {
return $response;
}

return new Response();
}

/**
* {@inheritdoc}
*/
public function supports($name)
{
return true;
}

/**
* {@inheritdoc}
*/
public function exists($name)
{
return true;
}
}
73 changes: 11 additions & 62 deletions Tests/Block/Service/FakeTemplating.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,17 @@

namespace Sonata\BlockBundle\Tests\Block\Service;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\BlockBundle\Test\FakeTemplating as BaseTemplating;

class FakeTemplating implements EngineInterface
{
/**
* @var string
*/
public $view;

/**
* @var array
*/
public $parameters;

/**
* @var Response
*/
public $response;

/**
* @var string
*/
public $name;

/**
* {@inheritdoc}
*/
public function render($name, array $parameters = array())
{
$this->name = $name;
$this->parameters = $parameters;
}

/**
* {@inheritdoc}
*/
public function renderResponse($view, array $parameters = array(), Response $response = null)
{
$this->view = $view;
$this->parameters = $parameters;
@trigger_error(
'The '.__NAMESPACE__.'\FakeTemplating class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\BlockBundle\Test\FakeTemplating instead.',
E_USER_DEPRECATED
);

if ($response) {
return $response;
}

return new Response();
}

/**
* {@inheritdoc}
*/
public function supports($name)
{
return true;
}

/**
* {@inheritdoc}
*/
public function exists($name)
{
return true;
}
/**
* @deprecated since version 3.x and will be removed in 4.0. Use Sonata\BlockBundle\Test\FakeTemplating instead.
*/
class FakeTemplating extends BaseTemplating
{
}
61 changes: 61 additions & 0 deletions Tests/Test/FakeTemplatingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\BlockBundle\Tests\Test;

use Sonata\BlockBundle\Test\FakeTemplating;

class FakeTemplatingTest extends \PHPUnit_Framework_TestCase
{
public function testRender()
{
$templating = new FakeTemplating();
$templating->render('template.html.twig', array(
'foo' => 'bar',
));

$this->assertSame('template.html.twig', $templating->name);
$this->assertSame(array(
'foo' => 'bar',
), $templating->parameters);
}

public function testRenderResponse()
{
$response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')->getMock();

$templating = new FakeTemplating();
$templating->renderResponse('template.html.twig', array(
'foo' => 'bar',
), $response);

$this->assertSame('template.html.twig', $templating->view);
$this->assertSame(array(
'foo' => 'bar',
), $templating->parameters);
$this->assertSame($response, $templating->response);
}

public function testSupports()
{
$templating = new FakeTemplating();
$this->assertTrue($templating->supports('foo'));
}

/**
* {@inheritdoc}
*/
public function testExists()
{
$templating = new FakeTemplating();
$this->assertTrue($templating->exists('foo'));
}
}
5 changes: 5 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
UPGRADE 3.x
===========

## Deprecated test classes

The `Tests\Block\Service\FakeTemplating` class is deprecated. Use `Test\FakeTemplating` instead.


UPGRADE FROM 3.0 to 3.1
=======================

Expand Down

0 comments on commit 790ce52

Please sign in to comment.