-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Testing): Add asserts for View and View\\Factory contracts
- Loading branch information
Showing
16 changed files
with
732 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/Testing/Laravel/Contracts/View/FactoryAddNamespaceExpectation.php
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 LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryAddNamespaceExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $namespace, | ||
public readonly mixed $hints, | ||
) { | ||
} | ||
} |
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,194 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Contracts\View\Factory; | ||
use Illuminate\Contracts\View\View; | ||
use LaraStrict\Testing\AbstractExpectationCallsMap; | ||
use PHPUnit\Framework\Assert; | ||
|
||
class FactoryAssert extends AbstractExpectationCallsMap implements Factory | ||
{ | ||
/** | ||
* @param array<FactoryExistsExpectation> $exists | ||
* @param array<FactoryFileExpectation> $file | ||
* @param array<FactoryMakeExpectation> $make | ||
* @param array<FactoryShareExpectation> $share | ||
* @param array<FactoryComposerExpectation> $composer | ||
* @param array<FactoryCreatorExpectation> $creator | ||
* @param array<FactoryAddNamespaceExpectation> $addNamespace | ||
* @param array<FactoryReplaceNamespaceExpectation> $replaceNamespace | ||
*/ | ||
public function __construct( | ||
array $exists = [], | ||
array $file = [], | ||
array $make = [], | ||
array $share = [], | ||
array $composer = [], | ||
array $creator = [], | ||
array $addNamespace = [], | ||
array $replaceNamespace = [], | ||
) { | ||
$this->setExpectations(FactoryExistsExpectation::class, array_values(array_filter($exists))); | ||
$this->setExpectations(FactoryFileExpectation::class, array_values(array_filter($file))); | ||
$this->setExpectations(FactoryMakeExpectation::class, array_values(array_filter($make))); | ||
$this->setExpectations(FactoryShareExpectation::class, array_values(array_filter($share))); | ||
$this->setExpectations(FactoryComposerExpectation::class, array_values(array_filter($composer))); | ||
$this->setExpectations(FactoryCreatorExpectation::class, array_values(array_filter($creator))); | ||
$this->setExpectations(FactoryAddNamespaceExpectation::class, array_values(array_filter($addNamespace))); | ||
$this->setExpectations( | ||
FactoryReplaceNamespaceExpectation::class, | ||
array_values(array_filter($replaceNamespace)) | ||
); | ||
} | ||
|
||
/** | ||
* Determine if a given view exists. | ||
* | ||
* @param string $view | ||
* @return bool | ||
*/ | ||
public function exists($view) | ||
{ | ||
$expectation = $this->getExpectation(FactoryExistsExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->view, $view, $message); | ||
|
||
return $expectation->return; | ||
} | ||
|
||
/** | ||
* Get the evaluated view contents for the given path. | ||
* | ||
* @param string $path | ||
* @param Arrayable<string, mixed>|array $data | ||
* @param array $mergeData | ||
* @return View | ||
*/ | ||
public function file($path, $data = [], $mergeData = []) | ||
{ | ||
$expectation = $this->getExpectation(FactoryFileExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->path, $path, $message); | ||
Assert::assertEquals($expectation->data, $data, $message); | ||
Assert::assertEquals($expectation->mergeData, $mergeData, $message); | ||
|
||
return $expectation->return; | ||
} | ||
|
||
/** | ||
* Get the evaluated view contents for the given view. | ||
* | ||
* @param string $view | ||
* @param Arrayable<string, mixed>|array $data | ||
* @param array $mergeData | ||
* @return View | ||
*/ | ||
public function make($view, $data = [], $mergeData = []) | ||
{ | ||
$expectation = $this->getExpectation(FactoryMakeExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->view, $view, $message); | ||
Assert::assertEquals($expectation->data, $data, $message); | ||
Assert::assertEquals($expectation->mergeData, $mergeData, $message); | ||
|
||
return $expectation->return; | ||
} | ||
|
||
/** | ||
* Add a piece of shared data to the environment. | ||
* | ||
* @param array|string $key | ||
* @param mixed $value | ||
* @return mixed | ||
*/ | ||
public function share($key, $value = null) | ||
{ | ||
$expectation = $this->getExpectation(FactoryShareExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->key, $key, $message); | ||
Assert::assertEquals($expectation->value, $value, $message); | ||
|
||
return $expectation->return; | ||
} | ||
|
||
/** | ||
* Register a view composer event. | ||
* | ||
* @param array|string $views | ||
* @param Closure|string $callback | ||
* @return array | ||
*/ | ||
public function composer($views, $callback) | ||
{ | ||
$expectation = $this->getExpectation(FactoryComposerExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->views, $views, $message); | ||
Assert::assertEquals($expectation->callback, $callback, $message); | ||
|
||
return $expectation->return; | ||
} | ||
|
||
/** | ||
* Register a view creator event. | ||
* | ||
* @param array|string $views | ||
* @param Closure|string $callback | ||
* @return array | ||
*/ | ||
public function creator($views, $callback) | ||
{ | ||
$expectation = $this->getExpectation(FactoryCreatorExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->views, $views, $message); | ||
Assert::assertEquals($expectation->callback, $callback, $message); | ||
|
||
return $expectation->return; | ||
} | ||
|
||
/** | ||
* Add a new namespace to the loader. | ||
* | ||
* @param string $namespace | ||
* @param string|array $hints | ||
* @return $this | ||
*/ | ||
public function addNamespace($namespace, $hints) | ||
{ | ||
$expectation = $this->getExpectation(FactoryAddNamespaceExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->namespace, $namespace, $message); | ||
Assert::assertEquals($expectation->hints, $hints, $message); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Replace the namespace hints for the given namespace. | ||
* | ||
* @param string $namespace | ||
* @param string|array $hints | ||
* @return $this | ||
*/ | ||
public function replaceNamespace($namespace, $hints) | ||
{ | ||
$expectation = $this->getExpectation(FactoryReplaceNamespaceExpectation::class); | ||
$message = $this->getDebugMessage(); | ||
|
||
Assert::assertEquals($expectation->namespace, $namespace, $message); | ||
Assert::assertEquals($expectation->hints, $hints, $message); | ||
|
||
return $this; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Testing/Laravel/Contracts/View/FactoryComposerExpectation.php
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryComposerExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $return, | ||
public readonly mixed $views, | ||
public readonly mixed $callback, | ||
) { | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Testing/Laravel/Contracts/View/FactoryCreatorExpectation.php
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryCreatorExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $return, | ||
public readonly mixed $views, | ||
public readonly mixed $callback, | ||
) { | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Testing/Laravel/Contracts/View/FactoryExistsExpectation.php
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 LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryExistsExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $return, | ||
public readonly mixed $view, | ||
) { | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Testing/Laravel/Contracts/View/FactoryFileExpectation.php
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryFileExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $return, | ||
public readonly mixed $path, | ||
public readonly mixed $data = [], | ||
public readonly mixed $mergeData = [], | ||
) { | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Testing/Laravel/Contracts/View/FactoryMakeExpectation.php
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryMakeExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $return, | ||
public readonly mixed $view, | ||
public readonly mixed $data = [], | ||
public readonly mixed $mergeData = [], | ||
) { | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Testing/Laravel/Contracts/View/FactoryReplaceNamespaceExpectation.php
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 LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryReplaceNamespaceExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $namespace, | ||
public readonly mixed $hints, | ||
) { | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Testing/Laravel/Contracts/View/FactoryShareExpectation.php
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Laravel\Contracts\View; | ||
|
||
final class FactoryShareExpectation | ||
{ | ||
public function __construct( | ||
public readonly mixed $return, | ||
public readonly mixed $key, | ||
public readonly mixed $value = null, | ||
) { | ||
} | ||
} |
Oops, something went wrong.