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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## [6.0.0]
### Removed
- \#27 Remove deprecated `doctrine/annotations` implementation
- \#27 Remove deprecated `doctrine/annotations` implementation @migo315
- Support for pdo instance for database-activator dropped @migo315

### Changed
- Update to Flagception SDK Version ^2.0 @migo315
- Update to Flagception Database Activator Version ^2.0 @migo315

### Fix
- Fix deprecations @calderholding-r
Expand Down
12 changes: 10 additions & 2 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Upgrade from 5.x to 6.0
Support for annotations has been removed. Use PHP 8 attributes instead. In addition, the Flagception SDK has been updated to version 2.0.
The updated SDK added some types for the interfaces, but no other technical changes were made.
Support for annotations has been removed. Use PHP 8 attributes instead. In addition, the Flagception SDK and Flagception Database Activator has been updated to version 2.0.
The updated SDK added some types for the interfaces. The updated Database Activator added support for DBAL 4.0 and dropped support for DBAL 3.5 and below.

## Upgrade steps
### Custom Activators
If you have created custom activators, you need to update interface implementations to match the new SDK version. Only types are added.

### Database Activator
The database activator now requires DBAL 3.6 or higher. If you are using DBAL 3.5 or below, you need to update your dependencies.
In addition, a PDO instance is no longer supported. You need to pass the connection options as an array, string or DBAL instance.

Have fun with Flagception :-)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"require-dev": {
"symfony/phpunit-bridge": "^5.0 | ^6.0 | ^7.0",
"symfony/twig-bridge": "^4.4 | ^5.0 | ^6.0 | ^7.0",
"flagception/database-activator": "^1.0",
"flagception/database-activator": "^2.0",
"squizlabs/php_codesniffer": "^3.3.1",
"php-coveralls/php-coveralls": "^2.0"
},
Expand Down
10 changes: 2 additions & 8 deletions src/DependencyInjection/Configurator/DatabaseConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public function addActivator(ContainerBuilder $container, array $config, array $
$credentials = null;
if (isset($config['dbal'])) {
$credentials = new Reference($config['dbal']);
} elseif (isset($config['pdo'])) {
$credentials = ['pdo' => new Reference($config['pdo'])];
} elseif (isset($config['url'])) {
$credentials = ['url' => $config['url']];
$credentials = $config['url'];
} else {
$credentials = $config['credentials'];
}
Expand Down Expand Up @@ -81,11 +79,10 @@ public function addConfiguration(ArrayNodeDefinition $node)
->validate()
->ifTrue(function ($config) {
return !isset($config['url'])
&& !isset($config['pdo'])
&& !isset($config['dbal'])
&& !isset($config['credentials']);
})
->thenInvalid('You must either set the url, pdo, dbal or credentials field.')
->thenInvalid('You must either set the url, dbal or credentials field.')
->end()
->children()
->booleanNode('enable')
Expand All @@ -103,9 +100,6 @@ public function addConfiguration(ArrayNodeDefinition $node)
->scalarNode('url')
->info('Connection string for the database')
->end()
->scalarNode('pdo')
->info('Service with pdo instance')
->end()
->scalarNode('dbal')
->info('Service with dbal instance')
->end()
Expand Down
90 changes: 62 additions & 28 deletions tests/DependencyInjection/Configurator/DatabaseConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace Flagception\Tests\FlagceptionBundle\DependencyInjection\Configurator;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Flagception\Bundle\FlagceptionBundle\DependencyInjection\Configurator\DatabaseConfigurator;
use Flagception\Bundle\FlagceptionBundle\DependencyInjection\FlagceptionExtension;
use Flagception\Database\Activator\DatabaseActivator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -97,7 +100,7 @@ public function testActivatorCanByEnabled()
'activators' => [
'database' => [
'enable' => true,
'url' => 'mysql://foo'
'url' => 'pdo-sqlite://:memory:'
]
]
]
Expand All @@ -106,6 +109,11 @@ public function testActivatorCanByEnabled()
$extension->load($config, $this->container);

static::assertTrue($this->container->hasDefinition('flagception.activator.database_activator'));

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand All @@ -120,7 +128,7 @@ public function testActivatorCanByEnabledByString()
'activators' => [
'database' => [
'enable' => 'true',
'url' => 'mysql://foo'
'url' => 'pdo-sqlite://:memory:'
]
]
]
Expand All @@ -129,6 +137,11 @@ public function testActivatorCanByEnabledByString()
$extension->load($config, $this->container);

static::assertTrue($this->container->hasDefinition('flagception.activator.database_activator'));

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand All @@ -144,7 +157,7 @@ public function testActivatorSetPriority()
'database' => [
'enable' => true,
'priority' => 10,
'url' => 'mysql://foo'
'url' => 'pdo-sqlite://:memory:'
]
]
]
Expand All @@ -154,6 +167,11 @@ public function testActivatorSetPriority()

$definition = $this->container->getDefinition('flagception.activator.database_activator');
static::assertEquals(10, $definition->getTag('flagception.activator')[0]['priority']);

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand All @@ -168,7 +186,7 @@ public function testActivatorByUrl()
'activators' => [
'database' => [
'enable' => true,
'url' => 'mysql://foo'
'url' => 'pdo-sqlite://:memory:'
]
]
]
Expand All @@ -177,29 +195,11 @@ public function testActivatorByUrl()
$extension->load($config, $this->container);

static::assertTrue($this->container->hasDefinition('flagception.activator.database_activator'));
}

/**
* Test set activator by pdo
*
* @return void
*/
public function testActivatorByPdo()
{
$config = [
[
'activators' => [
'database' => [
'enable' => true,
'pdo' => 'my.pdo.service'
]
]
]
];
$extension = new FlagceptionExtension();
$extension->load($config, $this->container);
/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertTrue($this->container->hasDefinition('flagception.activator.database_activator'));
static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand All @@ -209,6 +209,14 @@ public function testActivatorByPdo()
*/
public function testActivatorByDbal()
{
$this->container->set('my.dbal.service', DriverManager::getConnection([
'dbname' => 'mydb',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost',
'driver' => 'pdo_mysql'
]));

$config = [
[
'activators' => [
Expand All @@ -219,10 +227,16 @@ public function testActivatorByDbal()
]
]
];

$extension = new FlagceptionExtension();
$extension->load($config, $this->container);

static::assertTrue($this->container->hasDefinition('flagception.activator.database_activator'));

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand Down Expand Up @@ -252,6 +266,11 @@ public function testActivatorByCredentials()
$extension->load($config, $this->container);

static::assertTrue($this->container->hasDefinition('flagception.activator.database_activator'));

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand Down Expand Up @@ -280,6 +299,11 @@ public function testActivatorByInvalidCredentials()
$extension->load($config, $this->container);

$this->container->hasDefinition('flagception.activator.database_activator');

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand Down Expand Up @@ -318,7 +342,7 @@ public function testActivatorCacheIsDisabled()
'activators' => [
'database' => [
'enable' => true,
'url' => 'foo'
'url' => 'pdo-sqlite://:memory:'
]
]
]
Expand All @@ -341,7 +365,7 @@ public function testActivatorWithCache()
'activators' => [
'database' => [
'enable' => true,
'url' => 'foo',
'url' => 'pdo-sqlite://:memory:',
'cache' => [
'enable' => true
]
Expand All @@ -359,6 +383,11 @@ public function testActivatorWithCache()
'flagception.activator.database_activator',
$definition->getDecoratedService()[0]
);

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}

/**
Expand All @@ -373,7 +402,7 @@ public function testActivatorWithCacheByString()
'activators' => [
'database' => [
'enable' => true,
'url' => 'foo',
'url' => 'pdo-sqlite://:memory:',
'cache' => [
'enable' => 'true'
]
Expand All @@ -385,5 +414,10 @@ public function testActivatorWithCacheByString()
$extension->load($config, $this->container);

static::assertTrue($this->container->hasDefinition('flagception.activator.database_activator.cache'));

/** @var DatabaseActivator $activator */
$activator = $this->container->get('flagception.activator.database_activator');

static::assertInstanceOf(Connection::class, $activator->getConnection());
}
}
2 changes: 1 addition & 1 deletion tests/Route/IsFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public function testFeatureIsActive()
$isFeature = new IsFeature($manager);
$this->assertTrue($isFeature->__invoke('feature_abc'));
}
}
}