Skip to content
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
108 changes: 108 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -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"
60 changes: 0 additions & 60 deletions .travis.yml

This file was deleted.

41 changes: 41 additions & 0 deletions DependencyInjection/TdbmCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace TheCodingMachine\TDBM\Bundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class TdbmCompilerPass implements CompilerPassInterface
{

/**
* @inheritDoc
*/
public function process(ContainerBuilder $container)
{
$generatorListeners = $this->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<string, array> $taggedServices Keys are services ids, this is the output of `ContainerBuilder::findTaggedServiceIds`
* @return array<Reference>
*/
private function taggedServicesToReferences(array $taggedServices): array
{
return array_map(static function (string $serviceId) {
return new Reference($serviceId);
}, array_keys($taggedServices));
}
}
11 changes: 10 additions & 1 deletion DependencyInjection/TdbmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);

Expand Down Expand Up @@ -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.

Expand Down
12 changes: 10 additions & 2 deletions TdbmBundle.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

declare(strict_types=1);

namespace TheCodingMachine\TDBM\Bundle;


use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use TheCodingMachine\TDBM\Bundle\DependencyInjection\TdbmCompilerPass;

class TdbmBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

}
$container->addCompilerPass(new TdbmCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
}
}