Skip to content

Commit 2a2872a

Browse files
committed
refactor(assert): replace AssertTypeSuccess with AssertionComposite in assertion classes
1 parent 9008e2f commit 2a2872a

18 files changed

+156
-97
lines changed

src/Assert/Internal/Assertion/AssertArray.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Testo\Assert\Api\Builtin\ArrayType;
88
use Testo\Assert\Internal\Assertion\Traits\IterableTrait;
99
use Testo\Assert\State\AssertTypeFailure;
10-
use Testo\Assert\State\AssertTypeSuccess;
10+
use Testo\Assert\State\AssertionComposite;
1111
use Testo\Assert\StaticState;
1212

1313
/**
@@ -21,7 +21,7 @@ class AssertArray implements ArrayType
2121

2222
public function __construct(
2323
private readonly array $value,
24-
private readonly AssertTypeSuccess $parent,
24+
private readonly AssertionComposite $parent,
2525
) {}
2626

2727
/**
@@ -33,7 +33,7 @@ public function __construct(
3333
*/
3434
public static function validateAndCreate(mixed $value): self
3535
{
36-
\is_array($value) or StaticState::fail(AssertTypeFailure::create('array', $value));
36+
\is_array($value) or StaticState::typeFail('array', $value);
3737

3838
$parent = StaticState::typeSuccess('array', $value);
3939
return new self($value, $parent);
@@ -58,7 +58,7 @@ public function hasKeys(int|string ...$keys): static
5858
$m = \count($keys) === 1 ? '' : 's';
5959
$str = "has key$m " . \implode(', ', $keys);
6060
if ($failedKeys === []) {
61-
$this->parent->log($str);
61+
$this->parent->success($str);
6262
return $this;
6363
}
6464

@@ -73,7 +73,7 @@ public function hasKeys(int|string ...$keys): static
7373
public function isList(string $message = ''): static
7474
{
7575
if (\array_is_list($this->value)) {
76-
$this->parent->log('is list');
76+
$this->parent->success('is list');
7777
return $this;
7878
}
7979

src/Assert/Internal/Assertion/AssertFloat.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Testo\Assert\Api\Builtin\FloatType;
88
use Testo\Assert\Internal\Assertion\Traits\NumericTrait;
99
use Testo\Assert\State\AssertTypeFailure;
10-
use Testo\Assert\State\AssertTypeSuccess;
10+
use Testo\Assert\State\AssertionComposite;
1111
use Testo\Assert\StaticState;
1212
use Testo\Assert\Support;
1313

@@ -22,7 +22,7 @@ class AssertFloat implements FloatType
2222

2323
public function __construct(
2424
private readonly float $value,
25-
private readonly AssertTypeSuccess $parent,
25+
private readonly AssertionComposite $parent,
2626
) {}
2727

2828
/**
@@ -34,7 +34,7 @@ public function __construct(
3434
*/
3535
public static function validateAndCreate(mixed $value): self
3636
{
37-
\is_float($value) or StaticState::fail(AssertTypeFailure::create('float', $value));
37+
\is_float($value) or StaticState::typeFail('float', $value);
3838

3939
$parent = StaticState::typeSuccess('float', $value);
4040
return new self($value, $parent);

src/Assert/Internal/Assertion/AssertInt.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Testo\Assert\Api\Builtin\IntType;
88
use Testo\Assert\Internal\Assertion\Traits\NumericTrait;
99
use Testo\Assert\State\AssertTypeFailure;
10-
use Testo\Assert\State\AssertTypeSuccess;
10+
use Testo\Assert\State\AssertionComposite;
1111
use Testo\Assert\StaticState;
1212
use Testo\Assert\Support;
1313

@@ -22,7 +22,7 @@ class AssertInt implements IntType
2222

2323
public function __construct(
2424
private readonly int $value,
25-
private readonly AssertTypeSuccess $parent,
25+
private readonly AssertionComposite $parent,
2626
) {}
2727

2828
/**
@@ -34,7 +34,7 @@ public function __construct(
3434
*/
3535
public static function validateAndCreate(mixed $value): self
3636
{
37-
\is_int($value) or StaticState::fail(AssertTypeFailure::create('int', $value));
37+
\is_int($value) or StaticState::typeFail('int', $value);
3838

3939
$parent = StaticState::typeSuccess('int', $value);
4040
return new self($value, $parent);

src/Assert/Internal/Assertion/AssertIterable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Testo\Assert\Api\Builtin\IterableType;
88
use Testo\Assert\Internal\Assertion\Traits\IterableTrait;
99
use Testo\Assert\State\AssertTypeFailure;
10-
use Testo\Assert\State\AssertTypeSuccess;
10+
use Testo\Assert\State\AssertionComposite;
1111
use Testo\Assert\StaticState;
1212
use Testo\Assert\Support;
1313

@@ -22,7 +22,7 @@ class AssertIterable implements IterableType
2222

2323
public function __construct(
2424
private readonly iterable $value,
25-
private readonly AssertTypeSuccess $parent,
25+
private readonly AssertionComposite $parent,
2626
) {}
2727

2828
/**
@@ -34,7 +34,7 @@ public function __construct(
3434
*/
3535
public static function validateAndCreate(mixed $value): self
3636
{
37-
\is_iterable($value) or StaticState::fail(AssertTypeFailure::create('iterable', $value));
37+
\is_iterable($value) or StaticState::typeFail('iterable', $value);
3838

3939
$parent = StaticState::typeSuccess('iterable', $value);
4040
return new self($value, $parent);

src/Assert/Internal/Assertion/AssertJson.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Testo\Assert\Api\Json\JsonCommon;
1010
use Testo\Assert\Api\Json\JsonObject;
1111
use Testo\Assert\Api\Json\JsonStructure;
12-
use Testo\Assert\State\AssertTypeSuccess;
12+
use Testo\Assert\State\AssertionComposite;
1313

1414
/**
1515
* Implementation of JSON assertions.
@@ -20,7 +20,7 @@ class AssertJson implements JsonAbstract
2020
{
2121
public function __construct(
2222
private mixed $value,
23-
private readonly AssertTypeSuccess $parent,
23+
private readonly AssertionComposite $parent,
2424
) {}
2525

2626
/**

src/Assert/Internal/Assertion/AssertNumeric.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Testo\Assert\Api\Builtin\IntType;
88
use Testo\Assert\Internal\Assertion\Traits\NumericTrait;
9-
use Testo\Assert\State\AssertTypeSuccess;
9+
use Testo\Assert\State\AssertionComposite;
1010

1111
/**
1212
* Assertion utilities for numeric data type.
@@ -19,6 +19,6 @@ class AssertNumeric implements IntType
1919

2020
public function __construct(
2121
public int|float $value,
22-
private readonly AssertTypeSuccess $parent,
22+
private readonly AssertionComposite $parent,
2323
) {}
2424
}

src/Assert/Internal/Assertion/AssertObject.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Testo\Assert\Api\Builtin\ObjectType;
88
use Testo\Assert\State\AssertException;
99
use Testo\Assert\State\AssertTypeFailure;
10-
use Testo\Assert\State\AssertTypeSuccess;
10+
use Testo\Assert\State\AssertionComposite;
1111
use Testo\Assert\StaticState;
1212

1313
/**
@@ -19,7 +19,7 @@ final class AssertObject implements ObjectType
1919
{
2020
public function __construct(
2121
private readonly object $value,
22-
private readonly AssertTypeSuccess $parent,
22+
private readonly AssertionComposite $parent,
2323
) {}
2424

2525
/**
@@ -33,7 +33,7 @@ public function __construct(
3333
*/
3434
public static function validateAndCreate(mixed $value): self
3535
{
36-
\is_object($value) or StaticState::fail(AssertTypeFailure::create('object', $value));
36+
\is_object($value) or StaticState::typeFail('object', $value);
3737

3838
$parent = StaticState::typeSuccess('object', $value);
3939
return new self($value, $parent);
@@ -44,7 +44,7 @@ public function instanceOf(string $expected, string $message = ''): self
4444
{
4545
$str = "is instance of `{$expected}`";
4646
$this->value instanceof $expected
47-
? $this->parent->log($str, $message)
47+
? $this->parent->success($str, $message)
4848
: throw $this->parent->fail($str, 'got `' . $this->value::class . '` instead', $message);
4949
return $this;
5050
}

src/Assert/Internal/Assertion/AssertString.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Testo\Assert\Api\Builtin\StringType;
88
use Testo\Assert\State\AssertException;
99
use Testo\Assert\State\AssertTypeFailure;
10-
use Testo\Assert\State\AssertTypeSuccess;
10+
use Testo\Assert\State\AssertionComposite;
1111
use Testo\Assert\StaticState;
1212
use Testo\Assert\Support;
1313

@@ -20,7 +20,7 @@ class AssertString implements StringType
2020
{
2121
public function __construct(
2222
private readonly string $value,
23-
private readonly AssertTypeSuccess $parent,
23+
private readonly AssertionComposite $parent,
2424
) {}
2525

2626
/**
@@ -33,7 +33,7 @@ public function __construct(
3333
*/
3434
public static function validateAndCreate(mixed $value): self
3535
{
36-
\is_string($value) or StaticState::fail(AssertTypeFailure::create('string', $value));
36+
\is_string($value) or StaticState::typeFail('string', $value);
3737

3838
$parent = StaticState::typeSuccess('string', $value);
3939
return new self($value, $parent);

src/Assert/Internal/Assertion/Traits/IterableTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Testo\Assert\Internal\Assertion\Traits;
66

7-
use Testo\Assert\State\AssertTypeSuccess;
7+
use Testo\Assert\State\AssertionComposite;
88
use Testo\Assert\Support;
99

1010
/**
1111
* Contains assertion methods for iterable values.
1212
*
1313
* @property iterable $value
14-
* @property AssertTypeSuccess $parent
14+
* @property AssertionComposite $parent
1515
*/
1616
trait IterableTrait
1717
{
@@ -21,7 +21,7 @@ public function contains(mixed $needle, string $message = ''): static
2121
$str = 'contains `' . Support::stringify($needle) . '`';
2222
foreach ($this->value as $item) {
2323
if ($item === $needle) {
24-
$this->parent->log($str);
24+
$this->parent->success($str);
2525
return $this;
2626
}
2727
}
@@ -40,7 +40,7 @@ public function sameSizeAs(iterable $expected, string $message = ''): static
4040
$countThis = self::countIterable($this->value);
4141
$countExpected = self::countIterable($expected);
4242
if ($countThis === $countExpected) {
43-
$this->parent->log($str);
43+
$this->parent->success($str);
4444
return $this;
4545
}
4646

@@ -72,7 +72,7 @@ public function allOf(string $type, string $message = ''): static
7272
);
7373
}
7474

75-
$this->parent->log($str);
75+
$this->parent->success($str);
7676
return $this;
7777
}
7878

@@ -82,7 +82,7 @@ public function hasCount(int $expected): static
8282
$count = self::countIterable($this->value);
8383
$str = "has count `$expected`";
8484
if ($count === $expected) {
85-
$this->parent->log($str);
85+
$this->parent->success($str);
8686
return $this;
8787
}
8888

src/Assert/Internal/Assertion/Traits/NumericTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace Testo\Assert\Internal\Assertion\Traits;
66

77
use Testo\Assert\State\AssertException;
8-
use Testo\Assert\State\AssertTypeSuccess;
8+
use Testo\Assert\State\AssertionComposite;
99

1010
/**
1111
* Contains methods for comparing numeric values
1212
* @property int|float $value
13-
* @property AssertTypeSuccess $parent
13+
* @property AssertionComposite $parent
1414
*/
1515
trait NumericTrait
1616
{
@@ -25,7 +25,7 @@ public function greaterThan(int|float $min, string $message = ''): self
2525
{
2626
$str = "greater than `{$min}`";
2727
if ($this->value > $min) {
28-
$this->parent->log($str, $message);
28+
$this->parent->success($str, $message);
2929
return $this;
3030
}
3131

@@ -47,7 +47,7 @@ public function greaterThanOrEqual(int|float $min, string $message = ''): self
4747
{
4848
$str = "greater than or equal to `{$min}`";
4949
if ($this->value >= $min) {
50-
$this->parent->log($str, $message);
50+
$this->parent->success($str, $message);
5151
return $this;
5252
}
5353

@@ -69,7 +69,7 @@ public function lessThan(int|float $max, string $message = ''): self
6969
{
7070
$str = "less than `{$max}`";
7171
if ($this->value < $max) {
72-
$this->parent->log($str, $message);
72+
$this->parent->success($str, $message);
7373
return $this;
7474
}
7575

@@ -91,7 +91,7 @@ public function lessThanOrEqual(int|float $max, string $message = ''): self
9191
{
9292
$str = "less than or equal to `{$max}`";
9393
if ($this->value <= $max) {
94-
$this->parent->log($str, $message);
94+
$this->parent->success($str, $message);
9595
return $this;
9696
}
9797

0 commit comments

Comments
 (0)