-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move FakeTemplating to public test namespace (#310)
- Loading branch information
1 parent
0f1429c
commit 790ce52
Showing
5 changed files
with
161 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters