-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from qodo-ai/dw/add-php
add php example
- Loading branch information
Showing
11 changed files
with
2,015 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Run the qodo-cover action (PHP) | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
desired_coverage: | ||
description: "Desired coverage percentage" | ||
required: false | ||
default: "70" | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
jobs: | ||
run-qodo-cover-php: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.ref }} | ||
|
||
- name: Install system dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y php-cli php-xml php-mbstring unzip php-xdebug | ||
php -v | ||
composer -V || (php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ | ||
&& php composer-setup.php \ | ||
&& php -r "unlink('composer-setup.php');" \ | ||
&& sudo mv composer.phar /usr/local/bin/composer) | ||
- name: Configure Xdebug for coverage | ||
run: | | ||
echo 'zend_extension="xdebug.so"' | sudo tee -a /etc/php/8.1/cli/conf.d/20-xdebug.ini | ||
echo 'xdebug.mode=coverage' | sudo tee -a /etc/php/8.1/cli/conf.d/20-xdebug.ini | ||
php -m | grep xdebug | ||
- name: Install app dependencies | ||
run: | | ||
composer install | ||
- name: Qodo Cover | ||
uses: qodo-ai/qodo-ci/.github/actions/qodo-cover@v0.1.3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
project_language: php | ||
project_root: templated_tests/php/myapp | ||
code_coverage_report_path: templated_tests/php/myapp/coverage.xml | ||
test_command: "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-cobertura coverage.xml --disable-coverage-ignore" | ||
model: gpt-4o | ||
desired_coverage: ${{ github.event.inputs.desired_coverage }} | ||
branch: ${{ github.ref_name }} | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Composer dependencies | ||
vendor/ | ||
|
||
# Coverage reports | ||
coverage.xml | ||
coverage/ | ||
|
||
# Editor/OS files | ||
.idea/ | ||
.vscode/ | ||
.DS_Store | ||
|
||
# phpunit | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
# MyApp - Example PHP Project with PHPUnit Coverage | ||
|
||
This is a sample PHP application with multiple source files and a PHPUnit test suite that demonstrates code coverage analysis using Xdebug and PHPUnit. | ||
|
||
## Prerequisites | ||
|
||
- **PHP** (version 8.1 or later recommended) | ||
- **Composer** (PHP dependency manager) | ||
- **PHPUnit** (for unit testing) | ||
- **Xdebug** (for code coverage) | ||
|
||
## Installation | ||
|
||
### macOS | ||
|
||
1. **Install PHP** via [Homebrew](https://brew.sh/): | ||
|
||
```bash | ||
brew install php | ||
``` | ||
|
||
Verify installation: | ||
|
||
```bash | ||
php -v | ||
``` | ||
|
||
2. **Install Composer**: | ||
|
||
```bash | ||
brew install composer | ||
``` | ||
|
||
Verify installation: | ||
|
||
```bash | ||
composer -V | ||
``` | ||
|
||
3. **Install Xdebug** via PECL: | ||
|
||
```bash | ||
pecl install xdebug | ||
``` | ||
|
||
Add `zend_extension="xdebug.so"` and `xdebug.mode=coverage` to your `php.ini`, then verify: | ||
|
||
```bash | ||
php -m | grep xdebug | ||
``` | ||
|
||
4. **Install Dependencies**: | ||
|
||
```bash | ||
composer install | ||
``` | ||
|
||
### Linux (Debian/Ubuntu) | ||
|
||
1. **Install PHP**: | ||
|
||
```bash | ||
sudo apt-get update | ||
sudo apt-get install php-cli php-xml php-mbstring unzip | ||
php -v | ||
``` | ||
|
||
2. **Install Composer**: | ||
|
||
```bash | ||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | ||
php composer-setup.php | ||
php -r "unlink('composer-setup.php');" | ||
sudo mv composer.phar /usr/local/bin/composer | ||
composer -V | ||
``` | ||
|
||
3. **Install Xdebug**: | ||
|
||
```bash | ||
sudo apt-get install php-xdebug | ||
``` | ||
|
||
Edit `php.ini` to include: | ||
|
||
```ini | ||
zend_extension="xdebug.so" | ||
xdebug.mode=coverage | ||
``` | ||
|
||
Then verify: | ||
|
||
```bash | ||
php -m | grep xdebug | ||
``` | ||
|
||
4. **Install Dependencies**: | ||
|
||
```bash | ||
composer install | ||
``` | ||
|
||
### Windows | ||
|
||
1. **Install PHP**: | ||
Download from [windows.php.net](https://windows.php.net/download/) and follow the instructions. Add `php.exe` to your `PATH`. | ||
Verify installation: | ||
|
||
```bash | ||
php -v | ||
``` | ||
|
||
2. **Install Composer**: | ||
Download and run [Composer Setup](https://getcomposer.org/download/). | ||
Verify: | ||
|
||
```bash | ||
composer -V | ||
``` | ||
|
||
3. **Install Xdebug**: | ||
Download the appropriate DLL from [xdebug.org](https://xdebug.org/download) and place it in your PHP `ext` directory. Update `php.ini`: | ||
|
||
```ini | ||
zend_extension="xdebug" | ||
xdebug.mode=coverage | ||
``` | ||
|
||
Verify: | ||
|
||
```bash | ||
php -m | findstr xdebug | ||
``` | ||
|
||
4. **Install Dependencies**: | ||
|
||
```bash | ||
composer install | ||
``` | ||
|
||
## Running Tests and Generating Coverage | ||
|
||
Ensure you have `XDEBUG_MODE=coverage` set (for macOS/Linux) or the equivalent `xdebug.mode=coverage` in `php.ini` for Windows. | ||
|
||
**Run Tests and Generate Cobertura Coverage XML:** | ||
|
||
```bash | ||
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-cobertura coverage.xml --disable-coverage-ignore | ||
``` | ||
|
||
**Generate HTML Coverage Report:** | ||
|
||
```bash | ||
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html coverage | ||
``` | ||
|
||
Open `coverage/index.html` in your browser to view detailed coverage information. | ||
|
||
## Files and Directories | ||
|
||
- `src/` - Source code (e.g., `Calculator.php` and `Math/AdvancedOperations.php`) | ||
- `tests/` - PHPUnit test files | ||
- `composer.json` - Composer configuration | ||
- `phpunit.xml` - PHPUnit configuration | ||
|
||
## Notes | ||
|
||
- Make sure `composer install` is run before testing to install PHPUnit. | ||
- Adjust PHP version and file paths as needed for your environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"require-dev": { | ||
"phpunit/phpunit": "^10.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"MyApp\\": "src/" | ||
} | ||
} | ||
} |
Oops, something went wrong.