Skip to content

Commit 608f883

Browse files
authored
Refactor tests (#344)
- Drop dependency on `OrmTestCase` and instead use `DoctrineBundle` for setting orm automatically instead of manually; - ~~Use MockHttpClient from symfony/http-client instead of making real http calls in tests~~ Use mock Client from php-http/mock-client; - Merge CI's phpunit jobs into single one; - Separate inlined fixtures in tests to separate classes;
1 parent 9628346 commit 608f883

35 files changed

+908
-601
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: "PHPStan"
1111
runs-on: ubuntu-latest
1212
env:
13-
php-version: 8.1
13+
php-version: 8.2
1414
steps:
1515
- name: "Setup PHP"
1616
uses: shivammathur/setup-php@v2
@@ -19,11 +19,12 @@ jobs:
1919
tools: flex
2020

2121
- name: "Checkout code"
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323

2424
- name: "Install Composer dependencies"
25-
run: |
26-
composer install --prefer-dist --no-progress --no-interaction --optimize-autoloader
25+
uses: "ramsey/composer-install@v2"
26+
with:
27+
composer-options: "--optimize-autoloader"
2728

2829
- name: "Run PHPStan"
2930
run: |
@@ -34,7 +35,7 @@ jobs:
3435
name: PHP-CS-Fixer
3536
runs-on: ubuntu-latest
3637
env:
37-
php-version: 8.1
38+
php-version: 8.2
3839
steps:
3940
- name: "Setup PHP"
4041
uses: shivammathur/setup-php@v2
@@ -43,11 +44,12 @@ jobs:
4344
tools: flex, cs2pr
4445

4546
- name: "Checkout code"
46-
uses: actions/checkout@v3
47+
uses: actions/checkout@v4
4748

4849
- name: "Install Composer dependencies"
49-
run: |
50-
composer install --prefer-dist --no-progress --no-interaction --optimize-autoloader
50+
uses: "ramsey/composer-install@v2"
51+
with:
52+
composer-options: "--optimize-autoloader"
5153

5254
- name: "Run PHP-CS-Fixer"
5355
run: vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no --format=checkstyle | cs2pr
@@ -59,63 +61,17 @@ jobs:
5961
max-parallel: 10
6062
fail-fast: true
6163
matrix:
62-
strategy: ['default']
64+
dependencies: ['highest']
6365
php: ['7.4', '8.0', '8.1', '8.2']
6466
include:
6567
- php: '7.4'
66-
sf_version: '5.4.*'
67-
strategy: 'lowest'
68-
- php: '8.0'
69-
sf_version: '5.4.*'
70-
- php: '8.1'
71-
sf_version: '5.4.*'
72-
- php: '8.0'
73-
sf_version: '6.0.*'
74-
- php: '8.1'
75-
sf_version: '6.0.*'
76-
- php: '8.2'
77-
sf_version: '6.2.*'
78-
steps:
79-
- name: "Setup PHP"
80-
uses: shivammathur/setup-php@v2
81-
with:
82-
php-version: ${{ matrix.php }}
83-
tools: flex
84-
coverage: none
85-
86-
- name: "Checkout code"
87-
uses: actions/checkout@v3
88-
89-
- name: "Install Composer dependencies (default)"
90-
if: matrix.strategy != 'lowest'
91-
env:
92-
SYMFONY_REQUIRE: ${{ matrix.sf_version }}
93-
run: composer update --no-interaction --optimize-autoloader
94-
95-
- name: "Install Composer dependencies (lowest)"
96-
if: matrix.strategy == 'lowest'
97-
env:
98-
SYMFONY_REQUIRE: ${{ matrix.sf_version }}
99-
run: composer update --no-interaction --prefer-stable --prefer-lowest --optimize-autoloader
100-
101-
- name: "Run tests"
102-
env:
103-
SYMFONY_DEPRECATIONS_HELPER: 'max[self]=2'
104-
run: ./vendor/bin/simple-phpunit -v --testsuite main
105-
106-
doctrine:
107-
name: "PHPUnit (Doctrine)"
108-
runs-on: ubuntu-latest
109-
strategy:
110-
max-parallel: 10
111-
fail-fast: true
112-
matrix:
113-
php: ['7.4', '8.0', '8.1', '8.2']
114-
include:
68+
sf_version: '4.4.*'
69+
dependencies: 'lowest'
11570
- php: '7.4'
11671
sf_version: '4.4.*'
11772
- php: '7.4'
11873
sf_version: '5.4.*'
74+
dependencies: 'lowest'
11975
- php: '8.0'
12076
sf_version: '5.4.*'
12177
- php: '8.1'
@@ -135,14 +91,27 @@ jobs:
13591
coverage: none
13692

13793
- name: "Checkout code"
138-
uses: actions/checkout@v3
94+
uses: actions/checkout@v4
13995

14096
- name: "Install Composer dependencies"
141-
env:
142-
SYMFONY_REQUIRE: ${{ matrix.sf_version }}
143-
run: composer update --prefer-source --no-interaction --optimize-autoloader
97+
uses: "ramsey/composer-install@v2"
98+
with:
99+
composer-options: "--optimize-autoloader"
100+
dependency-versions: "${{ matrix.dependencies }}"
101+
102+
# - name: "Install Composer dependencies (default)"
103+
# if: matrix.strategy != 'lowest'
104+
# env:
105+
# SYMFONY_REQUIRE: ${{ matrix.sf_version }}
106+
# run: composer update --no-interaction --optimize-autoloader
107+
#
108+
# - name: "Install Composer dependencies (lowest)"
109+
# if: matrix.strategy == 'lowest'
110+
# env:
111+
# SYMFONY_REQUIRE: ${{ matrix.sf_version }}
112+
# run: composer update --no-interaction --prefer-stable --prefer-lowest --optimize-autoloader
144113

145114
- name: "Run tests"
146115
env:
147-
SYMFONY_DEPRECATIONS_HELPER: 'max[self]=2'
148-
run: ./vendor/bin/simple-phpunit -v --testsuite doctrine
116+
SYMFONY_DEPRECATIONS_HELPER: 'max[self]=3&max[indirect]=1'
117+
run: ./vendor/bin/simple-phpunit -v

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
return (new PhpCsFixer\Config())
99
->setRules([
1010
'@Symfony' => true,
11+
'no_superfluous_phpdoc_tags' => false,
1112
])
1213
->setFinder($finder)
1314
;

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
"require": {
1414
"php": "^7.4 || ^8.0",
1515
"geocoder-php/plugin": "^1.5",
16+
"php-http/curl-client": "^2.3",
1617
"php-http/discovery": "^1.14",
1718
"symfony/console": "^4.4 || ^5.0 || ^6.0",
1819
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
1920
"symfony/options-resolver": "^4.4 || ^5.0 || ^6.0",
2021
"willdurand/geocoder": "^4.6"
2122
},
2223
"require-dev": {
24+
"doctrine/annotations": "^1.11.1 || ^2.0",
25+
"doctrine/doctrine-bundle": "^2.3",
2326
"doctrine/orm": "~2.8",
2427
"fakerphp/faker": "^1.20",
2528
"friendsofphp/php-cs-fixer": "^3.13",
@@ -56,9 +59,10 @@
5659
"nyholm/nsa": "^1.3",
5760
"nyholm/psr7": "^1.5",
5861
"nyholm/symfony-bundle-test": "dev-master",
59-
"php-http/curl-client": "^2.2",
62+
"php-http/mock-client": "^1.6",
6063
"php-http/message": "^1.13",
6164
"phpstan/phpstan": "^1.9.2",
65+
"psr/http-client": "^1.0",
6266
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
6367
"symfony/config": "^4.4 || ^5.0 || ^6.0",
6468
"symfony/phpunit-bridge": "^5.2 || ^6.0",
@@ -83,7 +87,8 @@
8387
},
8488
"config": {
8589
"allow-plugins": {
86-
"symfony/flex": true
90+
"symfony/flex": true,
91+
"php-http/discovery": false
8792
},
8893
"sort-packages": true
8994
},

doc/doctrine.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ You have to indicate which provider to use to reverse geocode the address. Here
8080
- '@bazinga_geocoder.provider.acme'
8181
- '@Bazinga\GeocoderBundle\Mapping\Driver\AnnotationDriver'
8282
tags:
83-
- doctrine.event_subscriber
83+
- { name: doctrine.event_listener, event: onFlush }
8484
```
8585
8686
It is done!
@@ -131,5 +131,5 @@ Then update your service configuration to register the `AttributeDriver`:
131131
- '@bazinga_geocoder.provider.acme'
132132
- '@Bazinga\GeocoderBundle\Mapping\Driver\AttributeDriver'
133133
tags:
134-
- doctrine.event_subscriber
134+
- { name: doctrine.event_listener, event: onFlush }
135135
```

phpunit.xml.dist

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
<testsuites>
1414
<testsuite name="main">
1515
<directory>./tests</directory>
16-
<exclude>./tests/Doctrine</exclude>
17-
</testsuite>
18-
19-
<testsuite name="doctrine">
20-
<directory>./tests/Doctrine</directory>
2116
</testsuite>
2217
</testsuites>
2318

src/BazingaGeocoderBundle.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
class BazingaGeocoderBundle extends Bundle
2525
{
2626
/**
27-
* {@inheritdoc}
28-
*
2927
* @return void
3028
*/
3129
public function build(ContainerBuilder $container)
@@ -37,9 +35,6 @@ public function build(ContainerBuilder $container)
3735
$container->addCompilerPass(new FactoryValidatorPass());
3836
}
3937

40-
/**
41-
* {@inheritdoc}
42-
*/
4338
public function getPath(): string
4439
{
4540
return \dirname(__DIR__);

src/Command/GeocodeCommand.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public function __construct(ProviderAggregator $geocoder)
3535
}
3636

3737
/**
38-
* {@inheritdoc}
39-
*
4038
* @return void
4139
*/
4240
protected function configure()
@@ -58,8 +56,6 @@ protected function configure()
5856
}
5957

6058
/**
61-
* {@inheritdoc}
62-
*
6359
* @return int
6460
*/
6561
protected function execute(InputInterface $input, OutputInterface $output)

src/DataCollector/GeocoderDataCollector.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function reset()
4545
}
4646

4747
/**
48-
* {@inheritdoc}
49-
*
5048
* @return void
5149
*/
5250
public function collect(Request $request, Response $response, \Throwable $exception = null)
@@ -117,9 +115,6 @@ public function addInstance(ProfilingPlugin $instance)
117115
$this->data['providers'][] = $instance->getName();
118116
}
119117

120-
/**
121-
* {@inheritdoc}
122-
*/
123118
public function getName(): string
124119
{
125120
return 'geocoder';

src/DependencyInjection/Compiler/FactoryValidatorPass.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class FactoryValidatorPass implements CompilerPassInterface
2929
private static $factoryServiceIds = [];
3030

3131
/**
32-
* {@inheritdoc}
33-
*
3432
* @return void
3533
*/
3634
public function process(ContainerBuilder $container)

src/DependencyInjection/Compiler/ProfilerPass.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
class ProfilerPass implements CompilerPassInterface
2626
{
2727
/**
28-
* {@inheritdoc}
29-
*
3028
* @return void
3129
*/
3230
public function process(ContainerBuilder $container)

0 commit comments

Comments
 (0)