Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maintenance] Add more separation rules to arkitect #15525

Merged
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
103 changes: 85 additions & 18 deletions phparkitect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,94 @@

return static function (Config $config): void
{
$srcClassSet = ClassSet::fromDir(__DIR__.'/src');
$specClassSet = ClassSet::fromDir(__DIR__ . '/src/Sylius/{Behat,Component/*,Bundle/*}/spec');

$rules = [];
$config->add(
$specClassSet,
Rule::allClasses()
->that(new Extend(ObjectBehavior::class))
->should(new HaveNameMatching('*Spec'))
->because('Specifications should follow PHPSpec naming convention')
,
Rule::allClasses()
->that(new Extend(ObjectBehavior::class))
->should(new IsFinal())
->because('Specifications should not be extendable')
,
);

$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Component'))
->should(new NotDependsOnTheseNamespaces('Sylius\Bundle'))
->because('Sylius components should be stand-alone')
;
$testsClassSet = ClassSet::fromDir(__DIR__ . '{/tests,/src/Sylius/Bundle/*/Tests}');

$rules[] = Rule::allClasses()
->that(new Extend(ObjectBehavior::class))
->should(new HaveNameMatching('*Spec'))
->because('This is a convention from PHPSpec')
;
$config->add(
diimpp marked this conversation as resolved.
Show resolved Hide resolved
$testsClassSet,
Rule::allClasses()
->that(new HaveNameMatching('*Test$'))
->should(new IsFinal())
->because('Tests should not be extendable')
,
);

$rules[] = Rule::allClasses()
->that(new Extend(ObjectBehavior::class))
->should(new IsFinal())
->because('Specifications should not be extendable')
;
$separationClassSet = ClassSet::fromDir(__DIR__ . '/src/Sylius/{Component,Bundle}');

$config->add($srcClassSet, ...$rules);
$config->add(
$separationClassSet,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Component'))
->should(new NotDependsOnTheseNamespaces('Sylius\Bundle'))
->because('Components should not depend on bundles')
,
Rule::allClasses()
->except('Sylius\Component\Core')
->that(new ResideInOneOfTheseNamespaces('Sylius\Component'))
->should(new NotDependsOnTheseNamespaces('Sylius\Component\Core'))
->because('Stand-alone components should not depend on Core')
,
Rule::allClasses()
->except(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ApiBundle',
'Sylius\Bundle\CoreBundle',
'Sylius\Bundle\PayumBundle',
'Sylius\Bundle\ShopBundle',
)
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle'))
->should(new NotDependsOnTheseNamespaces('Sylius\Component\Core'))
->because('Stand-alone bundles should not depend on Core')
,
Rule::allClasses()
->except(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ApiBundle',
'Sylius\Bundle\CoreBundle',
'Sylius\Bundle\ShopBundle',
)
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle'))
->should(new NotDependsOnTheseNamespaces('Sylius\Bundle\CoreBundle'))
->because('Stand-alone bundles should not depend on CoreBundle')
,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle\ShopBundle'))
->should(new NotDependsOnTheseNamespaces(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ApiBundle',
))
->because('Shop should not depend on Admin and Api')
,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle\AdminBundle'))
->should(new NotDependsOnTheseNamespaces(
'Sylius\Bundle\ApiBundle',
'Sylius\Bundle\ShopBundle',
))
->because('Admin should not depend on Shop and Api')
,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle\ApiBundle'))
->should(new NotDependsOnTheseNamespaces(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ShopBundle',
))
->because('Api should not depend on Admin and Shop')
,
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class DisablingApiTest extends ApiTestCase
final class DisablingApiTest extends ApiTestCase
{
use SetUpTestsTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use Symfony\Component\HttpFoundation\Response;

class DisablingDocumentationTest extends ApiTestCase
final class DisablingDocumentationTest extends ApiTestCase
{
use SetUpTestsTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class PostgreSQLDriverExceptionListenerTest extends TestCase
final class PostgreSQLDriverExceptionListenerTest extends TestCase
{
/** @test */
public function it_does_nothing_if_exception_is_not_a_driver_exception(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class CompositeChannelContextPassTest extends AbstractCompilerPassTestCase
final class CompositeChannelContextPassTest extends AbstractCompilerPassTestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class CompositeRequestResolverPassTest extends AbstractCompilerPassTestCase
final class CompositeRequestResolverPassTest extends AbstractCompilerPassTestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Sylius\Bundle\CoreBundle\DependencyInjection\Compiler\BackwardsCompatibility\CancelOrderStateMachineCallbackPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CancelOrderStateMachineCallbackPassTest extends AbstractCompilerPassTestCase
final class CancelOrderStateMachineCallbackPassTest extends AbstractCompilerPassTestCase
{
public array $smConfigs = [
'sylius_order' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionHasMethodCallConstraint;
use PHPUnit\Framework\Constraint\LogicalNot;
use Sylius\Bundle\OrderBundle\DependencyInjection\Compiler\RegisterProcessorsPass;
use Sylius\Component\Core\OrderProcessing\OrderAdjustmentsClearer;
use Sylius\Component\Order\Processor\CompositeOrderProcessor;
use Sylius\Component\Order\Processor\OrderProcessorInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -33,7 +33,7 @@ public function it_adds_method_call_to_composite_order_processor_if_exist(): voi
$compositeOrderProcessorDefinition = new Definition(CompositeOrderProcessor::class);
$this->setDefinition('sylius.order_processing.order_processor.composite', $compositeOrderProcessorDefinition);

$orderAdjustmentClearerDefinition = new Definition(OrderAdjustmentsClearer::class);
$orderAdjustmentClearerDefinition = new Definition(OrderProcessorInterface::class);
$orderAdjustmentClearerDefinition->addTag('sylius.order_processor');

$this->setDefinition('sylius.order_processing.order_adjustments_clearer', $orderAdjustmentClearerDefinition);
Expand All @@ -58,7 +58,7 @@ public function it_adds_method_call_to_composite_order_processor_with_custom_pri
$compositeOrderProcessorDefinition = new Definition(CompositeOrderProcessor::class);
$this->setDefinition('sylius.order_processing.order_processor.composite', $compositeOrderProcessorDefinition);

$orderAdjustmentClearerDefinition = new Definition(OrderAdjustmentsClearer::class);
$orderAdjustmentClearerDefinition = new Definition(OrderProcessorInterface::class);
$orderAdjustmentClearerDefinition->addTag('sylius.order_processor', ['priority' => 10]);

$this->setDefinition('sylius.order_processing.order_adjustments_clearer', $orderAdjustmentClearerDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;

class GenerateCouponsCommandTest extends KernelTestCase
final class GenerateCouponsCommandTest extends KernelTestCase
{
private Command $command;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Sylius\Bundle\UserBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class ConfigurationTest extends TestCase
final class ConfigurationTest extends TestCase
{
use ConfigurationTestCaseTrait;

Expand Down
5 changes: 1 addition & 4 deletions tests/Controller/AdminProductAjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@

namespace Sylius\Tests\Controller;

use ApiTestCase\JsonApiTestCase;
use Exception;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

final class AdminProductAjaxTest extends SessionAwareAjaxTest
final class AdminProductAjaxTest extends SessionAwareAjaxTestCase
{
/**
* @test
Expand Down
5 changes: 1 addition & 4 deletions tests/Controller/AdminProductVariantAjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@

namespace Sylius\Tests\Controller;

use ApiTestCase\JsonApiTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

final class AdminProductVariantAjaxTest extends SessionAwareAjaxTest
final class AdminProductVariantAjaxTest extends SessionAwareAjaxTestCase
{
/** @test */
public function it_denies_access_to_product_variants_for_not_authenticated_user(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/AdminTaxonAjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

final class AdminTaxonAjaxTest extends SessionAwareAjaxTest
final class AdminTaxonAjaxTest extends SessionAwareAjaxTestCase
{
/** @test */
public function it_denies_access_to_taxons_for_not_authenticated_user(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
use Symfony\Component\HttpFoundation\Request;

abstract class SessionAwareAjaxTest extends JsonApiTestCase
abstract class SessionAwareAjaxTestCase extends JsonApiTestCase
{
protected function setUp(): void
{
Expand Down
11 changes: 3 additions & 8 deletions tests/Functional/EligibleCatalogPromotionsProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@

use Fidry\AliceDataFixtures\LoaderInterface;
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
use Sylius\Bundle\PromotionBundle\Criteria\DateRange;
use Sylius\Bundle\PromotionBundle\Provider\EligibleCatalogPromotionsProvider;
use Sylius\Component\Core\Dashboard\Interval;
use Sylius\Component\Core\Dashboard\SalesSummary;
use Sylius\Component\Core\Model\CatalogPromotionInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class EligibleCatalogPromotionsProcessorTest extends WebTestCase
final class EligibleCatalogPromotionsProcessorTest extends WebTestCase
{
/** @var Client */
private static $client;
private static KernelBrowser $client;

protected function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/OrderByIdentifierSqlWalkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Doctrine\ORM\Query;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\SqlWalker\OrderByIdentifierSqlWalker;

class OrderByIdentifierSqlWalkerTest extends AbstractOrmTestCase
final class OrderByIdentifierSqlWalkerTest extends AbstractOrmTestCase
{
private EntityManagerInterface $entityManager;

Expand Down
Loading