diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..b634bd0 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,133 @@ +name: Lion-Command (CI Workflow) + +on: + push: + branches: + - actions-sleon + - actions-saco + pull_request: + branches: + - main + schedule: + - cron: "15 0 * * *" + +jobs: + composer-validation: + runs-on: ubuntu-latest + name: Composer Validation + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Cache Composer dependencies + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + extensions: mbstring, gd, zip + + - name: Composer Validate + run: composer validate --strict + + - name: Composer Check for vulnerabilities + run: composer audit --locked + + - name: Composer Install + run: composer install + + - name: Composer Dump-Autoload + run: composer dump-autoload --optimize --strict-psr + + docker-validation: + runs-on: ubuntu-latest + name: Docker Validation + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Validate Docker Compose configuration + run: docker compose config + + code-analyze: + runs-on: ubuntu-latest + name: PHP Code Analyze + needs: + - composer-validation + - docker-validation + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + extensions: mbstring, gd, zip + + - name: Composer Install + run: composer install + + - name: PHP CodeSnifer (Src) + run: php vendor/bin/phpcs --standard=PSR12 src/ + + - name: PHPStan (Src) + run: php -d memory_limit=-1 vendor/bin/phpstan analyse src + + - name: PHP CodeSnifer (Tests) + run: php vendor/bin/phpcs --standard=PSR12 tests/ + + - name: PHPStan (Tests) + run: php -d memory_limit=-1 vendor/bin/phpstan analyse tests + + tests: + runs-on: ubuntu-latest + name: PHP Tests + needs: code-analyze + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Tear down containers + run: docker compose down --volumes --remove-orphans + + - name: Stop running Docker containers (if any) + run: | + docker ps -q | xargs -r docker stop + docker ps -aq | xargs -r docker rm + + - name: Build the Docker image + run: docker build -t command-app . + + - name: Start services using Docker Compose + run: | + docker compose -f docker-compose.yml up -d + env: + COMPOSE_PROJECT_NAME: test + + - name: Install Composer dependencies + run: docker exec command-app composer install + + - name: Run PHP Tests + run: docker exec command-app php vendor/bin/phpunit diff --git a/Dockerfile b/Dockerfile index 30b0d2e..697a547 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,7 @@ RUN useradd -m lion && echo 'lion:lion' | chpasswd && usermod -aG sudo lion && u # Dependencies RUN apt-get update -y \ - && apt-get install -y sudo nano zsh git curl wget unzip cron sendmail golang-go \ - && apt-get install -y libpng-dev libzip-dev zlib1g-dev libonig-dev supervisor libevent-dev libssl-dev \ + && apt-get install -y sudo nano zsh git curl wget unzip golang-go libpng-dev libzip-dev zlib1g-dev libonig-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -46,10 +45,17 @@ USER root SHELL ["/bin/bash", "--login", "-c"] # Install logo-ls -RUN wget https://github.com/Yash-Handa/logo-ls/releases/download/v1.3.7/logo-ls_amd64.deb \ - && dpkg -i logo-ls_amd64.deb \ - && rm logo-ls_amd64.deb \ - && curl https://raw.githubusercontent.com/UTFeight/logo-ls-modernized/master/INSTALL | bash +RUN ARCH=$(uname -m) && \ + if [ "$ARCH" = "x86_64" ]; then \ + wget https://github.com/Yash-Handa/logo-ls/releases/download/v1.3.7/logo-ls_amd64.deb; \ + elif [ "$ARCH" = "aarch64" ]; then \ + wget https://github.com/Yash-Handa/logo-ls/releases/download/v1.3.7/logo-ls_arm64.deb; \ + else \ + echo "Unsupported architecture: $ARCH" && exit 1; \ + fi && \ + dpkg -i logo-ls_*.deb && \ + rm logo-ls_*.deb && \ + curl https://raw.githubusercontent.com/UTFeight/logo-ls-modernized/master/INSTALL | bash # Add configuration in .zshrc RUN echo 'alias ls="logo-ls"' >> /home/lion/.zshrc \ diff --git a/composer.json b/composer.json index 2e7df49..488b9b1 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,8 @@ "require-dev": { "phpunit/phpunit": "^10.4", "lion/test": "^1.4", - "symfony/console": "^7.2" + "symfony/console": "^7.2", + "phpstan/phpstan": "^2.0", + "squizlabs/php_codesniffer": "^3.11" } } diff --git a/composer.lock b/composer.lock index f78e34b..649f9d0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "586bec709c0fc4af5f1812cf7fb7254e", + "content-hash": "ee51ed899574849ba4c03479ecc61ec8", "packages": [], "packages-dev": [ { @@ -280,6 +280,64 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpstan", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "50d276fc3bf1430ec315f2f109bbde2769821524" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/50d276fc3bf1430ec315f2f109bbde2769821524", + "reference": "50d276fc3bf1430ec315f2f109bbde2769821524", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-12-17T17:14:01+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "10.1.16", @@ -603,16 +661,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.38", + "version": "10.5.40", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a86773b9e887a67bc53efa9da9ad6e3f2498c132" + "reference": "e6ddda95af52f69c1e0c7b4f977cccb58048798c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a86773b9e887a67bc53efa9da9ad6e3f2498c132", - "reference": "a86773b9e887a67bc53efa9da9ad6e3f2498c132", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e6ddda95af52f69c1e0c7b4f977cccb58048798c", + "reference": "e6ddda95af52f69c1e0c7b4f977cccb58048798c", "shasum": "" }, "require": { @@ -622,7 +680,7 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.12.0", + "myclabs/deep-copy": "^1.12.1", "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=8.1", @@ -684,7 +742,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.38" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.40" }, "funding": [ { @@ -700,7 +758,7 @@ "type": "tidelift" } ], - "time": "2024-10-28T13:06:21+00:00" + "time": "2024-12-21T05:49:06+00:00" }, { "name": "psr/container", @@ -1671,18 +1729,98 @@ ], "time": "2023-02-07T11:34:05+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.11.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/1368f4a58c3c52114b86b1abe8f4098869cb0079", + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-12-11T16:04:26+00:00" + }, { "name": "symfony/console", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "23c8aae6d764e2bae02d2a99f7532a7f6ed619cf" + "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/23c8aae6d764e2bae02d2a99f7532a7f6ed619cf", - "reference": "23c8aae6d764e2bae02d2a99f7532a7f6ed619cf", + "url": "https://api.github.com/repos/symfony/console/zipball/fefcc18c0f5d0efe3ab3152f15857298868dc2c3", + "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3", "shasum": "" }, "require": { @@ -1746,7 +1884,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.2.0" + "source": "https://github.com/symfony/console/tree/v7.2.1" }, "funding": [ { @@ -1762,7 +1900,7 @@ "type": "tidelift" } ], - "time": "2024-11-06T14:24:19+00:00" + "time": "2024-12-11T03:49:26+00:00" }, { "name": "symfony/deprecation-contracts", @@ -1783,12 +1921,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { "dev-main": "3.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -1857,8 +1995,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -1933,8 +2071,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2011,8 +2149,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2095,8 +2233,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -2173,12 +2311,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { "dev-main": "3.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" } }, "autoload": { diff --git a/src/LionCommand/Kernel.php b/src/LionCommand/Kernel.php index 94524cb..1f2316e 100644 --- a/src/LionCommand/Kernel.php +++ b/src/LionCommand/Kernel.php @@ -63,7 +63,7 @@ public function setApplication(Application $application): Kernel public function commands(array $commands): void { foreach ($commands as $command) { - $this->application->add(new $command); + $this->application->add(new $command()); } } diff --git a/test.sh b/test.sh deleted file mode 100644 index 104347c..0000000 --- a/test.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -echo -e "\n\033[0;36m\t>> Set Time Zone \033[0m" -export TZ=America/Bogota -echo -e "\033[0;36m\t>> America/Bogota \033[0m" -start_time=$(date +"%Y-%m-%d %H:%M:%S") -echo -e "\n\033[0;31m>> -------------------------------------------------------------------------------------- << \n\033[0m"; - -echo -e "\033[0;36m\t>> Install Dependencies \033[0m" -rm -rf vendor/ -composer install -echo -e "\n\033[0;31m>> -------------------------------------------------------------------------------------- << \n\033[0m"; - -echo -e "\033[0;36m\t>> Dump Autoload \033[0m" -composer dump-autoload -echo -e "\n\033[0;31m>> -------------------------------------------------------------------------------------- << \n\033[0m"; - -echo -e "\033[0;36m\t>> Suite All-Test \033[0m" -php vendor/bin/phpunit --testsuite All-Test -echo -e "\n\033[0;31m>> -------------------------------------------------------------------------------------- << \n\033[0m"; - -end_time=$(date +"%Y-%m-%d %H:%M:%S") -start_seconds=$(date -d "$start_time" +%s) -end_seconds=$(date -d "$end_time" +%s) -time_diff=$((end_seconds - start_seconds)) -minutes=$((time_diff / 60)) -seconds=$((time_diff % 60)) - -echo -e "\033[0;36m\t>> Start date and time: ${start_time} \033[0m" -echo -e "\033[0;36m\t>> End date and time: ${end_time} \033[0m" -echo -e "\033[0;32m\t>> Time execution: ${minutes} minutes ${seconds} seconds \n \033[0m" diff --git a/tests/CommandTest.php b/tests/CommandTest.php index db78f80..a39bd68 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -2,25 +2,26 @@ declare(strict_types=1); -namespace Test; +namespace Tests; use Lion\Command\Command; use Lion\Test\Test; class CommandTest extends Test { - const TEST = 'Test'; - const ERROR_OUTPUT = "\033[0;31mTest\033[0m"; - const SUCCESS_OUTPUT = "\033[0;32mTest\033[0m"; - const WARNING_OUTPUT = "\033[0;33mTest\033[0m"; - const INFO_OUTPUT = "\033[0;36mTest\033[0m"; - const PURPLE_OUTPUT = "\033[0;95mTest\033[0m"; + private const string TEST = 'Test'; + private const string ERROR_OUTPUT = "\033[0;31mTest\033[0m"; + private const string SUCCESS_OUTPUT = "\033[0;32mTest\033[0m"; + private const string WARNING_OUTPUT = "\033[0;33mTest\033[0m"; + private const string INFO_OUTPUT = "\033[0;36mTest\033[0m"; + private const string PURPLE_OUTPUT = "\033[0;95mTest\033[0m"; private $customCommand; public function setUp(): void { - $this->customCommand = new class extends Command {}; + $this->customCommand = new class extends Command { + }; } public function testErrorOutput(): void diff --git a/tests/KernelTest.php b/tests/KernelTest.php index d8189b2..c6b9f58 100644 --- a/tests/KernelTest.php +++ b/tests/KernelTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Test; +namespace Tests; use Lion\Command\Command; use Lion\Command\Kernel; @@ -13,10 +13,12 @@ class KernelTest extends Test { - const OUTPUT = ['Example command']; + private const array OUTPUT = [ + 'Example command', + ]; private Kernel $kernel; - private object $customClass; + private Command $customClass; public function setUp(): void {