Skip to content

Commit 6f10b05

Browse files
committed
- Refactor test infrastructure: replace ApiTestCase implementations with WebTestCase and refactor traits for shared logic.
- Update PHPUnit assertions to use stricter methods for status code verification. - Adjust composer constraints for improved compatibility with future Symfony and Doctrine releases. - Simplify and enhance XML and JSON test helpers for better reusability across controllers.
1 parent 6f571a6 commit 6f10b05

20 files changed

+582
-321
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
orm: ['2.*', '3.*']
26-
php: ["8.1", "8.2", "8.3"]
26+
php: ["8.1", "8.2", "8.3", "8.4"]
2727
composer-flags: ['--no-scripts --prefer-stable --prefer-dist']
2828
symfony: ["^6.4", "^7.1"]
2929
app_env: ["test"]
@@ -90,13 +90,6 @@ jobs:
9090
composer analyse
9191
(cd src/Component && composer validate --strict)
9292
93-
-
94-
name: Run Phpspec tests
95-
run: |
96-
vendor/bin/phpspec run --ansi --no-interaction
97-
(cd src/Component && vendor/bin/phpspec run --no-interaction)
98-
(cd src/Component && vendor/bin/phpspec run --no-interaction --config legacy/phpspec.yml.dist)
99-
10093
-
10194
name: Run PHPUnit tests
10295
run: vendor/bin/phpunit --colors=always

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"doctrine/collections": "^2.2",
3333
"doctrine/event-manager": "^1.1 || ^2.0",
3434
"doctrine/inflector": "^2.0",
35-
"doctrine/persistence": "^3.3",
35+
"doctrine/persistence": "^3.3 || ^4.0",
3636
"gedmo/doctrine-extensions": "^3.17.1",
3737
"sylius/registry": "^1.2",
3838
"symfony/config": "^6.4 || ^7.1",
@@ -56,14 +56,13 @@
5656
"sylius/resource": "self.version"
5757
},
5858
"require-dev": {
59-
"doctrine/doctrine-bundle": "^2.13",
59+
"doctrine/doctrine-bundle": "^2.13 || ^3.0",
6060
"doctrine/orm": "^2.18 || ^3.3",
6161
"doctrine/phpcr-odm": "^2.1",
6262
"friendsofsymfony/rest-bundle": "^3.7",
6363
"jackalope/jackalope": "^2.0",
6464
"jackalope/jackalope-doctrine-dbal": "^2.0",
6565
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
66-
"lchrusciel/api-test-case": "^5.0",
6766
"matthiasnoback/symfony-dependency-injection-test": "^6.1.0",
6867
"pagerfanta/pagerfanta": "^4.4",
6968
"pamil/phpspec-skip-example-extension": "^4.2",
@@ -77,9 +76,11 @@
7776
"rector/rector": "^0.18.2",
7877
"sylius-labs/coding-standard": "^4.4",
7978
"sylius/grid-bundle": "^1.13",
79+
"symfony/browser-kit": "^6.4 || ^7.1",
8080
"symfony/console": "^6.4 || ^7.1",
8181
"symfony/css-selector": "^6.4 || ^7.1",
8282
"symfony/dependency-injection": "^6.4 || ^7.1",
83+
"symfony/dom-crawler": "^6.4 || ^7.1",
8384
"symfony/dotenv": "^6.4 || ^7.1",
8485
"symfony/http-kernel": "^6.4 || ^7.1",
8586
"symfony/messenger": "^6.4 || ^7.1",
@@ -96,7 +97,6 @@
9697
},
9798
"conflict": {
9899
"doctrine/orm": "<2.18",
99-
"doctrine/doctrine-bundle": "<2.0 || ^3.0",
100100
"friendsofsymfony/rest-bundle": "<3.0",
101101
"jms/serializer-bundle": "<3.5",
102102
"pagerfanta/pagerfanta" : "<4.4",

src/Component/tests/Doctrine/Common/State/PersistProcessorTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ public function testItOnlyFlushesWhenManagerContainsTheResource(): void
6464
$operation = $this->prophesize(Operation::class);
6565
$data = new \stdClass();
6666

67-
$this->managerRegistry->getManagerForClass(\stdClass::class)->willReturn($manager);
67+
$metadata = $this->prophesize(ClassMetadata::class);
68+
69+
$metadata->isChangeTrackingDeferredExplicit()->willReturn(false);
70+
71+
$this->managerRegistry
72+
->getManagerForClass(\stdClass::class)
73+
->willReturn($manager->reveal())
74+
;
75+
6876
$manager->contains($data)->willReturn(true);
69-
$manager->getClassMetadata(\stdClass::class)->willReturn($data);
77+
$manager->getClassMetadata(\stdClass::class)->willReturn($metadata->reveal());
7078

7179
$manager->persist($data)->shouldNotBeCalled();
7280
$manager->flush()->shouldBeCalled();

tests/Application/config/bundles.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
use BabDev\PagerfantaBundle\BabDevPagerfantaBundle;
1515
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
1616
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
17-
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
1817
use FOS\RestBundle\FOSRestBundle;
1918
use JMS\SerializerBundle\JMSSerializerBundle;
20-
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
2119
use Sylius\Bundle\GridBundle\SyliusGridBundle;
2220
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
2321
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
@@ -35,8 +33,6 @@
3533
FOSRestBundle::class => ['all' => true, 'test_without_fosrest' => false],
3634
JMSSerializerBundle::class => ['all' => true, 'test_without_fosrest' => false],
3735
BazingaHateoasBundle::class => ['all' => true, 'test_without_hateoas' => false, 'test_without_fosrest' => false, 'test_with_attributes' => false],
38-
FidryAliceDataFixturesBundle::class => ['all' => true],
39-
NelmioAliceBundle::class => ['all' => true],
4036
winzouStateMachineBundle::class => ['all' => true, 'test_without_state_machine' => false],
4137
SyliusGridBundle::class => ['all' => true, 'test_without_twig' => false],
4238
Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],

tests/Application/config/packages/doctrine.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ doctrine:
44
path: "%database_path%"
55
charset: UTF8
66
orm:
7-
auto_generate_proxy_classes: true
87
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
98
auto_mapping: true
109
mappings:

tests/Application/src/Tests/Controller/BlogPostApiTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,27 @@
1313

1414
namespace App\Tests\Controller;
1515

16-
use ApiTestCase\JsonApiTestCase;
1716
use App\Foundry\Factory\BlogPostFactory;
17+
use App\Tests\Trait\JsonApiTestTrait;
1818
use PHPUnit\Framework\Attributes\Test;
19-
use Sylius\Bundle\ResourceBundle\ResourceBundleInterface;
19+
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
20+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
2021
use Symfony\Component\HttpFoundation\Response;
2122
use Zenstruck\Foundry\Test\Factories;
23+
use Zenstruck\Foundry\Test\ResetDatabase;
2224

23-
final class BlogPostApiTest extends JsonApiTestCase
25+
final class BlogPostApiTest extends WebTestCase
2426
{
2527
use Factories;
28+
use ResetDatabase;
29+
use JsonApiTestTrait;
30+
31+
private KernelBrowser $client;
32+
33+
protected function setUp(): void
34+
{
35+
$this->client = static::createClient();
36+
}
2637

2738
#[Test]
2839
public function it_allows_creating_a_blog_post(): void
@@ -31,6 +42,7 @@ public function it_allows_creating_a_blog_post(): void
3142

3243
$this->client->request('POST', '/blog-posts/', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
3344
$response = $this->client->getResponse();
45+
3446
$this->assertResponse($response, 'blog-posts/create_response', Response::HTTP_CREATED);
3547
}
3648

@@ -46,6 +58,7 @@ public function it_allows_reviewing_a_blog_post(): void
4658

4759
$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/to_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
4860
$response = $this->client->getResponse();
61+
4962
$this->assertResponse($response, 'blog-posts/to_review_response', Response::HTTP_OK);
5063
}
5164

@@ -61,6 +74,7 @@ public function it_allows_publishing_a_blog_post(): void
6174

6275
$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
6376
$response = $this->client->getResponse();
77+
6478
$this->assertResponse($response, 'blog-posts/publish_response', Response::HTTP_OK);
6579
}
6680

@@ -76,6 +90,7 @@ public function it_allows_rejecting_a_blog_post(): void
7690

7791
$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
7892
$response = $this->client->getResponse();
93+
7994
$this->assertResponse($response, 'blog-posts/reject_response', Response::HTTP_OK);
8095
}
8196

@@ -91,7 +106,8 @@ public function it_does_not_allow_to_publish_a_blog_post_with_draft_status(): vo
91106

92107
$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
93108
$response = $this->client->getResponse();
94-
$this->assertResponseCode($response, Response::HTTP_BAD_REQUEST);
109+
110+
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
95111
}
96112

97113
#[Test]
@@ -106,17 +122,7 @@ public function it_does_not_allow_to_reject_a_blog_post_with_draft_status(): voi
106122

107123
$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
108124
$response = $this->client->getResponse();
109-
$this->assertResponseCode($response, Response::HTTP_BAD_REQUEST);
110-
}
111-
112-
private function markAsSkippedIfNecessary(): void
113-
{
114-
$container = self::getContainer();
115-
116-
$stateMachine = $container->getParameter('sylius.resource.settings')['state_machine_component'];
117125

118-
if (ResourceBundleInterface::STATE_MACHINE_SYMFONY !== $stateMachine) {
119-
$this->markTestSkipped();
120-
}
126+
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
121127
}
122128
}

0 commit comments

Comments
 (0)