Skip to content

Commit

Permalink
SymfonyResponseComparator was added
Browse files Browse the repository at this point in the history
  • Loading branch information
m.yakunin committed May 27, 2019
1 parent 8db7b14 commit 3cf48bc
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
59 changes: 59 additions & 0 deletions Tests/Common/Comparator/SymfonyResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Liip\ThemeBundle\Tests\Common\Comparator;

use SebastianBergmann\Comparator\Comparator;
use SebastianBergmann\Comparator\Factory;
use SebastianBergmann\Comparator\ObjectComparator;
use Symfony\Component\HttpFoundation\Response;

class SymfonyResponse extends Comparator
{
const PREDEFINED_DATE = 'Tue, 15 Nov 1994 08:12:31 GMT';

/**
* @var ObjectComparator
*/
private $inner;

public function __construct()
{
parent::__construct();

$this->inner = new ObjectComparator();
}

/**
* {@inheritdoc}
*/
public function accepts($expected, $actual)
{
return
$expected instanceof Response
&&
$actual instanceof Response
&&
$this->inner->accepts($expected, $actual);
}

/**
* @param Response $expected
* @param Response $actual
* {@inheritdoc}
*/
public function assertEquals($expected, $actual, $delta = 0, $canonicalize = false, $ignoreCase = false)
{
$expected->headers->set('Date', self::PREDEFINED_DATE);
$actual->headers->set('Date', self::PREDEFINED_DATE);

$this->inner->assertEquals($expected, $actual, $delta, $canonicalize, $ignoreCase);
}

/**
* {@inheritdoc}
*/
public function setFactory(Factory $factory)
{
$this->inner->setFactory($factory);
}
}
26 changes: 25 additions & 1 deletion Tests/Controller/ThemeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
* with this source code in the file LICENSE.
*/

namespace Liip\ThemeBundle\Controller;
namespace Liip\ThemeBundle\Tests\Controller;

use Liip\ThemeBundle\ActiveTheme;
use Liip\ThemeBundle\Controller\ThemeController;
use Liip\ThemeBundle\Tests\Common\Comparator\SymfonyResponse as SymfonyResponseComparator;
use PHPUnit\Framework\MockObject\Matcher\Invocation;
use SebastianBergmann\Comparator\Factory as ComparatorFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -23,6 +26,11 @@ class ThemeControllerTest extends \PHPUnit\Framework\TestCase
const REFERER = 'some_referer';
const DEFAULT_REDIRECT_URL = '/';

/**
* @var SymfonyResponseComparator
*/
private $symfonyResponseComparator;

/**
* @dataProvider switchActionDataProvider
* @param string|null $referer
Expand Down Expand Up @@ -81,6 +89,22 @@ public function testSwitchActionWithNotFoundTheme()
$controller->switchAction($this->createRequestWithWrongTheme());
}

protected function setUp()
{
parent::setUp();

$this->symfonyResponseComparator = new SymfonyResponseComparator();
ComparatorFactory::getInstance()->register($this->symfonyResponseComparator);
}

protected function tearDown()
{
ComparatorFactory::getInstance()->unregister($this->symfonyResponseComparator);
$this->symfonyResponseComparator = null;

parent::tearDown();
}

/**
* @param Invocation $activeThemeInvocation
* @param mixed[]|null $cookieOptions
Expand Down

0 comments on commit 3cf48bc

Please sign in to comment.