Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tattali committed Jan 16, 2024
1 parent 3219235 commit 5225a11
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 62 deletions.
20 changes: 10 additions & 10 deletions tests/DataCollector/DeviceDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use MobileDetectBundle\Helper\DeviceView;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -53,8 +53,8 @@ protected function setUp(): void
parent::setUp();

$this->request = $this->getMockBuilder(Request::class)->getMock();
$this->request->query = new ParameterBag();
$this->request->cookies = new ParameterBag();
$this->request->query = new InputBag();
$this->request->cookies = new InputBag();
$this->request->server = new ServerBag();
$this->request->expects(self::any())->method('duplicate')->willReturn($this->request);

Expand All @@ -75,7 +75,7 @@ public function testCollectCurrentViewMobileIsCurrent(): void
'status_code' => Response::HTTP_FOUND,
'action' => RequestResponseListener::REDIRECT,
];
$this->request->cookies = new ParameterBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_MOBILE]);
$this->request->cookies = new InputBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_MOBILE]);
$deviceView = new DeviceView($this->requestStack);
$deviceDataCollector = new DeviceDataCollector($deviceView);
$deviceDataCollector->setRedirectConfig($redirectConfig);
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testCollectCurrentViewMobileCanUseTablet(): void
'status_code' => Response::HTTP_FOUND,
'action' => RequestResponseListener::REDIRECT,
];
$this->request->query = new ParameterBag(['param1' => 'value1']);
$this->request->query = new InputBag(['param1' => 'value1']);
$this->request->expects(self::any())->method('getSchemeAndHttpHost')->willReturn('http://t.testsite.com');
$this->request->expects(self::any())->method('getBaseUrl')->willReturn('/base-url');
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/path-info');
Expand All @@ -126,7 +126,7 @@ public function testCollectCurrentViewMobileCanUseTablet(): void

return $test->request->getSchemeAndHttpHost().$test->request->getBaseUrl().$test->request->getPathInfo().$qs;
});
$this->request->cookies = new ParameterBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_MOBILE]);
$this->request->cookies = new InputBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_MOBILE]);
$deviceView = new DeviceView($this->requestStack);
$deviceDataCollector = new DeviceDataCollector($deviceView);
$deviceDataCollector->setRedirectConfig($redirectConfig);
Expand Down Expand Up @@ -172,7 +172,7 @@ public function testCollectCurrentViewFullCanUseMobile(): void
'status_code' => Response::HTTP_FOUND,
'action' => RequestResponseListener::REDIRECT,
];
$this->request->query = new ParameterBag(['param1' => 'value1']);
$this->request->query = new InputBag(['param1' => 'value1']);
$this->request->expects(self::any())->method('getSchemeAndHttpHost')->willReturn('http://t.testsite.com');
$this->request->expects(self::any())->method('getBaseUrl')->willReturn('/base-url');
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/path-info');
Expand All @@ -189,7 +189,7 @@ public function testCollectCurrentViewFullCanUseMobile(): void

return $test->request->getSchemeAndHttpHost().$test->request->getBaseUrl().$test->request->getPathInfo().$qs;
});
$this->request->cookies = new ParameterBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_FULL]);
$this->request->cookies = new InputBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_FULL]);
$deviceView = new DeviceView($this->requestStack);
$deviceDataCollector = new DeviceDataCollector($deviceView);
$deviceDataCollector->setRedirectConfig($redirectConfig);
Expand Down Expand Up @@ -235,7 +235,7 @@ public function testCollectCurrentViewFullCantUseMobile(): void
'status_code' => Response::HTTP_FOUND,
'action' => RequestResponseListener::REDIRECT,
];
$this->request->query = new ParameterBag(['param1' => 'value1']);
$this->request->query = new InputBag(['param1' => 'value1']);
$this->request->expects(self::any())->method('getSchemeAndHttpHost')->willReturn('http://testsite.com');
$this->request->expects(self::any())->method('getBaseUrl')->willReturn('/base-url');
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/path-info');
Expand All @@ -252,7 +252,7 @@ public function testCollectCurrentViewFullCantUseMobile(): void

return $test->request->getSchemeAndHttpHost().$test->request->getBaseUrl().$test->request->getPathInfo().$qs;
});
$this->request->cookies = new ParameterBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_FULL]);
$this->request->cookies = new InputBag([DeviceView::COOKIE_KEY_DEFAULT => DeviceView::VIEW_FULL]);
$deviceView = new DeviceView($this->requestStack);
$deviceDataCollector = new DeviceDataCollector($deviceView);
$deviceDataCollector->setRedirectConfig($redirectConfig);
Expand Down
16 changes: 8 additions & 8 deletions tests/EventListener/RequestResponseListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -71,8 +71,8 @@ protected function setUp(): void
$this->request->expects(self::any())->method('getSchemeAndHttpHost')->willReturn('http://testhost.com');
$this->request->expects(self::any())->method('get')->willReturn('value');
$this->request->expects(self::any())->method('getUriForPath')->willReturn('/');
$this->request->query = new ParameterBag();
$this->request->cookies = new ParameterBag();
$this->request->query = new InputBag();
$this->request->cookies = new InputBag();

$this->requestStack = $this->getMockBuilder(RequestStack::class)->disableOriginalConstructor()->getMock();
$this->requestStack->expects(self::any())
Expand All @@ -89,7 +89,7 @@ protected function setUp(): void

public function testHandleRequestHasSwitchParam(): void
{
$this->request->query = new ParameterBag(['myparam' => 'myvalue', $this->switchParam => DeviceView::VIEW_MOBILE]);
$this->request->query = new InputBag(['myparam' => 'myvalue', $this->switchParam => DeviceView::VIEW_MOBILE]);
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/');
$deviceView = new DeviceView($this->requestStack);
$deviceView->setRedirectConfig([DeviceView::VIEW_MOBILE => ['status_code' => Response::HTTP_FOUND]]);
Expand All @@ -114,7 +114,7 @@ public function testHandleRequestHasSwitchParam(): void

public function testHandleRequestBis(): void
{
$this->request->query = new ParameterBag(['myparam' => 'myvalue', $this->switchParam => DeviceView::VIEW_MOBILE]);
$this->request->query = new InputBag(['myparam' => 'myvalue', $this->switchParam => DeviceView::VIEW_MOBILE]);
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/');
$deviceView = new DeviceView($this->requestStack);
$deviceView->setRedirectConfig([DeviceView::VIEW_MOBILE => ['status_code' => Response::HTTP_FOUND]]);
Expand All @@ -141,7 +141,7 @@ public function testHandleRequestHasSwitchParamAndQuery(): void
{
$this->config['mobile'] = ['is_enabled' => true, 'host' => 'http://mobilehost.com'];

$this->request->query = new ParameterBag(['myparam' => 'myvalue', $this->switchParam => DeviceView::VIEW_MOBILE]);
$this->request->query = new InputBag(['myparam' => 'myvalue', $this->switchParam => DeviceView::VIEW_MOBILE]);
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/');
$this->request->expects(self::any())->method('get')->willReturn('value');
$this->router->expects(self::exactly(2))->method('getRouteCollection')->willReturn(
Expand Down Expand Up @@ -241,7 +241,7 @@ public function testHandleRequestHasTabletRedirect(): void
{
$this->config['tablet'] = ['is_enabled' => true, 'host' => 'http://t.testsite.com', 'status_code' => Response::HTTP_FOUND];

$this->request->query = new ParameterBag(['some' => 'param']);
$this->request->query = new InputBag(['some' => 'param']);
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/some/parameters');
$this->request->expects(self::any())->method('get')->willReturn('value');
$this->router->expects(self::exactly(2))->method('getRouteCollection')->willReturn(
Expand Down Expand Up @@ -284,7 +284,7 @@ public function testHandleRequestWithDifferentSwitchParamRedirect(): void

$switchParam = 'custom_param';

$this->request->query = new ParameterBag(['some' => 'param']);
$this->request->query = new InputBag(['some' => 'param']);
$this->request->expects(self::any())->method('getPathInfo')->willReturn('/some/parameters');
$this->router->expects(self::exactly(2))->method('getRouteCollection')->willReturn(
$this->createRouteCollectionWithRouteAndRoutingOption(RequestResponseListener::REDIRECT, 2)
Expand Down
Loading

0 comments on commit 5225a11

Please sign in to comment.