Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added linting + test menu builder #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
119 changes: 119 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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

- name: 'Twig'
if: always() && steps.deps.outcome == 'success'
run: php bin/lint.twig.php Resources/views

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