diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 8f206bd3..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,139 +0,0 @@ -# PHP CircleCI 2.1 configuration file -# -# Check https://circleci.com/docs/2.0/language-php/ for more details -# -version: 2.1 - -.environment_variables: &environment_variables - APP_ENV: test - DATABASE_URL: mysql://root:root@127.0.0.1:3306/su_content_test - DATABASE_CHARSET: utf8mb4 - DATABASE_COLLATE: utf8mb4_unicode_ci - -commands: - enable_php_pcov: - steps: - - run: - name: Enable PCOV, disable Xdebug - command: | - docker-php-ext-enable pcov - rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini || true - - disable_php_memory_limit: - steps: - - run: - name: Disable PHP memory limit - command: echo -e 'memory_limit=-1' > /usr/local/etc/php/conf.d/memory_limit.ini - -workflows: - version: 2 - default: - jobs: - - composer - - lint: - requires: - - composer - - test: - requires: - - composer - - check-coverage: - requires: - - composer - - test - - coverage-all-upload: - requires: - - test - -jobs: - composer: - docker: - - image: composer:latest - steps: - - checkout - - run: composer config -g cache-dir "$(pwd)/.composer-cache" - - run: composer config platform.php "7.4.12" - - restore_cache: - keys: - - v10-composer-cache-{{ checksum "composer.json" }} - - v10-composer-cache- - - run: composer install -n --prefer-dist --no-scripts - - run: composer phpunit -- install - - run: curl --show-error --silent https://getcomposer.org/installer | php - - save_cache: - paths: - - .composer-cache - key: v10-composer-cache-{{ checksum "composer.json" }} - - persist_to_workspace: - root: . - paths: - - vendor - - composer.phar - - composer.lock - lint: - docker: - - image: sulu/php:7.4-cli - - image: mysql:5.7 - environment: - MYSQL_ROOT_PASSWORD: root - environment: *environment_variables - steps: - - run: echo "waiting for mysql container startup" && sleep 5 - - checkout - - attach_workspace: - at: . - - run: php composer.phar config platform.php "7.4.12" - - run: php composer.phar info - - run: php composer.phar bootstrap-test-environment - - run: php composer.phar lint - - test: - docker: - - image: sulu/php:7.4-cli - - image: mysql:5.7 - environment: - MYSQL_ROOT_PASSWORD: root - environment: *environment_variables - steps: - - run: echo "waiting for mysql container startup" && sleep 5 - - checkout - - attach_workspace: - at: . - - enable_php_pcov - - disable_php_memory_limit - - run: php -m - - run: php composer.phar bootstrap-test-environment - - run: php composer.phar test-with-coverage - - store_artifacts: - path: Tests/reports/html - - store_test_results: - path: Tests/reports - - persist_to_workspace: - root: . - paths: - - Tests/reports - - check-coverage: - docker: - - image: sulu/php:7.4-cli - environment: *environment_variables - steps: - - checkout - - attach_workspace: - at: . - - enable_php_pcov - - disable_php_memory_limit - - run: php composer.phar check-coverage - - coverage-all-upload: - docker: - - image: sulu/php:7.4-cli - environment: *environment_variables - steps: - - checkout - - attach_workspace: - at: . - - disable_php_memory_limit - - run: curl -L https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar --output php-coveralls.phar - - run: chmod +x php-coveralls.phar - - run: apt-get update && apt-get install git -y - - run: php php-coveralls.phar --coverage_clover Tests/reports/clover.xml --json_path Tests/reports/coveralls.json diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 00000000..aaf4992c --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,3 @@ +service_name: github-actions +coverage_clover: Tests/reports/clover.xml +json_path: Tests/reports/coveralls.json diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml new file mode 100644 index 00000000..1d500e25 --- /dev/null +++ b/.github/workflows/test-application.yaml @@ -0,0 +1,101 @@ +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 }}, Lint ${{ matrix.lint }}, Coverage ${{ matrix.coverage }})' + runs-on: ubuntu-latest + + env: + DATABASE_URL: mysql://root:root@127.0.0.1:3306/su_headless_test?serverVersion=5.7 + DATABASE_CHARSET: utf8mb4 + DATABASE_COLLATE: utf8mb4_unicode_ci + + strategy: + fail-fast: false + matrix: + include: + - php-version: '7.2' + lint: false + coverage: false + dependency-versions: 'lowest' + tools: 'composer:v1' + env: + SYMFONY_DEPRECATIONS_HELPER: disabled + + - php-version: '7.4' + lint: true + coverage: true + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + + - php-version: '8.0' + lint: false + coverage: false + dependency-versions: 'highest' + tools: 'composer:v2' + composer-options: '--ignore-platform-reqs' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + + services: + mysql: + image: mysql:5.7 + 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 + coverage: pcov + tools: ${{ matrix.tools }} + + - name: Install composer dependencies + uses: ramsey/composer-install@v1 + with: + dependency-versions: ${{ matrix.dependency-versions }} + composer-options: ${{ matrix.composer-options }} + + - name: Bootstrap test environment + run: composer bootstrap-test-environment + + - name: Execute test + if: matrix.coverage == false + run: composer test + + - name: Execute test with coverage + if: ${{ matrix.coverage }} + run: composer test-with-coverage + + - name: Lint Code + if: ${{ matrix.lint }} + run: composer lint + + - name: Coverage all upload + if: ${{ matrix.coverage }} + run: | + composer global require php-coveralls/php-coveralls + php-coveralls -vvv + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check coverage + if: ${{ matrix.coverage }} + run: composer check-coverage diff --git a/Content/Infrastructure/Doctrine/MetadataLoader.php b/Content/Infrastructure/Doctrine/MetadataLoader.php index f2fca388..6d460b30 100644 --- a/Content/Infrastructure/Doctrine/MetadataLoader.php +++ b/Content/Infrastructure/Doctrine/MetadataLoader.php @@ -14,7 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine; use Doctrine\Common\EventSubscriber; -use Doctrine\Common\Inflector\Inflector; +use Doctrine\Inflector\InflectorFactory; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadataInfo; @@ -196,7 +196,7 @@ private function addField(ClassMetadataInfo $metadata, string $name, string $typ private function getRelationTableName(ClassMetadataInfo $metadata, string $relationName): string { - $inflector = new Inflector(); + $inflector = InflectorFactory::create()->build(); $tableNameParts = explode('_', $metadata->getTableName()); $singularName = $inflector->singularize($tableNameParts[\count($tableNameParts) - 1]) . '_'; $tableNameParts[\count($tableNameParts) - 1] = $singularName; diff --git a/DependencyInjection/SuluContentExtension.php b/DependencyInjection/SuluContentExtension.php index 91951ee8..cb453174 100644 --- a/DependencyInjection/SuluContentExtension.php +++ b/DependencyInjection/SuluContentExtension.php @@ -54,6 +54,7 @@ public function load(array $configs, ContainerBuilder $container): void if ($container->hasParameter('kernel.bundles')) { // TODO FIXME add test here // @codeCoverageIgnoreStart + /** @var string[] $bundles */ $bundles = $container->getParameter('kernel.bundles'); if (\array_key_exists('SuluAutomationBundle', $bundles)) { diff --git a/Tests/Application/Kernel.php b/Tests/Application/Kernel.php index b8a0d4b3..0f82fc54 100644 --- a/Tests/Application/Kernel.php +++ b/Tests/Application/Kernel.php @@ -48,4 +48,14 @@ public function registerContainerConfiguration(LoaderInterface $loader) parent::registerContainerConfiguration($loader); $loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yml'); } + + protected function getKernelParameters() + { + $parameters = parent::getKernelParameters(); + + $gedmoReflection = new \ReflectionClass(\Gedmo\Exception::class); + $parameters['gedmo_directory'] = \dirname($gedmoReflection->getFileName()); + + return $parameters; + } } diff --git a/Tests/Application/config/config.yml b/Tests/Application/config/config.yml index cad22d0f..8180da20 100644 --- a/Tests/Application/config/config.yml +++ b/Tests/Application/config/config.yml @@ -7,7 +7,7 @@ doctrine: gedmo_tree: type: xml prefix: Gedmo\Tree\Entity - dir: "%kernel.project_dir%/../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity" + dir: "%gedmo_directory%/Tree/Entity" alias: GedmoTree is_bundle: false diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php index 417f95e4..83f6c279 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentPublishTaskHandlerTest.php @@ -13,8 +13,8 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Automation; -use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ObjectRepository; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php index 410efc54..07507069 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Automation/ContentUnpublishTaskHandlerTest.php @@ -13,8 +13,8 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Infrastructure\Sulu\Automation; -use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ObjectRepository; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; diff --git a/composer.json b/composer.json index e4abb952..33a3ad07 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,16 @@ "homepage": "https://github.com/sulu/SuluContentBundle", "license": "MIT", "require": { - "php": "^7.2", + "php": "^7.2 || ^8.0", + "doctrine/inflector": "^1.4.1 || ^2.0.1", + "doctrine/collections": "^1.0", + "doctrine/orm": "^2.5.3", + "doctrine/persistence": "^1.3 || ^2.0", "doctrine/doctrine-bundle": "^1.10 || ^2.0", "friendsofsymfony/rest-bundle": "^2.6 || ^3.0", "massive/search-bundle": "^2.4", "ramsey/uuid": "^3.8", - "sulu/sulu": "^2.0.4", + "sulu/sulu": "^2.0.4 || ^2.3@dev", "symfony/config": "^4.3 || ^5.0", "symfony/dependency-injection": "^4.3 || ^5.0", "symfony/event-dispatcher": "^4.3 || ^5.0", @@ -31,7 +35,8 @@ "webmozart/assert": "^1.3" }, "require-dev": { - "coduo/php-matcher": "^3.2 || ^4.0 || ^5.0", + "coduo/php-matcher": "^3.2 || ^4.0 || ^5.0 || ^6.0", + "doctrine/data-fixtures": "^1.3.3", "doctrine/doctrine-fixtures-bundle": "^2.0 || ^3.0", "friendsofphp/php-cs-fixer": "^2.17", "handcraftedinthealps/code-coverage-checker": "^0.2.1", @@ -40,6 +45,7 @@ "jangregor/phpstan-prophecy": "^0.8", "matthiasnoback/symfony-config-test": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^4.0", + "php-coveralls/php-coveralls": "^2.4", "phpstan/phpstan": "^0.12", "phpstan/phpstan-doctrine": "^0.12", "phpstan/phpstan-phpunit": "^0.12", @@ -54,6 +60,7 @@ "symfony/framework-bundle": "^4.3 || ^5.0", "symfony/monolog-bundle": "^3.1", "symfony/phpunit-bridge": "^5.2", + "symfony/string": "^4.3 || ^5.0", "thecodingmachine/phpstan-strict-rules": "^0.12" }, "conflict": {