From 2cc00ecea62f3aff3fd5ed3f5e37341f62247000 Mon Sep 17 00:00:00 2001 From: teiling88 Date: Wed, 22 Nov 2023 14:16:38 +0100 Subject: [PATCH 01/11] update composer.json to support older php versions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ad0e70e..c70949a 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^7.3||^8.0", + "php": "^7.1.3 | ^8.0", "flagception/flagception": "^1.7", "doctrine/dbal": "^2.12", "symfony/options-resolver": ">=2.7" From 25d39ac5911d9925b0b86b1cc4a1ef46194bd39e Mon Sep 17 00:00:00 2001 From: Marcin Morawski Date: Sat, 25 Nov 2023 12:42:05 +0100 Subject: [PATCH 02/11] Fix support for PHP 7.1 Trailing Commas are NOT allowed in calls before PHP 7.3 https://www.php.net/manual/en/migration73.new-features.php#migration73.new-features.core.trailing-commas --- composer.json | 2 +- src/Activator/DatabaseActivator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c70949a..3099a50 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^7.1.3 | ^8.0", + "php": "^7.1.3 || ^8.0", "flagception/flagception": "^1.7", "doctrine/dbal": "^2.12", "symfony/options-resolver": ">=2.7" diff --git a/src/Activator/DatabaseActivator.php b/src/Activator/DatabaseActivator.php index eb94be0..ca53e7b 100644 --- a/src/Activator/DatabaseActivator.php +++ b/src/Activator/DatabaseActivator.php @@ -94,7 +94,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(); From 0e700def95a75cbd7c7a4ed551c0ba5ca994a72c Mon Sep 17 00:00:00 2001 From: teiling88 Date: Wed, 29 Nov 2023 22:05:05 +0100 Subject: [PATCH 03/11] NTR - add dbal v3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3099a50..3f5255c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^7.1.3 || ^8.0", "flagception/flagception": "^1.7", - "doctrine/dbal": "^2.12", + "doctrine/dbal": "^2.12 | ^3.0 ", "symfony/options-resolver": ">=2.7" }, "require-dev": { From aae9f50f7ba1a76f2ac76fe0756ed86910515f44 Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Wed, 26 Feb 2025 18:34:31 +0100 Subject: [PATCH 04/11] feature: update to new sdk version 2.0 --- CHANGELOG.md | 3 +++ composer.json | 2 +- src/Activator/DatabaseActivator.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 550ce10..a123181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [2.0.0] +- Update to new flagception sdk version 2.0 @migo315 + ## [1.1.1] - Parametrize sql query to avoid postgres error @martingtheodo diff --git a/composer.json b/composer.json index 3f5255c..16a02b7 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^7.1.3 || ^8.0", - "flagception/flagception": "^1.7", + "flagception/flagception": "^2.0", "doctrine/dbal": "^2.12 | ^3.0 ", "symfony/options-resolver": ">=2.7" }, diff --git a/src/Activator/DatabaseActivator.php b/src/Activator/DatabaseActivator.php index ca53e7b..3053b59 100644 --- a/src/Activator/DatabaseActivator.php +++ b/src/Activator/DatabaseActivator.php @@ -84,7 +84,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(); From 7993056889d1a71ca015935fedfbf6ebb64d5009 Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Wed, 26 Feb 2025 18:39:47 +0100 Subject: [PATCH 05/11] feature: add working build process for testing --- .coveralls.yml | 1 - .github/workflows/php.yml | 49 +++++++++++++++++++++ .github/workflows/php_code_coverage.yml | 58 +++++++++++++++++++++++++ .travis.yml | 25 ----------- build.xml | 32 -------------- composer.json | 14 +++--- 6 files changed, 116 insertions(+), 63 deletions(-) delete mode 100644 .coveralls.yml create mode 100644 .github/workflows/php.yml create mode 100644 .github/workflows/php_code_coverage.yml delete mode 100644 .travis.yml delete mode 100644 build.xml 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..e23e28d --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,49 @@ +name: ci + +on: + pull_request: + types: [opened, synchronize] + +jobs: + build: + strategy: + matrix: + php: ['7.2','7.3','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 + - name: Make code coverage badge + uses: timkrase/phpunit-coverage-badge@v1.2.1 + with: + coverage_badge_path: output/coverage.svg + push_badge: false diff --git a/.github/workflows/php_code_coverage.yml b/.github/workflows/php_code_coverage.yml new file mode 100644 index 0000000..6f8c402 --- /dev/null +++ b/.github/workflows/php_code_coverage.yml @@ -0,0 +1,58 @@ +name: ci + +on: + push: + branches: [ master ] + +jobs: + build: + strategy: + matrix: + php: ['7.2','7.3','7.4','8.0', '8.1', '8.2', '8.3'] + 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 + - name: Make code coverage badge + uses: timkrase/phpunit-coverage-badge@v1.2.1 + with: + coverage_badge_path: output/coverage.svg + push_badge: false + + - name: Git push to image-data branch + uses: peaceiris/actions-gh-pages@v3 + with: + publish_dir: ./output + publish_branch: image-data + github_token: ${{ secrets.GITHUB_TOKEN }} + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' 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/build.xml b/build.xml deleted file mode 100644 index 57bc2ed..0000000 --- a/build.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/composer.json b/composer.json index 16a02b7..fafd4a2 100644 --- a/composer.json +++ b/composer.json @@ -18,11 +18,9 @@ }, "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 --coverage-text -c build/phpunit.xml", + "checkstyle": "phpcs --standard=./build/phpcs.xml ./src", + "analyze": "@checkstyle", + "test": "@phpunit" } } From 86440ff55e02c3df53edb0fa4cdc720ef5fa1205 Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Wed, 26 Feb 2025 18:45:24 +0100 Subject: [PATCH 06/11] feature: use real pdo instance for test --- tests/Activator/DatabaseActivatorTest.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/Activator/DatabaseActivatorTest.php b/tests/Activator/DatabaseActivatorTest.php index b61092b..9ab5145 100644 --- a/tests/Activator/DatabaseActivatorTest.php +++ b/tests/Activator/DatabaseActivatorTest.php @@ -87,16 +87,12 @@ public function testSetConnectByUri() */ public function testSetConnectByPdo() { + $pdo = new PDO('sqlite::memory:'); + $activator = new DatabaseActivator([ - 'pdo' => $pdo = $this->createMock(PDO::class) + 'pdo' => $pdo ]); - $pdo - ->expects(static::once()) - ->method('getAttribute') - ->with(PDO::ATTR_DRIVER_NAME) - ->willReturn('mysql'); - static::assertInstanceOf(Connection::class, $activator->getConnection()); } From 22084c8e0147764171024385f677864191f4537e Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Thu, 27 Feb 2025 10:54:07 +0100 Subject: [PATCH 07/11] feature: update to current supported dbal versions --- CHANGELOG.md | 4 +++- composer.json | 2 +- src/Activator/DatabaseActivator.php | 8 +++++-- tests/Activator/DatabaseActivatorTest.php | 26 ++--------------------- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a123181..05fe8a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [2.0.0] -- Update to new flagception sdk version 2.0 @migo315 +- Update to new flagception sdk version ^2.0 @migo315 +- Support dbal version ^4.0 @migo315 +- Drop support for dbal version <= 3.5 @migo315 ## [1.1.1] - Parametrize sql query to avoid postgres error @martingtheodo diff --git a/composer.json b/composer.json index fafd4a2..da92903 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^7.1.3 || ^8.0", "flagception/flagception": "^2.0", - "doctrine/dbal": "^2.12 | ^3.0 ", + "doctrine/dbal": "^3.6 | ^4.0", "symfony/options-resolver": ">=2.7" }, "require-dev": { diff --git a/src/Activator/DatabaseActivator.php b/src/Activator/DatabaseActivator.php index 3053b59..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; } @@ -111,7 +115,7 @@ public function isActive(string $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 9ab5145..11041a5 100644 --- a/tests/Activator/DatabaseActivatorTest.php +++ b/tests/Activator/DatabaseActivatorTest.php @@ -71,27 +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() - { - $pdo = new PDO('sqlite::memory:'); - - $activator = new DatabaseActivator([ - 'pdo' => $pdo - ]); + $activator = new DatabaseActivator('pdo-mysql://user:secret@localhost/mydb'); static::assertInstanceOf(Connection::class, $activator->getConnection()); } @@ -122,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', From 6188ee8b4c5e98d7984326a205f02477c52c6188 Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Thu, 27 Feb 2025 10:58:47 +0100 Subject: [PATCH 08/11] feature: update minimum php version 7.4 --- .github/workflows/php.yml | 2 +- .github/workflows/php_code_coverage.yml | 2 +- CHANGELOG.md | 1 + composer.json | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index e23e28d..208ec67 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -8,7 +8,7 @@ jobs: build: strategy: matrix: - php: ['7.2','7.3','7.4','8.0', '8.1', '8.2'] + php: ['7.4','8.0', '8.1', '8.2'] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/php_code_coverage.yml b/.github/workflows/php_code_coverage.yml index 6f8c402..50a92e6 100644 --- a/.github/workflows/php_code_coverage.yml +++ b/.github/workflows/php_code_coverage.yml @@ -8,7 +8,7 @@ jobs: build: strategy: matrix: - php: ['7.2','7.3','7.4','8.0', '8.1', '8.2', '8.3'] + php: ['7.4','8.0', '8.1', '8.2', '8.3'] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 05fe8a3..d85378a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - 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/composer.json b/composer.json index da92903..d2b38fa 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^7.1.3 || ^8.0", + "php": "^7.4 || ^8.0", "flagception/flagception": "^2.0", "doctrine/dbal": "^3.6 | ^4.0", "symfony/options-resolver": ">=2.7" From b10be602502be67d84c15da524495284b6858c71 Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Thu, 27 Feb 2025 11:07:55 +0100 Subject: [PATCH 09/11] fix: remove not working coverage --- .github/workflows/php_code_coverage.yml | 58 ------------------------- build/phpunit.xml | 10 +---- composer.json | 2 +- 3 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 .github/workflows/php_code_coverage.yml diff --git a/.github/workflows/php_code_coverage.yml b/.github/workflows/php_code_coverage.yml deleted file mode 100644 index 50a92e6..0000000 --- a/.github/workflows/php_code_coverage.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: ci - -on: - push: - branches: [ master ] - -jobs: - build: - strategy: - matrix: - php: ['7.4','8.0', '8.1', '8.2', '8.3'] - 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 - - name: Make code coverage badge - uses: timkrase/phpunit-coverage-badge@v1.2.1 - with: - coverage_badge_path: output/coverage.svg - push_badge: false - - - name: Git push to image-data branch - uses: peaceiris/actions-gh-pages@v3 - with: - publish_dir: ./output - publish_branch: image-data - github_token: ${{ secrets.GITHUB_TOKEN }} - user_name: 'github-actions[bot]' - user_email: 'github-actions[bot]@users.noreply.github.com' 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 d2b38fa..aa46d10 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ } }, "scripts": { - "phpunit": "phpunit --coverage-text -c build/phpunit.xml", + "phpunit": "phpunit -c build/phpunit.xml", "checkstyle": "phpcs --standard=./build/phpcs.xml ./src", "analyze": "@checkstyle", "test": "@phpunit" From a4d42e857f84b81651963d3f8e8929414020c5e7 Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Thu, 27 Feb 2025 11:14:51 +0100 Subject: [PATCH 10/11] feature: update documentation --- README.md | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) 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' From c4fa122129c26bd3f2aa75fc50d28279f74b4f6a Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Thu, 27 Feb 2025 11:16:58 +0100 Subject: [PATCH 11/11] feature: remove coverage badge --- .github/workflows/php.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 208ec67..0a11672 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -42,8 +42,3 @@ jobs: run: composer test - name: run analyze run: composer analyze - - name: Make code coverage badge - uses: timkrase/phpunit-coverage-badge@v1.2.1 - with: - coverage_badge_path: output/coverage.svg - push_badge: false