diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index dbf699e7..edffed96 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -15,12 +15,16 @@ jobs: - name: "checkout" uses: "actions/checkout@v4" - - name: "build the environment" - run: "dev/bin/docker-compose build" + - name: "setup php" + uses: "shivammathur/setup-php@v2" + with: + php-version: "latest" + tools: "composer, flex" - - name: "check coding standards" - run: "dev/bin/php php-cs-fixer fix --dry-run --diff --ansi" + - name: "install composer dependencies" + uses: "ramsey/composer-install@v3" + env: + COMPOSER_PREFER_STABLE: 1 - - name: clear docker volumes - if: ${{ always() }} - run: dev/bin/docker-compose down --volumes + - name: "check coding standards" + run: "vendor/bin/php-cs-fixer fix --dry-run --diff --ansi" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index db713a25..e6bdf369 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,29 +11,20 @@ jobs: static-analysis: name: "static analysis" runs-on: "ubuntu-latest" - strategy: - fail-fast: false - matrix: - php: ['8.4'] - symfony: ['7.2.*'] - composer-flags: ['--prefer-stable'] - - env: - SYMFONY_REQUIRE: ${{ matrix.symfony }} - steps: - name: "checkout" uses: "actions/checkout@v4" - - name: "build the environment" - run: "dev/bin/docker-compose build --build-arg PHP_VERSION=${{ matrix.php }} php" + - name: "setup php" + uses: "shivammathur/setup-php@v2" + with: + php-version: "latest" + tools: "composer, flex" - - name: "install dependencies" - run: "dev/bin/php composer update --ansi ${{ matrix.composer-flags }}" + - name: "install composer dependencies" + uses: "ramsey/composer-install@v3" + env: + COMPOSER_PREFER_STABLE: 1 - name: "run phpstan static analysis" - run: "dev/bin/php phpstan --memory-limit=256M --ansi" - - - name: clear docker volumes - if: ${{ always() }} - run: dev/bin/docker-compose down --volumes + run: "vendor/bin/phpstan --ansi" diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e08f1307..8a0ef0f8 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -5,25 +5,27 @@ on: push: ~ schedule: # Do not make it the first of the month and/or midnight since it is a very busy time - - cron: "10 10 5 * *" + - cron: "* 10 5 * *" jobs: tests: - runs-on: ubuntu-latest - continue-on-error: ${{ matrix.can-fail }} + runs-on: "ubuntu-latest" + continue-on-error: "${{ matrix.can-fail }}" strategy: fail-fast: false matrix: - php: ['8.1', '8.2', '8.3', '8.4'] - symfony: ['6.4.*', '7.1.*', '7.2.*'] - doctrine-orm: ['^2.14', '^3.0'] - composer-flags: ['--prefer-stable'] + php: ["8.1", "8.2", "8.3", "8.4"] + symfony: ["6.4.*", "7.1.*", "7.2.*"] + doctrine-orm: ["^2.14", "^3.0"] + dependency-versions: ["highest"] + composer-stable: ["1"] can-fail: [false] include: - php: "8.1" symfony: "6.4.*" doctrine-orm: "^2.14" - composer-flags: '--prefer-stable --prefer-lowest' + dependency-versions: "lowest" + composer-stable: "1" can-fail: false exclude: - php: "8.1" @@ -31,27 +33,34 @@ jobs: - php: "8.1" symfony: "7.2.*" - name: "PHP ${{ matrix.php }} - Doctrine ${{ matrix.doctrine-orm }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}" - - env: - SYMFONY_REQUIRE: ${{ matrix.symfony }} + name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }} - Doctrine ORM ${{ matrix.doctrine-orm }} - Composer ${{ matrix.dependency-versions }}" steps: - name: "checkout" uses: "actions/checkout@v4" - - name: "build the PHP environment" - run: "dev/bin/docker-compose build --build-arg PHP_VERSION=${{ matrix.php }} --build-arg XDEBUG_VERSION='3.4.0' php" + - name: "setup php" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php }}" + tools: "composer, flex" + + - name: "enable Symfony Flex plugin" + run: "composer global config --no-interaction allow-plugins.symfony/flex true" - name: "require specific Doctrine ORM version" - run: "dev/bin/php composer require --ansi ${{ matrix.composer-flags }} --no-install doctrine/orm:${{ matrix.doctrine-orm }}" + env: + SYMFONY_REQUIRE: "${{ matrix.symfony }}" + COMPOSER_PREFER_STABLE: "${{ matrix.composer-stable }}" + run: "composer require --no-scripts --no-install --dev doctrine/orm:${{ matrix.doctrine-orm }} --ansi" - - name: "install dependencies" - run: "dev/bin/php composer update --ansi ${{ matrix.composer-flags }}" + - name: "install composer dependencies" + uses: "ramsey/composer-install@v3" + env: + SYMFONY_REQUIRE: "${{ matrix.symfony }}" + COMPOSER_PREFER_STABLE: "${{ matrix.composer-stable }}" + with: + dependency-versions: "${{ matrix.dependency-versions }}" - name: "run unit tests" - run: "dev/bin/php-test vendor/bin/simple-phpunit --colors=always" - - - name: clear docker volumes - if: ${{ always() }} - run: dev/bin/docker-compose down --volumes + run: "vendor/bin/simple-phpunit --colors=always" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f05172b..a3ce35cb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,40 +16,22 @@ We accept contributions via Pull Requests on [Github](https://github.com/thephpl ## Development -[Docker](https://www.docker.com/) and [Docker Compose](https://github.com/docker/compose) are required for the development environment. +[PHP](https://www.php.net/) 8.1+ and [Composer](https://getcomposer.org/) 2+ are required for the development environment. ### Building the environment -Make sure your Docker images are all built and up-to-date using the following command: +Download all the needed packages required to develop the project: ```sh -dev/bin/docker-compose build +composer update --prefer-stable ``` -> **NOTE:** You can target a different version of PHP during development by appending the `--build-arg PHP_VERSION=` argument. - -After that, download all the needed packages required to develop the project: - -```sh -dev/bin/php composer update --prefer-stable -``` - -### Debugging - -You can run the debugger using the following command: - -```sh -dev/bin/php-debug vendor/bin/simple-phpunit -``` - -Make sure your IDE is setup properly, for more information check out the [dedicated documentation](docs/debugging.md). - ### Code linting This bundle enforces the PSR-2 and Symfony code standards during development by using the [PHP CS Fixer](https://cs.symfony.com/) utility. Before committing any code, you can run the utility to fix any potential rule violations: ```sh -dev/bin/php php-cs-fixer fix +vendor/bin/php-cs-fixer fix ``` ### Running static analysis @@ -57,7 +39,7 @@ dev/bin/php php-cs-fixer fix You can run static anaysis of code using the following command: ```sh -dev/bin/php phpstan --memory-limit=256M +vendor/bin/phpstan ``` ### Testing @@ -65,7 +47,7 @@ dev/bin/php phpstan --memory-limit=256M You can run the whole test suite using the following command: ```sh -dev/bin/php-test vendor/bin/simple-phpunit +vendor/bin/simple-phpunit ``` **Happy coding**! diff --git a/composer.json b/composer.json index fbc3f136..77b993d4 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,9 @@ "ext-pdo_sqlite": "*", "doctrine/doctrine-bundle": "^2.8.0", "doctrine/orm": "^2.14|^3.0", + "php-cs-fixer/shim": "^3.38", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-symfony": "2.0", "symfony/browser-kit": "^6.4|^7.0", "symfony/phpunit-bridge": "^7.2" }, diff --git a/dev/bin/docker-compose b/dev/bin/docker-compose deleted file mode 100755 index 91764980..00000000 --- a/dev/bin/docker-compose +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -e - -export HOST_USER_ID=$(id -u) -export HOST_GROUP_ID=$(id -g) - -docker compose "$@" diff --git a/dev/bin/php b/dev/bin/php deleted file mode 100755 index 83d3d17f..00000000 --- a/dev/bin/php +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -e - -readonly BASE_DIR=$(cd "$(dirname "$0")"; pwd) - -"${BASE_DIR}"/docker-compose run --rm --no-deps php "$@" diff --git a/dev/bin/php-debug b/dev/bin/php-debug deleted file mode 100755 index 5dd4e4c9..00000000 --- a/dev/bin/php-debug +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -e - -readonly BASE_DIR=$(cd "$(dirname "$0")"; pwd) - -"${BASE_DIR}"/docker-compose run --rm --no-deps \ - -e PHP_IDE_CONFIG=serverName="${PHP_IDE_CONFIG:-oauth}" \ - -e XDEBUG_START_WITH_REQUEST=1 \ - php "$@" diff --git a/dev/bin/php-test b/dev/bin/php-test deleted file mode 100755 index b3596fbe..00000000 --- a/dev/bin/php-test +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -e - -readonly BASE_DIR=$(cd "$(dirname "$0")"; pwd) - -"${BASE_DIR}"/docker-compose run --rm --no-deps \ - php "$@" diff --git a/dev/docker/Dockerfile b/dev/docker/Dockerfile deleted file mode 100644 index 679c61ba..00000000 --- a/dev/docker/Dockerfile +++ /dev/null @@ -1,75 +0,0 @@ -ARG PHP_VERSION=8.1 - -FROM php:${PHP_VERSION}-cli-alpine -LABEL maintainer="Petar Obradović " - -# This is where we're going to store all of our non-project specific binaries -RUN mkdir -p /app/bin -ENV PATH /app/bin:$PATH - -ARG XDEBUG_VERSION=3.4.0 - -# Install needed core and PECL extensions -RUN apk add --update --no-cache --virtual .build-deps \ - ${PHPIZE_DEPS} \ - libxml2-dev \ - libzip-dev \ - linux-headers \ - zlib-dev \ - && docker-php-ext-install -j $(getconf _NPROCESSORS_ONLN) \ - xml \ - zip \ - && pecl install \ - xdebug-${XDEBUG_VERSION} \ - && docker-php-ext-enable \ - xdebug \ - && apk del --purge .build-deps - -RUN mv ${PHP_INI_DIR}/php.ini-development ${PHP_INI_DIR}/php.ini - -ENV XDEBUG_START_WITH_REQUEST 0 - -RUN echo '[xdebug]' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \ - && echo 'xdebug.start_with_request = ${XDEBUG_START_WITH_REQUEST}' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \ - && echo 'xdebug.mode = debug' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \ - && echo 'xdebug.discover_client_host = 0' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \ - && echo 'xdebug.client_host = %XDEBUG_CLIENT_HOST%' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini - -# Utilities needed to run this image -RUN apk add --update --no-cache \ - git \ - libzip \ - unzip \ - su-exec \ - shadow - -# Composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/app/bin --filename=composer \ - && chmod a+x /app/bin/composer - -# Create the user that's going to run our application -RUN useradd -ms /bin/sh app - -# Composer bin plugin -RUN su-exec app composer global config --no-interaction allow-plugins.bamarni/composer-bin-plugin true \ - && su-exec app composer global config --no-interaction allow-plugins.symfony/flex true \ - && su-exec app composer global require --dev bamarni/composer-bin-plugin - -# PHP-CS-Fixer -RUN su-exec app composer global bin php-cs-fixer require --dev friendsofphp/php-cs-fixer \ - && ln -s /home/app/.composer/vendor/bin/php-cs-fixer /app/bin/php-cs-fixer - -# PHPstan -RUN su-exec app composer global bin phpstan require --dev phpstan/phpstan phpstan/phpstan-symfony \ -&& ln -s /home/app/.composer/vendor/bin/phpstan /app/bin/phpstan - -# Enable parallel package installation for Composer -RUN su-exec app composer global require symfony/flex - -COPY entrypoint.sh /usr/local/bin/docker-entrypoint - -VOLUME /app/src -WORKDIR /app/src - -ENTRYPOINT ["docker-entrypoint"] -CMD ["php", "-a"] diff --git a/dev/docker/entrypoint.sh b/dev/docker/entrypoint.sh deleted file mode 100755 index 1deec6e9..00000000 --- a/dev/docker/entrypoint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -e - -usermod -ou "${HOST_USER_ID}" app &> /dev/null -groupmod -og "${HOST_GROUP_ID}" app &> /dev/null - -HOST_IP="${HOST_IP:-$(ip route | grep ^default | awk '{ print $3 }')}" - -sed -i "s/%XDEBUG_CLIENT_HOST%/$HOST_IP/" \ - /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini - -su-exec app docker-php-entrypoint "$@" diff --git a/docs/debugging.md b/docs/debugging.md deleted file mode 100644 index 4a00d7b9..00000000 --- a/docs/debugging.md +++ /dev/null @@ -1,18 +0,0 @@ -# Debugging - -Before you start you'll need to setup your IDE, the following is an example in PhpStorm: - -![PhpStorm XDebug](resources/phpstorm-xdebug.png) - -Then all you need to do is run the following command: - -```sh -dev/bin/php-debug vendor/bin/simple-phpunit -``` - -If you wish to use a different server name, you can do this with the -`PHP_IDE_CONFIG` env variable: - -```sh -PHP_IDE_CONFIG=some_other_name dev/bin/php-debug vendor/bin/simple-phpunit -``` diff --git a/phpstan.dist.neon b/phpstan.dist.neon index a9ebff6c..53946318 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,6 +1,6 @@ includes: - - /home/app/.composer/vendor-bin/phpstan/vendor/phpstan/phpstan-symfony/extension.neon - - /home/app/.composer/vendor-bin/phpstan/vendor/phpstan/phpstan-symfony/rules.neon + - ./vendor/phpstan/phpstan-symfony/extension.neon + - ./vendor/phpstan/phpstan-symfony/rules.neon parameters: level: 8 diff --git a/tests/Fixtures/FixtureFactory.php b/tests/Fixtures/FixtureFactory.php index 47b61866..eac39085 100644 --- a/tests/Fixtures/FixtureFactory.php +++ b/tests/Fixtures/FixtureFactory.php @@ -21,7 +21,7 @@ * Development hints: * * You can easily generate token identifiers using the following command: - * --- dev/bin/php -r "echo bin2hex(random_bytes(40)) . PHP_EOL;" + * --- php -r "echo bin2hex(random_bytes(40)) . PHP_EOL;" */ final class FixtureFactory {