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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.0.1] - 12/04/2025
## [0.0.1alpha5] - 12/04/2025

### Additions
- Renamed some methods

## [0.0.1alpha1] - 12/04/2025

### Additions
- Initial release
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ use FallegaHQ\JsonTestUtils\JsonValidator;

$validator = new JsonValidator($json);
$validator->has('data')
->whereType('data', 'array')
->whereNotEmpty('data')
->whereEach('data.items', function($item) {
->isType('data', 'array')
->isNotEmpty('data')
->passesEach('data.items', function($item) {
return isset($item['id']) ? true : 'Item must have an ID';
});

if ($validator->fails()) {
var_dump($validator->errors());
if ($validator->failed()) {
var_dump($validator->getErrors());
}
```

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1alpha4
0.0.1alpha5
16 changes: 8 additions & 8 deletions examples/AdvancedExamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,21 @@ public function testDirectValidatorUsage(): void {

// First level validation
$validator->has('settings');
$validator->whereType('settings', 'array');
$validator->isType('settings', 'array');

// Validate notification settings
$validator->has('settings.notifications');
$validator->whereType('settings.notifications.email', 'boolean');
$validator->whereType('settings.notifications.push', 'boolean');
$validator->whereType('settings.notifications.sms', 'boolean');
$validator->isType('settings.notifications.email', 'boolean');
$validator->isType('settings.notifications.push', 'boolean');
$validator->isType('settings.notifications.sms', 'boolean');

// Validate privacy settings
$validator->has('settings.privacy');
$validator->whereType('settings.privacy.share_data', 'boolean');
$validator->whereType('settings.privacy.public_profile', 'boolean');
$validator->isType('settings.privacy.share_data', 'boolean');
$validator->isType('settings.privacy.public_profile', 'boolean');

// Advanced: custom logic check across multiple values
$validator->whereIs('settings', function ($settings) {
$validator->passes('settings', function ($settings) {
// Example: at least one notification type must be enabled
$notifications = $settings['notifications'] ?? [];
$hasOneEnabled = false;
Expand All @@ -209,6 +209,6 @@ public function testDirectValidatorUsage(): void {
return $hasOneEnabled ? true : 'At least one notification must be enabled';
});

self::assertTrue($validator->passes(), 'Validation failed: '.json_encode($validator->errors(), JSON_THROW_ON_ERROR));
self::assertTrue($validator->validated(), 'Validation failed: '.json_encode($validator->getErrors(), JSON_THROW_ON_ERROR));
}
}
16 changes: 8 additions & 8 deletions src/JsonAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function assertJsonHasKey(array|string $json, string $key, ?string $me
$validator = new JsonValidator($json);
$validator->has($key);

Assert::assertTrue($validator->passes(), $message ?? $this->formatValidatorErrors($validator->errors()));
Assert::assertTrue($validator->validated(), $message ?? $this->formatValidatorErrors($validator->getErrors()));
}

/**
Expand All @@ -50,7 +50,7 @@ protected function assertJsonNotHasKey(array|string $json, string $key, ?string
$validator = new JsonValidator($json);
$validator->hasNot($key);

Assert::assertTrue($validator->passes(), $message ?? $this->formatValidatorErrors($validator->errors()));
Assert::assertTrue($validator->validated(), $message ?? $this->formatValidatorErrors($validator->getErrors()));
}

/**
Expand All @@ -63,9 +63,9 @@ protected function assertJsonNotHasKey(array|string $json, string $key, ?string
*/
protected function assertJsonEquals(array|string $json, string $key, mixed $expectedValue, ?string $message = null): void {
$validator = new JsonValidator($json);
$validator->where($key, $expectedValue);
$validator->hasWithValue($key, $expectedValue);

Assert::assertTrue($validator->passes(), $message ?? $this->formatValidatorErrors($validator->errors()));
Assert::assertTrue($validator->validated(), $message ?? $this->formatValidatorErrors($validator->getErrors()));
}

/**
Expand All @@ -78,9 +78,9 @@ protected function assertJsonEquals(array|string $json, string $key, mixed $expe
*/
protected function assertJsonType(array|string $json, string $key, string $expectedType, ?string $message = null): void {
$validator = new JsonValidator($json);
$validator->whereType($key, $expectedType);
$validator->isType($key, $expectedType);

Assert::assertTrue($validator->passes(), $message ?? $this->formatValidatorErrors($validator->errors()));
Assert::assertTrue($validator->validated(), $message ?? $this->formatValidatorErrors($validator->getErrors()));
}

/**
Expand All @@ -93,9 +93,9 @@ protected function assertJsonType(array|string $json, string $key, string $expec
*/
protected function assertJsonCondition(array|string $json, string $key, callable $condition, ?string $message = null): void {
$validator = new JsonValidator($json);
$validator->whereIs($key, $condition);
$validator->passes($key, $condition);

Assert::assertTrue($validator->passes(), $message ?? $this->formatValidatorErrors($validator->errors()));
Assert::assertTrue($validator->validated(), $message ?? $this->formatValidatorErrors($validator->getErrors()));
}

/**
Expand Down
Loading