diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..be23455 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,108 @@ +name: "Continuous Integration" + +on: + pull_request: + push: + branches: + - master + +jobs: + phpunit: + name: "PHPUnit (with MySQL)" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.2" + - "7.3" + - "7.4" + + services: + mysql: + image: "mysql:5.7" + env: + MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_ROOT_PASSWORD: + ports: + - "3306:3306" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "" + coverage: "pcov" + tools: "cs2pr" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v1" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml" + + - name: "Upload Code Coverage" + if: ${{ matrix.php-version == '7.4' }} + uses: "codecov/codecov-action@v1" + + - name: "Run a static analysis with phpstan/phpstan" + run: "composer phpstan -- --error-format=checkstyle | cs2pr" + + phpunit-prefer-lowest: + name: "PHPUnit with prefer-lowest" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.2" + - "7.3" + - "7.4" + + services: + mysql: + image: "mysql:8" + env: + MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_ROOT_PASSWORD: + ports: + - "3306:3306" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "" + coverage: "pcov" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v1" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer update --no-interaction --no-progress --no-suggest --prefer-lowest" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b2eaa61..0000000 --- a/.travis.yml +++ /dev/null @@ -1,60 +0,0 @@ -language: php -sudo: false -cache: - directories: - - $HOME/.composer/cache/files - #- $HOME/symfony-bridge/.phpunit - -env: - global: - - PHPUNIT_FLAGS="-v" - - COMPOSER_MEMORY_LIMIT=-1 - #- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit" - -services: - - mysql - -matrix: - fast_finish: true - include: - # Test the latest stable release - - php: 7.2 - - php: 7.3 - - php: 7.4 - env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text" - - # Test LTS versions. - - php: 7.3 - env: DEPENDENCIES="symfony/lts:^4" - - # Latest commit to master - - php: 7.3 - env: STABILITY="dev" - - allow_failures: - # Minimum supported dependencies with the latest and oldest PHP version - - php: 7.3 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" - - php: 7.1 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" - # Dev-master is allowed to fail. - - env: STABILITY="dev" - -before_install: - - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - - if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi; - - if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; - -install: - # To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355 - - if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi - - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction - #- ./vendor/bin/simple-phpunit install - -script: - - composer validate --strict --no-check-lock - # simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and - # it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge) - #- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS - - composer phpstan - - ./vendor/bin/phpunit diff --git a/DependencyInjection/TdbmCompilerPass.php b/DependencyInjection/TdbmCompilerPass.php new file mode 100644 index 0000000..5aadb94 --- /dev/null +++ b/DependencyInjection/TdbmCompilerPass.php @@ -0,0 +1,41 @@ +taggedServicesToReferences($container->findTaggedServiceIds(TdbmExtension::TAG_GENERATOR_LISTENER)); + $codeGeneratorListeners = $this->taggedServicesToReferences($container->findTaggedServiceIds(TdbmExtension::TAG_CODE_GENERATOR_LISTENER)); + + $tdbmConfigurations = array_keys($container->findTaggedServiceIds(TdbmExtension::TAG_TDBM_CONFIGURATION)); + + foreach ($tdbmConfigurations as $tdbmConfiguration) { + $configuration = $container->getDefinition($tdbmConfiguration); + $configuration->setArgument('$generatorListeners', $generatorListeners); + $configuration->setArgument('$codeGeneratorListeners', $codeGeneratorListeners); + } + } + + /** + * @param array $taggedServices Keys are services ids, this is the output of `ContainerBuilder::findTaggedServiceIds` + * @return array + */ + private function taggedServicesToReferences(array $taggedServices): array + { + return array_map(static function (string $serviceId) { + return new Reference($serviceId); + }, array_keys($taggedServices)); + } +} diff --git a/DependencyInjection/TdbmExtension.php b/DependencyInjection/TdbmExtension.php index 6a5c604..5558b13 100644 --- a/DependencyInjection/TdbmExtension.php +++ b/DependencyInjection/TdbmExtension.php @@ -25,7 +25,9 @@ use TheCodingMachine\TDBM\Schema\LockFileSchemaManager; use TheCodingMachine\TDBM\TDBMService; use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser; +use TheCodingMachine\TDBM\Utils\CodeGeneratorListenerInterface; use TheCodingMachine\TDBM\Utils\DefaultNamingStrategy; +use TheCodingMachine\TDBM\Utils\GeneratorListenerInterface; use TheCodingMachine\TDBM\Utils\NamingStrategyInterface; use TheCodingMachine\TDBM\SchemaLockFileDumper; use TheCodingMachine\TDBM\Utils\RootProjectLocator; @@ -39,6 +41,10 @@ class TdbmExtension extends Extension { + public const TAG_GENERATOR_LISTENER = 'tdbm.generatorListener'; + public const TAG_CODE_GENERATOR_LISTENER = 'tdbm.codeGeneratorListener'; + public const TAG_TDBM_CONFIGURATION = 'tdbm.configuration'; + private const DEFAULT_CONFIGURATION_ID = TDBMConfiguration::class; private const DEFAULT_NAMING_STRATEGY_ID = DefaultNamingStrategy::class; @@ -51,6 +57,9 @@ class TdbmExtension extends Extension */ public function load(array $configs, ContainerBuilder $container): void { + $container->registerForAutoconfiguration(GeneratorListenerInterface::class)->addTag(self::TAG_GENERATOR_LISTENER); + $container->registerForAutoconfiguration(CodeGeneratorListenerInterface::class)->addTag(self::TAG_CODE_GENERATOR_LISTENER); + $configuration = new Configuration(); $processedConfig = $this->processConfiguration($configuration, $configs); @@ -138,8 +147,8 @@ private function getConfigurationDefinition(ConnectionConfiguration $config, str $configuration->setArgument(1, $config->getDaoNamespace()); $configuration->setArgument('$connection', new Reference($config->getConnection())); $configuration->setArgument('$namingStrategy', new Reference($namingStrategyServiceId)); - $configuration->setArgument('$codeGeneratorListeners', [new Reference(SymfonyCodeGeneratorListener::class)]); $configuration->setArgument('$cache', new Reference('tdbm.cache')); + $configuration->addTag(self::TAG_TDBM_CONFIGURATION); // Let's name the tdbm lock file after the name of the DBAL connection. diff --git a/TdbmBundle.php b/TdbmBundle.php index 3634617..7b3f0a7 100644 --- a/TdbmBundle.php +++ b/TdbmBundle.php @@ -1,12 +1,20 @@ addCompilerPass(new TdbmCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1); + } +}