diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index f6e9ef4..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -coverage_clover: build/logs/clover.xml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..0a11672 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,44 @@ +name: ci + +on: + pull_request: + types: [opened, synchronize] + +jobs: + build: + strategy: + matrix: + php: ['7.4','8.0', '8.1', '8.2'] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer + coverage: false + - name: Install Dependencies + run: composer update --prefer-dist --no-interaction + - name: run tests + run: composer test + - name: run analyze + run: composer analyze + + coverage: + strategy: + matrix: + php: ['8.3'] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer + coverage: xdebug + - name: Install Dependencies + run: composer update --prefer-dist --no-interaction + - name: run tests + run: composer test + - name: run analyze + run: composer analyze diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b9e6823..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: php -sudo: false - -env: - - XDEBUG_MODE=coverage - -php: - - 7.3 - - 7.4 - - 8.0 - -before_install: - - composer self-update - -cache: - directories: - - $HOME/.composer/cache - -install: composer update --prefer-dist --no-interaction - -script: - - ./vendor/bin/phing build - -after_success: - - travis_retry php vendor/bin/coveralls diff --git a/CHANGELOG.md b/CHANGELOG.md index 550ce10..d85378a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [2.0.0] +- Update to new flagception sdk version ^2.0 @migo315 +- Support dbal version ^4.0 @migo315 +- Drop support for dbal version <= 3.5 @migo315 +- Updated min php version to 7.4 (which is also minimum for dbal) @migo315 + ## [1.1.1] - Parametrize sql query to avoid postgres error @martingtheodo diff --git a/README.md b/README.md index 06b70db..86ee5d3 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ class YourClass { public function run() { - $activator = new DatabaseActivator(['url' => 'mysql://user:secret@localhost/mydb']); + $activator = new DatabaseActivator('pdo-mysql://user:secret@localhost/mydb'); $manager = new FeatureManager($activator); if ($manager->isActive('your_feature_name')) { @@ -69,27 +69,7 @@ class YourClass { public function run() { - $activator = new DatabaseActivator([ - 'url' => 'mysql://user:secret@localhost/mydb' - ]); - - // ... - } -} -``` - -###### PDO instance - -``` -// YourClass.php - -class YourClass -{ - public function run() - { - $activator = new DatabaseActivator([ - 'pdo' => $this->myPdoInstance - ]); + $activator = new DatabaseActivator('pdo-mysql://user:secret@localhost/mydb'); // ... } @@ -127,7 +107,7 @@ class YourClass { public function run() { - $activator = new DatabaseActivator(['url' => 'mysql://user:secret@localhost/mydb'], [ + $activator = new DatabaseActivator('pdo-mysql://user:secret@localhost/mydb', [ 'db_table' => 'my_feature_table', 'db_column_feature' => 'foo_feature_name', 'db_column_state' => 'foo_is_active' diff --git a/build.xml b/build.xml deleted file mode 100644 index 57bc2ed..0000000 --- a/build.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/build/phpunit.xml b/build/phpunit.xml index ae2a66d..88637ca 100644 --- a/build/phpunit.xml +++ b/build/phpunit.xml @@ -3,14 +3,6 @@ - - - ../src - - - - - @@ -20,4 +12,4 @@ - + \ No newline at end of file diff --git a/composer.json b/composer.json index ad0e70e..aa46d10 100644 --- a/composer.json +++ b/composer.json @@ -11,18 +11,16 @@ } ], "require": { - "php": "^7.3||^8.0", - "flagception/flagception": "^1.7", - "doctrine/dbal": "^2.12", + "php": "^7.4 || ^8.0", + "flagception/flagception": "^2.0", + "doctrine/dbal": "^3.6 | ^4.0", "symfony/options-resolver": ">=2.7" }, "require-dev": { "ext-pdo": "*", - "phing/phing": "^2.16", - "symfony/phpunit-bridge": "^5.2", - "phpunit/phpunit": "^9.5", - "squizlabs/php_codesniffer": "^3.5", - "php-coveralls/php-coveralls": "^v2.4" + "phpunit/phpunit": "*", + "php-coveralls/php-coveralls": "^2.4.3", + "squizlabs/php_codesniffer": "^3.5" }, "autoload": { "psr-4": { @@ -39,5 +37,11 @@ "name": "flagception/flagception", "url": "https://github.com/bestit/flagception-sdk" } + }, + "scripts": { + "phpunit": "phpunit -c build/phpunit.xml", + "checkstyle": "phpcs --standard=./build/phpcs.xml ./src", + "analyze": "@checkstyle", + "test": "@phpunit" } } diff --git a/src/Activator/DatabaseActivator.php b/src/Activator/DatabaseActivator.php index eb94be0..454c83d 100644 --- a/src/Activator/DatabaseActivator.php +++ b/src/Activator/DatabaseActivator.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Tools\DsnParser; use Flagception\Activator\FeatureActivatorInterface; use Flagception\Model\Context; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -50,13 +51,16 @@ class DatabaseActivator implements FeatureActivatorInterface /** * DatabaseActivator constructor. * - * @param Connection|array $clientOrDsn + * @param Connection|string|array $clientOrDsn * @param array $options */ public function __construct($clientOrDsn, array $options = []) { if ($clientOrDsn instanceof Connection) { $this->connection = $clientOrDsn; + } elseif (is_string($clientOrDsn)) { + $dnsParser = new DsnParser(); + $this->dsn = $dnsParser->parse($clientOrDsn); } else { $this->dsn = $clientOrDsn; } @@ -84,7 +88,7 @@ public function getName(): string * * @throws DBALException|DBALDriverException */ - public function isActive($name, Context $context): bool + public function isActive(string $name, Context $context): bool { $this->setup(); @@ -94,7 +98,7 @@ public function isActive($name, Context $context): bool 'SELECT %s FROM %s WHERE %s = :feature_name', $this->options['db_column_state'], $this->options['db_table'], - $this->options['db_column_feature'], + $this->options['db_column_feature'] ), ['feature_name' => $name] )->fetchOne(); @@ -111,7 +115,7 @@ public function isActive($name, Context $context): bool */ private function setup(): void { - $manager = $this->getConnection()->getSchemaManager(); + $manager = $this->getConnection()->createSchemaManager(); if ($this->tablesExist === true || $manager->tablesExist([$this->options['db_table']]) === true) { $this->tablesExist = true; diff --git a/tests/Activator/DatabaseActivatorTest.php b/tests/Activator/DatabaseActivatorTest.php index b61092b..11041a5 100644 --- a/tests/Activator/DatabaseActivatorTest.php +++ b/tests/Activator/DatabaseActivatorTest.php @@ -71,31 +71,7 @@ public function testSetConnectByCredentials() */ public function testSetConnectByUri() { - $activator = new DatabaseActivator([ - 'url' => 'mysql://user:secret@localhost/mydb' - ]); - - static::assertInstanceOf(Connection::class, $activator->getConnection()); - } - - /** - * Test connection by pdo - * - * @return void - * - * @throws DBALException - */ - public function testSetConnectByPdo() - { - $activator = new DatabaseActivator([ - 'pdo' => $pdo = $this->createMock(PDO::class) - ]); - - $pdo - ->expects(static::once()) - ->method('getAttribute') - ->with(PDO::ATTR_DRIVER_NAME) - ->willReturn('mysql'); + $activator = new DatabaseActivator('pdo-mysql://user:secret@localhost/mydb'); static::assertInstanceOf(Connection::class, $activator->getConnection()); } @@ -126,9 +102,7 @@ public function testSetConnectByDbalInstance() public function testActiveStates() { $activator = new DatabaseActivator( - [ - 'url' => 'sqlite:///:memory:' - ], + 'pdo-sqlite://:memory:', [ 'db_table' => 'my_feature_table', 'db_column_feature' => 'foo_feature_name',