Skip to content

Commit a250bc1

Browse files
committed
chore(behat): make phpstan & behat tests working
1 parent e201928 commit a250bc1

File tree

9 files changed

+99
-124
lines changed

9 files changed

+99
-124
lines changed

.github/workflows/behat.yml

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ jobs:
2929
php: [ 8.3, 8.5 ]
3030
symfony: [ 6.4.*, 7.4.* ]
3131
deps: [ highest, lowest ]
32-
env:
33-
DATABASE_URL: 'sqlite:///%kernel.project_dir%/var/data.db'
34-
USE_DAMA_DOCTRINE_TEST_BUNDLE: 1
35-
USE_PHP_84_LAZY_OBJECTS: 1
36-
MONGO_URL: ''
3732
steps:
3833
- name: Checkout code
3934
uses: actions/checkout@v3
@@ -81,3 +76,70 @@ jobs:
8176

8277
- name: Reset DB disabled
8378
run: vendor/bin/behat --colors -vvv --profile=reset-disabled
79+
80+
phpunit:
81+
name: P:${{ matrix.php }}, S:${{ matrix.symfony }}${{ matrix.deps == 'lowest' && ' (lowest)' || '' }}
82+
runs-on: ubuntu-latest
83+
strategy:
84+
fail-fast: false
85+
matrix:
86+
php: [ 8.3, 8.5 ]
87+
symfony: [ 6.4.*, 7.4.* ]
88+
deps: [ highest, lowest ]
89+
steps:
90+
- name: Checkout code
91+
uses: actions/checkout@v3
92+
93+
- name: Setup PHP
94+
uses: shivammathur/setup-php@v2
95+
with:
96+
php-version: ${{ matrix.php }}
97+
coverage: none
98+
tools: flex
99+
100+
- name: Add the polyfill compatible with Doctrine ^2.16
101+
if: ${{ matrix.deps == 'lowest' }}
102+
run: composer require --dev symfony/polyfill-php80:^1.16 --no-update
103+
104+
- name: Install dependencies
105+
uses: ramsey/composer-install@v2
106+
with:
107+
working-directory: "src/Test/Behat"
108+
dependency-versions: ${{ matrix.deps }}
109+
composer-options: --prefer-dist
110+
env:
111+
SYMFONY_REQUIRE: ${{ matrix.symfony }}
112+
113+
- name: Run tests
114+
run: vendor/bin/phpunit
115+
116+
phpstan:
117+
name: PhpStan
118+
runs-on: ubuntu-latest
119+
steps:
120+
- name: Checkout code
121+
uses: actions/checkout@v3
122+
123+
- name: Setup PHP
124+
uses: shivammathur/setup-php@v2
125+
with:
126+
php-version: 8.5
127+
coverage: none
128+
tools: flex
129+
130+
- name: Install dependencies
131+
uses: ramsey/composer-install@v2
132+
with:
133+
working-directory: "src/Test/Behat"
134+
composer-options: --prefer-dist
135+
env:
136+
SYMFONY_REQUIRE: 7.4.*
137+
138+
- name: Install PHPStan
139+
run: composer bin phpstan install
140+
141+
- name: Install PHPBench & Behat
142+
run: composer bin phpbench install
143+
144+
- name: Run PHPStan
145+
run: bin/tools/phpstan/vendor/phpstan/phpstan/phpstan analyse

bin/tools/behat/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin/tools/behat/composer.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

bin/tools/behat/symfony.lock

Lines changed: 0 additions & 49 deletions
This file was deleted.

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@
103103
}
104104
},
105105
"scripts": {
106-
"post-install-cmd": ["@composer bin phpstan install", "@composer bin phpbench install", "@composer bin behat install"]
106+
"post-install-cmd": [
107+
"@composer bin phpstan install",
108+
"@composer bin phpbench install",
109+
"@composer update --working-dir=src/Test/Behat"
110+
],
111+
"post-update-cmd": [
112+
"@composer run-script post-install-cmd"
113+
]
107114
},
108115
"minimum-stability": "dev",
109116
"prefer-stable": true

phpunit-10.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
defaultTestSuite="main">
1212
<php>
1313
<ini name="error_reporting" value="-1"/>
14-
<server name="KERNEL_CLASS" value="Zenstruck\Foundry\Test\Behat\Tests\Fixture\BehatTestKernel"/>
14+
<server name="KERNEL_CLASS" value="Zenstruck\Foundry\Tests\Fixture\TestKernel"/>
1515
<server name="SHELL_VERBOSITY" value="-1"/>
1616
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
1717
<env name="APP_ENV" value="test"/>

src/Test/Behat/bin/console

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use Symfony\Bundle\FrameworkBundle\Console\Application;
5+
use Zenstruck\Foundry\Test\Behat\Tests\Fixture\BehatTestKernel;
6+
7+
require_once __DIR__ . '/../tests/bootstrap.php';
8+
9+
foreach ($argv ?? [] as $i => $arg) {
10+
if (($arg === '--env' || $arg === '-e') && isset($argv[$i + 1])) {
11+
$_ENV['APP_ENV'] = $argv[$i + 1];
12+
break;
13+
}
14+
}
15+
16+
$application = new Application(new BehatTestKernel($_ENV['APP_ENV'], true));
17+
18+
$application->run();

src/Test/Behat/phpstan.neon

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,24 @@ parameters:
1010
checkMissingCallableSignature: true
1111

1212
paths:
13-
- config?
14-
- src
15-
- tests
13+
- ./config
14+
- ./src
15+
- ./tests
1616

1717
banned_code:
1818
non_ignorable: false
1919

2020
bootstrapFiles:
21-
- bin/tools/phpbench/vendor/autoload.php
21+
- ./vendor/autoload.php
2222

2323
ignoreErrors:
24-
# suppress strange behavior of PHPStan where it considers proxy() return type as *NEVER*
25-
- message: '#Return type of call to function Zenstruck\\Foundry\\Persistence\\proxy contains unresolvable type#'
26-
path: src/Persistence/ProxyRepositoryDecorator.php
27-
2824
# prevent PHPStan to force to type data providers
2925
- identifier: missingType.iterableValue
3026
path: tests/
3127

32-
# PHPStan does not understand PHP version checks
33-
- message: '#Comparison operation "(<|>|<=|>=)" between int<80\d+, 80\d+> and 80\d+ is always (false|true).#'
34-
35-
# Hydrator and Factory are annotated @immutable
36-
- identifier: property.readOnlyByPhpDocDefaultValue
37-
paths:
38-
- src/Object/Hydrator.php
39-
- src/Factory.php
40-
- src/ObjectFactory.php
41-
- src/Persistence/PersistentObjectFactory.php
42-
43-
# Hydrator and Factory are annotated @immutable
44-
- identifier: property.readOnlyByPhpDocAssignNotInConstructor
45-
paths:
46-
- src/Object/Hydrator.php
47-
- src/Factory.php
48-
- src/ObjectFactory.php
49-
- src/Persistence/PersistentObjectFactory.php
50-
51-
# generics annotation are not so helpful in maker code
52-
- identifier: missingType.generics
53-
path: src/Maker/Factory/
54-
55-
# not relevant for factories generated by maker
56-
- identifier: missingType.callable
57-
path: tests/Fixture/Maker/expected/
58-
5928
# not relevant for files outside from Foundry's namespace
6029
- identifier: classConstant.internalClass
6130
path: config/
62-
- identifier: function.internal
63-
path: tests/bootstrap-reset-database.php
6431

6532
excludePaths:
6633
- config/reference.php (?)
67-
68-
- tests/Fixture/Maker/expected/can_create_factory_with_auto_activated_not_persisted_option.php
69-
- tests/Fixture/Maker/expected/can_create_factory_interactively.php
70-
- tests/Fixture/Maker/expected/can_create_factory_with_embeddable_with_data_set_odm.php
71-
- tests/Fixture/Maker/expected/can_create_factory_with_embeddable_with_data_set_orm.php
72-
73-
# phpstan runs with orm 3 - there are too many failures in these files which are compatible with orm 2
74-
- ./src/Maker/Factory/LegacyORMDefaultPropertiesGuesser.php
75-
- ./src/Maker/Factory/DoctrineScalarFieldsDefaultPropertiesGuesser.php
76-
- ./src/ORM/OrmV2PersistenceStrategy.php
77-
78-
- ./src/Test/Behat/

src/ZenstruckFoundryBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function build(ContainerBuilder $container): void
277277
$container->addCompilerPass(new AsFixtureStoryCompilerPass());
278278

279279
if (class_exists(BehatServicesCompilerPass::class)) {
280-
$container->addCompilerPass(new BehatServicesCompilerPass());
280+
$container->addCompilerPass(new BehatServicesCompilerPass()); // @phpstan-ignore argument.type
281281
}
282282
}
283283

0 commit comments

Comments
 (0)