From 37d58faad1bd0f9688221f92114f424617290869 Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Thu, 11 Apr 2024 23:55:35 +0200 Subject: [PATCH 1/7] Setup bundle --- .gitignore | 60 +++++++++++++++++++ .php-cs-fixer.dist.php | 50 ++++++++++++++++ composer.json | 29 +++++++++ .../DependencyInjection/Configuration.php | 25 ++++++++ src/SuluPhpcrMigrationBundle.php | 10 ++++ 5 files changed, 174 insertions(+) create mode 100644 .gitignore create mode 100644 .php-cs-fixer.dist.php create mode 100644 composer.json create mode 100644 src/Infrastructure/Symfony/DependencyInjection/Configuration.php create mode 100644 src/SuluPhpcrMigrationBundle.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f52e705 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# composer +/composer.phar +composer.lock +/vendor + +.php-cs-fixer.cache +.eslintcache +.env.local + +# phpunit +.phpunit +phpunit.xml +.phpunit.result.cache + +# IDEs +/.idea +*.iml +*~ +.web-server-pid + +# System files +.DS_Store + +# Styleguide +/styleguide + +# IDEs +.idea +*.iml + +# Jackrabbit +jackrabbit-standalone* +jackrabbit/* + +# Symfony CLI +# https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project +/php.ini +/.php-version + +###> symfony/framework-bundle ### +/.env.local +/.env.local.php +/.env.*.local +/public/bundles/ +/var/ +/vendor/ +###< symfony/framework-bundle ### + +###> phpunit/phpunit ### +/phpunit.xml +###< phpunit/phpunit ### + +###> symfony/phpunit-bridge ### +.phpunit +/phpunit.xml +###< symfony/phpunit-bridge ### + +###> symfony/web-server-bundle ### +/.web-server-pid +###< symfony/web-server-bundle ### \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..649058a --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,50 @@ +exclude(['var/cache', 'tests/Resources/cache', 'node_modules']) + ->in(__DIR__); + +$config = new PhpCsFixer\Config(); +$config->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'class_definition' => false, + 'concat_space' => ['spacing' => 'one'], + 'function_declaration' => ['closure_function_spacing' => 'none'], + 'header_comment' => ['header' => $header], + 'native_constant_invocation' => true, + 'native_function_casing' => true, + 'native_function_invocation' => ['include' => ['@internal']], + 'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false], + 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true], + 'ordered_imports' => true, + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_types_order' => false, + 'single_line_throw' => false, + 'single_line_comment_spacing' => false, + 'phpdoc_to_comment' => [ + 'ignored_tags' => ['todo', 'var'], + ], + 'phpdoc_separation' => [ + 'groups' => [ + ['Serializer\\*', 'VirtualProperty', 'Accessor', 'Type', 'Groups', 'Expose', 'Exclude', 'SerializedName', 'Inline', 'ExclusionPolicy'], + ], + ], + 'get_class_to_class_keyword' => false, // should be enabled as soon as support for php < 8 is dropped + 'nullable_type_declaration_for_default_null_value' => true, + 'no_null_property_initialization' => false, + 'fully_qualified_strict_types' => false, + ]) + ->setFinder($finder); + +return $config; \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c3d4afc --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "sulu/sulu-phpcr-migration-bundle", + "license": "MIT", + "description": "The bundle provides command to migrate the Sulu database from phpCr to the SuluContentBundle.", + "keywords": ["sulu", "phpcr", "migration", "content-bundle"], + "type": "sulu-bundle", + "authors": [ + { + "name": "Sulu Community", + "homepage": "https://github.com/sulu/SuluPHPCRMigrationBundle/graphs/contributors" + } + ], + "require": { + "php": "^8.1", + "jackalope/jackalope-doctrine-dbal": "^1.7", + "symfony/console": "^6.0 | ^7.0", + "symfony/dependency-injection": "^6.0 | ^7.0", + "symfony/config": "^6.0 | ^7.0", + "symfony/framework-bundle": "^6.0 | ^7.0" + }, + "autoload": { + "psr-4": { + "Sulu\\Bundle\\PhpcrMigrationBundle\\": "src/" + } + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.14" + } +} \ No newline at end of file diff --git a/src/Infrastructure/Symfony/DependencyInjection/Configuration.php b/src/Infrastructure/Symfony/DependencyInjection/Configuration.php new file mode 100644 index 0000000..fa60576 --- /dev/null +++ b/src/Infrastructure/Symfony/DependencyInjection/Configuration.php @@ -0,0 +1,25 @@ + Date: Mon, 29 Apr 2024 00:52:10 +0200 Subject: [PATCH 2/7] Add configuration --- README.md | 2 +- Resources/config/command.xml | 14 +++ Resources/config/session.xml | 14 +++ composer.json | 7 +- src/Application/Session/SessionManager.php | 74 +++++++++++++ .../DependencyInjection/Configuration.php | 25 ----- src/SuluPhpcrMigrationBundle.php | 103 +++++++++++++++++- .../Command/MigratePhpcrCommand.php | 35 ++++++ 8 files changed, 246 insertions(+), 28 deletions(-) create mode 100644 Resources/config/command.xml create mode 100644 Resources/config/session.xml create mode 100644 src/Application/Session/SessionManager.php delete mode 100644 src/Infrastructure/Symfony/DependencyInjection/Configuration.php create mode 100644 src/UserInterface/Command/MigratePhpcrCommand.php diff --git a/README.md b/README.md index 834d129..41bc2c7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ We are committed to a fully transparent development process and **highly appreci In case you have questions, we are happy to welcome you in our official [Slack channel](https://sulu.io/services-and-support). If you found a bug or miss a specific feature, feel free to **file a new issue** with a respective title and description -on the the [sulu/SuluHeadlessBundle](https://github.com/sulu/SuluHeadlessBundle) repository. +on the [sulu/SuluPHPCRMigrationBundle](https://github.com/sulu/SuluPHPCRMigrationBundle) repository. ## 📘  License diff --git a/Resources/config/command.xml b/Resources/config/command.xml new file mode 100644 index 0000000..039df9a --- /dev/null +++ b/Resources/config/command.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/Resources/config/session.xml b/Resources/config/session.xml new file mode 100644 index 0000000..0888f23 --- /dev/null +++ b/Resources/config/session.xml @@ -0,0 +1,14 @@ + + + + + + %sulu_phpcr_migration.configuration% + + + + + diff --git a/composer.json b/composer.json index c3d4afc..055965d 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "require": { "php": "^8.1", "jackalope/jackalope-doctrine-dbal": "^1.7", + "jackalope/jackalope-jackrabbit": "^1.4", "symfony/console": "^6.0 | ^7.0", "symfony/dependency-injection": "^6.0 | ^7.0", "symfony/config": "^6.0 | ^7.0", @@ -25,5 +26,9 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.14" + }, + "scripts": { + "php-cs-fix": "@php vendor/bin/php-cs-fixer fix", + "lint-php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run" } -} \ No newline at end of file +} diff --git a/src/Application/Session/SessionManager.php b/src/Application/Session/SessionManager.php new file mode 100644 index 0000000..6ac1680 --- /dev/null +++ b/src/Application/Session/SessionManager.php @@ -0,0 +1,74 @@ +workspace = $configuration['workspace']['default']; + $this->workspaceLive = $configuration['workspace']['live']; + } + + public function getDefaultSession(): SessionInterface + { + return $this->getSession($this->workspace); + } + + public function getLiveSession(): SessionInterface + { + return $this->getSession($this->workspaceLive); + } + + private function getSession(string $workspace): SessionInterface + { + $factory = $this->connection ? new RepositoryFactoryDoctrineDBAL() : new RepositoryFactoryJackrabbit(); + $repository = $factory->getRepository(\array_filter([ + 'jackalope.doctrine_dbal_connection' => $this->connection, + 'jackalope.jackrabbit_uri' => $this->configuration['connection']['url'] ?? null, + ])); + + $credentials = new SimpleCredentials( + $this->configuration['connection']['user'] ?? 'dummy', + $this->configuration['connection']['password'] ?? 'dummy' + ); + + return $repository->login($credentials, $workspace); + } +} diff --git a/src/Infrastructure/Symfony/DependencyInjection/Configuration.php b/src/Infrastructure/Symfony/DependencyInjection/Configuration.php deleted file mode 100644 index fa60576..0000000 --- a/src/Infrastructure/Symfony/DependencyInjection/Configuration.php +++ /dev/null @@ -1,25 +0,0 @@ -load('session.xml'); + $loader->load('command.xml'); + } + + public function configure(DefinitionConfigurator $definition): void + { + $definition->rootNode() + ->children() + ->scalarNode('DSN')->isRequired()->end() + ->end(); + } + + public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void + { + $config = $builder->getExtensionConfig('sulu_phpcr_migration'); + + /** @var string $dsn */ + $dsn = $config[0]['DSN']; + $builder->setParameter('sulu_phpcr_migration.dsn', $dsn); + + $configuration = $this->getConnectionConfiguration($dsn); + $builder->setParameter('sulu_phpcr_migration.configuration', $configuration); + + if ('dbal' === $configuration['connection']['type']) { + $builder->setAlias('sulu_phpcr_migration.connection', \sprintf('doctrine.dbal.%s_connection', $configuration['connection']['name'])); + + return; + } + } + + /** + * @return array{ + * connection: array{ + * type: 'dbal' | 'jackrabbit', + * name?: string, + * url?: string, + * user?: string, + * password?: string + * }, + * workspace: array{ + * default: string, + * live: string + * } + * } + */ + private function getConnectionConfiguration(string $dsn): array + { + $parts = \parse_url($dsn); + \parse_str($parts['query'], $query); + + $workspace = $query['workspace']; + unset($query['workspace']); + + if (!$workspace) { + throw new \InvalidArgumentException('Workspace is missing in DSN'); + } + + $result = [ + 'connection' => [ + 'type' => $parts['scheme'], + ], + 'workspace' => [ + 'default' => $workspace, + 'live' => $workspace . '_live', + ], + ]; + + if ('dbal' === $parts['scheme']) { + $result['connection']['name'] = $parts['host']; + + return $result; + } + + $result['url'] = \sprintf( + '%s:%s/%s%s', + $parts['host'], + $parts['port'], + $parts['path'], + $query ? '?' . \http_build_query($query) : '', + ); + $result['user'] = $parts['user'] ?? null; + $result['password'] = $parts['pass'] ?? null; -} \ No newline at end of file + return $result; + } +} diff --git a/src/UserInterface/Command/MigratePhpcrCommand.php b/src/UserInterface/Command/MigratePhpcrCommand.php new file mode 100644 index 0000000..3485690 --- /dev/null +++ b/src/UserInterface/Command/MigratePhpcrCommand.php @@ -0,0 +1,35 @@ +sessionManager->getDefaultSession(); + $liveSession = $this->sessionManager->getLiveSession(); + + return Command::SUCCESS; + } +} From 755b76ac6c3f17fd4ac32662027388491db79d36 Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Mon, 29 Apr 2024 01:52:04 +0200 Subject: [PATCH 3/7] Add phpstan --- .gitignore | 1 + composer.json | 32 +++++++++++--- phpstan.neon | 5 +++ src/Application/Session/SessionManager.php | 1 - src/SuluPhpcrMigrationBundle.php | 51 ++++++++++++++-------- 5 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 phpstan.neon diff --git a/.gitignore b/.gitignore index f52e705..3eae03f 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ jackrabbit/* /public/bundles/ /var/ /vendor/ +/Tests/Application/var ###< symfony/framework-bundle ### ###> phpunit/phpunit ### diff --git a/composer.json b/composer.json index 055965d..791edfe 100644 --- a/composer.json +++ b/composer.json @@ -14,21 +14,43 @@ "php": "^8.1", "jackalope/jackalope-doctrine-dbal": "^1.7", "jackalope/jackalope-jackrabbit": "^1.4", + "symfony/config": "^6.0 | ^7.0", "symfony/console": "^6.0 | ^7.0", "symfony/dependency-injection": "^6.0 | ^7.0", - "symfony/config": "^6.0 | ^7.0", "symfony/framework-bundle": "^6.0 | ^7.0" }, "autoload": { "psr-4": { - "Sulu\\Bundle\\PhpcrMigrationBundle\\": "src/" - } + "Sulu\\Bundle\\PhpcrMigrationBundle\\": "" + }, + "exclude-from-classmap": ["/Tests/"] }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.14" + "friendsofphp/php-cs-fixer": "^3.41", + "jangregor/phpstan-prophecy": "^1.0", + "phpspec/prophecy-phpunit": "^2.1", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-doctrine": "^1.3", + "phpstan/phpstan-phpunit": "^1.3", + "phpstan/phpstan-symfony": "^1.3", + "phpstan/phpstan-webmozart-assert": "^1.2", + "thecodingmachine/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^10.0", + "symfony/dotenv": "^6.0 || ^7.0" }, "scripts": { "php-cs-fix": "@php vendor/bin/php-cs-fixer fix", - "lint-php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run" + "lint-php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run", + "phpstan": [ + "@php vendor/bin/phpstan analyse" + ] + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true, + "php-http/discovery": true + } } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..433d232 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + paths: + - src + - tests + level: max \ No newline at end of file diff --git a/src/Application/Session/SessionManager.php b/src/Application/Session/SessionManager.php index 6ac1680..3cfff12 100644 --- a/src/Application/Session/SessionManager.php +++ b/src/Application/Session/SessionManager.php @@ -19,7 +19,6 @@ class SessionManager { - private const WORKSPACE_POSTFIX = '_live'; private string $workspace; private string $workspaceLive; diff --git a/src/SuluPhpcrMigrationBundle.php b/src/SuluPhpcrMigrationBundle.php index 7120e07..b20ff18 100644 --- a/src/SuluPhpcrMigrationBundle.php +++ b/src/SuluPhpcrMigrationBundle.php @@ -11,6 +11,7 @@ namespace Sulu\Bundle\PhpcrMigrationBundle; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,6 +21,9 @@ class SuluPhpcrMigrationBundle extends AbstractBundle { + /** + * @param mixed[] $config + */ public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void { $loader = new XmlFileLoader($builder, new FileLocator(__DIR__ . '/../Resources/config')); @@ -29,7 +33,9 @@ public function loadExtension(array $config, ContainerConfigurator $container, C public function configure(DefinitionConfigurator $definition): void { - $definition->rootNode() + /** @var ArrayNodeDefinition $rootNode */ + $rootNode = $definition->rootNode(); + $rootNode ->children() ->scalarNode('DSN')->isRequired()->end() ->end(); @@ -37,17 +43,17 @@ public function configure(DefinitionConfigurator $definition): void public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void { + /** @var array{'DSN': string}[] $config */ $config = $builder->getExtensionConfig('sulu_phpcr_migration'); - /** @var string $dsn */ $dsn = $config[0]['DSN']; $builder->setParameter('sulu_phpcr_migration.dsn', $dsn); $configuration = $this->getConnectionConfiguration($dsn); $builder->setParameter('sulu_phpcr_migration.configuration', $configuration); - if ('dbal' === $configuration['connection']['type']) { - $builder->setAlias('sulu_phpcr_migration.connection', \sprintf('doctrine.dbal.%s_connection', $configuration['connection']['name'])); + if ('dbal' === $configuration['connection']['type'] && $name = ($configuration['connection']['name'] ?? null)) { + $builder->setAlias('sulu_phpcr_migration.connection', \sprintf('doctrine.dbal.%s_connection', $name)); return; } @@ -56,11 +62,11 @@ public function prependExtension(ContainerConfigurator $container, ContainerBuil /** * @return array{ * connection: array{ - * type: 'dbal' | 'jackrabbit', + * type: string, * name?: string, * url?: string, - * user?: string, - * password?: string + * user?: string|null, + * password?: string|null * }, * workspace: array{ * default: string, @@ -70,10 +76,21 @@ public function prependExtension(ContainerConfigurator $container, ContainerBuil */ private function getConnectionConfiguration(string $dsn): array { + /** @var array{ + * scheme: string, + * host?: string, + * port?: string, + * path?: string, + * query: string, + * user?: string, + * pass?: string + * } $parts + */ $parts = \parse_url($dsn); \parse_str($parts['query'], $query); - $workspace = $query['workspace']; + /** @var string|null $workspace */ + $workspace = $query['workspace'] ?? ''; unset($query['workspace']); if (!$workspace) { @@ -90,21 +107,21 @@ private function getConnectionConfiguration(string $dsn): array ], ]; - if ('dbal' === $parts['scheme']) { - $result['connection']['name'] = $parts['host']; + if ('dbal' === $parts['scheme'] && ($host = $parts['host'] ?? null)) { + $result['connection']['name'] = $host; return $result; } - $result['url'] = \sprintf( - '%s:%s/%s%s', - $parts['host'], - $parts['port'], - $parts['path'], + $result['connection']['url'] = \sprintf( + '%s:%s%s%s', + $parts['host'] ?? '', + $parts['port'] ?? '', + $parts['path'] ?? '', $query ? '?' . \http_build_query($query) : '', ); - $result['user'] = $parts['user'] ?? null; - $result['password'] = $parts['pass'] ?? null; + $result['connection']['user'] = $parts['user'] ?? null; + $result['connection']['password'] = $parts['pass'] ?? null; return $result; } From 38deb6ca6a70994c20fa06d5b86edb20b964ea7c Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Tue, 30 Apr 2024 11:25:31 +0200 Subject: [PATCH 4/7] Add CI and linting tools --- .editorconfig | 20 ++++ .github/workflows/test-application.yaml | 84 ++++++++++++++++ .gitignore | 6 +- Tests/Application/.env | 1 + Tests/Application/config/bootstrap.php | 39 ++++++++ Tests/Functional/.gitkeep | 0 Tests/Unit/.gitkeep | 0 Tests/test-bootstrap.php | 16 +++ composer.json | 124 ++++++++++++++---------- deptrac.yaml | 32 ++++++ phpstan.neon | 4 +- phpunit.xml.dist | 25 +++++ 12 files changed, 296 insertions(+), 55 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/test-application.yaml create mode 100644 Tests/Application/.env create mode 100644 Tests/Application/config/bootstrap.php create mode 100644 Tests/Functional/.gitkeep create mode 100644 Tests/Unit/.gitkeep create mode 100644 Tests/test-bootstrap.php create mode 100644 deptrac.yaml create mode 100644 phpunit.xml.dist diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4a27d2a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 120 + +[{docker-compose.yml,docker-compose.override.yml}] +indent_size = 2 + +# markdown uses two trailing spaces for explicit line breaks +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml new file mode 100644 index 0000000..ac7b131 --- /dev/null +++ b/.github/workflows/test-application.yaml @@ -0,0 +1,84 @@ +name: Test application + +on: + pull_request: + push: + branches: + - '[0-9]+.x' + - '[0-9]+.[0-9]+' + +jobs: + test: + name: 'PHP ${{ matrix.php-version }} (${{ matrix.dependency-versions }})' + runs-on: ubuntu-latest + + env: + APP_ENV: test + DATABASE_URL: mysql://root:root@127.0.0.1:3306/su_content_test?serverVersion=5.7.32 + DATABASE_CHARSET: utf8mb4 + DATABASE_COLLATE: utf8mb4_unicode_ci + + strategy: + fail-fast: false + matrix: + include: + - php-version: '8.1' + dependency-versions: 'lowest' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + + - php-version: '8.2' + dependency-versions: 'highest' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 + + steps: + - name: Checkout project + uses: actions/checkout@v2 + + - name: Install and configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: ctype, iconv, mysql + tools: 'composer:v2' + + - name: Install composer dependencies + uses: ramsey/composer-install@v2 + with: + dependency-versions: ${{ matrix.dependency-versions }} + composer-options: ${{ matrix.composer-options }} + + - name: Execute test cases + run: composer test + + lint: + name: "PHP Lint" + runs-on: ubuntu-latest + + steps: + - name: Checkout project + uses: actions/checkout@v2 + + - name: Install and configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + extensions: ctype, iconv, mysql + + - name: Install composer dependencies + uses: ramsey/composer-install@v2 + with: + dependency-versions: highest + + - name: Lint Code + run: composer lint diff --git a/.gitignore b/.gitignore index 3eae03f..bb19384 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,8 @@ jackrabbit/* ###> symfony/web-server-bundle ### /.web-server-pid -###< symfony/web-server-bundle ### \ No newline at end of file +###< symfony/web-server-bundle ### + +###> qossmic/deptrac ### +/.deptrac.cache +###< qossmic/deptrac ### diff --git a/Tests/Application/.env b/Tests/Application/.env new file mode 100644 index 0000000..afd9352 --- /dev/null +++ b/Tests/Application/.env @@ -0,0 +1 @@ +APP_ENV=test diff --git a/Tests/Application/config/bootstrap.php b/Tests/Application/config/bootstrap.php new file mode 100644 index 0000000..7314acf --- /dev/null +++ b/Tests/Application/config/bootstrap.php @@ -0,0 +1,39 @@ +=1.2) +if (\is_array($env = @include \dirname(__DIR__) . '/.env.local.php')) { + $_SERVER += $env; + $_ENV += $env; +} elseif (!\class_exists(Dotenv::class)) { + throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); +} else { + $path = \dirname(__DIR__) . '/.env'; + $dotenv = new Dotenv(); + $dotenv->loadEnv($path); +} + +$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; +$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; +$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || \filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/Tests/Functional/.gitkeep b/Tests/Functional/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Tests/Unit/.gitkeep b/Tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Tests/test-bootstrap.php b/Tests/test-bootstrap.php new file mode 100644 index 0000000..42cbea5 --- /dev/null +++ b/Tests/test-bootstrap.php @@ -0,0 +1,16 @@ + + + + + + + + + + + + + ./Tests/Unit + + + + ./Tests/Functional + + + From 7782f23a25ad636c611054c0a7f1b3e892bffedf Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Tue, 30 Apr 2024 13:59:52 +0200 Subject: [PATCH 5/7] Add rector --- Tests/Application/config/bootstrap.php | 2 +- composer.json | 12 +++++++ rector.php | 33 +++++++++++++++++++ src/Application/Session/SessionManager.php | 8 ++--- .../Command/MigratePhpcrCommand.php | 2 +- 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 rector.php diff --git a/Tests/Application/config/bootstrap.php b/Tests/Application/config/bootstrap.php index 7314acf..36801a1 100644 --- a/Tests/Application/config/bootstrap.php +++ b/Tests/Application/config/bootstrap.php @@ -35,5 +35,5 @@ } $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; -$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; +$_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || \filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/composer.json b/composer.json index 2e7a829..d7ed68e 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "phpstan/phpstan-webmozart-assert": "^1.2", "phpunit/phpunit": "^10.0", "qossmic/deptrac": "^1.0", + "rector/rector": "^1.0", "symfony/dotenv": "^6.0 || ^7.0", "thecodingmachine/phpstan-strict-rules": "^1.0" }, @@ -51,6 +52,7 @@ "lint": [ "@phpstan", "@php-cs", + "@lint-rector", "@lint-composer", "@deptrac" ], @@ -61,8 +63,18 @@ "phpstan": [ "@php vendor/bin/phpstan analyze" ], + "fix": [ + "@rector", + "@php-cs-fix" + ], "php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run", "php-cs-fix": "@php vendor/bin/php-cs-fixer fix", + "rector": [ + "@php vendor/bin/rector process" + ], + "lint-rector": [ + "@php vendor/bin/rector process --dry-run" + ], "lint-composer": "@composer validate --strict", "deptrac": "@php vendor/qossmic/deptrac/deptrac.php" }, diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..60374f6 --- /dev/null +++ b/rector.php @@ -0,0 +1,33 @@ +paths([__DIR__ . '/src', __DIR__ . '/Tests']); + + $rectorConfig->phpstanConfigs([ + __DIR__ . '/phpstan.neon', + ]); + + // basic rules + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(false); + + $rectorConfig->sets([ + SetList::CODE_QUALITY, + LevelSetList::UP_TO_PHP_81, + ]); +}; diff --git a/src/Application/Session/SessionManager.php b/src/Application/Session/SessionManager.php index 3cfff12..7ee6a1a 100644 --- a/src/Application/Session/SessionManager.php +++ b/src/Application/Session/SessionManager.php @@ -19,8 +19,8 @@ class SessionManager { - private string $workspace; - private string $workspaceLive; + private readonly string $workspace; + private readonly string $workspaceLive; /** * @param array{ @@ -39,7 +39,7 @@ class SessionManager */ public function __construct( private array $configuration, - private ?Connection $connection = null, + private readonly ?Connection $connection = null, ) { $this->workspace = $configuration['workspace']['default']; $this->workspaceLive = $configuration['workspace']['live']; @@ -57,7 +57,7 @@ public function getLiveSession(): SessionInterface private function getSession(string $workspace): SessionInterface { - $factory = $this->connection ? new RepositoryFactoryDoctrineDBAL() : new RepositoryFactoryJackrabbit(); + $factory = $this->connection instanceof Connection ? new RepositoryFactoryDoctrineDBAL() : new RepositoryFactoryJackrabbit(); $repository = $factory->getRepository(\array_filter([ 'jackalope.doctrine_dbal_connection' => $this->connection, 'jackalope.jackrabbit_uri' => $this->configuration['connection']['url'] ?? null, diff --git a/src/UserInterface/Command/MigratePhpcrCommand.php b/src/UserInterface/Command/MigratePhpcrCommand.php index 3485690..174355a 100644 --- a/src/UserInterface/Command/MigratePhpcrCommand.php +++ b/src/UserInterface/Command/MigratePhpcrCommand.php @@ -20,7 +20,7 @@ #[AsCommand(name: 'sulu:phpcr-migration:migrate', description: 'Migrate the PHPCR content repository to the SuluContentBundle.')] class MigratePhpcrCommand extends Command { - public function __construct(private SessionManager $sessionManager) + public function __construct(private readonly SessionManager $sessionManager) { parent::__construct(); } From b088f44bfd0027f92876b185e0de81a94810ffb7 Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Tue, 30 Apr 2024 16:10:01 +0200 Subject: [PATCH 6/7] Fix package name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d7ed68e..d4096f7 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sulu/sulu-phpcr-migration-bundle", + "name": "sulu/phpcr-migration-bundle", "license": "MIT", "description": "The bundle provides command to migrate the Sulu database from phpCr to the SuluContentBundle.", "keywords": [ From a54843067676288fa39eb888f337676e45cdb687 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 30 Apr 2024 16:19:57 +0200 Subject: [PATCH 7/7] Update .github/workflows/test-application.yaml --- .github/workflows/test-application.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index ac7b131..d8ee319 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -32,6 +32,11 @@ jobs: env: SYMFONY_DEPRECATIONS_HELPER: weak + - php-version: '8.3' + dependency-versions: 'highest' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + services: mysql: image: mysql:8.0