Skip to content

Commit 6ca9cc7

Browse files
authored
Merge pull request #22 from iazaran/Optimize-flexible
Optimize flexible
2 parents 3219956 + c55a85f commit 6ca9cc7

File tree

13 files changed

+3013
-409
lines changed

13 files changed

+3013
-409
lines changed

README.md

Lines changed: 436 additions & 216 deletions
Large diffs are not rendered by default.

TESTING.md

Lines changed: 104 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,80 @@ composer test-coverage
4747
# Generates HTML coverage report in ./coverage/ directory
4848
```
4949

50+
### Test New Features
51+
```bash
52+
# Test Laravel 12 SWR methods
53+
vendor/bin/phpunit tests/Unit/Laravel12/Laravel12SWRTest.php
54+
55+
# Test HTTP command execution
56+
vendor/bin/phpunit tests/Unit/Http/HttpCommandExecutionTest.php
57+
58+
# Test performance monitoring
59+
vendor/bin/phpunit tests/Unit/Monitoring/PerformanceMonitoringTest.php
60+
61+
# Test complete feature integration
62+
vendor/bin/phpunit tests/Feature/EnhancedSmartCacheControllerTest.php
63+
```
64+
65+
## New Enhanced Features Testing
66+
67+
SmartCache v1.5+ includes comprehensive testing for new enterprise features:
68+
69+
### Laravel 12 SWR Methods Testing
70+
- **SWR (Stale-While-Revalidate)** pattern validation
71+
- **Stale serving** with extended TTL support
72+
- **Refresh-ahead** proactive caching
73+
- **Flexible caching** with custom duration arrays
74+
- **Cross-compatibility** between facade and helper methods
75+
- **Optimization integration** with SWR patterns
76+
77+
### HTTP Command Execution Testing
78+
- **Command discovery** and metadata retrieval
79+
- **Programmatic execution** of cache commands
80+
- **Parameter handling** and validation
81+
- **Error handling** and graceful failures
82+
- **Security validation** for non-managed keys
83+
- **Facade integration** for HTTP commands
84+
85+
### Performance Monitoring Testing
86+
- **Metrics collection** for hits, misses, and writes
87+
- **Cache efficiency** calculation and reporting
88+
- **Optimization impact** tracking and analysis
89+
- **Performance analysis** with automated recommendations
90+
- **Metrics persistence** across application instances
91+
- **Dashboard integration** capabilities
92+
93+
### Integration Testing
94+
- **Real-world scenarios** like e-commerce platforms
95+
- **Multi-pattern usage** combining SWR methods
96+
- **Performance monitoring integration** with caching operations
97+
- **HTTP command execution** in application context
98+
- **Complete feature workflows** from cache to monitoring
99+
100+
## Testing Best Practices
101+
102+
When contributing to SmartCache, follow these testing guidelines:
103+
104+
### Unit Tests
105+
- **Isolated functionality** - Test individual components
106+
- **Mock external dependencies** - Use Laravel's testing mocks
107+
- **Edge case coverage** - Test boundary conditions
108+
- **Error scenarios** - Ensure graceful failure handling
109+
110+
### Feature Tests
111+
- **Real Laravel environment** - Use Orchestra Testbench
112+
- **Integration scenarios** - Test component interactions
113+
- **End-to-end workflows** - Validate complete user journeys
114+
- **Performance validation** - Ensure optimization benefits
115+
116+
### Test Data Organization
117+
```bash
118+
# Generate test data of different sizes
119+
$smallData = range(1, 10); # No optimization
120+
$mediumData = range(1, 1000); # May trigger compression
121+
$largeData = range(1, 5000); # Likely chunking + compression
122+
```
123+
50124
### Test with Different PHP Versions
51125
If you have multiple PHP versions installed:
52126
```bash
@@ -57,23 +131,41 @@ php8.3 vendor/bin/phpunit
57131

58132
## Test Structure
59133

134+
SmartCache maintains **comprehensive test coverage** with **252 tests** organized for maintainability:
135+
60136
```
61137
tests/
62-
├── bootstrap.php # Test bootstrap (sets up environment)
63-
├── TestCase.php # Base test class
64-
├── Unit/ # Unit tests (isolated component testing)
65-
│ ├── SmartCacheTest.php # Main SmartCache functionality
66-
│ ├── Console/ # Console command tests
138+
├── bootstrap.php # Test bootstrap (sets up environment)
139+
├── TestCase.php # Base test class with common utilities
140+
├── Unit/ # Unit tests (isolated component testing)
141+
│ ├── SmartCacheTest.php # Core SmartCache functionality
142+
│ ├── Console/ # Console command tests
67143
│ │ ├── ClearCommandTest.php
68144
│ │ └── StatusCommandTest.php
69-
│ ├── Providers/ # Service provider tests
145+
│ ├── Http/ # HTTP-related tests
146+
│ │ └── HttpCommandExecutionTest.php # HTTP command execution
147+
│ ├── Laravel12/ # Laravel 12+ features
148+
│ │ └── Laravel12SWRTest.php # SWR methods (swr, stale, refreshAhead)
149+
│ ├── Monitoring/ # Performance monitoring
150+
│ │ └── PerformanceMonitoringTest.php
151+
│ ├── Providers/ # Service provider tests
70152
│ │ └── SmartCacheServiceProviderTest.php
71-
│ └── Strategies/ # Strategy tests
72-
│ ├── CompressionStrategyTest.php
73-
│ └── ChunkingStrategyTest.php
74-
├── Feature/ # Integration tests
75-
│ └── SmartCacheIntegrationTest.php
76-
└── Fixtures/ # Test fixtures and data
153+
│ ├── Services/ # Service tests
154+
│ │ └── CacheInvalidationServiceTest.php
155+
│ ├── Strategies/ # Strategy tests
156+
│ │ ├── CompressionStrategyTest.php
157+
│ │ └── ChunkingStrategyTest.php
158+
│ ├── Traits/ # Trait tests
159+
│ │ └── ModelIntegrationTest.php
160+
│ ├── DependencyTrackingTest.php
161+
│ ├── PatternBasedInvalidationTest.php
162+
│ ├── StrategyOrderingTest.php
163+
│ └── TagBasedInvalidationTest.php
164+
├── Feature/ # Integration tests
165+
│ ├── SmartCacheIntegrationTest.php
166+
│ ├── AdvancedInvalidationIntegrationTest.php
167+
│ └── EnhancedSmartCacheControllerTest.php # Full feature integration
168+
└── Fixtures/ # Test fixtures and data
77169
```
78170

79171
## Test Categories

config/smart-cache.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@
5555
'log_errors' => true,
5656
],
5757

58+
/*
59+
|--------------------------------------------------------------------------
60+
| Performance Monitoring
61+
|--------------------------------------------------------------------------
62+
|
63+
| Enable performance monitoring to track cache hit/miss ratios,
64+
| optimization impact, and operation durations.
65+
|
66+
*/
67+
'monitoring' => [
68+
'enabled' => true,
69+
'metrics_ttl' => 3600, // How long to keep metrics in cache (seconds)
70+
'recent_entries_limit' => 100, // Number of recent operations to track per type
71+
],
72+
5873
/*
5974
|--------------------------------------------------------------------------
6075
| Cache Drivers

0 commit comments

Comments
 (0)