Skip to content

Commit 105deb5

Browse files
authored
Allow Symfony 7.x and Doctrine ORM 3.x (#58)
* Allow Symfony 7.x and Doctrine ORM 3.x * Fixed missing doctrine-version var in testing matrix * Fixed PHP version range for Symfony 7.x * Simplify testing matrix * Fixed phpstan error ignore config structure * Fixed remove ClassUtils * Removed phpspec/prophecy-phpunit * Fixed static analysis errors in DoctrineUserManager * Fixed EntityManager::flush argument was removed * Use ClassUtils again but declare dependency to doctrine/common
1 parent 5f85ac1 commit 105deb5

14 files changed

+314
-303
lines changed

.github/actions/install/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
symfony-version:
1010
required: true
1111
type: string
12+
doctrine-version:
13+
required: true
14+
type: string
1215
coverage-mode:
1316
required: false
1417
type: string
@@ -29,4 +32,5 @@ runs:
2932
shell: bash
3033
run: |
3134
composer require --no-update "symfony/framework-bundle:${{ inputs.symfony-version }}"
35+
composer require --no-update "doctrine/orm:${{ inputs.doctrine-version }}"
3236
composer update --no-interaction --no-progress --no-suggest

.github/workflows/tests.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ jobs:
1515
include:
1616
- php-version: '7.4'
1717
symfony-version: '4.4.*'
18-
- php-version: '8.2'
19-
symfony-version: '4.4.*'
18+
doctrine-version: '^2.7'
2019
- php-version: '7.4'
2120
symfony-version: '5.4.*'
22-
- php-version: '8.2'
23-
symfony-version: '5.4.*'
21+
doctrine-version: '^2.7'
2422
- php-version: '8.1'
25-
symfony-version: '6.3.*'
23+
symfony-version: '6.4.*'
24+
doctrine-version: '^2.7'
25+
- php-version: '8.2'
26+
symfony-version: '6.4.*'
27+
doctrine-version: '^3.0'
2628
- php-version: '8.2'
27-
symfony-version: '6.3.*'
29+
symfony-version: '^7.0'
30+
doctrine-version: '^2.7'
31+
- php-version: '8.3'
32+
symfony-version: '^7.0'
33+
doctrine-version: '^3.0'
2834
steps:
2935
- name: "Checkout"
3036
uses: actions/checkout@v2
@@ -33,6 +39,7 @@ jobs:
3339
with:
3440
php-version: ${{ matrix.php-version }}
3541
symfony-version: ${{ matrix.symfony-version }}
42+
doctrine-version: ${{ matrix.doctrine-version }}
3643
- name: "Run tests with phpunit/phpunit"
3744
run: vendor/bin/phpunit
3845

@@ -46,7 +53,8 @@ jobs:
4653
uses: ./.github/actions/install
4754
with:
4855
php-version: '8.1'
49-
symfony-version: '6.1.*'
56+
symfony-version: '6.4.*'
57+
doctrine-version: '^3.0'
5058
- name: "Run static analyzis with phpstan/phpstan"
5159
run: vendor/bin/phpstan analyze
5260

@@ -60,7 +68,8 @@ jobs:
6068
uses: ./.github/actions/install
6169
with:
6270
php-version: '8.1'
63-
symfony-version: '6.1.*'
71+
symfony-version: '6.4.*'
72+
doctrine-version: '^3.0'
6473
- name: "Run checkstyle with symplify/easy-coding-standard"
6574
run: vendor/bin/ecs
6675

@@ -74,7 +83,8 @@ jobs:
7483
uses: ./.github/actions/install
7584
with:
7685
php-version: '8.1'
77-
symfony-version: '6.1.*'
86+
symfony-version: '6.4.*'
87+
doctrine-version: '^3.0'
7888
coverage-mode: 'xdebug'
7989
- name: "Run tests with phpunit/phpunit"
8090
env:

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
"require": {
1212
"php": "^7.4|^8.0",
1313
"ext-openssl": "*",
14-
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
15-
"doctrine/orm": "^2.7",
14+
"symfony/framework-bundle": "^4.4|^5.0|^6.0|^7.0",
15+
"doctrine/common": "^3.0",
16+
"doctrine/orm": "^2.7|^3.0",
1617
"doctrine/doctrine-bundle": "^2.0",
1718
"yokai/dependency-injection": "^1.0"
1819
},
1920
"require-dev": {
2021
"phpunit/phpunit": "^9.5",
21-
"phpspec/prophecy-phpunit": "^2.0",
22-
"symfony/yaml": "^4.4|^5.2|^6.0",
22+
"symfony/yaml": "^4.4|^5.2|^6.0|^7.0",
2323
"phpstan/phpstan": "^1.7",
2424
"symplify/easy-coding-standard": "^11.3"
2525
},

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ parameters:
5050
count: 1
5151
path: src/Manager/DoctrineUserManager.php
5252

53+
-
54+
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:flush\\(\\) invoked with 1 parameter, 0 required\\.$#"
55+
count: 1
56+
path: src/Repository/DoctrineORMTokenRepository.php
57+

phpstan.neon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ includes:
22
- phpstan-baseline.neon
33
parameters:
44
level: max
5-
checkMissingIterableValueType: false
6-
checkGenericClassInNonGenericObjectType: false
5+
ignoreErrors:
6+
- identifier: missingType.generics
7+
- identifier: missingType.iterableValue
78
paths:
89
- src/

src/Manager/DoctrineUserManager.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ public function get(string $class, string $id)
5454
public function getClass($user): string
5555
{
5656
/** @var object $user */
57-
/** @var class-string $class */
58-
$class = ClassUtils::getClass($user);
5957

60-
return $class;
58+
return ClassUtils::getClass($user);
6159
}
6260

6361
public function getId($user): string

src/Repository/DoctrineORMTokenRepository.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function get(string $value, string $purpose): Token
4444
[
4545
'value' => $value,
4646
'purpose' => $purpose,
47-
]
47+
],
4848
);
4949

5050
if (!$token instanceof Token) {
@@ -67,7 +67,7 @@ public function findExisting(string $userClass, string $userId, string $purpose)
6767
'userClass' => $userClass,
6868
'userId' => $userId,
6969
'purpose' => $purpose,
70-
]
70+
],
7171
);
7272
if (!$token instanceof Token) {
7373
return null;
@@ -81,14 +81,12 @@ public function findExisting(string $userClass, string $userId, string $purpose)
8181

8282
public function create(Token $token): void
8383
{
84-
$this->manager->persist($token);
85-
$this->manager->flush($token);
84+
$this->save($token);
8685
}
8786

8887
public function update(Token $token): void
8988
{
90-
$this->manager->persist($token);
91-
$this->manager->flush($token);
89+
$this->save($token);
9290
}
9391

9492
public function exists(string $value, string $purpose): bool
@@ -107,4 +105,15 @@ public function exists(string $value, string $purpose): bool
107105

108106
return intval($result) > 0;
109107
}
108+
109+
private function save(Token $token): void
110+
{
111+
$this->manager->persist($token);
112+
113+
if ((new \ReflectionMethod($this->manager, 'flush'))->getNumberOfParameters() > 0) {
114+
$this->manager->flush($token);
115+
} else {
116+
$this->manager->flush();
117+
}
118+
}
110119
}

tests/Command/ArchiveTokenCommandTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Yokai\SecurityTokenBundle\Tests\Command;
66

7-
use Prophecy\PhpUnit\ProphecyTrait;
8-
use Prophecy\Prophecy\ObjectProphecy;
7+
use PHPUnit\Framework\MockObject\MockObject;
98
use Symfony\Bundle\FrameworkBundle\Console\Application;
109
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1110
use Symfony\Component\Console\Command\Command;
@@ -19,10 +18,8 @@
1918
*/
2019
class ArchiveTokenCommandTest extends KernelTestCase
2120
{
22-
use ProphecyTrait;
23-
2421
/**
25-
* @var ArchivistInterface|ObjectProphecy
22+
* @var MockObject<ArchivistInterface>
2623
*/
2724
private $archivist;
2825

@@ -33,10 +30,10 @@ class ArchiveTokenCommandTest extends KernelTestCase
3330

3431
protected function setUp(): void
3532
{
36-
$this->archivist = $this->prophesize(ArchivistInterface::class);
33+
$this->archivist = $this->createMock(ArchivistInterface::class);
3734

3835
self::bootKernel();
39-
self::$kernel->getContainer()->set('yokai_security_token.archivist', $this->archivist->reveal());
36+
self::$kernel->getContainer()->set('yokai_security_token.archivist', $this->archivist);
4037

4138
$this->application = new Application(self::$kernel);
4239
}
@@ -75,8 +72,9 @@ public function it_archive_every_token_when_run_without_options_with_confirmatio
7572
{
7673
$command = $this->command();
7774

78-
$this->archivist->archive(null)
79-
->shouldBeCalledTimes(1)
75+
$this->archivist->expects(self::once())
76+
->method('archive')
77+
->with(null)
8078
->willReturn(10);
8179

8280
$output = $this->runCommand($command);
@@ -91,8 +89,9 @@ public function it_archive_partial_tokens_when_run_with_options(): void
9189
{
9290
$command = $this->command();
9391

94-
$this->archivist->archive('init_password')
95-
->shouldBeCalledTimes(1)
92+
$this->archivist->expects(self::once())
93+
->method('archive')
94+
->with('init_password')
9695
->willReturn(10);
9796

9897
$output = $this->runCommand($command, ['purpose' => 'init_password']);

tests/DependencyInjection/DependencyInjectionTest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
1111
use Generator;
1212
use PHPUnit\Framework\TestCase;
13-
use Prophecy\PhpUnit\ProphecyTrait;
14-
use Prophecy\Prophecy\ProphecySubjectInterface;
1513
use Psr\Log\LoggerInterface;
1614
use Symfony\Component\Config\FileLocator;
1715
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -23,7 +21,6 @@
2321
use Yokai\SecurityTokenBundle\Archive\ArchivistInterface;
2422
use Yokai\SecurityTokenBundle\Configuration\TokenConfiguration;
2523
use Yokai\SecurityTokenBundle\Factory\TokenFactoryInterface;
26-
use Yokai\SecurityTokenBundle\Generator\OpenSslTokenGenerator;
2724
use Yokai\SecurityTokenBundle\Generator\TokenGeneratorInterface;
2825
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesserInterface;
2926
use Yokai\SecurityTokenBundle\Manager\TokenManagerInterface;
@@ -38,8 +35,6 @@
3835
*/
3936
class DependencyInjectionTest extends TestCase
4037
{
41-
use ProphecyTrait;
42-
4338
/**
4439
* @var ContainerBuilder
4540
*/
@@ -60,7 +55,7 @@ protected function setUp(): void
6055
$this->container->setParameter('kernel.debug', true);
6156
$this->container->setParameter('kernel.bundles', $bundles);
6257
$this->container->setParameter('kernel.environment', 'test');
63-
$this->container->set('logger', $this->prophesize(LoggerInterface::class)->reveal());
58+
$this->container->set('logger', $this->createMock(LoggerInterface::class));
6459
$this->container->setDefinition('doctrine', new Definition(ManagerRegistry::class));
6560
$this->container->setDefinition('doctrine.orm.default_entity_manager', new Definition(EntityManager::class));
6661
$this->container->setDefinition(
@@ -82,7 +77,7 @@ protected function setUp(): void
8277
'archivist_mock' => ArchivistInterface::class,
8378
];
8479
foreach ($mocks as $id => $class) {
85-
$service = $this->prophesize($class)->reveal();
80+
$service = $this->createMock($class);
8681
$this->container->setDefinition($id, new Definition(get_class($service)));
8782
}
8883

@@ -173,12 +168,12 @@ public function configurationProvider(): Generator
173168
'names.' . $format,
174169
[
175170
'security_password_init' => [
176-
'generator' => OpenSslTokenGenerator::class,
171+
'generator' => TokenGeneratorInterface::class,
177172
'duration' => '+2 days',
178173
'usages' => 1,
179174
],
180175
'security_password_reset' => [
181-
'generator' => OpenSslTokenGenerator::class,
176+
'generator' => TokenGeneratorInterface::class,
182177
'duration' => '+2 days',
183178
'usages' => 1,
184179
],
@@ -190,12 +185,12 @@ public function configurationProvider(): Generator
190185
'full.' . $format,
191186
[
192187
'security_password_init' => [
193-
'generator' => ProphecySubjectInterface::class,
188+
'generator' => TokenGeneratorInterface::class,
194189
'duration' => '+1 month',
195190
'usages' => 2,
196191
],
197192
'security_password_reset' => [
198-
'generator' => ProphecySubjectInterface::class,
193+
'generator' => TokenGeneratorInterface::class,
199194
'duration' => '+2 monthes',
200195
'usages' => 3,
201196
],

0 commit comments

Comments
 (0)