-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Matmper\Exceptions; | ||
|
||
use Exception; | ||
use Illuminate\Http\Response; | ||
use Throwable; | ||
|
||
class ValueIsNotStringException extends Exception | ||
{ | ||
/** | ||
* @param string|null $message | ||
* @param int $code | ||
* @param Throwable|null $previous | ||
*/ | ||
public function __construct( | ||
string $message = null, | ||
int $code = Response::HTTP_BAD_REQUEST, | ||
Throwable $previous = null, | ||
) { | ||
$message = "Parameter value is not a valid string: {$message}"; | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests; | ||
|
||
class NotHtmlRuleTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @dataProvider testNotHtmlDataProvider | ||
*/ | ||
public function test_not_html(mixed $value, bool $assert): void | ||
{ | ||
$rule = app(\Matmper\Rules\NotHtmlRule::class); | ||
$passes = $rule->passes(fake()->word(), $value); | ||
|
||
$this->assertEquals($passes, $assert); | ||
} | ||
|
||
/** | ||
* Data Provider: test_not_html | ||
* | ||
* @return array | ||
*/ | ||
public function testNotHtmlDataProvider(): array | ||
{ | ||
return [ | ||
'true_string' => [$value = fake()->text(100), true], | ||
'false_string_01' => ["<div>{$value}</div>", false], | ||
'false_string_02' => ["<div>", false], | ||
'false_string_03' => ["</div>", false], | ||
'false_string_04' => ["<div><p></p></div>", false], | ||
'false_string_05' => ["$value<div></div>", false], | ||
'false_string_05' => ["<div></div>$value", false], | ||
]; | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider testNotHtmlExceptionDataProvider | ||
*/ | ||
public function test_not_html_string_exception(mixed $value): void | ||
{ | ||
$this->expectException(\Matmper\Exceptions\ValueIsNotStringException::class); | ||
|
||
$rule = app(\Matmper\Rules\NotHtmlRule::class); | ||
$rule->passes(fake()->word(), $value); | ||
} | ||
|
||
/** | ||
* Data Provider: test_not_html_string_exception | ||
* | ||
* @return array | ||
*/ | ||
public function testNotHtmlExceptionDataProvider(): array | ||
{ | ||
return [ | ||
'false_int' => [fake()->randomDigitNotZero()], | ||
'false_float' => [fake()->randomFloat(2)], | ||
'false_array' => [[1, 2, 3]], | ||
]; | ||
} | ||
} |