Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract PECL code from Aspect to PeclAspect #223

Merged
merged 55 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
bdd9651
Fix extension requirement typo in AspectTest
koriym Sep 14, 2024
98fb101
Remove PECL-based instance creation logic
koriym Nov 4, 2024
868b957
Remove runtime extension check in applyInterceptors.
koriym Nov 4, 2024
848f2ac
Add ClassName extraction utility and corresponding tests
koriym Nov 4, 2024
91050bb
Refactor code by removing unused functions
koriym Nov 4, 2024
4248913
Add Fake classes and tests for aspect weaving
koriym Nov 4, 2024
74a12e1
Refactor weaving logic to new AspectPecl class
koriym Nov 4, 2024
9598e5b
Refactor `rayaop` extension check placement
koriym Nov 4, 2024
2eb9885
Change NotWritableException to extend RuntimeException
koriym Nov 4, 2024
819846f
Add PHP and extension requirements to tests
koriym Nov 4, 2024
913b296
Add Codecov action for coverage reporting
koriym Nov 4, 2024
b35b751
Stop running 05-pecl.php in demo and add it to CI
koriym Nov 4, 2024
ec67460
Enable PHP 7.2 compat
koriym Nov 4, 2024
a41c17e
Remove redundant extension check in weave method
koriym Nov 4, 2024
40dd6a1
Remove redundant type annotations in ClassName.php
koriym Nov 4, 2024
d12eac1
Fix function_exists check for method_intercept usage
koriym Nov 4, 2024
01a867b
Refactor class name extraction logic with helper methods
koriym Nov 4, 2024
ef95161
Remove unused assert function import
koriym Nov 4, 2024
ffe1055
Simplify Composer installation steps
koriym Nov 4, 2024
4a24ed5
Refactor Fake class structure and update namespaces
koriym Nov 4, 2024
29adc3c
Update phpdocumentor/type-resolver to version 1.9.0
koriym Nov 4, 2024
d9f4176
fixup! Refactor Fake class structure and update namespaces
koriym Nov 4, 2024
3c7bdcc
Add type hint for tokens variable
koriym Nov 4, 2024
7dd2e0b
Exclude explicit assertion sniff in PHPCS config
koriym Nov 4, 2024
cf605e1
Add debugging output to display fully qualified class names
koriym Nov 4, 2024
b611c1c
Refactor tests to use FakeNonFinalClass
koriym Nov 4, 2024
7d7f597
Add test for class with declare statement
koriym Nov 4, 2024
52dc82c
Add debugging var_dump for token parsing
koriym Nov 4, 2024
344c3cc
Refactor namespace parsing for unified approach
koriym Nov 4, 2024
f332582
Refactor namespace parsing and improve token handling
koriym Nov 4, 2024
f538442
Add debug statements for token and FQN output
koriym Nov 4, 2024
3ccfe9b
Add debug statements for token and FQN output
koriym Nov 4, 2024
a331515
Refactor token parsing and add debugging
koriym Nov 4, 2024
e856dc3
Refactor class name extraction logic
koriym Nov 4, 2024
7a4a679
Add debug statement to log tokens
koriym Nov 4, 2024
7228740
Add debug statements for namespace parsing
koriym Nov 4, 2024
ab9f892
Refactor class extraction to use ClassList
koriym Nov 4, 2024
f6ace02
Add demo script for PECL usage in billing service
koriym Nov 4, 2024
1ef6e33
Refactor setup and class list logic, remove unused imports
koriym Nov 4, 2024
6879add
Add phpstan baseline configuration for error suppression
koriym Nov 4, 2024
11d730d
Add debug statements to ClassList
koriym Nov 4, 2024
94ccf71
Refactor namespace parsing logic in ClassList
koriym Nov 4, 2024
8db1da6
Refactor ClassList to improve namespace handling
koriym Nov 4, 2024
994079d
Refactor anonymous function in namespace collection
koriym Nov 4, 2024
62d9569
Refactor ClassList to remove token_get_all usage
koriym Nov 4, 2024
882e97b
Replace deprecated str_contains with strpos
koriym Nov 4, 2024
bcdee69
Remove unnecessary script execution
koriym Nov 4, 2024
fcc3e8f
Replace str_contains with strpos in ClassList.php
koriym Nov 4, 2024
e6989b4
Combine and optimize CI workflow steps
koriym Nov 4, 2024
0a64c0d
Update CI to enrich PHP extensions and improve log handling
koriym Nov 4, 2024
933f083
Refactor ClassList fetching and testing logic
koriym Nov 4, 2024
9a60866
Add demo script execution under Valgrind in CI workflow
koriym Nov 4, 2024
219fa30
Add code coverage ignore annotations for PECL extension code
koriym Nov 4, 2024
7633fd7
Refactor class existence check in ClassList
koriym Nov 4, 2024
02caaff
Rename method for clarity and enhance code coverage
koriym Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 64 additions & 58 deletions .github/workflows/continuous-integration-pecl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
php-version: ['8.1', '8.2', '8.3']
fail-fast: false

steps:
- name: Checkout code
Expand All @@ -21,7 +22,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
extensions: mbstring, intl, dom, json, libxml, xml, xmlwriter, tokenizer
tools: phpize, composer:v2

- name: Install build tools and Valgrind
Expand All @@ -30,10 +31,7 @@ jobs:
sudo apt-get install -y autoconf automake libtool bison re2c valgrind

- name: Install Composer dependencies
run: composer install --no-dev --prefer-dist --no-progress

- name: Install PHPUnit
run: composer require phpunit/phpunit --dev --prefer-dist --no-progress
run: composer install --prefer-dist --no-progress

- name: Build extension
id: build_extension
Expand All @@ -43,75 +41,83 @@ jobs:
phpize
./configure
make

- name: PHP info
id: php_info
run: |
php -dextension=./ext-rayaop/modules/rayaop.so -i | grep rayaop

- name: Run PECL demo with debug logging
id: run_pecl_demo
run: |
timeout 60s php -n -dextension=./ext-rayaop/modules/rayaop.so -dmemory_limit=128M -dreport_memleaks=1 -dzend.assertions=1 -dassert.exception=1 ./ext-rayaop/smoke.php
continue-on-error: true

- name: Check loaded extension
id: check_loaded_extension
run: |
php -dextension=./ext-rayaop/modules/rayaop.so -r 'var_dump(extension_loaded("rayaop"));'

- name: Check function exists
id: check_function_exists
# Combined step for PHPUnit and Valgrind analysis
- name: Run Tests with Valgrind
if: success() || failure()
id: test_with_valgrind
run: |
php -dextension=./ext-rayaop/modules/rayaop.so -r 'var_dump(function_exists("method_intercept"));'

- name: Run PHPUnit tests
id: run_phpunit_tests
run: |
php -dextension=./ext-rayaop/modules/rayaop.so vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Run Valgrind memory check
if: steps.build_extension.outcome == 'failure' || steps.run_pecl_demo.outcome == 'failure'
run: |
cat << EOF > valgrind.supp
# Create Valgrind suppression file
cat << EOF > rayaop.supp
{
<insert_a_suppression_name_here>
php_startup_leak
Memcheck:Leak
match-leak-kinds: reachable
...
fun:php_module_startup
...
}
{
zend_mm_startup_leak
Memcheck:Leak
match-leak-kinds: reachable
...
fun:zend_mm_startup
...
}
EOF
valgrind --suppressions=valgrind.supp --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt php -n -dextension=./ext-rayaop/modules/rayaop.so vendor/bin/phpunit

- name: Check Valgrind results
if: steps.build_extension.outcome == 'failure' || steps.run_pecl_demo.outcome == 'failure'
run: |
if [ -f valgrind-out.txt ]; then
echo "Valgrind log found:"
cat valgrind-out.txt
if ! grep -q "ERROR SUMMARY: 0 errors from 0 contexts" valgrind-out.txt; then
echo "Valgrind found errors"
exit 1
fi
else
echo "Valgrind log not found. This is unexpected."
exit 1
fi

- name: Upload Valgrind log file
if: steps.build_extension.outcome == 'failure' || steps.run_pecl_demo.outcome == 'failure'

# Run PHPUnit under Valgrind
valgrind \
--suppressions=rayaop.supp \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--verbose \
--error-exitcode=0 \
--log-file=valgrind.log \
php -n \
-d extension=./ext-rayaop/modules/rayaop.so \
-d memory_limit=256M \
vendor/bin/phpunit \
--coverage-clover=coverage.xml || true

# Display Valgrind log
echo "=== Valgrind Log ==="
cat valgrind.log

# Upload debug information with unique names per PHP version
- name: Upload debug logs
if: always()
uses: actions/upload-artifact@v4
with:
name: valgrind-log
path: valgrind-out.txt
name: debug-logs-php${{ matrix.php-version }}
path: |
valgrind.log
coverage.xml
core*
if-no-files-found: warn

# Upload coverage report
- name: Upload coverage report
if: always()
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true

- name: Final status check
if: always()
run: |
if [[ "${{ steps.build_extension.outcome }}" == 'failure' || "${{ steps.run_pecl_demo.outcome }}" == 'failure' ]]; then
echo "Build extension and run failed. Please check the logs for more information."
exit 1
echo "PHP Version: ${{ matrix.php-version }}"
echo "Extension build status: ${{ steps.build_extension.outcome }}"
echo "Test with Valgrind status: ${{ steps.test_with_valgrind.outcome }}"

# Check for critical issues in Valgrind log
if [ -f valgrind.log ]; then
echo "=== Valgrind Error Summary ==="
grep "ERROR SUMMARY:" valgrind.log || true
grep "definitely lost:" valgrind.log || true
grep "indirectly lost:" valgrind.log || true
fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"autoload-dev": {
"psr-4": {
"Ray\\Aop\\": ["tests/", "tests/Fake/", "tests/Aspect", "tests/Aspect/Fake", "tests/Aspect/Fake/src"]
"Ray\\Aop\\": ["tests/", "tests/Fake/", "tests/Aspect", "tests/Aspect/Fake"]
},
"files": [
"src-mock/method_intercept.php",
Expand Down
29 changes: 29 additions & 0 deletions demo/05-pecl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Ray\Aop\Demo;

use Ray\Aop\Aspect;
use Ray\Aop\Matcher;
use RuntimeException;

use const PHP_EOL;

require __DIR__ . '/bootstrap.php';

$aspect = new Aspect(__DIR__ . '/tmp');
$aspect->bind(
(new Matcher())->any(),
new IsContainsMatcher('charge'),
[new WeekendBlocker()]
);
$aspect->weave(__DIR__. '/src');

try {
$billingService = new RealBillingService();
echo $billingService->chargeOrder();
} catch (RuntimeException $e) {
echo $e->getMessage() . PHP_EOL;
exit(1);
}
1 change: 1 addition & 0 deletions demo/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
passthru('php ' . __DIR__ . '/02-matcher-bind.php');
passthru('php ' . __DIR__ . '/03-annotation-bind.php');
passthru('php ' . __DIR__ . '/04-my-matcher.php');
//passthru('php ' . __DIR__ . '/05-pecl.php');
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ com
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion"/>
<!-- /Base -->
<!-- Option -->
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma"/>
Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Used function method_intercept not found\\.$#"
count: 1
path: src/AspectPecl.php
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
includes:
- phpstan-baseline.neon
parameters:
phpVersion: 80200
level: max
Expand Down
Loading
Loading