From 38deb6ca6a70994c20fa06d5b86edb20b964ea7c Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Tue, 30 Apr 2024 11:25:31 +0200 Subject: [PATCH] Add CI and linting tools --- .editorconfig | 20 ++++ .github/workflows/test-application.yaml | 84 ++++++++++++++++ .gitignore | 6 +- Tests/Application/.env | 1 + Tests/Application/config/bootstrap.php | 39 ++++++++ Tests/Functional/.gitkeep | 0 Tests/Unit/.gitkeep | 0 Tests/test-bootstrap.php | 16 +++ composer.json | 124 ++++++++++++++---------- deptrac.yaml | 32 ++++++ phpstan.neon | 4 +- phpunit.xml.dist | 25 +++++ 12 files changed, 296 insertions(+), 55 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/test-application.yaml create mode 100644 Tests/Application/.env create mode 100644 Tests/Application/config/bootstrap.php create mode 100644 Tests/Functional/.gitkeep create mode 100644 Tests/Unit/.gitkeep create mode 100644 Tests/test-bootstrap.php create mode 100644 deptrac.yaml create mode 100644 phpunit.xml.dist diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4a27d2a --- /dev/null +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml new file mode 100644 index 0000000..ac7b131 --- /dev/null +++ b/.github/workflows/test-application.yaml @@ -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:root@127.0.0.1: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 diff --git a/.gitignore b/.gitignore index 3eae03f..bb19384 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,8 @@ jackrabbit/* ###> symfony/web-server-bundle ### /.web-server-pid -###< symfony/web-server-bundle ### \ No newline at end of file +###< symfony/web-server-bundle ### + +###> qossmic/deptrac ### +/.deptrac.cache +###< qossmic/deptrac ### diff --git a/Tests/Application/.env b/Tests/Application/.env new file mode 100644 index 0000000..afd9352 --- /dev/null +++ b/Tests/Application/.env @@ -0,0 +1 @@ +APP_ENV=test diff --git a/Tests/Application/config/bootstrap.php b/Tests/Application/config/bootstrap.php new file mode 100644 index 0000000..7314acf --- /dev/null +++ b/Tests/Application/config/bootstrap.php @@ -0,0 +1,39 @@ +=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'; diff --git a/Tests/Functional/.gitkeep b/Tests/Functional/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Tests/Unit/.gitkeep b/Tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Tests/test-bootstrap.php b/Tests/test-bootstrap.php new file mode 100644 index 0000000..42cbea5 --- /dev/null +++ b/Tests/test-bootstrap.php @@ -0,0 +1,16 @@ + + + + + + + + + + + + + ./Tests/Unit + + + + ./Tests/Functional + + +