From ef6d3344fa5a4652f5cef1d7a253617f2cf75462 Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Sat, 21 Oct 2023 12:27:32 -0400 Subject: [PATCH] Remove scripts support because of cakephp 4.5 (#20) Fix for cakephp 4.5 by removing support for scripts. --- .github/workflows/merge.yml | 6 +- .github/workflows/pull-request.yml | 92 +++++++++++++------ composer.json | 13 ++- src/Preloader.php | 4 +- tests/Dockerfile | 11 ++- .../TestCase/Command/PreloaderCommandTest.php | 3 +- tests/php.ini | 10 +- 7 files changed, 92 insertions(+), 47 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 152b8cc..aada130 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -2,18 +2,16 @@ name: Merge on: push: - branches: [ main ] + branches: [ v0 ] jobs: run: - + name: PHP ${{ matrix.php-versions }} Test runs-on: ubuntu-latest strategy: matrix: operating-system: [ ubuntu-20.04 ] php-versions: ['8.0'] - - name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ecff5e5..d9c1e82 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -4,15 +4,41 @@ on: pull_request: jobs: - run: - + test_and_analyze: + name: PHP ${{ matrix.php-versions }} Test runs-on: ubuntu-latest strategy: matrix: operating-system: [ ubuntu-20.04 ] - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['7.4', '8.0', '8.1', '8.2'] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, curl + + - name: PHP Version + run: php -v + + - name: Install dependencies + run: | + composer validate + composer install --prefer-dist --no-progress - name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} + - name: Test Suite + Static Analysis + run: composer test + + coverage: + name: Code Coverage + runs-on: ubuntu-latest + strategy: + matrix: + operating-system: [ ubuntu-20.04 ] + php-versions: ['7.4'] steps: - name: Checkout uses: actions/checkout@v2 @@ -21,7 +47,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, intl, xdebug + extensions: mbstring, intl, xdebug, curl - name: PHP Version run: php -v @@ -32,27 +58,20 @@ jobs: composer validate composer install --prefer-dist --no-progress --no-suggest - - name: Test (8.0) - if: ${{ matrix.php-versions != '7.4' }} - run: vendor/bin/phpunit - - - name: Test + Coverage + Static Analysis (7.4 only) - if: ${{ matrix.php-versions == '7.4' }} + - name: Code Coverage env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - composer check - echo ${{ matrix.php-versions }} - export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=clover.xml - vendor/bin/php-coveralls --coverage_clover=clover.xml -v - # - # CakePHP version compatability - # + composer global require php-coveralls/php-coveralls + export CODECOVERAGE=1 && vendor/bin/phpunit --coverage-clover=clover.xml + php-coveralls --coverage_clover=clover.xml -v + compatibility: + name: CakePHP ${{ matrix.version }} Test runs-on: ubuntu-latest strategy: matrix: - version: ['~4.2.0', '^4.3'] + version: ['~4.2.0', '~4.3.0', '~4.4.0', '^4.5'] steps: - name: Checkout uses: actions/checkout@v2 @@ -61,7 +80,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '7.4' - extensions: mbstring, intl + extensions: mbstring, intl, curl - name: PHP Version run: php -v @@ -73,10 +92,31 @@ jobs: composer require cakephp/cakephp:${{matrix.version}} --no-update composer install --prefer-dist --no-progress composer test - # - # Verify we can run php with opcache preload - # - docker: + + integration_test_cake_43: + name: Integration Test CakePHP ~4.3.0 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v5.1 + - name: Docker Build + run: docker build -t cakepreloader:test tests/ --no-cache --build-arg CAKE_VERSION=~4.3.0 --build-arg BRANCH=dev-${{ steps.branch-name.outputs.current_branch }} + - name: Docker Run + run: docker run -d cakepreloader:test + - name: Test Container + run: | + if docker ps | grep "cakepreloader:test"; then + echo "container is running" + else + echo "container is not running" + exit 1 + fi + + integration_test_cake_45: + name: Integration Test CakePHP ^4.5 runs-on: ubuntu-latest steps: - name: Checkout @@ -85,7 +125,7 @@ jobs: id: branch-name uses: tj-actions/branch-names@v5.1 - name: Docker Build - run: docker build -t cakepreloader:test tests/ --no-cache --build-arg BRANCH=dev-${{ steps.branch-name.outputs.current_branch }} + run: docker build -t cakepreloader:test tests/ --no-cache --build-arg CAKE_VERSION=^4.5 --build-arg BRANCH=dev-${{ steps.branch-name.outputs.current_branch }} - name: Docker Run run: docker run -d cakepreloader:test - name: Test Container @@ -94,6 +134,6 @@ jobs: echo "container is running" else echo "container is not running" - docker run cakepreloader:test && exit 1 + exit 1 fi diff --git a/composer.json b/composer.json index 9c56167..8a0f2ed 100644 --- a/composer.json +++ b/composer.json @@ -5,15 +5,15 @@ "license": "MIT", "keywords": ["cakephp","preload","preloader","opcache preloader","cakephp preloader", "cakephp opcache preloader"], "require": { - "php": ">=7.4", - "cakephp/cakephp": "^4.2.0" + "php": "^7.4|^8.0", + "cakephp/cakephp": "^4.2" }, "require-dev": { "phpunit/phpunit": "^8.5 || ^9.3", "cakephp/cakephp-codesniffer": "^4.4", "phpmd/phpmd": "^2.10", "php-coveralls/php-coveralls": "^2.4", - "phpstan/phpstan": "^0.12.32" + "phpstan/phpstan": "^1.4" }, "autoload": { "psr-4": { @@ -49,5 +49,10 @@ "name": "Chris Nizzardini", "role": "Developer" } - ] + ], + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": false + } + } } diff --git a/src/Preloader.php b/src/Preloader.php index 5747632..15171f6 100644 --- a/src/Preloader.php +++ b/src/Preloader.php @@ -83,8 +83,6 @@ function (SplFileInfo $file) use ($callback) { $result = $this->isClass($file); if ($result === true) { $this->preloadResources[] = new PreloadResource('require_once', $file->getPathname()); - } elseif ($result === false) { - $this->preloadResources[] = new PreloadResource('opcache_compile_file', $file->getPathname()); } } @@ -161,7 +159,7 @@ private function contents(): string if (!empty($scripts)) { echo "# Scripts \n"; - echo implode('', $scripts ?? []); + echo implode('', $scripts); } $content = ob_get_contents(); diff --git a/tests/Dockerfile b/tests/Dockerfile index e21d52b..9eead85 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -1,6 +1,7 @@ -FROM cnizzardini/php-fpm-alpine:8.0-latest +FROM cnizzardini/php-fpm-alpine:8.1-latest ARG BRANCH=main +ARG CAKE_VERSION=~4.3.0 COPY php.ini /usr/local/etc/php/php.ini @@ -8,8 +9,12 @@ WORKDIR /srv/app COPY --from=composer /usr/bin/composer /usr/bin/composer -RUN composer create-project --prefer-dist --no-interaction cakephp/app:~4.2 . -RUN composer require cnizzardini/cakephp-preloader:$BRANCH +RUN composer create-project --prefer-dist --no-interaction cakephp/app:$CAKE_VERSION . +RUN composer config minimum-stability dev +RUN composer config prefer-stable true +RUN composer update -W --no-cache +RUN composer require cnizzardini/cakephp-preloader:$BRANCH --no-cache +RUN composer dump-autoload RUN bin/cake plugin load CakePreloader RUN bin/cake preloader diff --git a/tests/TestCase/Command/PreloaderCommandTest.php b/tests/TestCase/Command/PreloaderCommandTest.php index bc81471..4c870ec 100644 --- a/tests/TestCase/Command/PreloaderCommandTest.php +++ b/tests/TestCase/Command/PreloaderCommandTest.php @@ -51,9 +51,8 @@ public function test_default(): void $contains = [ 'vendor/autoload.php', 'vendor/cakephp/cakephp/src/Cache/Cache.php', - 'vendor/cakephp/cakephp/src/basics.php', 'require_once', - 'opcache_compile_file' + //'opcache_compile_file', ]; foreach ($contains as $file) { diff --git a/tests/php.ini b/tests/php.ini index 9da9fc2..7a2fea0 100644 --- a/tests/php.ini +++ b/tests/php.ini @@ -1,11 +1,11 @@ ; ; Development ; -extension=intl.so -extension=pdo_mysql.so -extension=sodium -extension=zip.so -zend_extension=opcache.so +;extension=intl.so +;extension=pdo_mysql.so +;extension=sodium +;extension=zip.so +;zend_extension=opcache.so [php] session.auto_start = Off