Skip to content
Open
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
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
26 changes: 3 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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');

// ...
}
Expand Down Expand Up @@ -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'
Expand Down
32 changes: 0 additions & 32 deletions build.xml

This file was deleted.

10 changes: 1 addition & 9 deletions build/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true"
bootstrap="../vendor/autoload.php">
<coverage>
<include>
<directory>../src</directory>
</include>
<report>
<clover outputFile="./logs/clover.xml"/>
</report>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
Expand All @@ -20,4 +12,4 @@
</testsuite>
</testsuites>
<logging/>
</phpunit>
</phpunit>
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
12 changes: 8 additions & 4 deletions src/Activator/DatabaseActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,13 +51,16 @@ class DatabaseActivator implements FeatureActivatorInterface
/**
* DatabaseActivator constructor.
*
* @param Connection|array<string> $clientOrDsn
* @param Connection|string|array<string> $clientOrDsn
* @param array<string> $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;
}
Expand Down Expand Up @@ -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();

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

Expand Down
30 changes: 2 additions & 28 deletions tests/Activator/DatabaseActivatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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',
Expand Down