Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: false
matrix:
orm: ['2.*', '3.*']
php: ["8.1", "8.2", "8.3"]
php: ["8.1", "8.2", "8.3", "8.4", "8.5"]
composer-flags: ['--no-scripts --prefer-stable --prefer-dist']
symfony: ["^6.4", "^7.1"]
app_env: ["test"]
Expand Down Expand Up @@ -90,13 +90,6 @@ jobs:
composer analyse
(cd src/Component && composer validate --strict)

-
name: Run Phpspec tests
run: |
vendor/bin/phpspec run --ansi --no-interaction
(cd src/Component && vendor/bin/phpspec run --no-interaction)
(cd src/Component && vendor/bin/phpspec run --no-interaction --config legacy/phpspec.yml.dist)

-
name: Run PHPUnit tests
run: vendor/bin/phpunit --colors=always
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"doctrine/collections": "^2.2",
"doctrine/event-manager": "^1.1 || ^2.0",
"doctrine/inflector": "^2.0",
"doctrine/persistence": "^3.3",
"doctrine/persistence": "^3.3 || ^4.0",
"gedmo/doctrine-extensions": "^3.17.1",
"sylius/registry": "^1.2",
"symfony/config": "^6.4 || ^7.1",
Expand All @@ -56,14 +56,14 @@
"sylius/resource": "self.version"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.13",
"coduo/php-matcher": "^6.0",
"doctrine/doctrine-bundle": "^2.13 || ^3.0",
"doctrine/orm": "^2.18 || ^3.3",
"doctrine/phpcr-odm": "^2.1",
"friendsofsymfony/rest-bundle": "^3.7",
"jackalope/jackalope": "^2.0",
"jackalope/jackalope-doctrine-dbal": "^2.0",
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
"lchrusciel/api-test-case": "^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^6.1.0",
"pagerfanta/pagerfanta": "^4.4",
"pamil/phpspec-skip-example-extension": "^4.2",
Expand All @@ -77,9 +77,11 @@
"rector/rector": "^0.18.2",
"sylius-labs/coding-standard": "^4.4",
"sylius/grid-bundle": "^1.13",
"symfony/browser-kit": "^6.4 || ^7.1",
"symfony/console": "^6.4 || ^7.1",
"symfony/css-selector": "^6.4 || ^7.1",
"symfony/dependency-injection": "^6.4 || ^7.1",
"symfony/dom-crawler": "^6.4 || ^7.1",
"symfony/dotenv": "^6.4 || ^7.1",
"symfony/http-kernel": "^6.4 || ^7.1",
"symfony/messenger": "^6.4 || ^7.1",
Expand All @@ -96,7 +98,6 @@
},
"conflict": {
"doctrine/orm": "<2.18",
"doctrine/doctrine-bundle": "<2.0 || ^3.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you need to keep a conflict here.
It's an optional requirement.
"doctrine/doctrine-bundle": "<2.13",

"friendsofsymfony/rest-bundle": "<3.0",
"jms/serializer-bundle": "<3.5",
"pagerfanta/pagerfanta" : "<4.4",
Expand Down
24 changes: 24 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,27 @@ parameters:
-
message: '#If condition is always false#'
path: src/Bundle/Event/ResourceControllerEvent.php

# Symfony 7.4 introduced generics on NodeBuilder which phpstan-symfony does not handle correctly yet
# See: https://github.com/phpstan/phpstan-symfony/issues/431
-
message: '#Call to method \w+Node\(\) on an unknown class Symfony\\Component\\Config\\Definition\\Builder\\NodeBuilder<.*>#'
identifier: class.notFound

# Symfony 7.4 introduced generics for TreeBuilder and ArrayNodeDefinition.
# These classes are not generic in Symfony 6.4, causing PHPStan errors when analyzing against the older version.
# This rule allows us to keep generic type hints for Symfony 7 while ignoring errors on Symfony 6.
-
message: '#PHPDoc tag @(return|param|var) .* contains generic type .* but class .* is not generic\.#'
paths:
- 'src/Bundle/DependencyInjection/'
- 'src/Bundle/Routing/'

# Specific ignore for TreeBuilder return type on Symfony 6.4.
# Required to allow "TreeBuilder<mixed>" or "TreeBuilder<'array'>" return types.
-
message: '#PHPDoc tag @return contains generic type .*TreeBuilder.* but class .*TreeBuilder is not generic#'
paths:
- 'src/Bundle/DependencyInjection/Configuration.php'
- 'src/Bundle/DependencyInjection/PagerfantaConfiguration.php'
- 'src/Bundle/Routing/Configuration.php'
21 changes: 20 additions & 1 deletion src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Sylius\Resource\Factory\Factory;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeParentInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

final class Configuration implements ConfigurationInterface
{
/**
* @phpstan-return TreeBuilder<'array'>
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sylius_resource');
/** @var ArrayNodeDefinition $rootNode */
/**
* @var ArrayNodeDefinition $rootNode
* @phpstan-var ArrayNodeDefinition<NodeParentInterface|null> $rootNode
*/
$rootNode = $treeBuilder->getRootNode();

$this->addResourcesSection($rootNode);
Expand Down Expand Up @@ -60,6 +67,9 @@ public function getConfigTreeBuilder(): TreeBuilder
return $treeBuilder;
}

/**
* @phpstan-param ArrayNodeDefinition<NodeParentInterface|null> $node
*/
private function addResourcesSection(ArrayNodeDefinition $node): void
{
$node
Expand Down Expand Up @@ -112,6 +122,9 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
;
}

/**
* @phpstan-param ArrayNodeDefinition<NodeParentInterface|null> $node
*/
private function addSettingsSection(ArrayNodeDefinition $node): void
{
$node
Expand All @@ -138,6 +151,9 @@ private function addSettingsSection(ArrayNodeDefinition $node): void
;
}

/**
* @phpstan-param ArrayNodeDefinition<NodeParentInterface|null> $node
*/
private function addTranslationsSection(ArrayNodeDefinition $node): void
{
$node
Expand All @@ -151,6 +167,9 @@ private function addTranslationsSection(ArrayNodeDefinition $node): void
;
}

/**
* @phpstan-param ArrayNodeDefinition<NodeParentInterface|null> $node
*/
private function addDriversSection(ArrayNodeDefinition $node): void
{
$node
Expand Down
5 changes: 4 additions & 1 deletion src/Bundle/DependencyInjection/PagerfantaConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Bundle\ResourceBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeParentInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -26,11 +27,12 @@ final class PagerfantaConfiguration implements ConfigurationInterface
{
public const EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND = 'to_http_not_found';

/** @return TreeBuilder<'array'> */
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('white_october_pagerfanta');

/** @var ArrayNodeDefinition $rootNode */
/** @var ArrayNodeDefinition<NodeParentInterface|null> $rootNode */
$rootNode = $treeBuilder->getRootNode();
$rootNode->setDeprecated('sylius/resource-bundle', '1.7', 'The "%node%" configuration node is deprecated, migrate your configuration to the "babdev_pagerfanta" configuration node.');

Expand All @@ -47,6 +49,7 @@ public function getConfigTreeBuilder(): TreeBuilder
return $treeBuilder;
}

/** @param ArrayNodeDefinition<NodeParentInterface|null> $node */
private function addExceptionsStrategySection(ArrayNodeDefinition $node): void
{
$node
Expand Down
4 changes: 3 additions & 1 deletion src/Bundle/Routing/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
namespace Sylius\Bundle\ResourceBundle\Routing;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeParentInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

final class Configuration implements ConfigurationInterface
{
/** @return TreeBuilder<'array'> */
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('routing');
/** @var ArrayNodeDefinition $rootNode */
/** @var ArrayNodeDefinition<NodeParentInterface|null> $rootNode */
$rootNode = $treeBuilder->getRootNode();

$rootNode
Expand Down
12 changes: 10 additions & 2 deletions src/Component/tests/Doctrine/Common/State/PersistProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ public function testItOnlyFlushesWhenManagerContainsTheResource(): void
$operation = $this->prophesize(Operation::class);
$data = new \stdClass();

$this->managerRegistry->getManagerForClass(\stdClass::class)->willReturn($manager);
$metadata = $this->prophesize(ClassMetadata::class);

$metadata->isChangeTrackingDeferredExplicit()->willReturn(false);

$this->managerRegistry
->getManagerForClass(\stdClass::class)
->willReturn($manager->reveal())
;

$manager->contains($data)->willReturn(true);
$manager->getClassMetadata(\stdClass::class)->willReturn($data);
$manager->getClassMetadata(\stdClass::class)->willReturn($metadata->reveal());

$manager->persist($data)->shouldNotBeCalled();
$manager->flush()->shouldBeCalled();
Expand Down
4 changes: 0 additions & 4 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
use BabDev\PagerfantaBundle\BabDevPagerfantaBundle;
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use FOS\RestBundle\FOSRestBundle;
use JMS\SerializerBundle\JMSSerializerBundle;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Sylius\Bundle\GridBundle\SyliusGridBundle;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
Expand All @@ -35,8 +33,6 @@
FOSRestBundle::class => ['all' => true, 'test_without_fosrest' => false],
JMSSerializerBundle::class => ['all' => true, 'test_without_fosrest' => false],
BazingaHateoasBundle::class => ['all' => true, 'test_without_hateoas' => false, 'test_without_fosrest' => false, 'test_with_attributes' => false],
FidryAliceDataFixturesBundle::class => ['all' => true],
NelmioAliceBundle::class => ['all' => true],
winzouStateMachineBundle::class => ['all' => true, 'test_without_state_machine' => false],
SyliusGridBundle::class => ['all' => true, 'test_without_twig' => false],
Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],
Expand Down
1 change: 0 additions & 1 deletion tests/Application/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ doctrine:
path: "%database_path%"
charset: UTF8
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
Expand Down
36 changes: 21 additions & 15 deletions tests/Application/src/Tests/Controller/BlogPostApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,27 @@

namespace App\Tests\Controller;

use ApiTestCase\JsonApiTestCase;
use App\Foundry\Factory\BlogPostFactory;
use App\Tests\Trait\JsonApiTestTrait;
use PHPUnit\Framework\Attributes\Test;
use Sylius\Bundle\ResourceBundle\ResourceBundleInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

final class BlogPostApiTest extends JsonApiTestCase
final class BlogPostApiTest extends WebTestCase
{
use Factories;
use ResetDatabase;
use JsonApiTestTrait;

private KernelBrowser $client;

protected function setUp(): void
{
$this->client = static::createClient();
}

#[Test]
public function it_allows_creating_a_blog_post(): void
Expand All @@ -31,6 +42,7 @@ public function it_allows_creating_a_blog_post(): void

$this->client->request('POST', '/blog-posts/', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
$response = $this->client->getResponse();

$this->assertResponse($response, 'blog-posts/create_response', Response::HTTP_CREATED);
}

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

$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/to_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
$response = $this->client->getResponse();

$this->assertResponse($response, 'blog-posts/to_review_response', Response::HTTP_OK);
}

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

$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
$response = $this->client->getResponse();

$this->assertResponse($response, 'blog-posts/publish_response', Response::HTTP_OK);
}

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

$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
$response = $this->client->getResponse();

$this->assertResponse($response, 'blog-posts/reject_response', Response::HTTP_OK);
}

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

$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_BAD_REQUEST);

$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
}

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

$this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}');
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_BAD_REQUEST);
}

private function markAsSkippedIfNecessary(): void
{
$container = self::getContainer();

$stateMachine = $container->getParameter('sylius.resource.settings')['state_machine_component'];

if (ResourceBundleInterface::STATE_MACHINE_SYMFONY !== $stateMachine) {
$this->markTestSkipped();
}
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
}
}
Loading
Loading