Skip to content

Commit

Permalink
QA
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslaw-przylucki committed May 30, 2024
1 parent 428c85f commit 2ddde79
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
15 changes: 9 additions & 6 deletions src/Support/LanguageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@

final class LanguageHelper
{

public static function join(array $strings): string
/**
* @param string[] $parts
*
* @return string
*/
public static function join(array $parts): string
{
$last = array_pop($strings);
$last = array_pop($parts);

if ($strings) {
return implode(', ', $strings) . ' ' . 'and' . ' ' . $last;
if ($parts) {
return implode(', ', $parts) . ' ' . 'and' . ' ' . $last;
}

return $last;
}

}
2 changes: 1 addition & 1 deletion src/Validation/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Tempest\Validation\Exceptions;

use Exception;
use Tempest\Validation\Rule;
use Tempest\Support\ArrayHelper;
use Tempest\Support\LanguageHelper;
use Tempest\Validation\Rule;

final class ValidationException extends Exception
{
Expand Down
4 changes: 3 additions & 1 deletion src/Validation/Rules/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Attribute;
use Tempest\Validation\Rule;
use Tempest\Support\LanguageHelper;

#[Attribute]
final readonly class Password implements Rule
Expand Down Expand Up @@ -52,6 +51,9 @@ public function isValid(mixed $value): bool
return true;
}

/**
* @return string[]
*/
public function message(): array
{
$messages = ["Value should contain at least {$this->min} characters"];
Expand Down
25 changes: 12 additions & 13 deletions tests/Unit/Validation/ValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Tests\Tempest\Unit\Validation;

use stdClass;
use Tempest\Validation\Rule;
use PHPUnit\Framework\TestCase;
use stdClass;
use Tempest\Validation\Exceptions\ValidationException;
use Tempest\Validation\Rule;

/**
* @internal
* @small
*/
final class ValidationExceptionTest extends TestCase
{

public function test_exception_message(): void
{
$this->expectException(ValidationException::class);
Expand All @@ -20,8 +23,7 @@ public function test_exception_message(): void

throw new ValidationException(new stdClass(), [
'email' => [
new class implements Rule {

new class () implements Rule {
public function isValid(mixed $value): bool
{
return false;
Expand All @@ -31,8 +33,8 @@ public function message(): string|array
{
return 'Value should be a valid email address';
}
}
]
},
],
]);
}

Expand All @@ -45,8 +47,7 @@ public function test_exception_message_with_multiple_messages(): void

throw new ValidationException(new stdClass(), [
'email' => [
new class implements Rule {

new class () implements Rule {
public function isValid(mixed $value): bool
{
return false;
Expand All @@ -57,8 +58,7 @@ public function message(): string|array
return 'Value should be a valid email address';
}
},
new class implements Rule {

new class () implements Rule {
public function isValid(mixed $value): bool
{
return false;
Expand All @@ -72,8 +72,7 @@ public function message(): string|array
'the new gods from the future',
];
}
}]
}],
]);
}

}

0 comments on commit 2ddde79

Please sign in to comment.