Skip to content

Commit a726803

Browse files
norkunasNyholm
authored andcommitted
Fix tests and deprecations (#266)
1 parent 3260b6b commit a726803

File tree

15 files changed

+134
-66
lines changed

15 files changed

+134
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ composer.phar
33
phpunit.xml
44
vendor/
55
.php_cs.cache
6+
.phpunit.result.cache

.travis.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,31 @@ env:
1414
matrix:
1515
fast_finish: true
1616
include:
17-
# Minimum supported dependencies with the latest and oldest PHP version
18-
- php: 7.2
19-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
17+
# Minimum supported dependencies with the oldest PHP version
2018
- php: 7.1
21-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
19+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_PHPUNIT_VERSION=7.5
2220

2321
# Test the latest stable release
2422
- php: 7.1
2523
- php: 7.2
2624
- php: 7.3
25+
- php: 7.4
2726
env: COVERAGE=true PHPUNIT_FLAGS="-v --testsuite main --coverage-text --coverage-clover=build/coverage.xml"
2827

2928
- php: 7.1
3029
# We need `--prefer-source`, otherwise the `Doctrine\Tests\OrmTestCase` class won't be found.
31-
env: PHPUNIT_FLAGS="-v --testsuite doctrine" COMPOSER_FLAGS="--prefer-source" DEPENDENCIES="dunglas/symfony-lock:^3"
32-
- php: 7.2
33-
env: DEPENDENCIES="dunglas/symfony-lock:^3"
34-
- php: 7.2
35-
env: DEPENDENCIES="dunglas/symfony-lock:^4"
30+
env: PHPUNIT_FLAGS="-v --testsuite doctrine" COMPOSER_FLAGS="--prefer-source" SYMFONY_VERSION=3.4.* SYMFONY_PHPUNIT_VERSION=7.5
31+
- php: 7.4
32+
env: SYMFONY_VERSION=3.4.*
33+
- php: 7.4
34+
env: SYMFONY_VERSION=4.3.*
35+
- php: 7.4
36+
env: SYMFONY_VERSION=4.4.*
37+
- php: 7.4
38+
env: SYMFONY_VERSION=5.0.*
3639

3740
# Latest commit to master
38-
- php: 7.2
41+
- php: 7.4
3942
env: STABILITY="dev"
4043

4144
allow_failures:
@@ -45,7 +48,7 @@ matrix:
4548
before_install:
4649
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
4750
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
48-
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
51+
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
4952

5053
install:
5154
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction

Command/GeocodeCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
9292
is_array($value) ? json_encode($value) : $value
9393
));
9494
}
95+
96+
return 0;
9597
}
9698

9799
private function humanize(string $text): string
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the BazingaGeocoderBundle package.
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @license MIT License
9+
*/
10+
11+
namespace Bazinga\GeocoderBundle\DataCollector;
12+
13+
use Bazinga\GeocoderBundle\Plugin\ProfilingPlugin;
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\HttpKernel\Kernel;
17+
18+
if (Kernel::VERSION_ID >= 40308) {
19+
trait DataCollectorSymfonyCompatibilityTrait
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function collect(Request $request, Response $response, \Throwable $exception = null)
25+
{
26+
if (!empty($this->data['queries'])) {
27+
// To avoid collection more that once.
28+
return;
29+
}
30+
31+
/** @var ProfilingPlugin[] $instances */
32+
$instances = $this->instances;
33+
34+
foreach ($instances as $instance) {
35+
foreach ($instance->getQueries() as $query) {
36+
$query['query'] = $this->cloneVar($query['query']);
37+
$query['result'] = $this->cloneVar($query['result']);
38+
$this->data['queries'][] = $query;
39+
}
40+
}
41+
}
42+
}
43+
} else {
44+
trait DataCollectorSymfonyCompatibilityTrait
45+
{
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function collect(Request $request, Response $response, \Exception $exception = null)
50+
{
51+
if (!empty($this->data['queries'])) {
52+
// To avoid collection more that once.
53+
return;
54+
}
55+
56+
/** @var ProfilingPlugin[] $instances */
57+
$instances = $this->instances;
58+
59+
foreach ($instances as $instance) {
60+
foreach ($instance->getQueries() as $query) {
61+
$query['query'] = $this->cloneVar($query['query']);
62+
$query['result'] = $this->cloneVar($query['result']);
63+
$this->data['queries'][] = $query;
64+
}
65+
}
66+
}
67+
}
68+
}

DataCollector/GeocoderDataCollector.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
namespace Bazinga\GeocoderBundle\DataCollector;
1414

1515
use Bazinga\GeocoderBundle\Plugin\ProfilingPlugin;
16-
use Symfony\Component\HttpFoundation\Request;
17-
use Symfony\Component\HttpFoundation\Response;
1816
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
1917

2018
/**
2119
* @author Michal Dabrowski <[email protected]>
2220
*/
2321
class GeocoderDataCollector extends DataCollector
2422
{
23+
use DataCollectorSymfonyCompatibilityTrait;
24+
2525
/**
2626
* @var ProfilingPlugin[]
2727
*/
@@ -43,24 +43,6 @@ public function reset()
4343
$this->data['providers'] = [];
4444
}
4545

46-
/**
47-
* {@inheritdoc}
48-
*/
49-
public function collect(Request $request, Response $response, \Exception $exception = null)
50-
{
51-
if (!empty($this->data['queries'])) {
52-
// To avoid collection more that once.
53-
return;
54-
}
55-
foreach ($this->instances as $instance) {
56-
foreach ($instance->getQueries() as $query) {
57-
$query['query'] = $this->cloneVar($query['query']);
58-
$query['result'] = $this->cloneVar($query['result']);
59-
$this->data['queries'][] = $query;
60-
}
61-
}
62-
}
63-
6446
/**
6547
* Returns an array of collected requests.
6648
*/

Resources/config/services.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ services:
2525

2626
Bazinga\GeocoderBundle\Command\GeocodeCommand:
2727
arguments: ['@Geocoder\ProviderAggregator']
28-
tags: [{ name: 'console.command' }]
28+
tags: ['console.command']
2929

3030
Bazinga\GeocoderBundle\Validator\Constraint\AddressValidator:
3131
arguments: ['@geocoder']
32-
tags:
33-
- { name: 'validator.constraint_validator' }
32+
tags: ['validator.constraint_validator']
3433

3534
# Keep these aliases for BC purpose
3635
bazinga_geocoder.geocoder:

Tests/Command/GeocodeCommandTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use PHPUnit\Framework\TestCase;
2323
use Symfony\Bundle\FrameworkBundle\Console\Application;
2424
use Symfony\Component\Console\Tester\CommandTester;
25+
use Symfony\Component\DependencyInjection\Container;
26+
use Symfony\Component\HttpKernel\Kernel;
2527

2628
/**
2729
* @author Markus Bachmann <[email protected]>
@@ -44,26 +46,24 @@ public function testExecute()
4446
'countryCode' => $country->getCode(),
4547
]);
4648

47-
$geocoder = $this->getMockBuilder(ProviderAggregator::class)->getMock();
49+
$geocoder = $this->createMock(ProviderAggregator::class);
4850
$query = GeocodeQuery::create(self::$address);
4951
$geocoder->expects($this->once())
5052
->method('geocodeQuery')
5153
->with($query)
52-
->will($this->returnValue(new AddressCollection([$address])));
54+
->willReturn(new AddressCollection([$address]));
5355

54-
$container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->getMock();
56+
$container = $this->createMock(Container::class);
5557

56-
$kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
57-
->disableOriginalConstructor()
58-
->getMock();
58+
$kernel = $this->createMock(Kernel::class);
5959

6060
$kernel->expects($this->any())
6161
->method('getContainer')
6262
->will($this->returnValue($container));
6363

6464
$kernel->expects($this->any())
6565
->method('getBundles')
66-
->will($this->returnValue([]));
66+
->willReturn([]);
6767

6868
$app = new Application($kernel);
6969
$app->add(new GeocodeCommand($geocoder));

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testGetConfigTreeBuilder()
3434

3535
$this->assertTrue($config['profiling']['enabled']);
3636
$this->assertTrue($config['fake_ip']['enabled']);
37-
$this->assertEquals('33.33.33.11', $config['fake_ip']['ip']);
37+
$this->assertSame('33.33.33.11', $config['fake_ip']['ip']);
3838
}
3939

4040
public function testGetConfigTreeBuilderNoDebug()

Tests/Doctrine/ORM/GeocoderListenerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
use Doctrine\Tests\OrmTestCase;
2424
use Geocoder\Provider\Nominatim\Nominatim;
2525
use Http\Client\Curl\Client;
26+
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
2627

2728
/**
2829
* @author Markus Bachmann <[email protected]>
2930
*/
3031
class GeocoderListenerTest extends OrmTestCase
3132
{
33+
use SetUpTearDownTrait;
34+
3235
/**
3336
* @var EntityManager
3437
*/
@@ -39,7 +42,7 @@ class GeocoderListenerTest extends OrmTestCase
3942
*/
4043
private $listener;
4144

42-
public static function setUpBeforeClass()
45+
public static function doSetUpBeforeClass(): void
4346
{
4447
if (!class_exists(DoctrineTestCase::class)) {
4548
/*
@@ -48,10 +51,9 @@ public static function setUpBeforeClass()
4851
*/
4952
static::fail('Doctrine\Tests\OrmTestCase was not found.');
5053
}
51-
parent::setUpBeforeClass();
5254
}
5355

54-
protected function setUp()
56+
protected function doSetUp(): void
5557
{
5658
AnnotationRegistry::registerLoader('class_exists');
5759

Tests/Functional/BundleInitializationTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
use Nyholm\BundleTest\BaseBundleTestCase;
2828
use Nyholm\BundleTest\CompilerPass\PublicServicePass;
2929
use Nyholm\NSA;
30+
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
3031

3132
class BundleInitializationTest extends BaseBundleTestCase
3233
{
33-
protected function setUp()
34+
use SetUpTearDownTrait;
35+
36+
protected function doSetUp(): void
3437
{
35-
parent::setUp();
3638
$this->addCompilerPass(new PublicServicePass('|[Bb]azinga:*|'));
3739
$this->addCompilerPass(new PublicServicePass('|[gG]eocoder:*|'));
3840
}
@@ -50,9 +52,9 @@ public function testInitBundle()
5052
// Get the container
5153
$container = $this->getContainer();
5254

53-
// Test if you services exists
54-
$this->assertTrue($container->has('Geocoder\ProviderAggregator'));
55-
$service = $container->get('Geocoder\ProviderAggregator');
55+
// Test if services exists
56+
$this->assertTrue($container->has(ProviderAggregator::class));
57+
$service = $container->get(ProviderAggregator::class);
5658
$this->assertInstanceOf(ProviderAggregator::class, $service);
5759
}
5860

0 commit comments

Comments
 (0)