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

(Added) Addition of Trace class and related tests #5

Merged
merged 20 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
40cd954
Add isExcludedClass method and related tests
MarjovanLier Feb 24, 2024
0d095c8
Update PHPUnit versions in composer.json
MarjovanLier Feb 24, 2024
2bf502b
Improve code readability in Trace.php
MarjovanLier Feb 24, 2024
d4e2ed3
Add PHPUnit configuration and test execution
MarjovanLier Feb 24, 2024
0bff0c2
Refactor IsExcludedClassTest.php for consistent spacing
MarjovanLier Feb 24, 2024
179bf33
Add Dockerfiles and local testing script
MarjovanLier Feb 24, 2024
e2fcf7e
Update PHP version and adjust unit test path
MarjovanLier Feb 24, 2024
1703b3f
Update PHPUnit versions in composer.json
MarjovanLier Feb 24, 2024
ee9ea1e
Add autoload dump to Composer workflow
MarjovanLier Feb 24, 2024
e1a690e
Update PHPUnit dependencies in composer.json
MarjovanLier Feb 24, 2024
b901e6c
Update conditional for Composer autoload
MarjovanLier Feb 24, 2024
83b9c45
Enhance PHPUnit configuration settings
MarjovanLier Feb 24, 2024
7fa8743
Update job names in GitHub workflow
MarjovanLier Feb 24, 2024
f221fee
Update PHP CI workflow and enhance testing process
MarjovanLier Feb 24, 2024
184ee75
Disable linting, Pint and PHPMD tests in CI workflow
MarjovanLier Feb 24, 2024
c8e5002
Update PHP versions and disable some workflow steps
MarjovanLier Feb 24, 2024
ec60e58
Update PHPUnit and Code Coverage versions
MarjovanLier Feb 24, 2024
749e73a
Update Dockerfiles, simplify system dependencies
MarjovanLier Feb 24, 2024
1fc0efd
Update Docker commands in localTest.sh
MarjovanLier Feb 24, 2024
90c189d
Refactor local test script with loop
MarjovanLier Feb 24, 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
154 changes: 123 additions & 31 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# This is a GitHub Actions workflow for PHP Continuous Integration (CI).
name: PHP CI

# This workflow gets triggered on push or pull request events to the main branch.
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
Test:
build:
# The job runs on the latest version of Ubuntu.
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ["8.0", "8.1", "8.2", "8.3"]
php-versions: ["8.1", "8.2", "8.3"]

steps:
# This step checks out a copy of your repository.
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v3
with:
fetch-depth: 0
id: checkout
Expand All @@ -29,44 +33,40 @@ jobs:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, zip, pdo_mysql

# This step validates the composer.json and composer.lock files.
- name: Validate composer.json and composer.lock
id: composer-validate
if: steps.setup-php.outcome == 'success'
run: composer validate --strict

# This step installs the project dependencies.
- name: Install dependencies
id: composer-install
if: steps.composer-validate.outcome == 'success'
run: composer install --prefer-dist --no-progress --no-interaction

# This step caches the Composer packages for faster execution.
- name: Cache Composer packages
id: composer-cache
if: steps.composer-install.outcome =='success'
if: steps.composer-validate.outcome == 'success'
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

# This step validates the composer.json and composer.lock files.
- name: Validate composer.json and composer.lock
id: composer-validate
if: steps.setup-php.outcome == 'success'
run: composer validate --strict

# This step installs the project dependencies.
- name: Install dependencies
id: composer-install
run: composer install --prefer-dist --no-progress --no-suggest

# This step sets up Go environment for the job.
- name: Set up Go
id: setup-go
uses: actions/setup-go@v3
if: steps.composer-cache.outcome == 'success'
with:
go-version: '1.22'
go-version: "1.22"

# This step installs osv-scanner for vulnerability scanning.
- name: Install osv-scanner
id: install-osv-scanner
if: steps.setup-go.outcome == 'success'
run: go install github.com/google/osv-scanner/cmd/osv-scanner@v1

# This step scans composer.lock for vulnerabilities using osv-scanner.
- name: Scan composer.lock for vulnerabilities
id: scan-vulnerabilities
if: steps.install-osv-scanner.outcome == 'success'
run: osv-scanner scan --no-ignore composer.lock

# This step checks for vulnerabilities in the project dependencies.
Expand All @@ -75,13 +75,67 @@ jobs:
if: steps.composer-install.outcome == 'success'
run: composer test:vulnerabilities-check

Release:
needs: test
# This step runs linting in parallel to speed up the process.
# - name: Run parallel linting
# id: parallel-lint
# if: steps.vulnerabilities-check.outcome == 'success'
# run: composer test:lint
#
# # This step checks the code style with Pint.
# - name: Run tests with Pint
# id: code-style
# if: steps.parallel-lint.outcome == 'success'
# run: composer test:code-style
#
# # This step runs tests with PHPMD.
# - name: Run tests with PHPMD
# id: phpmd
# if: steps.code-style.outcome == 'success'
# run: composer test:phpmd

# This step runs tests with PHPUnit.
- name: Run tests with PHPUnit
id: phpunit
if: steps.vulnerabilities-check.outcome == 'success'
run: composer test:phpunit

# # This step runs mutation testing with Infection.
# - name: Run Mutation Testing
# id: infection
# if: steps.phpunit.outcome == 'success'
# run: composer test:infection
#
# # This step runs static analysis with PHPStan.
# - name: Run static analysis with PHPStan
# id: phpstan
# if: steps.infection.outcome == 'success'
# run: composer test:phpstan
#
# # This step runs static analysis with Phan.
# - name: Run static analysis with phan
# id: phan
# if: steps.phpstan.outcome == 'success'
# run: composer test:phan
#
# # This step runs static analysis with Psalm.
# - name: Run static analysis with psalm
# id: psalm
# if: steps.phan.outcome == 'success'
# run: composer test:psalm
#
# # This step runs Rector for code quality.
# - name: Run rector for code quality
# id: rector
# if: steps.psalm.outcome == 'success'
# run: composer test:rector

release:
needs: build
runs-on: ubuntu-latest
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
# This step checks out a copy of your repository.
- uses: actions/checkout@v3
with:
fetch-depth: 0
id: checkout
Expand All @@ -95,14 +149,14 @@ jobs:
# This step gets the latest tag from the repository.
- name: Get latest tag
id: latest-tag
if: steps.fetch-tags.outcome == 'success' && steps.checkout.outcome == 'success'
if: steps.fetch-tags.outcome == 'success'
run: |
echo "LATEST_TAG=$(git tag | sort -V | tail -n1)" >> $GITHUB_ENV

# This step increments the minor version of the latest tag.
- name: Increment the minor version
id: new-tag
if: env.LATEST_TAG != '' && steps.checkout.outcome == 'success'
if: env.LATEST_TAG != '' && steps.latest-tag.outcome == 'success'
run: |
MAJOR=$(echo $LATEST_TAG | cut -d. -f1)
MINOR=$(echo $LATEST_TAG | cut -d. -f2)
Expand All @@ -114,7 +168,45 @@ jobs:
# This step creates and pushes a new tag to the repository.
- name: Create and push new tag
id: push-tag
if: github.ref == 'refs/heads/main' && env.NEW_TAG != '' && steps.checkout.outcome == 'success'
if: github.ref == 'refs/heads/main' && env.NEW_TAG != '' && steps.new-tag.outcome == 'success'
run: |
git tag $NEW_TAG
git push origin $NEW_TAG

# This step creates a comparison link between the latest and the new tag.
- name: Create comparison link
id: comparison-link
if: env.LATEST_TAG != '' && steps.push-tag.outcome == 'success'
run: |
echo "COMPARISON_LINK=https://github.com/MarjovanLier/StringManipulation/compare/${LATEST_TAG}...${NEW_TAG}" >> $GITHUB_ENV

# This step gets the commit messages between the latest tag and the HEAD.
- name: Get commit messages
id: get-commits
if: github.ref == 'refs/heads/main' && steps.comparison-link.outcome == 'success'
run: |
# Capture the output of git log command
GIT_LOG_OUTPUT=$(git log $LATEST_TAG..HEAD --pretty=format:'%h - %s')

# Append the output to the GITHUB_ENV, setting it as a multi-line env variable
echo "GIT_LOG_OUTPUT<<EOF" >> $GITHUB_ENV
echo "$GIT_LOG_OUTPUT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

# This step creates a new release with the new tag and the commit messages as the body.
- name: Create release
id: create_release
if: github.ref == 'refs/heads/main' && steps.get-commits.outcome == 'success'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.NEW_TAG }}
release_name: Release ${{ env.NEW_TAG }}
body: |
Changes included in this release:
${{ env.GIT_LOG_OUTPUT }}

View changes: ${{ env.COMPARISON_LINK }}
draft: false
prerelease: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ composer.phar
composer.lock
/vendor/
.idea/
*.cache
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"autoload-dev": {
"psr-4": {
"MarjovanLier\\XhprofTrace\\Tests\\": "tests"
"MarjovanLier\\XhprofTrace\\Tests\\Unit\\": "tests"
}
},
"config": {
Expand All @@ -41,21 +41,25 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.0|^8.1|^8.2",
"php": "^8.1|^8.2|^8.3",
"symfony/console": "^v5|^v6|^v7"
},
"require-dev": {
"enlightn/security-checker": "^v1|^v2"
"enlightn/security-checker": "^v1|^v2",
"phpunit/php-code-coverage": "^10|^11",
"phpunit/phpunit": "^10|^11"
},
"scripts": {
"post-update-cmd": [
"composer validate --strict",
"php -d memory_limit=-1 ./vendor/bin/security-checker security:check",
"composer outdated -D"
],
"test:phpunit": "phpunit --version && phpunit --no-coverage --no-logging",
"test:vulnerabilities-check": "php -d memory_limit=-1 ./vendor/bin/security-checker security:check"
},
"scripts-descriptions": {
"test:phpunit": "Execute PHPUnit tests to verify code functionality.",
"test:vulnerabilities-check": "Scan dependencies for known security vulnerabilities."
}
}
16 changes: 16 additions & 0 deletions docker/Dockerfile81
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM php:8.1-cli

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
zip \
libzip-dev \
&& rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install zip

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www
16 changes: 16 additions & 0 deletions docker/Dockerfile82
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM php:8.2-cli

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
zip \
libzip-dev \
&& rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install zip

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www
16 changes: 16 additions & 0 deletions docker/Dockerfile83
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM php:8.3-cli

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
zip \
libzip-dev \
&& rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install zip

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www
21 changes: 21 additions & 0 deletions localTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -euo pipefail


docker build -t php-xprof-trace-composer-81 -f docker/Dockerfile81 .
docker build -t php-xprof-trace-composer-82 -f docker/Dockerfile82 .
docker build -t php-xprof-trace-composer-83 -f docker/Dockerfile83 .

mkdir -p "$HOME"/.composer/docker-cache

for version in 80 81 82 83; do
DOCKER_CMD="docker run -it --rm -v $(pwd):/var/www -v $HOME/.composer/docker-cache:/root/.composer php-xprof-trace-composer-$version"
rm -f composer.lock && \
$DOCKER_CMD composer --version && \
$DOCKER_CMD composer install && \
$DOCKER_CMD composer test:vulnerabilities-check && \
$DOCKER_CMD composer test:phpunit
done

echo "All tests passed successfully!"
40 changes: 40 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit executionOrder="random"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
<coverage>
<report>
<html outputDirectory="reports/code-coverage/html"/>
<clover outputFile="reports/code-coverage/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="reports/code-coverage/junit.xml"/>
</logging>
</phpunit>
Loading
Loading