Skip to content

Commit

Permalink
Added linting + test menu builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Jarrand committed Aug 6, 2021
1 parent 520741c commit e0bef4b
Show file tree
Hide file tree
Showing 14 changed files with 537 additions and 28 deletions.
115 changes: 115 additions & 0 deletions .github/workflow/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: 'CI'

on:
push:
branches:
- master
pull_request:

jobs:

lint:
name: 'Lint'
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
coverage: "none"
extensions: "json"
ini-values: "memory_limit=-1"
php-version: "8.0"

- name: 'Determine composer cache directory'
id: composer-cache
run: echo "::set-output name=directory::$(composer config cache-dir)"

- name: 'Cache composer dependencies'
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: 7.4-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: 7.4-composer-

- name: 'Install dependencies'
id: deps
run: |
echo "::group::composer update"
composer update --no-progress --ansi
echo "::endgroup::"
echo "::group::install phpunit"
# Required for PhpStan
vendor/bin/simple-phpunit install
echo "::endgroup::"
- name: 'Composer validate'
if: always() && steps.deps.outcome == 'success'
run: composer validate --strict

- name: 'PHP CS Fixer'
if: always() && steps.deps.outcome == 'success'
run: vendor/bin/php-cs-fixer fix --dry-run --diff

- name: 'PhpStan'
if: always() && steps.deps.outcome == 'success'
run: vendor/bin/phpstan analyse

tests:
name: 'Tests'
runs-on: ubuntu-latest
timeout-minutes: 5

strategy:
fail-fast: false # don't cancel other matrix jobs on failure
matrix:
php: [ '7.4', '8.0' ]

steps:
- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
coverage: "none"
extensions: "json"
ini-values: "memory_limit=-1"
php-version: "${{ matrix.php }}"

- name: 'Determine composer cache directory'
id: composer-cache
run: echo "::set-output name=directory::$(composer config cache-dir)"

- name: 'Cache composer dependencies'
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-

- name: 'Fixup Composer'
if: matrix.php == 8.0
run: |
echo "::group::Fixup Composer platform config for third-parties deps not PHP 8 ready yet"
composer config platform.php 7.4.99
echo "::endgroup::"
- name: 'Install dependencies'
run: |
echo "::group::composer update"
composer update --no-progress --ansi
echo "::endgroup::"
echo "::group::install phpunit"
vendor/bin/simple-phpunit install
echo "::endgroup::"
- name: 'Run tests'
run: vendor/bin/simple-phpunit --testdox

11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ######

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

/vendor/
composer.lock
29 changes: 29 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$finder = (new PhpCsFixer\Finder())->in([
__DIR__
]);

return (new PhpCsFixer\Config())
->setFinder($finder)
->setCacheFile('.php-cs-fixer.cache') // forward compatibility with 3.x line
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@Symfony' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'no_superfluous_phpdoc_tags' => true,
'ordered_imports' => true,
'phpdoc_annotation_without_dot' => false,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'simplified_null_return' => false,
'single_line_throw' => false,
'void_return' => true,
'yoda_style' => false,
])
;
6 changes: 3 additions & 3 deletions DependencyInjection/ElaoAdminThemeExtension.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

declare(strict_types=1);

namespace Elao\Bundle\AdminThemeBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class ElaoAdminThemeExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
Expand Down
2 changes: 2 additions & 0 deletions ElaoAdminThemeBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Elao\Bundle\AdminThemeBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down
55 changes: 52 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
.SILENT:

## Colors
COLOR_RESET = \033[0m
COLOR_INFO = \033[32m
COLOR_COMMENT = \033[33m

## Help
help:
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n"
printf " make [target]\n\n"
printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n"
awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

###########
# Install #
###########

## Install dependencies
install:
composer install
composer update

########
# Lint #
########

lint: lint-twig
## Run code style checks
lint: lint.php-cs-fixer lint.phpstan lint.composer lint.twig

lint.php-cs-fixer:
vendor/bin/php-cs-fixer fix

lint.phpstan:
vendor/bin/phpstan analyse .

lint.composer:
composer validate --strict

lint-twig:
lint.twig:
php bin/lint.twig.php Resources/views

############
# Security #
############

# Run Symfony security check
security.symfony:
symfony check:security

########
# Test #
########

## Run tests
test:
vendor/bin/simple-phpunit
Loading

0 comments on commit e0bef4b

Please sign in to comment.