Skip to content

Commit fea3ffb

Browse files
authored
Fixed test cases (#7643)
1 parent 356ea53 commit fea3ffb

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

src/Concerns/ValidatesAttributes.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ public function validateActiveUrl(string $attribute, $value): bool
108108

109109
if ($url = parse_url($value, PHP_URL_HOST)) {
110110
try {
111-
return count(dns_get_record($url . '.', DNS_A | DNS_AAAA)) > 0;
111+
$records = dns_get_record($url . '.', DNS_A | DNS_AAAA);
112+
if (! $records) {
113+
return false;
114+
}
115+
return count($records) > 0;
112116
} catch (Exception) {
113117
return false;
114118
}

src/Rules/ArrayRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
$this->keys = is_array($keys) ? $keys : func_get_args();
3131
}
3232

33-
public function __toString()
33+
public function __toString(): string
3434
{
3535
if (empty($this->keys)) {
3636
return 'array';

src/Rules/ExcludeIf.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ public function __construct($condition)
3636

3737
/**
3838
* Convert the rule to a validation string.
39-
*
40-
* @return string
4139
*/
42-
public function __toString()
40+
public function __toString(): string
4341
{
4442
if (is_callable($this->condition)) {
4543
return call_user_func($this->condition) ? 'exclude' : '';

src/Rules/ProhibitedIf.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ public function __construct($condition)
3838

3939
/**
4040
* Convert the rule to a validation string.
41-
*
42-
* @return string
4341
*/
44-
public function __toString()
42+
public function __toString(): string
4543
{
4644
if (is_callable($this->condition)) {
4745
return call_user_func($this->condition) ? 'prohibited' : '';

tests/Cases/ValidateAttributesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function __toString(): string
125125
}
126126
}));
127127

128-
$this->assertTrue($validator->validateJson('', new class {
128+
$this->assertTrue($validator->validateJson('', new class implements Stringable {
129129
public function __toString(): string
130130
{
131131
return json_encode(['foo' => 'bar'], JSON_UNESCAPED_UNICODE);

tests/Cases/ValidationValidatorTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use PHPUnit\Framework\Attributes\DataProvider;
3838
use PHPUnit\Framework\TestCase;
3939
use SplFileInfo;
40+
use Stringable;
4041

4142
/**
4243
* @internal
@@ -2856,16 +2857,16 @@ public function testValidateEmail()
28562857
$v = new Validator($trans, ['x' => ['not a string']], ['x' => 'Email']);
28572858
$this->assertFalse($v->passes());
28582859

2859-
$v = new Validator($trans, ['x' => new class {
2860-
public function __toString()
2860+
$v = new Validator($trans, ['x' => new class implements Stringable {
2861+
public function __toString(): string
28612862
{
28622863
return 'aslsdlks';
28632864
}
28642865
}], ['x' => 'Email']);
28652866
$this->assertFalse($v->passes());
28662867

2867-
$v = new Validator($trans, ['x' => new class {
2868-
public function __toString()
2868+
$v = new Validator($trans, ['x' => new class implements Stringable {
2869+
public function __toString(): string
28692870
{
28702871
28712872
}

0 commit comments

Comments
 (0)