Skip to content

Commit

Permalink
Don't use the deprecated interface with Symfony 4.2 (#208)
Browse files Browse the repository at this point in the history
* Update PHPUnit version (namespaced classes), remove hhvm from Travis build matrix

* Don't use the deprecated interface with Symfony 4.2
  • Loading branch information
hacfi authored and dbu committed Jan 5, 2019
1 parent 1f5ee7f commit ee0aad1
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 92 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cache:
directories:
- $HOME/.composer/cache/files

env: SYMFONY_VERSION='3.3.*' SYMFONY_PHPUNIT_VERSION=5.5
env: SYMFONY_VERSION='3.3.*'

matrix:
include:
Expand All @@ -21,7 +21,6 @@ matrix:
- COMPOSER_FLAGS="--prefer-lowest"
- SYMFONY_VERSION='2.8.*'
- php: 7.1
env:
env:
- SYMFONY_VERSION='2.8.*'
- php: 7.1
Expand All @@ -38,9 +37,10 @@ matrix:
- SYMFONY_VERSION='3.4.*@BETA'
- php: 7.1
env:
- SYMFONY_VERSION='4.0.*@BETA'
- php: hhvm
dist: trusty
- SYMFONY_VERSION='4.0.*'
- php: 7.2
env:
- SYMFONY_VERSION='4.1.*'

before_install:
- phpenv config-rm xdebug.ini || true
Expand Down
9 changes: 7 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('lunetics_locale');
$treeBuilder = new TreeBuilder('lunetics_locale');

if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
$rootNode = $treeBuilder->root('lunetics_locale');
}

$validStatuscodes = array(300, 301, 302, 303, 307);

Expand Down
25 changes: 15 additions & 10 deletions Tests/Controller/LocaleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,34 @@
*/
namespace Lunetics\LocaleBundle\Tests\Controller;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;

use Lunetics\LocaleBundle\Controller\LocaleController;

class LocaleControllerTest extends \PHPUnit_Framework_TestCase
class LocaleControllerTest extends TestCase
{
public function testControllerThrowsException()
{
$metaValidatorMock = $this->getMetaValidatorMock(false);
$metaValidatorMock->expects($this->atLeastOnce())
->method('isAllowed')
->with($this->anything())
->will($this->returnCallback(function ($v) {
return $v === 'de';
}));
->method('isAllowed')
->with($this->anything())
->will(
$this->returnCallback(
function ($v) {
return $v === 'de';
}
)
);

$request = $this->getRequestWithBrowserPreferences();
$request->setLocale('en');
$localeController = new LocaleController($this->getRouterMock(), $metaValidatorMock);

$this->setExpectedException('\InvalidArgumentException');
$this->expectException('\InvalidArgumentException');
$localeController->switchAction($request);
}

Expand Down Expand Up @@ -97,9 +102,9 @@ private function getRouterMock()
{
$routerMock = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->disableOriginalConstructor()->getMock();
$routerMock->expects($this->any())
->method('generate')
->with($this->equalTo('fallback_route'), $this->anything())
->will($this->returnValue('http://fallback_route.com/'));
->method('generate')
->with($this->equalTo('fallback_route'), $this->anything())
->will($this->returnValue('http://fallback_route.com/'));

return $routerMock;
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/Cookie/LocaleCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
namespace Lunetics\LocaleBundle\Tests\DependencyInjection;

use Lunetics\LocaleBundle\Cookie\LocaleCookie;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Cookie;

class LocaleCookieTest extends \PHPUnit_Framework_TestCase
class LocaleCookieTest extends TestCase
{
public function testCookieParamsAreSet()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
namespace Lunetics\LocaleBundle\Tests\DependencyInjection\Compiler;

use Lunetics\LocaleBundle\DependencyInjection\Compiler\GuesserCompilerPass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author Kevin Archer <[email protected]>
*/
class GuesserCompilerPassTest extends \PHPUnit_Framework_TestCase
class GuesserCompilerPassTest extends TestCase
{
public function testProcess()
{
Expand Down
15 changes: 8 additions & 7 deletions Tests/DependencyInjection/Compiler/RemoveSessionPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@
*/
namespace Lunetics\LocaleBundle\Tests\DependencyInjection\Compiler;

use Lunetics\LocaleBundle\DependencyInjection\Compiler\GuesserCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Lunetics\LocaleBundle\DependencyInjection\Compiler\RemoveSessionPass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author Asmir Mustafic <[email protected]>
*/
class RemoveSessionPassTest extends \PHPUnit_Framework_TestCase
class RemoveSessionPassTest extends TestCase
{
/**
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
private function getContainer(){
private function getContainer()
{
$container = new ContainerBuilder();

$container->register('lunetics_locale.session_guesser');
$container->register('lunetics_locale.locale_session');

return $container;
}

public function testSessionPresent()
{
$container = $this->getContainer();
Expand All @@ -39,8 +41,8 @@ public function testSessionPresent()

$this->assertTrue($container->hasDefinition('lunetics_locale.session_guesser'));
$this->assertTrue($container->hasDefinition('lunetics_locale.locale_session'));

}

public function testSessioAbsent()
{
$container = $this->getContainer();
Expand All @@ -49,7 +51,6 @@ public function testSessioAbsent()

$this->assertFalse($container->hasDefinition('lunetics_locale.session_guesser'));
$this->assertFalse($container->hasDefinition('lunetics_locale.locale_session'));

}

protected function process(ContainerBuilder $container)
Expand Down
12 changes: 5 additions & 7 deletions Tests/DependencyInjection/LuneticsLocaleExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
*/
namespace Lunetics\LocaleBundle\Tests\DependencyInjection;

use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Lunetics\LocaleBundle\DependencyInjection\LuneticsLocaleExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Parser;

/**
* @author Kevin Archer <[email protected]>
*/
class LuneticsLocaleExtensionTest extends \PHPUnit_Framework_TestCase
class LuneticsLocaleExtensionTest extends TestCase
{
/**
* @dataProvider getFullConfig
Expand Down Expand Up @@ -87,7 +86,6 @@ public function testBindParameters()

public function getFullConfig()
{

$parser = new Parser();
$data = array();

Expand All @@ -114,7 +112,7 @@ public function getFullConfig()
dutchversion.be: nl_BE
dutch-version.be: nl_BE
EOF;
$data[]=array($parser->parse($yaml), false);
$data[] = array($parser->parse($yaml), false);

$yaml = <<<EOF
lunetics_locale:
Expand All @@ -140,7 +138,7 @@ public function getFullConfig()
dutchversion.be: nl_BE
dutch-version.be: nl_BE
EOF;
$data[]=array($parser->parse($yaml), true);
$data[] = array($parser->parse($yaml), true);

return $data;
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/Event/FilterLocaleSwitchEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
namespace Lunetics\LocaleBundle\Tests\Event;

use Lunetics\LocaleBundle\Event\FilterLocaleSwitchEvent;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;

class FilterLocaleSwitchEventTest extends \PHPUnit_Framework_TestCase
class FilterLocaleSwitchEventTest extends TestCase
{
public function testFilterLocaleSwitchEvent()
{
Expand All @@ -29,7 +30,7 @@ public function testFilterLocaleSwitchEvent()
*/
public function testThrowsInvalidTypeException($locale)
{
$this->setExpectedException('\InvalidArgumentException');
$this->expectException('\InvalidArgumentException');
new FilterLocaleSwitchEvent(Request::create('/'), $locale);
}

Expand Down
31 changes: 10 additions & 21 deletions Tests/EventListener/LocaleListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@

namespace Lunetics\LocaleBundle\Tests\EventListener;

use Lunetics\LocaleBundle\LocaleGuesser\LocaleGuesserInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;

use Lunetics\LocaleBundle\EventListener\LocaleListener;
use Lunetics\LocaleBundle\LocaleBundleEvents;
use Lunetics\LocaleBundle\LocaleGuesser\LocaleGuesserManager;
use Lunetics\LocaleBundle\LocaleGuesser\RouterLocaleGuesser;
use Lunetics\LocaleBundle\LocaleGuesser\BrowserLocaleGuesser;
use Lunetics\LocaleBundle\LocaleGuesser\CookieLocaleGuesser;
use Lunetics\LocaleBundle\LocaleGuesser\QueryLocaleGuesser;
use Lunetics\LocaleBundle\Validator\MetaValidator;
use Lunetics\LocaleBundle\LocaleBundleEvents;
use Symfony\Component\HttpKernel\KernelEvents;
use Lunetics\LocaleBundle\Matcher\DefaultBestLocaleMatcher;
use Lunetics\LocaleBundle\LocaleInformation\AllowedLocalesProvider;
use Lunetics\LocaleBundle\Matcher\DefaultBestLocaleMatcher;
use Lunetics\LocaleBundle\Validator\MetaValidator;

class LocaleListenerTest extends \PHPUnit_Framework_TestCase
class LocaleListenerTest extends TestCase
{
public function testDefaultLocaleWithoutParams()
{
Expand All @@ -45,6 +45,7 @@ public function testDefaultLocaleWithoutParams()
$listener->onKernelRequest($event);
$this->assertEquals('fr', $request->getLocale());
}

public function getTestDataForBestLocaleMatcher()
{
return array(
Expand Down Expand Up @@ -227,7 +228,8 @@ public function testOnLocaleDetectedSetVaryHeader()
$listener->onLocaleDetectedSetVaryHeader($filterResponseEvent);
}

public function testOnLocaleDetectedDisabledVaryHeader () {
public function testOnLocaleDetectedDisabledVaryHeader()
{
$listener = $this->getListener();
$listener->setDisableVaryHeader(true);

Expand Down Expand Up @@ -360,14 +362,6 @@ private function getMockGuesserManager()
return $this->createMock(LocaleGuesserManager::class);
}

/**
* @return LocaleGuesserInterface
*/
private function getMockGuesser()
{
return $this->createMock(LocaleGuesserInterface::class);
}

/**
* @return MetaValidator
*/
Expand Down Expand Up @@ -408,11 +402,6 @@ private function getEmptyRequest()
return $request;
}

private function getMockRequest()
{
return $this->createMock(Request::class);
}

private function getMockResponse()
{
return $this->createMock(Response::class);
Expand Down
13 changes: 7 additions & 6 deletions Tests/EventListener/LocaleUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@

namespace Lunetics\LocaleBundle\Tests\EventListener;

use Lunetics\LocaleBundle\LocaleBundleEvents;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response;

use Lunetics\LocaleBundle\Cookie\LocaleCookie;
use Lunetics\LocaleBundle\Event\FilterLocaleSwitchEvent;
use Lunetics\LocaleBundle\EventListener\LocaleUpdateListener;
use Lunetics\LocaleBundle\LocaleBundleEvents;
use Lunetics\LocaleBundle\Session\LocaleSession;
use Lunetics\LocaleBundle\Cookie\LocaleCookie;

class LocaleUpdateTest extends \PHPUnit_Framework_TestCase
class LocaleUpdateTest extends TestCase
{
/**
* @var EventDispatcher
Expand Down
3 changes: 2 additions & 1 deletion Tests/Form/Extension/ChoiceList/LocaleChoiceListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
namespace Lunetics\LocaleBundle\Tests\Form\Extension\ChoiceList;

use Lunetics\LocaleBundle\Form\Extension\ChoiceList\LocaleChoiceList;
use PHPUnit\Framework\TestCase;

/**
* Test for the LocaleInformation
*
* @author Matthias Breddin <[email protected]>
*/
class LocaleChoiceListTest extends \PHPUnit_Framework_TestCase
class LocaleChoiceListTest extends TestCase
{

public function testDefaultChoiceList()
Expand Down
3 changes: 2 additions & 1 deletion Tests/Form/Extension/Type/LocaleTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

use Lunetics\LocaleBundle\Form\Extension\ChoiceList\LocaleChoiceList;
use Lunetics\LocaleBundle\Form\Extension\Type\LocaleType;
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Kevin Archer <[email protected]>
*/
class LocaleTypeTest extends \PHPUnit_Framework_TestCase
class LocaleTypeTest extends TestCase
{
public function testConfigureOptions()
{
Expand Down
Loading

0 comments on commit ee0aad1

Please sign in to comment.