Skip to content

Commit 4836323

Browse files
committed
Added tests for Notify scripts.
1 parent 102bc09 commit 4836323

35 files changed

+3777
-830
lines changed

.vortex/tooling/CLAUDE.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This document describes the Vortex tooling package - a collection of PHP helper
3535
│ │ ├── UnitTestCase.php # Base test case
3636
│ │ ├── ExitException.php # Exit exception for testing
3737
│ │ ├── ExitMockTest.php # Exit mocking tests
38-
│ │ ├── EnvTest.php # Environment tests
38+
│ │ ├── DotenvTest.php # Environment tests
3939
│ │ └── SelfTest.php # Self-tests for core functions
4040
│ └── Traits/
4141
│ └── MockTrait.php # Mock infrastructure (passthru, quit, request)
@@ -108,6 +108,96 @@ The package uses **three types of tests**:
108108
2. **Self Tests** (`tests/Self/`) - Test the mock infrastructure itself
109109
3. **Fixture Scripts** (`tests/Fixtures/`) - External scripts for integration testing
110110

111+
### Test Development Best Practices
112+
113+
**Environment Variable Management**:
114+
- Use `$this->envSet('VAR', 'value')` for setting single variables
115+
- Use `$this->envSetMultiple(['VAR1' => 'value1', 'VAR2' => 'value2'])` for multiple variables
116+
- Use `$this->envUnset('VAR')` for unsetting single variables
117+
- Use `$this->envUnsetMultiple(['VAR1', 'VAR2'])` for unsetting multiple variables
118+
- Use `$this->envUnsetPrefix('PREFIX_')` for unsetting all variables with a prefix
119+
- NEVER use `putenv()` directly - always use EnvTrait methods for automatic cleanup
120+
121+
**Documentation**:
122+
- Data provider method names should start with `dataProvider` prefix (e.g., `dataProviderHttpMethods`, not `providerHttpMethods`)
123+
- Block comments (PHPDoc /** ... */) are ONLY allowed on test classes, NOT on methods
124+
- Do NOT add block comments to test methods, data provider methods, or helper methods
125+
- Inline comments (// ...) are acceptable for explaining logic within method bodies
126+
- Keep test method names descriptive enough that block comments aren't needed
127+
128+
**Allowed Comments**:
129+
```php
130+
// ✅ CORRECT - Block comment on class only
131+
/**
132+
* Tests for webhook notification script.
133+
*/
134+
#[RunTestsInSeparateProcesses]
135+
class NotifyWebhookTest extends UnitTestCase {
136+
137+
// ✅ CORRECT - No block comment on methods, only inline comments
138+
public function testSuccessfulNotification(): void {
139+
// Mock HTTP request
140+
$this->mockRequest('https://example.com', [], ['status' => 200]);
141+
// ... test code ...
142+
}
143+
144+
// ✅ CORRECT - No block comment on data provider
145+
public static function dataProviderHttpMethods(): array {
146+
return ['POST' => ['POST'], 'GET' => ['GET']];
147+
}
148+
}
149+
150+
// ❌ INCORRECT - Block comments on methods
151+
/**
152+
* Test successful notification. // <-- Remove this
153+
*/
154+
public function testSuccessfulNotification(): void {
155+
// ...
156+
}
157+
```
158+
159+
**Example**:
160+
```php
161+
protected function setUp(): void {
162+
parent::setUp();
163+
require_once __DIR__ . '/../../src/helpers.php';
164+
165+
// CORRECT - Use envSetMultiple for multiple variables
166+
$this->envSetMultiple([
167+
'VORTEX_NOTIFY_PROJECT' => 'test-project',
168+
'VORTEX_NOTIFY_LABEL' => 'main',
169+
'VORTEX_NOTIFY_URL' => 'https://example.com',
170+
]);
171+
}
172+
173+
public function testCustomConfiguration(): void {
174+
// ✅ CORRECT - Use envSet for single variable
175+
$this->envSet('VORTEX_NOTIFY_CUSTOM', 'value');
176+
177+
// ... test code ...
178+
}
179+
180+
public function testFallbackVariables(): void {
181+
// ✅ CORRECT - Use envUnsetMultiple for unsetting multiple variables
182+
$this->envUnsetMultiple([
183+
'VORTEX_NOTIFY_SPECIFIC',
184+
'VORTEX_NOTIFY_ANOTHER',
185+
]);
186+
187+
// ✅ CORRECT - Set fallback variable
188+
$this->envSet('VORTEX_NOTIFY_GENERIC', 'fallback-value');
189+
190+
// ... test code ...
191+
}
192+
193+
public static function dataProviderHttpMethods(): array {
194+
return [
195+
'POST' => ['POST'],
196+
'GET' => ['GET'],
197+
];
198+
}
199+
```
200+
111201
### Mock System (MockTrait.php)
112202

113203
The package provides a comprehensive mocking system for testing scripts that use:

.vortex/tooling/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"require-dev": {
2020
"php": ">=8.2",
2121
"alexskrypnyk/file": "^0.15",
22-
"alexskrypnyk/phpunit-helpers": "^0.13.0",
22+
"alexskrypnyk/phpunit-helpers": "^0.14.0",
2323
"dealerdirect/phpcodesniffer-composer-installer": "^1.1.2",
24-
"drevops/phpcs-standard": "^0.4",
24+
"drevops/phpcs-standard": "dev-main",
2525
"drupal/coder": "^9@alpha",
2626
"ergebnis/composer-normalize": "^2.48.2",
2727
"php-mock/php-mock-phpunit": "^2.14",
@@ -52,7 +52,7 @@
5252
"check-no-exit": "php check-no-exit.php",
5353
"lint": [
5454
"phpcs",
55-
"phpstan",
55+
"phpstan --memory-limit=2G",
5656
"rector --dry-run",
5757
"@check-no-exit"
5858
],

.vortex/tooling/phpcs.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
<description>Custom PHPCS standard.</description>
44

55
<!-- Using Drupal coding standard as a base-fix. -->
6-
<rule ref="Drupal"/>
6+
<rule ref="Drupal" />
77
<rule ref="Generic.PHP.RequireStrictTypes" />
88
<rule ref="DrevOps.NamingConventions.LocalVariableSnakeCase"/>
99
<rule ref="DrevOps.NamingConventions.ParameterSnakeCase"/>
10+
<rule ref="DrevOps.TestingPractices.DataProviderPrefix" />
11+
<rule ref="DrevOps.TestingPractices.DataProviderMatchesTestName"/>
12+
<rule ref="DrevOps.TestingPractices.DataProviderOrder" />
1013

1114
<!-- Show sniff codes in all reports -->
1215
<arg value="s"/>
@@ -26,6 +29,11 @@
2629
<file>playground</file>
2730
<file>tests</file>
2831

32+
<!-- Allow delimiter spacing in inline comments in source files. -->
33+
<rule ref="Drupal.Commenting.InlineComment.SpacingAfter">
34+
<exclude-pattern>src\/.*</exclude-pattern>
35+
</rule>
36+
2937
<!-- Allow long array lines in tests. -->
3038
<rule ref="Drupal.Arrays.Array.LongLineDeclaration">
3139
<exclude-pattern>*.Test\.php</exclude-pattern>

0 commit comments

Comments
 (0)