Skip to content

Commit

Permalink
Merge pull request #26 from tattali/fix-tests
Browse files Browse the repository at this point in the history
Update main.yml
  • Loading branch information
tattali authored Jan 16, 2024
2 parents 0e63c7f + 5225a11 commit ed81577
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 102 deletions.
23 changes: 3 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,14 @@ jobs:
fail-fast: false
matrix:
php:
- 8.0
- 8.1
- 8.2
dependencies:
- highest
stability:
- stable
symfony-require:
# Test latest LTS
- 5.4.*
# Test last supported version
- 6.0.*
- 6.*
include:
# Tests the lowest set of dependencies
# - symfony-require: 5.4.*
# dependencies: lowest
# stability: stable
# php: 8.0

# Bleeding edge
- symfony-require: 6.*
php: 8.1
dependencies: highest
stability: dev

# Test latest stable version
- 7.*
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
4 changes: 0 additions & 4 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
'array_syntax' => [
'syntax' => 'short',
],
'braces' => [
'allow_single_line_closure' => true,
],
'compact_nullable_typehint' => true,
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
}
],
"require": {
"php": ">=7.2.5",
"php": ">=8.2",
"mobiledetect/mobiledetectlib": "^2.8.15",
"symfony/dependency-injection": "^5.0 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^5.0 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0",
"symfony/yaml": "^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^7.0",
"symfony/event-dispatcher": "^7.0",
"symfony/framework-bundle": "^7.0",
"symfony/yaml": "^7.0",
"twig/twig": "^2.0 || ^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4 || ^3.8",
"friendsofphp/php-cs-fixer": "^3.8",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-nette": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^8.5 || ^9.5",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6",
"symfony/dotenv": "^5.0 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^5.0 || ^6.0 || ^7.0"
"symfony/dotenv": "^7.0",
"symfony/phpunit-bridge": "^7.0"
},
"config": {
"sort-packages": true,
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/RequestResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ protected function getRedirectResponse(Request $request, string $view): ?Redirec
*/
protected function prepareResponseModification(string $view): void
{
$this->modifyResponseClosure = function (DeviceView $deviceView, ResponseEvent $event) use ($view) {
$this->modifyResponseClosure = static function (DeviceView $deviceView, ResponseEvent $event) use ($view) {
return $deviceView->modifyResponse($view, $event->getResponse());
};
}
Expand Down
32 changes: 16 additions & 16 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,24 +109,24 @@ 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');
$test = $this;
$this->request->expects(self::any())->method('getQueryString')->willReturnCallback(function () use ($test) {
$this->request->expects(self::any())->method('getQueryString')->willReturnCallback(static function () use ($test) {
$qs = Request::normalizeQueryString($test->request->server->get('QUERY_STRING'));

return '' === $qs ? null : $qs;
});
$this->request->expects(self::any())->method('getUri')->willReturnCallback(function () use ($test) {
$this->request->expects(self::any())->method('getUri')->willReturnCallback(static function () use ($test) {
if (null !== $qs = $test->request->getQueryString()) {
$qs = '?'.$qs;
}

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,24 +172,24 @@ 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');
$test = $this;
$this->request->expects(self::any())->method('getQueryString')->willReturnCallback(function () use ($test) {
$this->request->expects(self::any())->method('getQueryString')->willReturnCallback(static function () use ($test) {
$qs = Request::normalizeQueryString($test->request->server->get('QUERY_STRING'));

return '' === $qs ? null : $qs;
});
$this->request->expects(self::any())->method('getUri')->willReturnCallback(function () use ($test) {
$this->request->expects(self::any())->method('getUri')->willReturnCallback(static function () use ($test) {
if (null !== $qs = $test->request->getQueryString()) {
$qs = '?'.$qs;
}

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,24 +235,24 @@ 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');
$test = $this;
$this->request->expects(self::any())->method('getQueryString')->willReturnCallback(function () use ($test) {
$this->request->expects(self::any())->method('getQueryString')->willReturnCallback(static function () use ($test) {
$qs = Request::normalizeQueryString($test->request->server->get('QUERY_STRING'));

return '' === $qs ? null : $qs;
});
$this->request->expects(self::any())->method('getUri')->willReturnCallback(function () use ($test) {
$this->request->expects(self::any())->method('getUri')->willReturnCallback(static function () use ($test) {
if (null !== $qs = $test->request->getQueryString()) {
$qs = '?'.$qs;
}

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 ed81577

Please sign in to comment.