Skip to content

Commit

Permalink
Remove scripts support because of cakephp 4.5 (#20)
Browse files Browse the repository at this point in the history
Fix for cakephp 4.5 by removing support for scripts.
  • Loading branch information
cnizzardini authored Oct 21, 2023
1 parent 5383908 commit ef6d334
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 47 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 66 additions & 26 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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/[email protected]
- 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
Expand All @@ -85,7 +125,7 @@ jobs:
id: branch-name
uses: tj-actions/[email protected]
- 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
Expand All @@ -94,6 +134,6 @@ jobs:
echo "container is running"
else
echo "container is not running"
docker run cakepreloader:test && exit 1
exit 1
fi
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -49,5 +49,10 @@
"name": "Chris Nizzardini",
"role": "Developer"
}
]
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false
}
}
}
4 changes: 1 addition & 3 deletions src/Preloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -161,7 +159,7 @@ private function contents(): string

if (!empty($scripts)) {
echo "# Scripts \n";
echo implode('', $scripts ?? []);
echo implode('', $scripts);
}

$content = ob_get_contents();
Expand Down
11 changes: 8 additions & 3 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
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

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

Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Command/PreloaderCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions tests/php.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ef6d334

Please sign in to comment.