Skip to content

Commit

Permalink
Add CI and linting tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn committed Apr 30, 2024
1 parent 755b76a commit 38deb6c
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 55 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[{docker-compose.yml,docker-compose.override.yml}]
indent_size = 2

# markdown uses two trailing spaces for explicit line breaks
[*.md]
trim_trailing_whitespace = false
84 changes: 84 additions & 0 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Test application

on:
pull_request:
push:
branches:
- '[0-9]+.x'
- '[0-9]+.[0-9]+'

jobs:
test:
name: 'PHP ${{ matrix.php-version }} (${{ matrix.dependency-versions }})'
runs-on: ubuntu-latest

env:
APP_ENV: test
DATABASE_URL: mysql://root:[email protected]:3306/su_content_test?serverVersion=5.7.32
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci

strategy:
fail-fast: false
matrix:
include:
- php-version: '8.1'
dependency-versions: 'lowest'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.2'
dependency-versions: 'highest'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ctype, iconv, mysql
tools: 'composer:v2'

- name: Install composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependency-versions }}
composer-options: ${{ matrix.composer-options }}

- name: Execute test cases
run: composer test

lint:
name: "PHP Lint"
runs-on: ubuntu-latest

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: ctype, iconv, mysql

- name: Install composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest

- name: Lint Code
run: composer lint
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ jackrabbit/*

###> symfony/web-server-bundle ###
/.web-server-pid
###< symfony/web-server-bundle ###
###< symfony/web-server-bundle ###

###> qossmic/deptrac ###
/.deptrac.cache
###< qossmic/deptrac ###
1 change: 1 addition & 0 deletions Tests/Application/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_ENV=test
39 changes: 39 additions & 0 deletions Tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

use Symfony\Component\Dotenv\Dotenv;

$file = __DIR__ . '/../../../vendor/autoload.php';

if (!\file_exists($file)) {
throw new RuntimeException('Install dependencies to run test suite.');
}

require $file;

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (\is_array($env = @include \dirname(__DIR__) . '/.env.local.php')) {
$_SERVER += $env;
$_ENV += $env;
} elseif (!\class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
$path = \dirname(__DIR__) . '/.env';
$dotenv = new Dotenv();
$dotenv->loadEnv($path);
}

$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || \filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
Empty file added Tests/Functional/.gitkeep
Empty file.
Empty file added Tests/Unit/.gitkeep
Empty file.
16 changes: 16 additions & 0 deletions Tests/test-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

\date_default_timezone_set('UTC');

require __DIR__ . '/Application/config/bootstrap.php';
124 changes: 72 additions & 52 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,76 @@
{
"name": "sulu/sulu-phpcr-migration-bundle",
"license": "MIT",
"description": "The bundle provides command to migrate the Sulu database from phpCr to the SuluContentBundle.",
"keywords": ["sulu", "phpcr", "migration", "content-bundle"],
"type": "sulu-bundle",
"authors": [
{
"name": "Sulu Community",
"homepage": "https://github.com/sulu/SuluPHPCRMigrationBundle/graphs/contributors"
}
],
"require": {
"php": "^8.1",
"jackalope/jackalope-doctrine-dbal": "^1.7",
"jackalope/jackalope-jackrabbit": "^1.4",
"symfony/config": "^6.0 | ^7.0",
"symfony/console": "^6.0 | ^7.0",
"symfony/dependency-injection": "^6.0 | ^7.0",
"symfony/framework-bundle": "^6.0 | ^7.0"
},
"autoload": {
"psr-4": {
"Sulu\\Bundle\\PhpcrMigrationBundle\\": ""
"name": "sulu/sulu-phpcr-migration-bundle",
"license": "MIT",
"description": "The bundle provides command to migrate the Sulu database from phpCr to the SuluContentBundle.",
"keywords": [
"sulu",
"phpcr",
"migration",
"content-bundle"
],
"type": "sulu-bundle",
"authors": [
{
"name": "Sulu Community",
"homepage": "https://github.com/sulu/SuluPHPCRMigrationBundle/graphs/contributors"
}
],
"require": {
"php": "^8.1",
"jackalope/jackalope-doctrine-dbal": "^1.7",
"jackalope/jackalope-jackrabbit": "^1.4",
"symfony/config": "^6.0 | ^7.0",
"symfony/console": "^6.0 | ^7.0",
"symfony/dependency-injection": "^6.0 | ^7.0",
"symfony/framework-bundle": "^6.0 | ^7.0"
},
"autoload": {
"psr-4": {
"Sulu\\Bundle\\PhpcrMigrationBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.41",
"jangregor/phpstan-prophecy": "^1.0",
"phpspec/prophecy-phpunit": "^2.1",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^10.0",
"qossmic/deptrac": "^1.0",
"symfony/dotenv": "^6.0 || ^7.0",
"thecodingmachine/phpstan-strict-rules": "^1.0"
},
"scripts": {
"lint": [
"@phpstan",
"@php-cs",
"@lint-composer",
"@deptrac"
],
"test": [
"@phpunit"
],
"phpunit": "@php vendor/bin/phpunit",
"phpstan": [
"@php vendor/bin/phpstan analyze"
],
"php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
"php-cs-fix": "@php vendor/bin/php-cs-fixer fix",
"lint-composer": "@composer validate --strict",
"deptrac": "@php vendor/qossmic/deptrac/deptrac.php"
},
"exclude-from-classmap": ["/Tests/"]
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.41",
"jangregor/phpstan-prophecy": "^1.0",
"phpspec/prophecy-phpunit": "^2.1",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"phpstan/phpstan-webmozart-assert": "^1.2",
"thecodingmachine/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^10.0",
"symfony/dotenv": "^6.0 || ^7.0"
},
"scripts": {
"php-cs-fix": "@php vendor/bin/php-cs-fixer fix",
"lint-php-cs": "@php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
"phpstan": [
"@php vendor/bin/phpstan analyse"
]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true,
"php-http/discovery": true
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true,
"php-http/discovery": true
}
}
}
}
32 changes: 32 additions & 0 deletions deptrac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
parameters:
paths:
- ./src

layers:
- name: UserInterface
collectors:
- type: directory
regex: UserInterface/.*
- name: Infrastructure
collectors:
- type: directory
regex: Infrastructure/.*
- name: Application
collectors:
- type: directory
regex: Application/.*
- name: Domain
collectors:
- type: directory
regex: Domain/.*

ruleset:
UserInterface:
- Application
- Domain
Infrastructure:
- Application
- Domain
Application:
- Domain
Domain: ~
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
paths:
- src
- tests
level: max
- Tests
level: max
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="Tests/test-bootstrap.php"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<!-- See: https://symfony.com/doc/current/components/phpunit_bridge.html#modified-phpunit-script -->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>

<testsuites>
<testsuite name="Sulu Phpcr Migration Bundle Unit">
<directory>./Tests/Unit</directory>
</testsuite>

<testsuite name="Sulu Phpcr Migration Bundle Functional">
<directory>./Tests/Functional</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 38deb6c

Please sign in to comment.