Skip to content

Commit

Permalink
implement validation macro tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Sep 27, 2023
1 parent f402d3f commit c80c76e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
40 changes: 40 additions & 0 deletions tests/Validation/ValidationMacroTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Illuminate\Tests\Validation;

use Illuminate\Validation\Rule;
use PHPUnit\Framework\TestCase;

class ValidationMacroTest extends TestCase
{
public function testMacroable()
{
// Define a phone validation macro
Rule::macro('phone', function () {
return 'regex:/^([0-9\s\-\+\(\)]*)$/';
});

$actualRule = Rule::phone();
$this->assertSame('regex:/^([0-9\s\-\+\(\)]*)$/', $actualRule);
}

public function testMacroArguments()
{
Rule::macro('maxLength', function (int $length) {
return "max:{$length}";
});

$actualRule = Rule::maxLength(10);
$this->assertSame('max:10', $actualRule);
}

public function testMacroDefaultArguments()
{
Rule::macro('maxLength', function ($length = 255) {
return "max:{$length}";
});

$actualRule = Rule::maxLength(); // No argument provided, should use default value
$this->assertSame('max:255', $actualRule);
}
}
19 changes: 0 additions & 19 deletions tests/Validation/ValidationRuleTest.php

This file was deleted.

0 comments on commit c80c76e

Please sign in to comment.