Skip to content

Commit

Permalink
Merge pull request #42 from swagindustries/feature/php-8
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek- authored Dec 18, 2020
2 parents 12e6659 + f68bfb7 commit 68bec15
Show file tree
Hide file tree
Showing 25 changed files with 163 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ trim_trailing_whitespace = false
[*.feature]
indent_size = 2

[{ci.yml,behat.yaml}]
[behat.yaml]
indent_size = 2
143 changes: 85 additions & 58 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ vendor
.php_cs.cache
tests/TestApplication/var
.couscous
.phpunit.result.cache
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -16,18 +16,18 @@
"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",
"doctrine/orm": "^2.6",
"doctrine/orm": "^v2.6.6",
"justinrainbow/json-schema": "^5.2",
"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": {
Expand Down
6 changes: 4 additions & 2 deletions tests/Behat/Context/AbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 3 additions & 4 deletions tests/Melodiia/Crud/Controller/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -53,7 +54,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);
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 5 additions & 7 deletions tests/Melodiia/Crud/Controller/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -48,7 +50,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);
Expand All @@ -71,21 +73,17 @@ protected function setUp()
);
}

/**
* @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);
Expand Down
7 changes: 3 additions & 4 deletions tests/Melodiia/Crud/Controller/GetAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -53,7 +54,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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions tests/Melodiia/Crud/Controller/GetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -29,7 +30,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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions tests/Melodiia/Crud/Controller/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -54,7 +55,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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Melodiia/Crud/FilterCollectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 68bec15

Please sign in to comment.