Skip to content

Commit

Permalink
Merge pull request #72 from novaway/2.x-sf7
Browse files Browse the repository at this point in the history
Symfony 7 compatibility
  • Loading branch information
jdecool authored Dec 7, 2024
2 parents a29b63c + 6bb930e commit d7b02e7
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 17 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.1', '8.2', '8.3', '8.4']
flags: ['--prefer-lowest', '--prefer-stable']
symfony-version: ['5.4.*']
include:
- php: 8.2
symfony-version: 6.3.*
symfony-version: 6.4.*
- php: 8.2
symfony-version: 7.1.*
- php: 8.2
symfony-version: 7.2.*
fail-fast: false
steps:
- name: Checkout
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
"php": ">= 7.3",
"ext-json": "*",
"doctrine/annotations": "^1.12|^2.0",
"symfony/framework-bundle": "~4.4|~5.0|~6.0",
"symfony/yaml": "~4.4|~5.0|~6.0"
"symfony/framework-bundle": "~4.4|~5.0|~6.0|~7.0",
"symfony/yaml": "~4.4|~5.0|~6.0|76.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.7",
"phpunit/phpunit": "^9.5",
"symfony/asset": "~3.0|~4.0|~5.0|~6.0",
"symfony/browser-kit": "~4.0|~5.0|~6.0",
"symfony/css-selector": "~4.0|~5.0|~6.0",
"symfony/expression-language": "~4.0|~5.0|~6.0",
"symfony/templating": "~4.0|~5.0|~6.0",
"symfony/twig-bundle": "~4.0|~5.0|~6.0",
"symfony/asset": "~3.0|~4.0|~5.0|~6.0|~7.0",
"symfony/browser-kit": "~4.0|~5.0|~6.0|~7.0",
"symfony/css-selector": "~4.0|~5.0|~6.0|~7.0",
"symfony/expression-language": "~4.0|~5.0|~6.0|~7.0",
"symfony/templating": "~4.0|~5.0|~6.0|~7.0",
"symfony/twig-bundle": "~4.0|~5.0|~6.0|~7.0",
"twig/twig": "^2.15|^3.0"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListFeatureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function getCsvLine(array $columns): string
throw new \RuntimeException('Unable to open temporary file');
}

fputcsv($fp, $columns);
fputcsv($fp, $columns, ',', '"', '\\');

rewind($fp);
$data = fread($fp, 1048576); // 1MB
Expand Down
8 changes: 6 additions & 2 deletions src/EventListener/ControllerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

class ControllerListener implements EventSubscriberInterface
{
/** @var Reader */
/** @var Reader|null */
private $annotationReader;

/**
* Constructor
*/
public function __construct(Reader $reader)
public function __construct(?Reader $reader = null)
{
$this->annotationReader = $reader;
}
Expand Down Expand Up @@ -109,6 +109,10 @@ private function featuresFromAttributes(\ReflectionClass $class, \ReflectionMeth
*/
private function featuresFromAnnotations(\ReflectionClass $class, \ReflectionMethod $method): iterable
{
if (null === $this->annotationReader) {
return [];
}

foreach ($this->annotationReader->getClassAnnotations($class) as $annotation) {
if (!$annotation instanceof Feature) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
novaway_feature_flag.listener.controller:
class: Novaway\Bundle\FeatureFlagBundle\EventListener\ControllerListener
arguments:
- "@annotation_reader"
- "@?annotation_reader"
tags:
- { name: kernel.event_subscriber }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
namespace Novaway\Bundle\FeatureFlagBundle\Tests\Functional\Controller;

use Novaway\Bundle\FeatureFlagBundle\Tests\Functional\WebTestCase;
use Symfony\Component\HttpKernel\Kernel;

final class AnnotationClassDisabledControllerTest extends WebTestCase
{
public function testAnnotationFooDisabledAction(): void
{
if (Kernel::MAJOR_VERSION >= 7) {
static::markTestSkipped('This test is not compatible with Symfony > 7');
}

static::$client->request('GET', '/annotation/class/disabled');
$response = static::$client->getResponse();

Expand Down
17 changes: 17 additions & 0 deletions tests/Functional/Controller/DefaultControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Novaway\Bundle\FeatureFlagBundle\Tests\Functional\Controller;

use Novaway\Bundle\FeatureFlagBundle\Tests\Functional\WebTestCase;
use Symfony\Component\HttpKernel\Kernel;

final class DefaultControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -67,6 +68,10 @@ public function testRequestFooDisabled()

public function testAnnotationFooEnabledAction()
{
if (Kernel::MAJOR_VERSION >= 7) {
static::markTestSkipped('This test is not compatible with Symfony > 7');
}

$crawler = static::$client->request('GET', '/annotation/enabled');

static::assertSame(200, static::$client->getResponse()->getStatusCode());
Expand All @@ -78,6 +83,10 @@ public function testAnnotationFooEnabledAction()

public function testAnnotationFooDisabledAction()
{
if (Kernel::MAJOR_VERSION >= 7) {
static::markTestSkipped('This test is not compatible with Symfony > 7');
}

static::$client->request('GET', '/annotation/disabled');

static::assertSame(404, static::$client->getResponse()->getStatusCode());
Expand All @@ -88,6 +97,10 @@ public function testAnnotationFooDisabledAction()
*/
public function testTwoAnnotationsFooEnabledBarEnabledHasNoAccessBecauseFeatureFooIsEnabledButFeatureBarIsDisabled()
{
if (Kernel::MAJOR_VERSION >= 7) {
static::markTestSkipped('This test is not compatible with Symfony > 7');
}

static::$client->request('GET', '/annotation/bar/enabled/foo/enabled');

static::assertSame(404, static::$client->getResponse()->getStatusCode());
Expand All @@ -98,6 +111,10 @@ public function testTwoAnnotationsFooEnabledBarEnabledHasNoAccessBecauseFeatureF
*/
public function testTwoAnnotationsFooEnabledBarDisabledHasAccessBecauseFeatureFooIsEnabledAndFeatureBarIsDisabled()
{
if (Kernel::MAJOR_VERSION >= 7) {
static::markTestSkipped('This test is not compatible with Symfony > 7');
}

$crawler = static::$client->request('GET', '/annotation/bar/enabled/foo/disabled');

static::assertSame(200, static::$client->getResponse()->getStatusCode());
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Novaway\Bundle\FeatureFlagBundle\Tests\FixturePath;
use Novaway\Bundle\FeatureFlagBundle\Tests\Fixtures\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;

abstract class WebTestCase extends BaseWebTestCase
{
Expand All @@ -41,7 +41,7 @@ protected static function initializeClient(): void
}
}

protected static function getContainer(): ContainerInterface
protected static function getContainer(): Container
{
if (method_exists(BaseWebTestCase::class, 'getContainer')) {
return parent::getContainer();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace units\DependencyInjection;
namespace Novaway\Bundle\FeatureFlagBundle\Tests\Unit\DependencyInjection;

use Novaway\Bundle\FeatureFlagBundle\DependencyInjection\NovawayFeatureFlagExtension;
use Novaway\Bundle\FeatureFlagBundle\Tests\FixturePath;
Expand Down

0 comments on commit d7b02e7

Please sign in to comment.