diff --git a/.travis.yml b/.travis.yml index 35e7dd6..29555d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,9 @@ cache: - $HOME/.composer/cache/files php: - - 5.6 - hhvm - - 7.0 - 7.1 + - 7.2 dist: trusty @@ -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 diff --git a/Tests/EventListener/RequestResponseListenerTest.php b/Tests/EventListener/RequestResponseListenerTest.php index 3426446..3bf9559 100644 --- a/Tests/EventListener/RequestResponseListenerTest.php +++ b/Tests/EventListener/RequestResponseListenerTest.php @@ -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; @@ -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()); @@ -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) @@ -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(); @@ -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(); @@ -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) @@ -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) @@ -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(); @@ -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) @@ -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) @@ -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) @@ -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(); @@ -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) @@ -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) @@ -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) @@ -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(); @@ -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, @@ -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, diff --git a/Tests/Twig/Extension/MobileDetectExtensionTest.php b/Tests/Twig/Extension/MobileDetectExtensionTest.php index 2915ee9..eb92d7b 100644 --- a/Tests/Twig/Extension/MobileDetectExtensionTest.php +++ b/Tests/Twig/Extension/MobileDetectExtensionTest.php @@ -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); diff --git a/composer.json b/composer.json index 19b2f69..7fa8e14 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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",