Skip to content

Commit a1ee3eb

Browse files
committed
Add DEVELOPMENT.md for contributor guidelines and testing instructions
1 parent abcaa72 commit a1ee3eb

2 files changed

Lines changed: 82 additions & 125 deletions

File tree

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
1-
# Integration Test Setup
1+
# Development Guide
22

3-
## Test Strategy
3+
This guide is for contributors and developers working on the php-discogs-api library itself.
4+
5+
## 🧪 Testing
6+
7+
### Quick Commands
8+
9+
```bash
10+
# Unit tests (fast, CI-compatible, no external dependencies)
11+
composer test
12+
13+
# Integration tests (requires Discogs API credentials)
14+
composer test-integration
15+
16+
# All tests together (unit + integration)
17+
composer test-all
18+
19+
# Code coverage (HTML + XML reports)
20+
composer test-coverage
21+
```
22+
23+
### Static Analysis & Code Quality
24+
25+
```bash
26+
# Static analysis (PHPStan Level 8)
27+
composer analyse
28+
29+
# Code style check (PSR-12)
30+
composer cs
31+
32+
# Auto-fix code style
33+
composer cs-fix
34+
```
35+
36+
## 🔗 Integration Tests
437

538
Integration tests are **separated from the CI pipeline** to prevent:
639

@@ -9,24 +42,17 @@ Integration tests are **separated from the CI pipeline** to prevent:
942
- 🚫 Dependency on external API availability
1043
- 🚫 Slow build times (2+ minutes vs. 0.4 seconds)
1144

12-
## Running Tests
45+
### Test Strategy
1346

14-
```bash
15-
# Unit tests only (CI default - fast & reliable)
16-
composer test-unit
47+
- **Unit Tests (101)**: Fast, reliable, no external dependencies → **CI default**
48+
- **Integration Tests (31)**: Real API calls, rate-limited → **Manual execution**
49+
- **Total Coverage**: 100% lines, methods, and classes covered
1750

18-
# Integration tests only (manual - requires API access)
19-
composer test-integration
20-
21-
# All tests together (local development)
22-
composer test-all
23-
```
24-
25-
## GitHub Secrets Required
51+
### GitHub Secrets Required
2652

2753
To enable authenticated integration tests in CI/CD, add these secrets to your GitHub repository:
2854

29-
### Repository Settings → Secrets and variables → Actions
55+
#### Repository Settings → Secrets and variables → Actions
3056

3157
| Secret Name | Description | Where to get it |
3258
|---------------------------------|----------------------------------|---------------------------------------------------------------------------|
@@ -36,16 +62,16 @@ To enable authenticated integration tests in CI/CD, add these secrets to your Gi
3662
| `DISCOGS_OAUTH_TOKEN` | OAuth access token (optional) | OAuth flow result |
3763
| `DISCOGS_OAUTH_TOKEN_SECRET` | OAuth token secret (optional) | OAuth flow result |
3864

39-
## Test Levels
65+
### Test Levels
4066

41-
### 1. Public API Tests (Always Run)
67+
#### 1. Public API Tests (Always Run)
4268

4369
- File: `tests/Integration/PublicApiIntegrationTest.php`
4470
- No credentials required
4571
- Tests public endpoints: artists, releases, labels, masters
4672
- Safe for forks and pull requests
4773

48-
### 2. Authentication Levels Test (Conditional)
74+
#### 2. Authentication Levels Test (Conditional)
4975

5076
- File: `tests/Integration/AuthenticationLevelsTest.php`
5177
- Requires all three secrets above
@@ -55,7 +81,7 @@ To enable authenticated integration tests in CI/CD, add these secrets to your Gi
5581
- Level 3: Personal token (user data)
5682
- Level 4: OAuth (interactive flow, tested when tokens are available)
5783

58-
## Local Development
84+
### Local Development
5985

6086
```bash
6187
# Set environment variables
@@ -73,9 +99,39 @@ vendor/bin/phpunit tests/Integration/AuthenticationLevelsTest.php
7399
vendor/bin/phpunit tests/Integration/ --testdox
74100
```
75101

76-
## Safety Notes
102+
### Safety Notes
77103

78104
- Public tests are safe for any environment
79105
- Authentication tests will be skipped if secrets are missing
80106
- No credentials are logged or exposed in the test output
81107
- Tests use read-only operations only (no data modification)
108+
109+
## 🛠️ Development Workflow
110+
111+
1. Fork the repository
112+
2. Create feature branch (`git checkout -b feature/name`)
113+
3. Make changes with tests
114+
4. Run test suite (`composer test-all`)
115+
5. Check code quality (`composer analyse && composer cs`)
116+
6. Commit changes (`git commit -m 'Add feature'`)
117+
7. Push to branch (`git push origin feature/name`)
118+
8. Open Pull Request
119+
120+
## 📋 Code Standards
121+
122+
- **PHP Version**: ^8.1
123+
- **Code Style**: PSR-12 (enforced by PHP-CS-Fixer)
124+
- **Static Analysis**: PHPStan Level 8
125+
- **Test Coverage**: 100% lines, methods, and classes
126+
- **Dependencies**: Minimal (only Guzzle required)
127+
128+
## 🔍 Architecture
129+
130+
The library consists of only four main classes:
131+
132+
1. **`DiscogsClient`** - Main API client with magic method calls
133+
2. **`DiscogsClientFactory`** - Factory for creating authenticated clients
134+
3. **`OAuthHelper`** - OAuth 1.0a flow helper
135+
4. **`ConfigCache`** - Service configuration cache
136+
137+
Simple, focused architecture with minimal dependencies.

README.md

Lines changed: 6 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![PHPStan Level](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg)](https://phpstan.org/)
1111
[![Code Style](https://img.shields.io/badge/code%20style-PSR12-brightgreen.svg)](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
1212

13-
> **🚀 MINIMAL YET POWERFUL!** Focused ~750-line Discogs API client — as lightweight as possible while maintaining modern PHP comfort and clean APIs.
13+
> **🚀 MINIMAL YET POWERFUL!** Focused, lightweight Discogs API client — as compact as possible while maintaining modern PHP comfort and clean APIs.
1414
1515
## 📦 Installation
1616

@@ -93,7 +93,7 @@ $identity = $discogs->getIdentity();
9393
- **Simple Setup** – Works immediately with public data, easy authentication for advanced features
9494
- **Complete API Coverage** – All 60 Discogs API endpoints supported
9595
- **Clean Parameter API** – Natural method calls: `getArtist(123)` with named parameter support
96-
- **Lightweight Focus**~750 lines for 60 endpoints (12 lines per endpoint average) with minimal dependencies
96+
- **Lightweight Focus**Minimal codebase with only essential dependencies
9797
- **Modern PHP Comfort** – Full IDE support, type safety, PHPStan Level 8 without bloat
9898
- **Secure Authentication** – Full OAuth and Personal Access Token support
9999
- **Well Tested** – 100% test coverage, PSR-12 compliant
@@ -111,7 +111,7 @@ $identity = $discogs->getIdentity();
111111
- **User Wantlist Methods** – getUserWantlist(), addToWantlist(), updateWantlistItem(), removeFromWantlist()
112112
- **User Lists Methods** – getUserLists(), getUserList()
113113

114-
*All 60 Discogs API endpoints are supported with clean documentation — see [Discogs API Documentation](https://www.discogs.com/developers/) for complete method reference*
114+
*All Discogs API endpoints are supported with clean documentation — see [Discogs API Documentation](https://www.discogs.com/developers/) for complete method reference*
115115

116116
> 💡 **Note:** Some endpoints require special permissions (seller accounts, data ownership).
117117
@@ -228,107 +228,6 @@ $identity = $discogs->getIdentity();
228228
echo "Hello " . $identity['username'];
229229
```
230230

231-
## 🧪 Testing
232-
233-
### Quick Testing Commands
234-
235-
```bash
236-
# Unit tests (fast, CI-compatible, no external dependencies)
237-
composer test
238-
239-
# Integration tests (requires Discogs API credentials)
240-
composer test-integration
241-
242-
# All tests together (unit + integration)
243-
composer test-all
244-
245-
# Code coverage (HTML + XML reports)
246-
composer test-coverage
247-
```
248-
249-
### Static Analysis & Code Quality
250-
251-
```bash
252-
# Static analysis (PHPStan Level 8)
253-
composer analyse
254-
255-
# Code style check (PSR-12)
256-
composer cs
257-
258-
# Auto-fix code style
259-
composer cs-fix
260-
```
261-
262-
### Test Strategy
263-
264-
- **Unit Tests (101)**: Fast, reliable, no external dependencies → **CI default**
265-
- **Integration Tests (31)**: Real API calls, rate-limited → **Manual execution**
266-
- **Total Coverage**: 100% lines, methods, and classes covered
267-
268-
## 📚 API Documentation
269-
270-
Complete method documentation available at [Discogs API Documentation](https://www.discogs.com/developers/).
271-
272-
> ⚠️ **API Change Notice:** The `getReleaseStats()` endpoint format changed around 2024/2025. It now returns only `{"is_offensive": false}` instead of the documented `{"num_have": X, "num_want": Y}`. For community statistics, use `getRelease()` and access `community.have` and `community.want` instead. Our library handles both formats gracefully.
273-
274-
### Most Used Methods
275-
276-
| Method | Description | Auth Level |
277-
|-------------------------------|------------------|---------------|
278-
| `search()` | Database search | 2️⃣+ Consumer |
279-
| `getArtist()`, `getRelease()` | Public data | 1️⃣ None |
280-
| `listCollectionFolders()` | Your collections | 3️⃣+ Personal |
281-
| `getIdentity()` | User info | 3️⃣+ Personal |
282-
| `getUserInventory()` | Marketplace | 3️⃣+ Personal |
283-
284-
### Parameter Syntax Examples
285-
286-
#### Traditional Positional Parameters
287-
288-
```php
289-
// Good for methods with few parameters
290-
$artist = $discogs->getArtist(4470662); // Billie Eilish
291-
$release = $discogs->getRelease(30359313); // Happier Than Ever
292-
$results = $discogs->search('Taylor Swift', 'artist');
293-
$collection = $discogs->listCollectionItems('username', 0, 25);
294-
```
295-
296-
#### Named Parameters (PHP 8.0+, Recommended)
297-
298-
```php
299-
// Better for methods with many optional parameters
300-
$search = $discogs->search(
301-
query: 'Olivia Rodrigo',
302-
type: 'release',
303-
year: 2021,
304-
perPage: 50
305-
);
306-
307-
$releases = $discogs->listArtistReleases(
308-
artistId: 4470662,
309-
sort: 'year',
310-
sortOrder: 'desc',
311-
perPage: 25
312-
);
313-
314-
// Marketplace listing with named parameters
315-
$listing = $discogs->createMarketplaceListing(
316-
releaseId: 30359313,
317-
condition: 'Near Mint (NM or M-)',
318-
price: 45.99,
319-
status: 'For Sale',
320-
comments: 'Rare pressing, excellent condition'
321-
);
322-
```
323-
324-
#### Hybrid Approach
325-
326-
```php
327-
// Mix positional for required, named for optional
328-
$search = $discogs->search('Ariana Grande', 'artist', perPage: 50);
329-
$releases = $discogs->listArtistReleases(4470662, sort: 'year', sortOrder: 'desc');
330-
```
331-
332231
## 🤝 Contributing
333232

334233
1. Fork the repository
@@ -337,7 +236,9 @@ $releases = $discogs->listArtistReleases(4470662, sort: 'year', sortOrder: 'desc
337236
4. Push to branch (`git push origin feature/name`)
338237
5. Open Pull Request
339238

340-
Please follow PSR-12 standards and include tests.
239+
Contributions are welcome! See [DEVELOPMENT.md](DEVELOPMENT.md) for detailed setup instructions, testing guide, and development workflow.
240+
241+
Please follow PSR-12 standards and include tests for new features.
341242

342243
## 📄 License
343244

0 commit comments

Comments
 (0)