Skip to content

Commit

Permalink
Merge ae08b6c into a5769c3
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jul 1, 2016
2 parents a5769c3 + ae08b6c commit 6f79426
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 66 deletions.
6 changes: 3 additions & 3 deletions Test/AbstractBlockServiceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Tests\Block\Service\FakeTemplating;
use Sonata\BlockBundle\Test\Mock\MockTemplating;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -42,14 +42,14 @@ abstract class AbstractBlockServiceTestCase extends \PHPUnit_Framework_TestCase
protected $blockContextManager;

/**
* @var FakeTemplating
* @var MockTemplating
*/
protected $templating;

protected function setUp()
{
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$this->templating = new FakeTemplating();
$this->templating = new MockTemplating();

$blockLoader = $this->getMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
$this->blockServiceManager = $this->getMock('Sonata\BlockBundle\Block\BlockServiceManagerInterface');
Expand Down
84 changes: 84 additions & 0 deletions Test/Mock/MockTemplating.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\Mock;

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 MockTemplating 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\Mock\MockTemplating;

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\Mock\MockTemplating 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 Deprecated since version 3.x. Use Sonata\BlockBundle\Test\Mock\MockTemplating instead.
*/
class FakeTemplating extends MockTemplating
{
}
61 changes: 61 additions & 0 deletions Tests/Test/Mock/MockTemplatingTest.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\Mock;

use Sonata\BlockBundle\Test\Mock\MockTemplating;

class MockTemplatingTest extends \PHPUnit_Framework_TestCase
{
public function testRender()
{
$templating = new MockTemplating();
$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 MockTemplating();
$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 MockTemplating();
$this->assertTrue($templating->supports('foo'));
}

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

## Deprecated AbstractBlockServiceTest class
## Deprecated test classes

The `Tests\Block\AbstractBlockServiceTest` class is deprecated. Use `Test\AbstractBlockServiceTestCase` instead.
The `Tests\Block\Service\FakeTemplating` class is deprecated. Use `Test\Mock\MockTemplating` instead.

0 comments on commit 6f79426

Please sign in to comment.