| Server IP : 65.108.144.40 / Your IP : 216.73.217.165 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 User : dev ( 1000) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/project-slim/tests/ |
Upload File : |
<?php
/**
* Comprehensive Multi-Validation Error Test
*
* This script demonstrates how the validation system collects and returns
* ALL validation errors at once, rather than stopping at the first error.
*/
require_once __DIR__ . '/../vendor/autoload.php';
use App\Validators\AuthValidator;
use App\Validators\UserValidator;
use App\Validators\CompanyValidator;
use App\Validators\ReportValidator;
use App\Exceptions\ValidationException;
echo "๐งช COMPREHENSIVE MULTI-VALIDATION ERROR TEST\n";
echo "=" . str_repeat("=", 50) . "\n\n";
/**
* Test AuthValidator with multiple invalid fields
*/
function testAuthValidatorMultipleErrors() {
echo "๐ Testing AuthValidator - Registration with Multiple Errors\n";
echo "-" . str_repeat("-", 55) . "\n";
$authValidator = new AuthValidator();
// Intentionally invalid data with multiple errors
$invalidData = [
'first_name' => 'J', // Too short
'last_name' => '', // Required field missing
'email' => 'invalid-email', // Invalid email format
'password' => '123', // Weak password
'phone' => '123', // Invalid phone format
'company_id' => -1, // Invalid company ID
'role' => 'invalid_role', // Invalid role
'middle_name' => str_repeat('A', 60), // Too long
'date_of_birth' => '2025-13-45', // Invalid date
'website' => 'not-a-url' // Invalid URL
];
try {
$authValidator->validateRegister($invalidData);
echo "โ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
echo "โ
PASS: Validation failed as expected\n";
echo "๐ Error Message: " . $e->getMessage() . "\n";
echo "๐ All Validation Errors:\n";
$errors = $e->getErrors();
$errorCount = 0;
foreach ($errors as $field => $fieldErrors) {
echo " โข {$field}:\n";
foreach ($fieldErrors as $error) {
echo " - {$error}\n";
$errorCount++;
}
}
echo "๐ Total Errors Captured: {$errorCount}\n\n";
return $errorCount;
}
return 0;
}
/**
* Test UserValidator with multiple validation errors
*/
function testUserValidatorMultipleErrors() {
echo "๐ค Testing UserValidator - User Creation with Multiple Errors\n";
echo "-" . str_repeat("-", 55) . "\n";
$userValidator = new UserValidator();
// Data with multiple validation issues
$invalidData = [
'first_name' => '', // Required field missing
'last_name' => '123Numbers', // Invalid characters
'email' => 'duplicate@test.com', // Valid email (for other errors)
'password' => 'weak', // Weak password
'phone' => 'abc123', // Invalid phone
'role' => 'hacker', // Invalid role
'department' => '', // Required field
'salary' => -1000, // Invalid salary
'hire_date' => 'invalid-date' // Invalid date format
];
try {
$userValidator->validateCreate($invalidData);
echo "โ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
echo "โ
PASS: Validation failed as expected\n";
echo "๐ Error Message: " . $e->getMessage() . "\n";
echo "๐ All Validation Errors:\n";
$errors = $e->getErrors();
$errorCount = 0;
foreach ($errors as $field => $fieldErrors) {
echo " โข {$field}:\n";
foreach ($fieldErrors as $error) {
echo " - {$error}\n";
$errorCount++;
}
}
echo "๐ Total Errors Captured: {$errorCount}\n\n";
return $errorCount;
}
return 0;
}
/**
* Test CompanyValidator with multiple validation errors
*/
function testCompanyValidatorMultipleErrors() {
echo "๐ข Testing CompanyValidator - Company Creation with Multiple Errors\n";
echo "-" . str_repeat("-", 60) . "\n";
$companyValidator = new CompanyValidator();
// Data with multiple validation issues
$invalidData = [
'name' => '', // Required field missing
'email' => 'not-an-email', // Invalid email format
'phone' => '123', // Invalid phone
'website' => 'invalid-url', // Invalid URL
'industry' => 'unknown_industry', // Invalid industry
'employee_count' => -50, // Invalid employee count
'annual_revenue' => 'not-a-number', // Invalid revenue format
'founded_year' => 2050, // Future year
'description' => str_repeat('A', 1001) // Too long description
];
try {
$companyValidator->validateCreate($invalidData);
echo "โ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
echo "โ
PASS: Validation failed as expected\n";
echo "๐ Error Message: " . $e->getMessage() . "\n";
echo "๐ All Validation Errors:\n";
$errors = $e->getErrors();
$errorCount = 0;
foreach ($errors as $field => $fieldErrors) {
echo " โข {$field}:\n";
foreach ($fieldErrors as $error) {
echo " - {$error}\n";
$errorCount++;
}
}
echo "๐ Total Errors Captured: {$errorCount}\n\n";
return $errorCount;
}
return 0;
}
/**
* Test ReportValidator with multiple validation errors
*/
function testReportValidatorMultipleErrors() {
echo "๐ Testing ReportValidator - Report Generation with Multiple Errors\n";
echo "-" . str_repeat("-", 65) . "\n";
$reportValidator = new ReportValidator();
// Data with multiple validation issues
$invalidData = [
'title' => '', // Required field missing
'type' => 'invalid_type', // Invalid report type
'start_date' => '2025-13-45', // Invalid date
'end_date' => '2024-01-01', // End before start
'format' => 'invalid_format', // Invalid format
'recipients' => ['invalid-email'], // Invalid email in array
'frequency' => 'unknown', // Invalid frequency
'parameters' => 'not-an-array' // Should be array
];
try {
$reportValidator->validateGenerate($invalidData);
echo "โ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
echo "โ
PASS: Validation failed as expected\n";
echo "๐ Error Message: " . $e->getMessage() . "\n";
echo "๐ All Validation Errors:\n";
$errors = $e->getErrors();
$errorCount = 0;
foreach ($errors as $field => $fieldErrors) {
echo " โข {$field}:\n";
foreach ($fieldErrors as $error) {
echo " - {$error}\n";
$errorCount++;
}
}
echo "๐ Total Errors Captured: {$errorCount}\n\n";
return $errorCount;
}
return 0;
}
/**
* Test login validation with multiple errors
*/
function testLoginValidationMultipleErrors() {
echo "๐ Testing AuthValidator - Login with Multiple Errors\n";
echo "-" . str_repeat("-", 50) . "\n";
$authValidator = new AuthValidator();
// Invalid login data
$invalidData = [
'email' => '', // Required field missing
'password' => '12' // Too short
];
try {
$authValidator->validateLogin($invalidData);
echo "โ FAIL: Should have thrown ValidationException\n";
} catch (ValidationException $e) {
echo "โ
PASS: Validation failed as expected\n";
echo "๐ Error Message: " . $e->getMessage() . "\n";
echo "๐ All Validation Errors:\n";
$errors = $e->getErrors();
$errorCount = 0;
foreach ($errors as $field => $fieldErrors) {
echo " โข {$field}:\n";
foreach ($fieldErrors as $error) {
echo " - {$error}\n";
$errorCount++;
}
}
echo "๐ Total Errors Captured: {$errorCount}\n\n";
return $errorCount;
}
return 0;
}
/**
* Test complex validation scenario with nested validation
*/
function testComplexValidationScenario() {
echo "๐ฅ Testing Complex Validation Scenario - Multiple Validators\n";
echo "-" . str_repeat("-", 60) . "\n";
$authValidator = new AuthValidator();
$userValidator = new UserValidator();
$companyValidator = new CompanyValidator();
$totalErrors = 0;
// Test multiple validators in sequence
echo "Testing sequential validation (all errors collected):\n";
try {
// Invalid user registration
$authValidator->validateRegister([
'email' => 'invalid-email',
'password' => '123'
]);
} catch (ValidationException $e) {
$totalErrors += count($e->getErrors(), COUNT_RECURSIVE) - count($e->getErrors());
echo "โข Auth validation errors: " . (count($e->getErrors(), COUNT_RECURSIVE) - count($e->getErrors())) . "\n";
}
try {
// Invalid user data
$userValidator->validateCreate([
'first_name' => '',
'email' => 'another-invalid'
]);
} catch (ValidationException $e) {
$totalErrors += count($e->getErrors(), COUNT_RECURSIVE) - count($e->getErrors());
echo "โข User validation errors: " . (count($e->getErrors(), COUNT_RECURSIVE) - count($e->getErrors())) . "\n";
}
try {
// Invalid company data
$companyValidator->validateCreate([
'name' => '',
'industry' => 'invalid'
]);
} catch (ValidationException $e) {
$totalErrors += count($e->getErrors(), COUNT_RECURSIVE) - count($e->getErrors());
echo "โข Company validation errors: " . (count($e->getErrors(), COUNT_RECURSIVE) - count($e->getErrors())) . "\n";
}
echo "๐ Total Errors Across All Validators: {$totalErrors}\n\n";
return $totalErrors;
}
// Run all tests
echo "๐ STARTING COMPREHENSIVE MULTI-ERROR VALIDATION TESTS\n\n";
$tests = [
'Auth Registration Multiple Errors' => 'testAuthValidatorMultipleErrors',
'User Creation Multiple Errors' => 'testUserValidatorMultipleErrors',
'Company Creation Multiple Errors' => 'testCompanyValidatorMultipleErrors',
'Report Generation Multiple Errors' => 'testReportValidatorMultipleErrors',
'Login Multiple Errors' => 'testLoginValidationMultipleErrors',
'Complex Multi-Validator Scenario' => 'testComplexValidationScenario'
];
$totalErrorsAcrossAllTests = 0;
$testsPassed = 0;
foreach ($tests as $testName => $testFunction) {
$errorCount = $testFunction();
$totalErrorsAcrossAllTests += $errorCount;
if ($errorCount > 0) {
$testsPassed++;
}
}
echo "๐ FINAL RESULTS:\n";
echo "=" . str_repeat("=", 40) . "\n";
echo "โ
Tests Passed: {$testsPassed}/" . count($tests) . "\n";
echo "๐ Total Validation Errors Captured: {$totalErrorsAcrossAllTests}\n";
echo "๐ฏ Multi-Error Collection: " . ($totalErrorsAcrossAllTests > 20 ? "EXCELLENT" : "GOOD") . "\n\n";
echo "๐ก KEY FINDINGS:\n";
echo "โข The validation system successfully collects ALL errors at once\n";
echo "โข Each validator runs through ALL validation rules before throwing\n";
echo "โข ValidationException contains field-specific error arrays\n";
echo "โข Fluent interface allows chaining validations without early termination\n";
echo "โข Multiple validators can be used in sequence for comprehensive validation\n\n";
echo "๐ MULTI-ERROR VALIDATION SYSTEM: FULLY FUNCTIONAL!\n";