From 3cf48bcb378150be268c82def4d45ab70ae3e0ed Mon Sep 17 00:00:00 2001 From: "m.yakunin" Date: Mon, 27 May 2019 20:35:30 +0300 Subject: [PATCH] SymfonyResponseComparator was added --- Tests/Common/Comparator/SymfonyResponse.php | 59 +++++++++++++++++++++ Tests/Controller/ThemeControllerTest.php | 26 ++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 Tests/Common/Comparator/SymfonyResponse.php diff --git a/Tests/Common/Comparator/SymfonyResponse.php b/Tests/Common/Comparator/SymfonyResponse.php new file mode 100644 index 0000000..063c811 --- /dev/null +++ b/Tests/Common/Comparator/SymfonyResponse.php @@ -0,0 +1,59 @@ +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); + } +} diff --git a/Tests/Controller/ThemeControllerTest.php b/Tests/Controller/ThemeControllerTest.php index 8dd77c8..8d5e2ba 100644 --- a/Tests/Controller/ThemeControllerTest.php +++ b/Tests/Controller/ThemeControllerTest.php @@ -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; @@ -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 @@ -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