Skip to content

Commit dc4c041

Browse files
committed
Upate code
1 parent 838b63d commit dc4c041

3,881 files changed

Lines changed: 603101 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"MainTest::test_main_singleton_instance":4,"MainTest::test_main_constants_defined":4,"MainTest::test_get_plugin_name":4,"MainTest::test_get_version":4,"MainTest::test_get_loader":4,"MainTest::test_run_method":5,"MainTest::test_class_structure":4},"times":{"MainTest::test_main_singleton_instance":0.001,"MainTest::test_main_constants_defined":0,"MainTest::test_get_plugin_name":0,"MainTest::test_get_version":0,"MainTest::test_get_loader":0,"MainTest::test_run_method":0,"MainTest::test_class_structure":0,"I18nTest::test_i18n_can_be_instantiated":0.002,"I18nTest::test_do_load_textdomain_method_exists":0,"I18nTest::test_do_load_textdomain_executes":0,"I18nTest::test_class_follows_wordpress_standards":0.001}}

.wp-env.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": "WordPress/WordPress#trunk",
4+
"phpVersion": "8.1",
5+
"plugins": [
6+
"."
7+
],
8+
"themes": [
9+
"WordPress/twentytwentyfour"
10+
],
11+
"mappings": {
12+
"wp-content/mu-plugins": "./tests/mu-plugins"
13+
},
14+
"lifecycleHooks": {
15+
"afterStart": [
16+
"wp-env run tests-cli wp rewrite structure '/%postname%/' --hard"
17+
]
18+
},
19+
"env": {
20+
"tests": {
21+
"mappings": {
22+
"wp-content/plugins/wordpress-plugin-boilerplate": "."
23+
}
24+
}
25+
}
26+
}

README.md

Lines changed: 153 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,17 @@ php -v
7171
- `wpb-buddypress-or-buddyboss-dependency` - BuddyPress/BuddyBoss compatibility
7272
- `wpb-woocommerce-dependency` - WooCommerce integration support
7373
- And more specialized packages for common WordPress needs
74+
- **Optional**: Include comprehensive PHPUnit testing infrastructure:
75+
- PHPUnit with WordPress integration and pre-written test cases
76+
- PHP CodeSniffer with WordPress Coding Standards (WPCS 3.0)
77+
- PHPStan static analysis with WordPress extensions
78+
- wp-env development environment configuration
79+
- Complete testing workflow with NPM scripts
7480
- The script will automatically:
7581
- Create a new plugin with your details
7682
- Install selected packages via Composer
7783
- Add integration code to `includes/main.php`
84+
- Configure testing infrastructure (if selected)
7885
- Set up the complete development environment
7986

8087
### Method 2: Manual Setup
@@ -125,6 +132,115 @@ npm run makepot
125132
npm run packages-update
126133
```
127134

135+
### Testing & Quality Assurance
136+
137+
The boilerplate includes comprehensive testing infrastructure following WordPress and abilities-api patterns:
138+
139+
#### PHP Testing Commands
140+
141+
```bash
142+
# Run PHP CodeSniffer (WordPress Coding Standards)
143+
npm run lint:php
144+
145+
# Auto-fix PHP coding standards issues
146+
npm run lint:php:fix
147+
148+
# Run PHPStan static analysis
149+
npm run lint:php:stan
150+
151+
# Run PHPUnit tests
152+
npm run test:php
153+
154+
# Run PHPUnit tests with coverage report
155+
npm run test:php:coverage
156+
```
157+
158+
#### Local Development Environment (wp-env)
159+
160+
```bash
161+
# Start WordPress development environment
162+
npm run env:start
163+
164+
# Stop the environment
165+
npm run env:stop
166+
167+
# Restart the environment
168+
npm run env:restart
169+
170+
# Clean all containers and volumes
171+
npm run env:clean
172+
173+
# Reset environment (destroy and recreate)
174+
npm run env:reset
175+
176+
# Direct wp-env access
177+
npm run env -- --help
178+
```
179+
180+
#### JavaScript Testing
181+
182+
```bash
183+
# Run Jest unit tests
184+
npm run test:unit
185+
186+
# Run end-to-end tests
187+
npm run test:e2e
188+
```
189+
190+
#### Testing Stack
191+
192+
- **PHPUnit**: WordPress unit tests with test database
193+
- **PHP CodeSniffer**: WordPress Coding Standards enforcement
194+
- **PHPStan**: Static analysis for type safety and bug detection
195+
- **wp-env**: Dockerized WordPress development environment
196+
- **Jest**: JavaScript unit testing framework
197+
- **Playwright**: End-to-end testing (via @wordpress/scripts)
198+
199+
#### Test Structure
200+
201+
```
202+
tests/
203+
├── bootstrap.php # PHPUnit bootstrap
204+
├── test-sample.php # Example test case
205+
├── wordpress-constants.php # PHPStan WordPress constants
206+
└── mu-plugins/ # Must-use plugins for testing
207+
└── load-plugin.php # Auto-activate plugin in tests
208+
209+
bin/
210+
└── install-wp-tests.sh # WordPress test suite installer
211+
212+
phpunit.xml.dist # PHPUnit configuration
213+
phpstan.neon.dist # PHPStan configuration
214+
phpcs.xml.dist # PHP CodeSniffer rules
215+
.wp-env.json # wp-env environment config
216+
```
217+
218+
#### Running Your First Tests
219+
220+
1. **Set up the test environment**:
221+
```bash
222+
# Install dependencies
223+
composer install
224+
npm install
225+
226+
# Start wp-env environment
227+
npm run env:start
228+
```
229+
230+
2. **Run tests**:
231+
```bash
232+
# Run all PHP tests
233+
npm run test:php
234+
235+
# Check code quality
236+
npm run lint:php
237+
npm run lint:php:stan
238+
```
239+
240+
3. **Access the development site**:
241+
- Frontend: http://localhost:8888
242+
- Admin: http://localhost:8888/wp-admin (admin/password)
243+
128244
### Asset Pipeline
129245

130246
- **SCSS → CSS**: Automatic compilation with autoprefixing and minification
@@ -620,35 +736,53 @@ The boilerplate includes automated workflows for:
620736

621737
## 🧪 Testing Framework
622738

623-
### PHP Testing (PHPUnit)
739+
When you initialize your plugin with `init-plugin.sh`, you'll have the option to include comprehensive testing infrastructure:
740+
741+
### Included Testing Tools (Optional)
742+
743+
- **PHPUnit 9.6+**: WordPress-optimized unit testing
744+
- **PHP CodeSniffer 3.7+**: WordPress Coding Standards (WPCS 3.0)
745+
- **PHPStan 1.10+**: Static analysis with WordPress extensions
746+
- **wp-env**: Docker-based WordPress development environment
747+
748+
### PHP Testing (PHPUnit) - When Selected
624749
```bash
625-
# Install PHPUnit
626-
composer require --dev phpunit/phpunit
750+
# Run all tests
751+
npm run test
627752

628-
# Run PHP tests
629-
./vendor/bin/phpunit
753+
# Run specific test types
754+
npm run test:unit # Unit tests only
755+
npm run test:integration # Integration tests
756+
npm run test:coverage # With coverage report
757+
758+
# WordPress environment testing
759+
npm run env:start # Start test environment
760+
npm run env:clean # Clean test environment
761+
npm run env:stop # Stop test environment
630762
```
631763

632-
### JavaScript Testing (Jest)
764+
### Code Quality - When Selected
633765
```bash
634-
# Install Jest preset
635-
npm install --save-dev @wordpress/jest-preset-default
766+
# Check coding standards
767+
npm run lint:php
636768

637-
# Run JavaScript tests
638-
npm run test
769+
# Fix coding standards
770+
npm run lint:php:fix
771+
772+
# Static analysis
773+
npm run analyze
639774
```
640775

641-
### Test Structure
776+
### Test Structure (When Testing Infrastructure is Selected)
642777
```
643778
tests/
644-
├── php/
645-
│ ├── test-main.php
646-
│ └── test-blocks.php
647-
├── js/
648-
│ ├── main.test.js
649-
│ └── blocks.test.js
650-
└── e2e/
651-
└── plugin.test.js
779+
├── bootstrap-simple.php # Simple bootstrap for unit tests
780+
├── bootstrap.php # Full WordPress bootstrap
781+
├── Unit/
782+
│ ├── MainTest.php # Core plugin functionality tests
783+
│ └── ActivatorTest.php # Activation/deactivation tests
784+
├── Integration/ # WordPress integration tests
785+
└── _support/ # Test helpers and fixtures
652786
```
653787

654788
## 🔧 Advanced Development

0 commit comments

Comments
 (0)