From f14bf720070bdde66223d34e734ac6e1a9f35657 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Fri, 18 Dec 2020 00:20:27 +0100 Subject: [PATCH 1/4] update(php): Melodiia now supports 100% PHP8 --- .gitignore | 1 + composer.json | 10 +++++----- tests/Melodiia/Crud/Controller/CreateTest.php | 2 +- tests/Melodiia/Crud/Controller/DeleteTest.php | 2 +- tests/Melodiia/Crud/Controller/GetAllTest.php | 2 +- tests/Melodiia/Crud/Controller/GetTest.php | 2 +- tests/Melodiia/Crud/Controller/UpdateTest.php | 2 +- tests/Melodiia/Crud/FilterCollectionFactoryTest.php | 2 +- tests/Melodiia/Crud/FilterCollectionTest.php | 2 +- .../Crud/Pagination/PaginationRequestFactoryTest.php | 2 +- tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php | 4 ++-- .../Controller/SwaggerUiControllerTest.php | 2 +- tests/Melodiia/Error/OnErrorTest.php | 2 +- tests/Melodiia/Form/ApiRequestHandlerTest.php | 2 +- .../ReorderDataToMatchCollectionListenerTest.php | 2 +- tests/Melodiia/MelodiiaConfigurationTest.php | 2 +- tests/Melodiia/Response/FormErrorResponseTest.php | 2 +- .../Serialization/Json/OkContentNormalizerTest.php | 2 +- 18 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 9f4eb18..21e5f23 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor .php_cs.cache tests/TestApplication/var .couscous +.phpunit.result.cache diff --git a/composer.json b/composer.json index 08833ed..5c91a91 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Library that helps you build APIs", "type": "symfony-bundle", "scripts": { - "phpcs": "php-cs-fixer fix --using-cache=false", + "phpcs": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix --using-cache=false", "test-app": "@php -S localhost:8000 -t tests/TestApplication/public", "post-install-cmd": "make hooks.install" }, @@ -16,8 +16,8 @@ "symfony/serializer": "^4.3 || ^5.0" }, "require-dev": { - "phpunit/phpunit": "^7.5", - "friendsofphp/php-cs-fixer": "^2.13", + "phpunit/phpunit": "^8.5", + "friendsofphp/php-cs-fixer": "^2.17", "phpspec/prophecy": "^1.8", "twig/twig": "^2.5", "symfony/symfony": "^4.3 || ^5.0", @@ -26,8 +26,8 @@ "doctrine/annotations": "^1.8", "doctrine/doctrine-bundle": "^2.1", "behat/behat": "^3.7", - "friends-of-behat/symfony-extension": "^2.1", - "fzaninotto/faker": "^1.9" + "friends-of-behat/symfony-extension": "dev-master#c6c16503105ddd1852490884cdf4d2c1f253b7e6", + "fakerphp/faker": "^1.12.1" }, "autoload": { "psr-4": { diff --git a/tests/Melodiia/Crud/Controller/CreateTest.php b/tests/Melodiia/Crud/Controller/CreateTest.php index 5d6c148..01890b3 100644 --- a/tests/Melodiia/Crud/Controller/CreateTest.php +++ b/tests/Melodiia/Crud/Controller/CreateTest.php @@ -53,7 +53,7 @@ class CreateTest extends TestCase /** @var Create */ private $controller; - public function setUp() + public function setUp(): void { $this->formFactory = $this->prophesize(FormFactoryInterface::class); $this->form = $this->prophesize(FormInterface::class); diff --git a/tests/Melodiia/Crud/Controller/DeleteTest.php b/tests/Melodiia/Crud/Controller/DeleteTest.php index c670411..76bc94a 100644 --- a/tests/Melodiia/Crud/Controller/DeleteTest.php +++ b/tests/Melodiia/Crud/Controller/DeleteTest.php @@ -48,7 +48,7 @@ class DeleteTest extends TestCase /** @var Delete */ private $controller; - protected function setUp() + protected function setUp(): void { $this->request = $this->prophesize(Request::class); $this->dataStore = $this->prophesize(DataStoreInterface::class); diff --git a/tests/Melodiia/Crud/Controller/GetAllTest.php b/tests/Melodiia/Crud/Controller/GetAllTest.php index 845ba61..961d876 100644 --- a/tests/Melodiia/Crud/Controller/GetAllTest.php +++ b/tests/Melodiia/Crud/Controller/GetAllTest.php @@ -53,7 +53,7 @@ class GetAllTest extends TestCase /** @var GetAll */ private $controller; - public function setUp() + public function setUp(): void { $this->dataStore = $this->prophesize(DataStoreInterface::class); $this->authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class); diff --git a/tests/Melodiia/Crud/Controller/GetTest.php b/tests/Melodiia/Crud/Controller/GetTest.php index 9638800..b5dab3c 100644 --- a/tests/Melodiia/Crud/Controller/GetTest.php +++ b/tests/Melodiia/Crud/Controller/GetTest.php @@ -29,7 +29,7 @@ class GetTest extends TestCase /** @var Get */ private $controller; - public function setUp() + public function setUp(): void { $this->dataStore = $this->prophesize(DataStoreInterface::class); $this->authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class); diff --git a/tests/Melodiia/Crud/Controller/UpdateTest.php b/tests/Melodiia/Crud/Controller/UpdateTest.php index b8eca78..b2a75c2 100644 --- a/tests/Melodiia/Crud/Controller/UpdateTest.php +++ b/tests/Melodiia/Crud/Controller/UpdateTest.php @@ -54,7 +54,7 @@ class UpdateTest extends TestCase /** @var Update */ private $controller; - public function setUp() + public function setUp(): void { $this->formFactory = $this->prophesize(FormFactoryInterface::class); $this->form = $this->prophesize(FormInterface::class); diff --git a/tests/Melodiia/Crud/FilterCollectionFactoryTest.php b/tests/Melodiia/Crud/FilterCollectionFactoryTest.php index a08daa8..a790d5e 100644 --- a/tests/Melodiia/Crud/FilterCollectionFactoryTest.php +++ b/tests/Melodiia/Crud/FilterCollectionFactoryTest.php @@ -19,7 +19,7 @@ class FilterCollectionFactoryTest extends TestCase /** @var FormFactoryInterface|ObjectProphecy */ private $formFactory; - public function setUp() + public function setUp(): void { $this->formFactory = $this->prophesize(FormFactoryInterface::class); } diff --git a/tests/Melodiia/Crud/FilterCollectionTest.php b/tests/Melodiia/Crud/FilterCollectionTest.php index 7eb7089..46d3471 100644 --- a/tests/Melodiia/Crud/FilterCollectionTest.php +++ b/tests/Melodiia/Crud/FilterCollectionTest.php @@ -20,7 +20,7 @@ class FilterCollectionTest extends TestCase /** @var FormFactoryInterface|ObjectProphecy */ private $formFactory; - public function setUp() + public function setUp(): void { $formBuilder = $this->prophesize(FormBuilderInterface::class); $formBuilder->getForm()->willReturn($this->prophesize(FormInterface::class)->reveal()); diff --git a/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php b/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php index 39ae361..a0558d5 100644 --- a/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php +++ b/tests/Melodiia/Crud/Pagination/PaginationRequestFactoryTest.php @@ -29,7 +29,7 @@ class PaginationRequestFactoryTest extends TestCase /** @var PaginationRequestFactoryInterface */ private $subject; - protected function setUp() + protected function setUp(): void { $this->configuration = $this->prophesize(MelodiiaConfigurationInterface::class); $this->request = $this->prophesize(Request::class); diff --git a/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php b/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php index ad5fc26..279a753 100644 --- a/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php +++ b/tests/Melodiia/Crud/Tools/SimpleIdResolverTest.php @@ -15,12 +15,12 @@ class SimpleIdResolverTest extends TestCase { private $subject; - protected function setUp() + protected function setUp(): void { $this->subject = new SimpleIdResolver(); } - protected function tearDown() + protected function tearDown(): void { $this->subject = null; } diff --git a/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php b/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php index 701599c..806499f 100644 --- a/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php +++ b/tests/Melodiia/Documentation/Controller/SwaggerUiControllerTest.php @@ -21,7 +21,7 @@ class SwaggerUiControllerTest extends TestCase /** @var Environment|ObjectProphecy */ private $templating; - public function setUp() + public function setUp(): void { $this->templating = $this->prophesize(Environment::class); } diff --git a/tests/Melodiia/Error/OnErrorTest.php b/tests/Melodiia/Error/OnErrorTest.php index ced0875..dc6c135 100644 --- a/tests/Melodiia/Error/OnErrorTest.php +++ b/tests/Melodiia/Error/OnErrorTest.php @@ -19,7 +19,7 @@ class OnErrorTest extends TestCase /** @var SerializerInterface|ObjectProphecy */ private $serializer; - public function setUp() + public function setUp(): void { $this->serializer = $this->prophesize(SerializerInterface::class); $this->serializer->serialize(Argument::cetera())->willReturn('{}'); diff --git a/tests/Melodiia/Form/ApiRequestHandlerTest.php b/tests/Melodiia/Form/ApiRequestHandlerTest.php index c17c60e..d657f5e 100644 --- a/tests/Melodiia/Form/ApiRequestHandlerTest.php +++ b/tests/Melodiia/Form/ApiRequestHandlerTest.php @@ -40,7 +40,7 @@ public function setUp(): void $this->request->getMethod()->willReturn('POST'); } - public function tearDown() + public function tearDown(): void { $this->subject = null; $this->form = null; diff --git a/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php b/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php index ceb1770..e97cfbf 100644 --- a/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php +++ b/tests/Melodiia/Form/Listener/ReorderDataToMatchCollectionListenerTest.php @@ -28,7 +28,7 @@ protected function setUp(): void $this->subject = new ReorderDataToMatchCollectionListener(); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); $this->factory = null; diff --git a/tests/Melodiia/MelodiiaConfigurationTest.php b/tests/Melodiia/MelodiiaConfigurationTest.php index b96fab6..39c4c1e 100644 --- a/tests/Melodiia/MelodiiaConfigurationTest.php +++ b/tests/Melodiia/MelodiiaConfigurationTest.php @@ -18,7 +18,7 @@ class MelodiiaConfigurationTest extends TestCase /** @var MelodiiaConfiguration */ private $subject; - protected function setUp() + protected function setUp(): void { $this->router = $this->prophesize(RouterInterface::class); $this->subject = new MelodiiaConfiguration($this->provideConfig(), $this->router->reveal()); diff --git a/tests/Melodiia/Response/FormErrorResponseTest.php b/tests/Melodiia/Response/FormErrorResponseTest.php index 6250681..3760a6d 100644 --- a/tests/Melodiia/Response/FormErrorResponseTest.php +++ b/tests/Melodiia/Response/FormErrorResponseTest.php @@ -32,7 +32,7 @@ class FormErrorResponseTest extends TestCase */ private $formFactory; - public function setUp() + public function setUp(): void { $validator = Validation::createValidator(); $this->formFactory = Forms::createFormFactoryBuilder() diff --git a/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php b/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php index ec2d578..3763f0f 100644 --- a/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php +++ b/tests/Melodiia/Serialization/Json/OkContentNormalizerTest.php @@ -31,7 +31,7 @@ class OkContentNormalizerTest extends TestCase /** @var OkContentNormalizer */ private $okContentNormalizer; - public function setUp() + public function setUp(): void { $this->mainNormalizer = $this->prophesize(Serializer::class); $this->requestStack = $this->prophesize(RequestStack::class); From 63091827589c586ebe05fadf3c6d7bea69a1ff72 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Fri, 18 Dec 2020 00:25:42 +0100 Subject: [PATCH 2/4] feat(tests): prepare for phpunit 9 --- tests/Melodiia/Crud/Controller/CreateTest.php | 5 ++--- tests/Melodiia/Crud/Controller/DeleteTest.php | 10 ++++------ tests/Melodiia/Crud/Controller/GetAllTest.php | 5 ++--- tests/Melodiia/Crud/Controller/GetTest.php | 5 ++--- tests/Melodiia/Crud/Controller/UpdateTest.php | 5 ++--- tests/Melodiia/Crud/FilterCollectionTest.php | 8 ++------ tests/Melodiia/Response/FormErrorResponseTest.php | 9 +++------ 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/tests/Melodiia/Crud/Controller/CreateTest.php b/tests/Melodiia/Crud/Controller/CreateTest.php index 01890b3..dff745a 100644 --- a/tests/Melodiia/Crud/Controller/CreateTest.php +++ b/tests/Melodiia/Crud/Controller/CreateTest.php @@ -24,6 +24,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; class CreateTest extends TestCase { @@ -124,11 +125,9 @@ public function testICanChangeTheClearSubmitParam() $this->assertEquals(201, $res->httpStatus()); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException - */ public function testItThrowAccessDeniedInCaseOfNonGrantedAccess() { + $this->expectException(AccessDeniedException::class); $this->attributes->get(CrudControllerInterface::SECURITY_CHECK, null)->willReturn('edit'); $this->checker->isGranted(Argument::cetera())->willReturn(false); diff --git a/tests/Melodiia/Crud/Controller/DeleteTest.php b/tests/Melodiia/Crud/Controller/DeleteTest.php index 76bc94a..0bfc148 100644 --- a/tests/Melodiia/Crud/Controller/DeleteTest.php +++ b/tests/Melodiia/Crud/Controller/DeleteTest.php @@ -24,7 +24,9 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; class DeleteTest extends TestCase { @@ -71,21 +73,17 @@ protected function setUp(): void ); } - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - */ public function testItThrow404IfNonExistingItem() { + $this->expectException(NotFoundHttpException::class); $this->dataStore->find(Argument::any(), 'id')->willReturn(null); ($this->controller)($this->request->reveal()); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException - */ public function testItDoesNotAllowIllegalAccess() { + $this->expectException(AccessDeniedException::class); $this->dataStore->find(FakeMelodiiaModel::class, 'id')->willReturn(new \stdClass()); $this->attributes->get(CrudControllerInterface::SECURITY_CHECK, null)->willReturn('edit'); $this->checker->isGranted(Argument::cetera())->willReturn(false); diff --git a/tests/Melodiia/Crud/Controller/GetAllTest.php b/tests/Melodiia/Crud/Controller/GetAllTest.php index 961d876..5935d79 100644 --- a/tests/Melodiia/Crud/Controller/GetAllTest.php +++ b/tests/Melodiia/Crud/Controller/GetAllTest.php @@ -23,6 +23,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; class GetAllTest extends TestCase { @@ -115,11 +116,9 @@ public function testItStillReturn200OkOnEmptyPaginated() $this->assertInstanceOf(OkContent::class, $res); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException - */ public function testItCheckAccessToResourceIfSpecifiedInConfiguration() { + $this->expectException(AccessDeniedException::class); $this->attributes->get(CrudControllerInterface::SECURITY_CHECK, null)->willReturn('view'); $this->authorizationChecker->isGranted('view', Argument::any())->willReturn(false); diff --git a/tests/Melodiia/Crud/Controller/GetTest.php b/tests/Melodiia/Crud/Controller/GetTest.php index b5dab3c..f93aacd 100644 --- a/tests/Melodiia/Crud/Controller/GetTest.php +++ b/tests/Melodiia/Crud/Controller/GetTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; class GetTest extends TestCase { @@ -76,11 +77,9 @@ public function testItReturnNotFoundResponseInCaseOfNoResultFromDataStore() $this->assertInstanceOf(NotFound::class, $res); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException - */ public function testItCheckAccessToResourceIfSpecifiedInConfiguration() { + $this->expectException(AccessDeniedException::class); $this->dataStore->find(FakeMelodiiaModel::class, 'id')->willReturn(new \stdClass())->shouldBeCalled(); $request = $this->prophesize(Request::class); $attributes = $this->prophesize(ParameterBag::class); diff --git a/tests/Melodiia/Crud/Controller/UpdateTest.php b/tests/Melodiia/Crud/Controller/UpdateTest.php index b2a75c2..7ecbd4f 100644 --- a/tests/Melodiia/Crud/Controller/UpdateTest.php +++ b/tests/Melodiia/Crud/Controller/UpdateTest.php @@ -25,6 +25,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; class UpdateTest extends TestCase { @@ -115,11 +116,9 @@ public function testItUpdateMelodiiaObject() $this->assertInstanceOf(OkContent::class, $res); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException - */ public function testItThrowAccessDeniedInCaseOfNonGrantedAccess() { + $this->expectException(AccessDeniedException::class); $this->attributes->get(CrudControllerInterface::SECURITY_CHECK, null)->willReturn('edit'); $this->checker->isGranted(Argument::cetera())->willReturn(false); diff --git a/tests/Melodiia/Crud/FilterCollectionTest.php b/tests/Melodiia/Crud/FilterCollectionTest.php index 46d3471..e29b6f9 100644 --- a/tests/Melodiia/Crud/FilterCollectionTest.php +++ b/tests/Melodiia/Crud/FilterCollectionTest.php @@ -38,19 +38,15 @@ public function testItFilterQuery() $collection->filter($this->prophesize(QueryBuilder::class)->reveal()); } - /** - * @expectedException \TypeError - */ public function testItDoesNotAcceptSomethingElseThanFilter() { + $this->expectException(\TypeError::class); $collection = new FilterCollection($this->formFactory->reveal(), [new \stdClass()]); } - /** - * @expectedException \TypeError - */ public function testItDoesNotAcceptSomethingElseThanFilterInAdd() { + $this->expectException(\TypeError::class); $collection = new FilterCollection($this->formFactory->reveal()); $collection->add(new \stdClass()); } diff --git a/tests/Melodiia/Response/FormErrorResponseTest.php b/tests/Melodiia/Response/FormErrorResponseTest.php index 3760a6d..4a3a270 100644 --- a/tests/Melodiia/Response/FormErrorResponseTest.php +++ b/tests/Melodiia/Response/FormErrorResponseTest.php @@ -5,6 +5,7 @@ namespace SwagIndustries\Melodiia\Test\Response; use PHPUnit\Framework\TestCase; +use SwagIndustries\Melodiia\Exception\InvalidResponseException; use SwagIndustries\Melodiia\Response\FormErrorResponse; use SwagIndustries\Melodiia\Response\Model\UserDataError; use Symfony\Component\Form\AbstractType; @@ -41,20 +42,16 @@ public function setUp(): void ; } - /** - * @expectedException \SwagIndustries\Melodiia\Exception\InvalidResponseException - */ public function testItFailsIfFormNotSubmitted() { + $this->expectException(InvalidResponseException::class); $form = $this->formFactory->createNamedBuilder('')->add('foo')->getForm(); new FormErrorResponse($form); } - /** - * @expectedException \SwagIndustries\Melodiia\Exception\InvalidResponseException - */ public function testItFailsIfFormHasNoError() { + $this->expectException(InvalidResponseException::class); $form = $this->formFactory->createNamedBuilder('')->add('foo')->getForm(); $form->submit(['foo' => 'hello']); new FormErrorResponse($form); From 7ba216eab93d4569e4844e5d36af8ae9e57776e7 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Fri, 18 Dec 2020 00:37:05 +0100 Subject: [PATCH 3/4] feat(ci): review CI and add more tests version --- .editorconfig | 2 +- .github/workflows/ci.yml | 143 +++++++++++++++++++++++---------------- 2 files changed, 86 insertions(+), 59 deletions(-) diff --git a/.editorconfig b/.editorconfig index fb20aa5..19fec7f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -28,5 +28,5 @@ trim_trailing_whitespace = false [*.feature] indent_size = 2 -[{ci.yml,behat.yaml}] +[behat.yaml] indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0132ce4..f8666fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,63 +1,90 @@ name: Test suite on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - schedule: - - cron: '0 0 * * *' + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + - cron: '0 0 * * *' jobs: - unit-test: - runs-on: ubuntu-latest - - strategy: - matrix: - php: [7.4] - - steps: - - uses: actions/checkout@v2 - - - uses: actions/cache@v2 - id: cache-composer - with: - path: ~/.composer/cache - key: composer-php-${{ matrix.php }}-${{ github.sha }} - restore-keys: composer-php-${{ matrix.php }}- - - - name: Valid composer.json - run: make test.composer - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest - - - name: Run PHP CS Fixer - run: make test.phpcs - - - name: Run PHPUnit tests - run: make test.phpunit - - functional-test: - runs-on: ubuntu-latest - - strategy: - matrix: - php: [7.4] - - steps: - - uses: actions/checkout@v2 - - - uses: actions/cache@v2 - id: cache-composer - with: - path: ~/.composer/cache - key: composer-php-${{ matrix.php }}-${{ github.sha }} - restore-keys: composer-php-${{ matrix.php }}- - - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest - - - name: Run Behat tests - run: make test.behat + unit-test: + name: Unit tests + strategy: + matrix: + php: [ 7.4, 8.0 ] + os: [ ubuntu-latest ] + include: + - os: [ ubuntu-latest ] + php: 8.1 + composer-flag: "'--ignore-platform-reqs'" + + - os: [ ubuntu-latest ] + php: 7.3 + composer-flag: "'--prefer-lowest'" + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + + - uses: actions/cache@v2 + id: cache-composer + with: + path: ~/.composer/cache + key: composer-php-${{ matrix.php }}-${{ github.sha }} + restore-keys: composer-php-${{ matrix.php }}- + + - name: Valid composer.json + run: make test.composer + + - name: Install dependencies + run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-flag }} + + - name: Run PHP CS Fixer + run: make test.phpcs + + - name: Run PHPUnit tests + run: make test.phpunit + + functional-test: + name: Functionnal tests + strategy: + matrix: + php: [ 7.4, 8.0 ] + os: [ ubuntu-latest ] + include: + - os: [ ubuntu-latest ] + php: 8.1 + composer-flag: "'--ignore-platform-reqs'" + + - os: [ ubuntu-latest ] + php: 7.3 + composer-flag: "'--prefer-lowest'" + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + + - uses: actions/cache@v2 + id: cache-composer + with: + path: ~/.composer/cache + key: composer-php-${{ matrix.php }}-${{ github.sha }} + restore-keys: composer-php-${{ matrix.php }}- + + + - name: Install dependencies + run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-flag }} + + - name: Run Behat tests + run: make test.behat From f68bfb70ac9717b73be88a373811925e1e342ef8 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Fri, 18 Dec 2020 01:22:01 +0100 Subject: [PATCH 4/4] feat(compatibility): fix compatibility with Sf 4.4 --- composer.json | 2 +- tests/Behat/Context/AbstractContext.php | 6 +++-- tests/TestApplication/config/bootstrap.php | 7 ++++- tests/TestApplication/config/config.yaml | 3 +++ .../src/Controller/TodoContainsAction.php | 6 ++--- tests/TestApplication/src/Kernel.php | 27 ++++++++++++++----- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 5c91a91..ac14084 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "phpspec/prophecy": "^1.8", "twig/twig": "^2.5", "symfony/symfony": "^4.3 || ^5.0", - "doctrine/orm": "^2.6", + "doctrine/orm": "^v2.6.6", "justinrainbow/json-schema": "^5.2", "doctrine/annotations": "^1.8", "doctrine/doctrine-bundle": "^2.1", diff --git a/tests/Behat/Context/AbstractContext.php b/tests/Behat/Context/AbstractContext.php index 41b1dbd..99dfebf 100644 --- a/tests/Behat/Context/AbstractContext.php +++ b/tests/Behat/Context/AbstractContext.php @@ -12,8 +12,10 @@ abstract class AbstractContext implements Context { - private KernelInterface $kernel; - protected Generator $faker; + /** @var KernelInterface */ + private $kernel; + /** @var Generator */ + protected $faker; public function __construct(KernelInterface $kernel) { diff --git a/tests/TestApplication/config/bootstrap.php b/tests/TestApplication/config/bootstrap.php index 9ca86d1..960f20d 100644 --- a/tests/TestApplication/config/bootstrap.php +++ b/tests/TestApplication/config/bootstrap.php @@ -6,4 +6,9 @@ require dirname(__DIR__) . '/../../vendor/autoload.php'; -(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env'); +$dotenv = new Dotenv(); +if (method_exists($dotenv, 'bootEnv')) { + $dotenv->bootEnv(dirname(__DIR__) . '/.env'); +} else { + $dotenv->load(dirname(__DIR__) . '/.env'); +} diff --git a/tests/TestApplication/config/config.yaml b/tests/TestApplication/config/config.yaml index 83cb231..269acf5 100644 --- a/tests/TestApplication/config/config.yaml +++ b/tests/TestApplication/config/config.yaml @@ -1,6 +1,9 @@ parameters: router.request_context.host: 'localhost' + # BC Layer for Symfony 4.4 + kernel.secret: 'SuperSecret' + framework: serializer: ~ form: ~ diff --git a/tests/TestApplication/src/Controller/TodoContainsAction.php b/tests/TestApplication/src/Controller/TodoContainsAction.php index e4523e5..67c9bb7 100644 --- a/tests/TestApplication/src/Controller/TodoContainsAction.php +++ b/tests/TestApplication/src/Controller/TodoContainsAction.php @@ -5,9 +5,9 @@ namespace TestApplication\Controller; use Doctrine\ORM\EntityManagerInterface; +use Nekland\Tools\StringTools; use SwagIndustries\Melodiia\Response\Model\Collection; use SwagIndustries\Melodiia\Response\OkContent; -use Symfony\Component\String\UnicodeString; use TestApplication\Entity\Todo; class TodoContainsAction @@ -18,9 +18,7 @@ class TodoContainsAction public function __invoke(EntityManagerInterface $manager, $word) { $todos = array_filter($manager->getRepository(Todo::class)->findAll(), function (Todo $todo) use ($word) { - $str = new UnicodeString($todo->getContent()); - - return $str->containsAny($word); + return StringTools::contains($todo->getContent(), $word); }); return new OkContent(new Collection($todos)); diff --git a/tests/TestApplication/src/Kernel.php b/tests/TestApplication/src/Kernel.php index 8d70395..7306849 100644 --- a/tests/TestApplication/src/Kernel.php +++ b/tests/TestApplication/src/Kernel.php @@ -5,21 +5,23 @@ namespace TestApplication; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel; -use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; class Kernel extends BaseKernel { use MicroKernelTrait; - protected function configureContainer(ContainerConfigurator $container): void + protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { - $container->import('../config/config.yaml'); - $container->import('../config/melodiia.yaml'); +// $container->import('../config/config.yaml'); +// $container->import('../config/melodiia.yaml'); + $loader->load(__DIR__ . '/../config/config.yaml'); + $loader->load(__DIR__ . '/../config/melodiia.yaml'); } - protected function configureRoutes(RoutingConfigurator $routes): void + protected function configureRoutes($routes): void { $routes->import('../config/routing.yaml'); $routes->import('../config/routing_dev.yaml'); @@ -29,4 +31,17 @@ public function getProjectDir() { return dirname(__DIR__); } + + /** + * BC Layer for Symfony 4.4. + */ + public function registerBundles(): iterable + { + $contents = require $this->getProjectDir() . '/config/bundles.php'; + foreach ($contents as $class => $envs) { + if ($envs[$this->environment] ?? $envs['all'] ?? false) { + yield new $class(); + } + } + } }