Skip to content

Commit 6acf746

Browse files
authored
Migrate PHPSpec tests to PHPUnit (#281)
## Summary Drop PHPSpec in favor of PHPUnit. Reorganize test structure to follow Symfony conventions. ### Changes: - Migrate 9 PHPSpec specs to PHPUnit test classes - Remove `phpspec/phpspec` dependency - Upgrade to PHPUnit ^11.5 and `matthiasnoback/symfony-dependency-injection-test` ^6.0 - Reorganize tests from `src/Bundle/test(s)/` to top-level `tests/` with PSR-4 namespace `Sylius\Bundle\MailerBundle\Tests\` - Move test utilities to `tests/Helper/` (renamed from Fixtures - more accurate for utility classes) - Remove deprecated SwiftMailer support from test utilities - Use `testCamelCase` naming convention (PHPUnit standard) instead of `it_snake_case` (PHPSpec style) - Fix CI workflow env name bug (`test_no_mailers` → `test_with_no_mailers`) ### Test structure: ``` tests/ ├── Application/ # Test kernel and config (MicroKernelTrait) ├── Cli/ # CLI command tests ├── Helper/ # Test utilities (SentMessage, MessagesProvider, SentMessagesPurger) ├── Functional/ # Functional tests (DI, Compiler passes, Sender) ├── Integration/ # Integration tests (with symfony/translation) └── Unit/ ├── Bundle/ # Bundle unit tests (9 migrated from PHPSpec) └── Component/ # Component unit tests ``` All 52 tests pass.
2 parents aa336a6 + 828f4db commit 6acf746

File tree

59 files changed

+1099
-979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1099
-979
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,11 @@ jobs:
5252
composer analyse
5353
(cd src/Component && composer validate --strict)
5454
55-
-
56-
name: Run component tests
57-
run: (cd src/Component && vendor/bin/phpspec run)
58-
59-
-
60-
name: Run PHPSpec tests
61-
run: vendor/bin/phpspec run
62-
6355
-
6456
name: Test bundle (with all services)
6557
run: |
66-
rm -rf src/Bundle/test/var/cache
67-
(cd src/Bundle/test && APP_ENV=test bin/console lint:container)
58+
rm -rf tests/Application/var/cache
59+
(cd tests/Application && APP_ENV=test bin/console lint:container)
6860
vendor/bin/phpunit --testsuite "SyliusMailerBundle Test Suite"
6961
7062
-
@@ -76,6 +68,6 @@ jobs:
7668
-
7769
name: Run lint container (with no mailers)
7870
run: |
79-
rm -rf src/Bundle/test/var/cache
71+
rm -rf tests/Application/var/cache
8072
composer remove symfony/mailer --dev --no-scripts
81-
(cd src/Bundle/test && APP_ENV=test_no_mailers bin/console lint:container)
73+
(cd tests/Application && APP_ENV=test_with_no_mailers bin/console lint:container)

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/vendor/
22
/bin/
3+
/var/
4+
/tests/Application/var/
35

46
/composer.phar
57
/composer.lock
68

79
/.phpunit.result.cache
10+
.phpunit.cache/

composer.json

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@
3737
"sylius/mailer": "self.version"
3838
},
3939
"require-dev": {
40-
"matthiasnoback/symfony-dependency-injection-test": "^5.0",
41-
"phpspec/phpspec": "^7.0",
40+
"matthiasnoback/symfony-dependency-injection-test": "^6.0",
4241
"phpstan/phpstan": "1.12.5",
4342
"phpstan/phpstan-phpunit": "1.4.0",
4443
"phpstan/phpstan-webmozart-assert": "1.2.11",
45-
"phpunit/phpunit": "^10.5",
46-
"rector/rector": "^0.13.6",
44+
"phpunit/phpunit": "^11.5",
4745
"sylius-labs/coding-standard": "^4.0",
4846
"symfony/console": "^6.4 || ^7.4",
4947
"symfony/dotenv": "^6.4 || ^7.4",
@@ -69,17 +67,12 @@
6967
"psr-4": {
7068
"Sylius\\Bundle\\MailerBundle\\": "src/Bundle/",
7169
"Sylius\\Component\\Mailer\\": "src/Component/"
72-
},
73-
"exclude-from-classmap": [
74-
"src/Bundle/test/"
75-
]
70+
}
7671
},
7772
"autoload-dev": {
7873
"psr-4": {
79-
"Sylius\\Bundle\\MailerBundle\\spec\\": "src/Bundle/spec/",
80-
"Sylius\\Bundle\\MailerBundle\\Tests\\": "src/Bundle/test/",
81-
"Sylius\\Component\\Mailer\\spec\\": "src/Component/spec/",
82-
"App\\": "src/Bundle/test/src/"
74+
"Sylius\\Bundle\\MailerBundle\\Tests\\": "tests/",
75+
"App\\": "tests/Application/"
8376
}
8477
},
8578
"scripts": {
@@ -92,7 +85,7 @@
9285
"vendor/bin/ecs check src --fix"
9386
],
9487
"test": [
95-
"vendor/bin/phpspec run --ansi --no-interaction"
88+
"vendor/bin/phpunit --colors=always"
9689
]
9790
}
9891
}

ecs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
43
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
54
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
65
use PhpCsFixer\Fixer\Phpdoc\PhpdocTagTypeFixer;
@@ -35,7 +34,6 @@
3534
$config->skip([
3635
PhpdocTagTypeFixer::class,
3736
InlineDocCommentDeclarationSniff::class . '.MissingVariable',
38-
VisibilityRequiredFixer::class => ['*Spec.php'],
3937
NoSuperfluousPhpdocTagsFixer::class => ['src/Component/Sender/SenderInterface.php'],
4038
'**/var/*',
4139
'**/vendor/*',

phpspec.yml.dist

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

phpstan.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ parameters:
1010
excludePaths:
1111
- %currentWorkingDirectory%/src/Bundle/DependencyInjection/Configuration.php
1212
- %currentWorkingDirectory%/src/Bundle/DependencyInjection/SyliusMailerExtension.php
13-
- %currentWorkingDirectory%/src/Bundle/spec/*
1413
- %currentWorkingDirectory%/src/Bundle/test/*
1514
- %currentWorkingDirectory%/src/Bundle/tests/*
16-
- %currentWorkingDirectory%/src/Component/spec/*
1715
- %currentWorkingDirectory%/src/Component/vendor/*
16+
- %currentWorkingDirectory%/tests/*
1817

1918
ignoreErrors:
2019
- '/Property Sylius\\Component\\Mailer\\Model\\Email\:\:\$id is never written\, only read\./'

phpunit.xml.dist

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.4/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/11.5/phpunit.xsd"
55
colors="true"
6+
bootstrap="tests/Application/config/bootstrap.php"
7+
defaultTestSuite="SyliusMailerBundle Test Suite"
68
>
79
<php>
810
<server name="KERNEL_CLASS" value="App\Kernel" />
911
</php>
1012

1113
<testsuites>
1214
<testsuite name="SyliusMailerBundle Test Suite">
13-
<directory>./src/Bundle/tests/</directory>
14-
<exclude>./src/Bundle/tests/Integration/Cli/</exclude>
15+
<directory>./tests/</directory>
16+
<exclude>./tests/Integration/</exclude>
17+
<exclude>./tests/Application/</exclude>
1518
</testsuite>
1619
<testsuite name="SyliusMailerBundle Integration Test Suite">
17-
<directory>./src/Bundle/tests/Integration/Cli/</directory>
20+
<directory>./tests/Integration/</directory>
1821
</testsuite>
1922
</testsuites>
2023
</phpunit>

src/Bundle/spec/Renderer/Adapter/EmailDefaultAdapterSpec.php

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

src/Bundle/spec/Renderer/Adapter/EmailTwigAdapterSpec.php

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

src/Bundle/spec/Sender/Adapter/DefaultAdapterSpec.php

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

0 commit comments

Comments
 (0)