Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-and-test:
name: PHP ${{ matrix.php-versions }} Build and Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['8.0', '8.1', '8.2', '8.3']

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: curl, json
coverage: none

- name: Install Composer Dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Run PHP Syntax Check (Linter)
run: |
find src/ -type f -name "*.php" -exec php -l {} \;
find tests/ -type f -name "*.php" -exec php -l {} \;

- name: Run PHP CodeSniffer (PSR-12)
run: vendor/bin/phpcs --standard=PSR12 src/ tests/

- name: Run PHPUnit Test Suite
run: vendor/bin/phpunit
38 changes: 32 additions & 6 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,35 @@ sequenceDiagram

## 🛠️ Verification & Testing Guidelines

* **Linting**: Before committing code, ensure no syntax errors exist by running:
```powershell
Get-ChildItem -Filter *.php -Recurse | ForEach-Object { php -l $_.FullName }
```
* **Performance Analysis**: Make sure the Parallel Speedup metric remains accurate. Parallel cURL requests should run in a time frame close to:
$$\text{Total Time} \approx \text{Response time of the slowest single API request} + \text{Multi-cURL overhead}$$
This codebase uses automated tools to maintain code quality, security, and standards.

### 1. Code Style Enforcement
The codebase adheres to the **PSR-12 Extended Coding Style Guide**. Coding standard compliance is enforced in the CI/CD pipeline using **PHP_CodeSniffer**.

To run the style checker locally:
```bash
composer lint
```

To automatically format style violations using PHPCBF:
```bash
vendor/bin/phpcbf --standard=PSR12 src/ tests/
```

### 2. Automated Test Suite
Unit and integration tests are written using **PHPUnit** and are located in the `/tests` directory.

To run the full test suite locally:
```bash
composer test
```

### 3. Isolated Mock Testing (Networkless execution)
To test the API client logic without hitting the live GitHub API rate limits, we use **namespace-level function overriding**.
- Inside the test files, we override PHP's native cURL functions (e.g., `curl_errno`, `curl_getinfo`, `curl_multi_exec`, `curl_multi_getcontent`) within the `App\Client` and `App\Fetcher` namespaces.
- This intercepts calls when PHP resolves the functions, returning mocked response headers, status codes (such as `200`, `403`, `404`), and error numbers (like timeouts).
- This ensures test execution is extremely fast (~20ms) and works perfectly without an active internet connection.

### 4. Performance Analysis
Make sure the Parallel Speedup metric remains accurate. Parallel cURL requests should run in a time frame close to:
$$\text{Total Time} \approx \text{Response time of the slowest single API request} + \text{Multi-cURL overhead}$$
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# GitHub User Viewer using PHP Multi-cURL

[![CI Build Status](https://github.com/shubhamlabs-shubham/concurrent-api-client-php/actions/workflows/ci.yml/badge.svg)](https://github.com/shubhamlabs-shubham/concurrent-api-client-php/actions/workflows/ci.yml)
![PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892bf.svg)
![PHPUnit Tests](https://img.shields.io/badge/tests-14%20passed-brightgreen.svg)
![Code Style](https://img.shields.io/badge/code%20style-PSR--12-blue.svg)
![License](https://img.shields.io/badge/license-MIT-green.svg)

A high-performance, aesthetically pleasing PHP web application that queries the GitHub REST API concurrently to retrieve and compare user profile information. The project demonstrates how **PHP Multi-cURL** dramatically improves response times compared to traditional sequential HTTP requests.

The codebase is structured following modern **Object-Oriented Programming (OOP)** patterns with **PSR-4 Autoloading** via Composer.
Expand Down Expand Up @@ -97,3 +103,31 @@ $$\text{Total Time} \approx \max(T_1, T_2, T_3, \dots, T_n)$$

### Repository Viewer Modal
![GitHub Profile Fetcher - Repositories List Modal](assets/screenshots/repos_modal.png)

---

## 🧪 Testing & Linting

This project implements strict verification using **PHPUnit** and **PHP_CodeSniffer**.

### Running Unit Tests
A mock cURL testing technique is used so that the test suite does not trigger actual HTTP requests to the live GitHub API. This prevents API rate limit exhaustion and network delays during testing.

Run PHPUnit tests using the Composer shortcut:
```bash
composer test
```
Or directly:
```bash
vendor/bin/phpunit
```

### Checking Coding Standards
To check for PSR-12 code style compliance, run:
```bash
composer lint
```
Or directly:
```bash
vendor/bin/phpcs --standard=PSR12 src/ tests/
```
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"require": {
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.8"
},
"scripts": {
"test": "phpunit --colors=always",
"lint": "phpcs --standard=PSR12 src/ tests/"
}
}
Loading
Loading