generated from Soyhuce/package-skeleton-laravel
-
-
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.
Remove support for spatie/data-transfer-object, improve support for s…
…patie/laravel-data
- Loading branch information
1 parent
d657b55
commit d46c09e
Showing
8 changed files
with
142 additions
and
4 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,60 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soyhuce\Testing\Constraints; | ||
|
||
use Illuminate\Support\Collection; | ||
use PHPUnit\Framework\Constraint\Constraint; | ||
use SebastianBergmann\Comparator\ComparisonFailure; | ||
use Spatie\LaravelData\Data; | ||
|
||
class DataEquals extends Constraint | ||
{ | ||
public function __construct( | ||
protected Data $value, | ||
) { | ||
} | ||
|
||
public function evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool | ||
{ | ||
$success = $this->matches($other); | ||
|
||
if ($returnResult) { | ||
return $success; | ||
} | ||
|
||
if ($success) { | ||
return null; | ||
} | ||
|
||
$failure = $other instanceof Data | ||
? new ComparisonFailure( | ||
$this->value, | ||
$other, | ||
$this->exporter()->export($this->value), | ||
$this->exporter()->export($other) | ||
) | ||
: null; | ||
|
||
$this->fail($other, $description, $failure); | ||
} | ||
|
||
protected function matches(mixed $other): bool | ||
{ | ||
if (!$other instanceof Data) { | ||
return false; | ||
} | ||
|
||
return (new CollectionEquals(Collection::make($this->value->all()))) | ||
->matches(Collection::make($other->all())); | ||
} | ||
|
||
protected function failureDescription(mixed $other): string | ||
{ | ||
return $this->exporter()->export($other) . ' ' . $this->toString(); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return 'is same data that ' . $this->exporter()->export($this->value); | ||
} | ||
} |
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,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soyhuce\Testing\Tests\Fixtures; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
class SimpleData extends Data | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public int $age, | ||
) { | ||
} | ||
} |
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