diff --git a/overrides/Runner/TestSuiteLoader.php b/overrides/Runner/TestSuiteLoader.php index 19b37a82..5e59ae21 100644 --- a/overrides/Runner/TestSuiteLoader.php +++ b/overrides/Runner/TestSuiteLoader.php @@ -43,7 +43,7 @@ use function array_values; use function basename; use function class_exists; use function get_declared_classes; -use Pest\IgnorableTestCase; +use Pest\TestCases\IgnorableTestCase; use Pest\TestSuite; use PHPUnit\Framework\TestCase; use ReflectionClass; diff --git a/src/Exceptions/ExpectationNotFound.php b/src/Exceptions/ExpectationNotFound.php new file mode 100644 index 00000000..af47c03f --- /dev/null +++ b/src/Exceptions/ExpectationNotFound.php @@ -0,0 +1,21 @@ + */ final class Expectation { - use Retrievable; - use Pipeable; use Extendable; + use Pipeable; + use Retrievable; /** * Creates a new expectation. @@ -114,9 +116,9 @@ final class Expectation /** * Creates an expectation on each item of the iterable "value". * - * @return Each + * @return EachExpectation */ - public function each(callable $callback = null): Each + public function each(callable $callback = null): EachExpectation { if (!is_iterable($this->value)) { throw new BadMethodCallException('Expectation value is not iterable.'); @@ -128,7 +130,7 @@ final class Expectation } } - return new Each($this); + return new EachExpectation($this); } /** @@ -278,6 +280,11 @@ final class Expectation return $this; } + /** + * Creates a new expectation closure from the given name. + * + * @throws ExpectationNotFound + */ private function getExpectationClosure(string $name): Closure { if (method_exists(Mixins\Expectation::class, $name)) { @@ -293,13 +300,13 @@ final class Expectation } } - throw PipeException::expectationNotFound($name); + throw ExpectationNotFound::fromName($name); } /** * Dynamically calls methods on the class without any arguments or creates a new higher order expectation. * - * @return Expectation|OppositeExpectation|Each|HigherOrderExpectation, TValue|null>|TValue + * @return Expectation|OppositeExpectation|EachExpectation|HigherOrderExpectation, TValue|null>|TValue */ public function __get(string $name) { diff --git a/src/Each.php b/src/Expectations/EachExpectation.php similarity index 88% rename from src/Each.php rename to src/Expectations/EachExpectation.php index 19105945..df0cb1d0 100644 --- a/src/Each.php +++ b/src/Expectations/EachExpectation.php @@ -2,7 +2,10 @@ declare(strict_types=1); -namespace Pest; +namespace Pest\Expectations; + +use function expect; +use Pest\Expectation; /** * @internal @@ -11,7 +14,7 @@ namespace Pest; * * @mixin Expectation */ -final class Each +final class EachExpectation { private bool $opposite = false; @@ -43,7 +46,7 @@ final class Each * * @return self */ - public function not(): Each + public function not(): EachExpectation { $this->opposite = true; @@ -57,7 +60,7 @@ final class Each * * @return self */ - public function __call(string $name, array $arguments): Each + public function __call(string $name, array $arguments): EachExpectation { foreach ($this->original->value as $item) { /* @phpstan-ignore-next-line */ @@ -74,7 +77,7 @@ final class Each * * @return self */ - public function __get(string $name): Each + public function __get(string $name): EachExpectation { /* @phpstan-ignore-next-line */ return $this->$name(); diff --git a/src/HigherOrderExpectation.php b/src/Expectations/HigherOrderExpectation.php similarity index 95% rename from src/HigherOrderExpectation.php rename to src/Expectations/HigherOrderExpectation.php index 6480f0d7..83c43643 100644 --- a/src/HigherOrderExpectation.php +++ b/src/Expectations/HigherOrderExpectation.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace Pest; +namespace Pest\Expectations; use Pest\Concerns\Retrievable; +use Pest\Expectation; /** * @internal @@ -19,9 +20,9 @@ final class HigherOrderExpectation use Retrievable; /** - * @var Expectation|Each + * @var Expectation|EachExpectation */ - private Expectation|Each $expectation; + private Expectation|EachExpectation $expectation; private bool $opposite = false; diff --git a/src/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php similarity index 98% rename from src/OppositeExpectation.php rename to src/Expectations/OppositeExpectation.php index e2062e75..1ae9ccbe 100644 --- a/src/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace Pest; +namespace Pest\Expectations; +use Pest\Expectation; use PHPUnit\Framework\ExpectationFailedException; use SebastianBergmann\Exporter\Exporter; diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index b214631b..56686443 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -150,7 +150,7 @@ final class TestCaseFactory eval(" namespace $namespace; - use Pest\Datasets as __PestDatasets; + use Pest\Repositories\DatasetsRepository as __PestDatasets; use Pest\TestSuite as __PestTestSuite; final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN { diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index 1aaa2dae..d895db73 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Pest\Factories; use Closure; -use Pest\Datasets; use Pest\Exceptions\ShouldNotHappen; use Pest\Factories\Concerns\HigherOrderable; +use Pest\Repositories\DatasetsRepository; use Pest\Support\Str; use Pest\TestSuite; use PHPUnit\Framework\Assert; @@ -154,7 +154,7 @@ final class TestCaseMethodFactory */ private function buildDatasetForEvaluation(string $methodName, string $dataProviderName): string { - Datasets::with($this->filename, $methodName, $this->datasets); + DatasetsRepository::with($this->filename, $methodName, $this->datasets); return <<argument('name'); - $relativePath = sprintf(testDirectory('Datasets/%s.php'), ucfirst($name)); + $relativePath = sprintf(testDirectory('DatasetsRepository/%s.php'), ucfirst($name)); /* @phpstan-ignore-next-line */ $target = base_path($relativePath); diff --git a/src/Plugin.php b/src/Plugin.php index 5f676be4..6e73d59c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -7,8 +7,7 @@ namespace Pest; final class Plugin { /** - * The lazy callables to be executed - * once the test suite boots. + * The lazy callables to be executed once the test suite boots. * * @var array * diff --git a/src/Datasets.php b/src/Repositories/DatasetsRepository.php similarity index 98% rename from src/Datasets.php rename to src/Repositories/DatasetsRepository.php index 248b1d38..d8a57bfa 100644 --- a/src/Datasets.php +++ b/src/Repositories/DatasetsRepository.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pest; +namespace Pest\Repositories; use Closure; use Pest\Exceptions\DatasetAlreadyExist; @@ -15,7 +15,7 @@ use Traversable; /** * @internal */ -final class Datasets +final class DatasetsRepository { /** * Holds the datasets. diff --git a/src/IgnorableTestCase.php b/src/TestCases/IgnorableTestCase.php similarity index 85% rename from src/IgnorableTestCase.php rename to src/TestCases/IgnorableTestCase.php index ba4a4bf1..a2e9f5e9 100644 --- a/src/IgnorableTestCase.php +++ b/src/TestCases/IgnorableTestCase.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pest; +namespace Pest\TestCases; use PHPUnit\Framework\TestCase; diff --git a/tests/Features/Datasets.php b/tests/Features/Datasets.php index c7e695e1..4b7f9dc3 100644 --- a/tests/Features/Datasets.php +++ b/tests/Features/Datasets.php @@ -1,9 +1,9 @@ foo = 'bar'; @@ -13,28 +13,28 @@ it('throws exception if dataset does not exist', function () { $this->expectException(DatasetDoesNotExist::class); $this->expectExceptionMessage("A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`."); - Datasets::resolve('foo', ['first']); + DatasetsRepository::resolve('foo', ['first']); }); it('throws exception if dataset already exist', function () { - Datasets::set('second', [[]]); + DatasetsRepository::set('second', [[]]); $this->expectException(DatasetAlreadyExist::class); $this->expectExceptionMessage('A dataset with the name `second` already exist.'); - Datasets::set('second', [[]]); + DatasetsRepository::set('second', [[]]); }); it('sets closures', function () { - Datasets::set('foo', function () { + DatasetsRepository::set('foo', function () { yield [1]; }); - expect(Datasets::resolve('foo', ['foo']))->toBe(['foo with (1)' => [1]]); + expect(DatasetsRepository::resolve('foo', ['foo']))->toBe(['foo with (1)' => [1]]); }); it('sets arrays', function () { - Datasets::set('bar', [[2]]); + DatasetsRepository::set('bar', [[2]]); - expect(Datasets::resolve('bar', ['bar']))->toBe(['bar with (2)' => [2]]); + expect(DatasetsRepository::resolve('bar', ['bar']))->toBe(['bar with (2)' => [2]]); }); it('gets bound to test case object', function () { diff --git a/tests/Features/Expect/pipes.php b/tests/Features/Expect/pipes.php index 5e311e07..e6808dbb 100644 --- a/tests/Features/Expect/pipes.php +++ b/tests/Features/Expect/pipes.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Pest\Exceptions\ExpectationNotFound; use function PHPUnit\Framework\assertEquals; use function PHPUnit\Framework\assertEqualsIgnoringCase; use function PHPUnit\Framework\assertInstanceOf; diff --git a/tests/Unit/Datasets.php b/tests/Unit/Datasets.php index 08f82352..a93ac62e 100644 --- a/tests/Unit/Datasets.php +++ b/tests/Unit/Datasets.php @@ -1,9 +1,9 @@ [1], 'two' => [[2]], @@ -15,7 +15,7 @@ it('show only the names of named datasets in their description', function () { }); it('show the actual dataset of non-named datasets in their description', function () { - $descriptions = array_keys(Datasets::resolve('test description', [ + $descriptions = array_keys(DatasetsRepository::resolve('test description', [ [ [1], [[2]], @@ -27,7 +27,7 @@ it('show the actual dataset of non-named datasets in their description', functio }); it('show only the names of multiple named datasets in their description', function () { - $descriptions = array_keys(Datasets::resolve('test description', [ + $descriptions = array_keys(DatasetsRepository::resolve('test description', [ [ 'one' => [1], 'two' => [[2]], @@ -45,7 +45,7 @@ it('show only the names of multiple named datasets in their description', functi }); it('show the actual dataset of multiple non-named datasets in their description', function () { - $descriptions = array_keys(Datasets::resolve('test description', [ + $descriptions = array_keys(DatasetsRepository::resolve('test description', [ [ [1], [[2]], @@ -63,7 +63,7 @@ it('show the actual dataset of multiple non-named datasets in their description' }); it('show the correct description for mixed named and not-named datasets', function () { - $descriptions = array_keys(Datasets::resolve('test description', [ + $descriptions = array_keys(DatasetsRepository::resolve('test description', [ [ 'one' => [1], [[2]],