Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix test cases + only support php >= 7.1 #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ cache:
- $HOME/.composer/cache/files

php:
- 5.6
- hhvm
- 7.0
- 7.1
- 7.2

dist: trusty

Expand All @@ -20,24 +19,12 @@ matrix:
- php: hhvm
fast_finish: true
include:
- php: 5.6
env: SYMFONY_VERSION='2.8.*'
- php: 5.6
env: SYMFONY_VERSION='3.0.*'
- php: 5.6
env: SYMFONY_VERSION='3.2.*'
- php: 5.6
env: SYMFONY_VERSION='3.3.*'
- php: 7.0
env: SYMFONY_VERSION='2.8.*'
- php: 7.0
env: SYMFONY_VERSION='3.0.*'
- php: 7.0
env: SYMFONY_VERSION='3.2.*'
- php: 7.0
env: SYMFONY_VERSION='3.3.*'
- php: 7.1
env: SYMFONY_VERSION='4.0.*'
- php: 7.2
env: SYMFONY_VERSION='4.0.*'
- php: 7.2
env: SYMFONY_VERSION='5.0.*'

before_install:
- if [[ "$TRAVIS_PHP_VERSION" != "5.6" && "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then phpenv config-rm xdebug.ini; fi
Expand Down
46 changes: 33 additions & 13 deletions Tests/EventListener/RequestResponseListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use SunCat\MobileDetectBundle\Helper\DeviceView;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\ParameterBag;

Expand Down Expand Up @@ -92,6 +92,8 @@ public function setUp()
public function handleRequestHasSwitchParam()
{
$this->request->query = new ParameterBag(array('myparam'=>'myvalue',$this->switchParam => DeviceView::VIEW_MOBILE));
$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/'));

$deviceView = new DeviceView($this->requestStack);
$deviceView->setRedirectConfig([DeviceView::VIEW_MOBILE => ['status_code' => 302]]);
$listener = new RequestResponseListener($this->mobileDetector, $deviceView, $this->router, array());
Expand Down Expand Up @@ -124,6 +126,8 @@ public function handleRequestHasSwitchParamAndQuery()

$this->request->query = new ParameterBag(array('myparam'=>'myvalue',$this->switchParam => DeviceView::VIEW_MOBILE));
$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->exactly(2))->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::REDIRECT, 2)
Expand Down Expand Up @@ -178,7 +182,7 @@ public function handleRequestIsFullView()
$this->assertNull($requestEventResponse);

$responseEventResponse = new Response('Full view', 200);
$filterResponseEvent = $this->createFilterResponseEvent($responseEventResponse);
$filterResponseEvent = $this->createResponseEvent($responseEventResponse);
$listener->handleResponse($filterResponseEvent);
$modifiedResponse = $filterResponseEvent->getResponse();

Expand Down Expand Up @@ -216,7 +220,7 @@ public function handleRequestIsNotMobileView()
$this->assertNull($requestEventResponse);

$responseEventResponse = new Response('Not mobile view', 200);
$filterResponseEvent = $this->createFilterResponseEvent($responseEventResponse);
$filterResponseEvent = $this->createResponseEvent($responseEventResponse);
$listener->handleResponse($filterResponseEvent);
$modifiedResponse = $filterResponseEvent->getResponse();

Expand All @@ -237,6 +241,8 @@ public function handleRequestHasTabletRedirect()

$this->request->query = new ParameterBag(array('some'=>'param'));
$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->exactly(2))->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::REDIRECT, 2)
Expand Down Expand Up @@ -287,6 +293,8 @@ public function handleRequestWithDifferentSwitchParamRedirect()

$this->request->query = new ParameterBag(array('some'=>'param'));
$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->exactly(2))->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::REDIRECT, 2)
Expand Down Expand Up @@ -349,7 +357,7 @@ public function handleDeviceIsTabletAndTabletRedirectIsDisabledAndDetectTabletAs
$this->assertNull($requestEventResponse);

$responseEventResponse = new Response('Tablet view', 200);
$filterResponseEvent = $this->createFilterResponseEvent($responseEventResponse);
$filterResponseEvent = $this->createResponseEvent($responseEventResponse);
$listener->handleResponse($filterResponseEvent);
$modifiedResponse = $filterResponseEvent->getResponse();

Expand Down Expand Up @@ -377,6 +385,8 @@ public function handleDeviceIsTabletAsMobileAndTabletRedirectIsDisabledAndDetect
$this->config['detect_tablet_as_mobile'] = true;

$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->atLeastOnce())->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::REDIRECT, 2)
Expand Down Expand Up @@ -424,6 +434,8 @@ public function handleRequestHasTabletRedirectWithoutPath()
$this->config['tablet'] = array('is_enabled' => true, 'host' => 'http://testsite.com', 'status_code' => 302);

$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->atLeastOnce())->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::REDIRECT_WITHOUT_PATH, 2)
Expand Down Expand Up @@ -472,6 +484,8 @@ public function handleRequestHasTabletNoRedirect()
$this->config['tablet'] = array('is_enabled' => true, 'host' => 'http://testsite.com', 'status_code' => 302);

$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->atLeastOnce())->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::NO_REDIRECT, 1)
Expand All @@ -493,7 +507,7 @@ public function handleRequestHasTabletNoRedirect()
$this->assertNull($requestEventResponse);

$responseEventResponse = new Response('Tablet view no redirect', 200);
$filterResponseEvent = $this->createFilterResponseEvent($responseEventResponse);
$filterResponseEvent = $this->createResponseEvent($responseEventResponse);
$listener->handleResponse($filterResponseEvent);
$modifiedResponse = $filterResponseEvent->getResponse();

Expand All @@ -520,6 +534,8 @@ public function handleRequestHasMobileRedirect()
$this->config['mobile'] = array('is_enabled' => true, 'host' => 'http://testsite.com', 'status_code' => 302);

$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->atLeastOnce())->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::REDIRECT, 2)
Expand Down Expand Up @@ -568,6 +584,8 @@ public function handleRequestHasMobileRedirectWithoutPath()
$this->config['mobile'] = array('is_enabled' => true, 'host' => 'http://testsite.com', 'status_code' => 302);

$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->atLeastOnce())->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::REDIRECT_WITHOUT_PATH, 2)
Expand Down Expand Up @@ -616,6 +634,8 @@ public function handleRequestHasMobileNoRedirect()
$this->config['mobile'] = array('is_enabled' => true, 'host' => 'http://testsite.com', 'status_code' => 123);

$this->request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/some/parameters'));
$this->request->expects($this->any())->method('get')->will($this->returnValue('routeName'));

$this->router->expects($this->atLeastOnce())->method('getRouteCollection')->will(
$this->returnValue(
$this->createRouteCollecitonWithRouteAndRoutingOption(RequestResponseListener::NO_REDIRECT, 1)
Expand All @@ -638,7 +658,7 @@ public function handleRequestHasMobileNoRedirect()
$this->assertNull($requestEventResponse);

$responseEventResponse = new Response('Mobile view no redirect', 200);
$filterResponseEvent = $this->createFilterResponseEvent($responseEventResponse);
$filterResponseEvent = $this->createResponseEvent($responseEventResponse);
$listener->handleResponse($filterResponseEvent);
$modifiedResponse = $filterResponseEvent->getResponse();

Expand Down Expand Up @@ -696,11 +716,11 @@ private function createRouteCollecitonWithRouteAndRoutingOption($returnValue, $t
* @param string $method Method
* @param array $headers Headers
*
* @return \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent
* @return \Symfony\Component\HttpKernel\Event\ViewEvent
*/
private function createGetResponseEvent($content, $method = 'GET', $headers = array())
{
$event = new GetResponseForControllerResultEvent(
$event = new ViewEvent(
$this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'),
$this->request,
HttpKernelInterface::MASTER_REQUEST,
Expand All @@ -712,17 +732,17 @@ private function createGetResponseEvent($content, $method = 'GET', $headers = ar
}

/**
* createFilterResponseEvent
* createResponseEvent
*
* @param Response $response
* @param string $method Method
* @param array $headers Headers
*
* @return \Symfony\Component\HttpKernel\Event\FilterResponseEvent
* @return \Symfony\Component\HttpKernel\Event\ResponseEvent
*/
private function createFilterResponseEvent($response, $method = 'GET', $headers = array())
private function createResponseEvent($response, $method = 'GET', $headers = array())
{
$event = new FilterResponseEvent(
$event = new ResponseEvent(
$this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'),
$this->request,
HttpKernelInterface::MASTER_REQUEST,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Twig/Extension/MobileDetectExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getFunctionsArray()
'device_version' => 'deviceVersion'
];
foreach ($functions as $function) {
$this->assertInstanceOf('\Twig_SimpleFunction', $function);
$this->assertInstanceOf(\Twig\TwigFunction::class, $function);
$name = $function->getName();
$callable = $function->getCallable();
$this->assertArrayHasKey($name, $names);
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "suncat/mobile-detect-bundle",
"description": "Symfony2/3/4 bundle for detect mobile devices, managing mobile view types, redirect to mobile version.",
"description": "Symfony4/5 bundle for detect mobile devices, managing mobile view types, redirect to mobile version.",
"keywords": ["mobile", "mobile detect", "symfony mobile", "mobile view managing", "mobile redirect"],
"homepage": "https://github.com/suncat2000/MobileDetectBundle",
"type": "symfony-bundle",
Expand All @@ -20,10 +20,10 @@
}
],
"require": {
"php": ">=5.5.9",
"symfony/framework-bundle": "~2.7|~3.3|~4.0|~5.0",
"php": ">=7.1",
"symfony/framework-bundle": "^4.0|^5.0",
"mobiledetect/mobiledetectlib": "~2.8",
"twig/twig": "~1.26|~2.0||^3.0"
"twig/twig": "^1.26|^2.0|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35|^5.4.3|^6.0",
Expand Down