diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06739d4..85ef7d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,13 +8,13 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['7.4'] - name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}' + php-version: ['7.4', '8.0'] + name: 'PHPUnit' steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl @@ -23,7 +23,7 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} @@ -39,13 +39,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.4'] - name: 'Psalm - PHP/${{ matrix.php-version }}' + php-version: ['7.4', '8.0'] + name: 'Psalm' steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl @@ -53,7 +53,7 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} @@ -61,4 +61,31 @@ jobs: - name: Install Dependencies run: composer install - name: Psalm - run: vendor/bin/psalm + run: vendor/bin/psalm --shepherd + cs: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['7.4'] + name: 'CS' + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-${{ matrix.php-version }}-composer- + - name: Install Dependencies + run: composer install --no-progress + - name: CS + run: vendor/bin/php-cs-fixer fix --diff --dry-run --diff-format udiff diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..1431d66 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,6 @@ + - - - - - ./tests - - - - - - . - - ./tests - ./vendor - - - + + + + . + + + ./tests + ./vendor + + + + + ./tests + + diff --git a/psalm.xml b/psalm.xml index 408036f..3240886 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ - - - - diff --git a/src/Expression/Level1.php b/src/Expression/Level1.php index 61b4974..ca483b5 100644 --- a/src/Expression/Level1.php +++ b/src/Expression/Level1.php @@ -27,9 +27,6 @@ public function __construct(Name $name) $this->encode = new UrlEncode; } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{[a-zA-Z0-9_]+\}$~')) { @@ -39,9 +36,6 @@ public static function of(Str $string): Expression return new self(new Name($string->trim('{}')->toString())); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { diff --git a/src/Expression/Level2/Fragment.php b/src/Expression/Level2/Fragment.php index 7af8230..61f6b28 100644 --- a/src/Expression/Level2/Fragment.php +++ b/src/Expression/Level2/Fragment.php @@ -28,9 +28,6 @@ public function __construct(Name $name) $this->encode = UrlEncode::allowReservedCharacters(); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{#[a-zA-Z0-9_]+\}$~')) { @@ -40,9 +37,6 @@ public static function of(Str $string): Expression return new self(new Name($string->trim('{#}')->toString())); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { diff --git a/src/Expression/Level2/Reserved.php b/src/Expression/Level2/Reserved.php index 226a5ea..63e1a0a 100644 --- a/src/Expression/Level2/Reserved.php +++ b/src/Expression/Level2/Reserved.php @@ -28,9 +28,6 @@ public function __construct(Name $name) $this->encode = UrlEncode::allowReservedCharacters(); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\+[a-zA-Z0-9_]+\}$~')) { @@ -40,9 +37,6 @@ public static function of(Str $string): Expression return new self(new Name($string->trim('{+}')->toString())); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { diff --git a/src/Expression/Level3.php b/src/Expression/Level3.php index 1725231..d370778 100644 --- a/src/Expression/Level3.php +++ b/src/Expression/Level3.php @@ -37,9 +37,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -58,9 +55,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( @@ -73,6 +67,7 @@ public function expand(Map $variables): string public function regex(): string { + /** @psalm-suppress InvalidArgument */ return $this->regex ?? $this->regex = join( ',', $this->names->mapTo( diff --git a/src/Expression/Level3/Fragment.php b/src/Expression/Level3/Fragment.php index 1e678b2..bb52f24 100644 --- a/src/Expression/Level3/Fragment.php +++ b/src/Expression/Level3/Fragment.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{#[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level3/Label.php b/src/Expression/Level3/Label.php index c9fa0eb..73d89a6 100644 --- a/src/Expression/Level3/Label.php +++ b/src/Expression/Level3/Label.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\.[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level3/NamedValues.php b/src/Expression/Level3/NamedValues.php index cb95f0f..530bd37 100644 --- a/src/Expression/Level3/NamedValues.php +++ b/src/Expression/Level3/NamedValues.php @@ -41,9 +41,6 @@ public function __construct(string $lead, string $separator, Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { throw new \LogicException('should not be used directly'); @@ -57,9 +54,6 @@ public static function keyOnlyWhenEmpty(string $lead, string $separator, Name .. return $self; } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { /** @var Sequence */ diff --git a/src/Expression/Level3/Parameters.php b/src/Expression/Level3/Parameters.php index 40baf30..247915d 100644 --- a/src/Expression/Level3/Parameters.php +++ b/src/Expression/Level3/Parameters.php @@ -24,9 +24,6 @@ public function __construct(Name ...$names) $this->expression = NamedValues::keyOnlyWhenEmpty(';', ';', ...$names); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{;[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -45,9 +42,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level3/Path.php b/src/Expression/Level3/Path.php index 34a1a41..0e97a90 100644 --- a/src/Expression/Level3/Path.php +++ b/src/Expression/Level3/Path.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{/[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return join( diff --git a/src/Expression/Level3/Query.php b/src/Expression/Level3/Query.php index e45d4ac..a442c23 100644 --- a/src/Expression/Level3/Query.php +++ b/src/Expression/Level3/Query.php @@ -24,9 +24,6 @@ public function __construct(Name ...$names) $this->expression = new NamedValues('?', '&', ...$names); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\?[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -45,9 +42,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level3/QueryContinuation.php b/src/Expression/Level3/QueryContinuation.php index 0b7bb89..fdb5ee6 100644 --- a/src/Expression/Level3/QueryContinuation.php +++ b/src/Expression/Level3/QueryContinuation.php @@ -24,9 +24,6 @@ public function __construct(Name ...$names) $this->expression = new NamedValues('&', '&', ...$names); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\&[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -45,9 +42,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level3/Reserved.php b/src/Expression/Level3/Reserved.php index b697818..3412069 100644 --- a/src/Expression/Level3/Reserved.php +++ b/src/Expression/Level3/Reserved.php @@ -39,9 +39,6 @@ public function __construct(Name ...$names) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if (!$string->matches('~^\{\+[a-zA-Z0-9_]+(,[a-zA-Z0-9_]+)+\}$~')) { @@ -60,9 +57,6 @@ public static function of(Str $string): Expression return new self(...unwrap($names)); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level4.php b/src/Expression/Level4.php index 33399b8..4a511f1 100644 --- a/src/Expression/Level4.php +++ b/src/Expression/Level4.php @@ -37,9 +37,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{[a-zA-Z0-9_]+\}$~')) { @@ -116,7 +113,7 @@ public function withSeparator(string $separator): self */ public function withExpression(string $expression): self { - if (!is_a($expression, Expression::class, true)) { + if (!\is_a($expression, Expression::class, true)) { throw new DomainException($expression); } @@ -126,9 +123,6 @@ public function withExpression(string $expression): self return $self; } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { if (!$variables->contains($this->name->toString())) { @@ -217,6 +211,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { @@ -229,8 +224,9 @@ static function(Sequence $values, $variableToExpand): Sequence { return ($values)($variableToExpand); }, ); + $expanded = $flattenedVariables - ->map(function(string $variableToExpand) use ($variables): string { + ->map(function($variableToExpand) use ($variables): string { // here we use the level1 expression to transform the variable to // be expanded to its string representation return $this->expression->expand( diff --git a/src/Expression/Level4/Composite.php b/src/Expression/Level4/Composite.php index 3357a68..9e7a277 100644 --- a/src/Expression/Level4/Composite.php +++ b/src/Expression/Level4/Composite.php @@ -73,9 +73,6 @@ static function(Expression $level4, Str $expression): Expression { ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { $expanded = $this->expressions->mapTo( diff --git a/src/Expression/Level4/Fragment.php b/src/Expression/Level4/Fragment.php index 12f9dc3..42fa2a9 100644 --- a/src/Expression/Level4/Fragment.php +++ b/src/Expression/Level4/Fragment.php @@ -29,9 +29,6 @@ public function __construct(Name $name) ->withExpression(Level2\Reserved::class); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{#[a-zA-Z0-9_]+\}$~')) { @@ -93,9 +90,6 @@ public function regex(): string return $this->expression->regex(); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level4/Label.php b/src/Expression/Level4/Label.php index 7fbca13..84721c9 100644 --- a/src/Expression/Level4/Label.php +++ b/src/Expression/Level4/Label.php @@ -26,9 +26,6 @@ public function __construct(Name $name) $this->expression = (new Level4($name))->withLead('.'); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\.[a-zA-Z0-9_]+\}$~')) { @@ -83,9 +80,6 @@ public function add(Str $pattern): Composite ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level4/Parameters.php b/src/Expression/Level4/Parameters.php index 2fe71a4..45cab79 100644 --- a/src/Expression/Level4/Parameters.php +++ b/src/Expression/Level4/Parameters.php @@ -38,9 +38,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{;[a-zA-Z0-9_]+\}$~')) { @@ -181,6 +178,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { diff --git a/src/Expression/Level4/Path.php b/src/Expression/Level4/Path.php index 6b2f106..eb40380 100644 --- a/src/Expression/Level4/Path.php +++ b/src/Expression/Level4/Path.php @@ -26,9 +26,6 @@ public function __construct(Name $name) $this->expression = (new Level4($name))->withLead('/'); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{/[a-zA-Z0-9_]+\}$~')) { @@ -83,9 +80,6 @@ public function add(Str $pattern): Composite ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Expression/Level4/Query.php b/src/Expression/Level4/Query.php index 66242c1..dfd61cd 100644 --- a/src/Expression/Level4/Query.php +++ b/src/Expression/Level4/Query.php @@ -38,9 +38,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\?[a-zA-Z0-9_]+\}$~')) { @@ -142,7 +139,7 @@ public function regex(): string $regex = $this->expression->regex(); } - return $this->regex = sprintf( + return $this->regex = \sprintf( '\?%s=%s', $this->name->toString(), $regex, @@ -181,6 +178,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { diff --git a/src/Expression/Level4/QueryContinuation.php b/src/Expression/Level4/QueryContinuation.php index 216023d..a2b05bb 100644 --- a/src/Expression/Level4/QueryContinuation.php +++ b/src/Expression/Level4/QueryContinuation.php @@ -38,9 +38,6 @@ public function __construct(Name $name) $this->expression = new Level1($name); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\&[a-zA-Z0-9_]+\}$~')) { @@ -181,6 +178,7 @@ private function expandList(Map $variables, ...$variablesToExpand): string return $this->explodeList($variables, $variablesToExpand); } + /** @var Sequence */ $flattenedVariables = Sequence::of('scalar|array', ...$variablesToExpand)->reduce( Sequence::of('scalar'), static function(Sequence $values, $variableToExpand): Sequence { diff --git a/src/Expression/Level4/Reserved.php b/src/Expression/Level4/Reserved.php index 1db65bf..b74d033 100644 --- a/src/Expression/Level4/Reserved.php +++ b/src/Expression/Level4/Reserved.php @@ -35,9 +35,6 @@ public function __construct(Name $name) ); } - /** - * {@inheritdoc} - */ public static function of(Str $string): Expression { if ($string->matches('~^\{\+[a-zA-Z0-9_]+\}$~')) { @@ -96,9 +93,6 @@ public function add(Str $pattern): Composite ); } - /** - * {@inheritdoc} - */ public function expand(Map $variables): string { return $this->expression->expand($variables); diff --git a/src/Template.php b/src/Template.php index 3168c9f..7e41fd0 100644 --- a/src/Template.php +++ b/src/Template.php @@ -50,7 +50,7 @@ public function expand(Map $variables): Url $url = $this->expressions->reduce( $this->template, - function(Str $template, Expression $expression) use ($variables): Str { + static function(Str $template, Expression $expression) use ($variables): Str { return $template->replace( $expression->toString(), $expression->expand($variables), @@ -106,6 +106,9 @@ public function toString(): string /** * Recursively find the expressions as Str::capture doesnt capture all of * them at the same time + * @param Sequence $expressions + * + * @return Sequence */ private function extractExpressions( Sequence $expressions, @@ -133,7 +136,10 @@ private function regex(): string ->reduce( $this->template->replace('~', '\~'), static function(Str $template, Expression $expression) use (&$i): Str { - /** @psalm-suppress MixedOperand */ + /** + * @psalm-suppress MixedOperand + * @psalm-suppress MixedAssignment + */ ++$i; return $template->replace( @@ -146,7 +152,10 @@ static function(Str $template, Expression $expression) use (&$i): Str { $template = $this->expressions->reduce( $template, static function(Str $template, Expression $expression) use (&$j): Str { - /** @psalm-suppress MixedOperand */ + /** + * @psalm-suppress MixedOperand + * @psalm-suppress MixedAssignment + */ ++$j; return $template->replace( diff --git a/src/UrlEncode.php b/src/UrlEncode.php index 91d4ab3..b75df39 100644 --- a/src/UrlEncode.php +++ b/src/UrlEncode.php @@ -15,14 +15,6 @@ public function __construct() $this->safeCharacters = Str::of(''); } - public static function allowReservedCharacters(): self - { - $self = new self; - $self->safeCharacters = Str::of(':/?#[]@!$&\'()*+,;='); - - return $self; - } - public function __invoke(string $string): string { if ($this->safeCharacters->empty()) { @@ -55,4 +47,12 @@ public function __invoke(string $string): string return \rawurlencode($string->toString()); } + + public static function allowReservedCharacters(): self + { + $self = new self; + $self->safeCharacters = Str::of(':/?#[]@!$&\'()*+,;='); + + return $self; + } } diff --git a/tests/Expression/Level4/FragmentTest.php b/tests/Expression/Level4/FragmentTest.php index 65fdf72..a475f52 100644 --- a/tests/Expression/Level4/FragmentTest.php +++ b/tests/Expression/Level4/FragmentTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class FragmentTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/LabelTest.php b/tests/Expression/Level4/LabelTest.php index 444de53..2775ecb 100644 --- a/tests/Expression/Level4/LabelTest.php +++ b/tests/Expression/Level4/LabelTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class LabelTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/ParametersTest.php b/tests/Expression/Level4/ParametersTest.php index 27e7ad4..ae6d2a4 100644 --- a/tests/Expression/Level4/ParametersTest.php +++ b/tests/Expression/Level4/ParametersTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class ParametersTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/PathTest.php b/tests/Expression/Level4/PathTest.php index 3b942fe..b0e7bf3 100644 --- a/tests/Expression/Level4/PathTest.php +++ b/tests/Expression/Level4/PathTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class PathTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/QueryContinuationTest.php b/tests/Expression/Level4/QueryContinuationTest.php index 7aac88a..4755e51 100644 --- a/tests/Expression/Level4/QueryContinuationTest.php +++ b/tests/Expression/Level4/QueryContinuationTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class QueryContinuationTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/QueryTest.php b/tests/Expression/Level4/QueryTest.php index 246d59c..b7471e2 100644 --- a/tests/Expression/Level4/QueryTest.php +++ b/tests/Expression/Level4/QueryTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class QueryTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4/ReservedTest.php b/tests/Expression/Level4/ReservedTest.php index a0c9d5f..57f8dee 100644 --- a/tests/Expression/Level4/ReservedTest.php +++ b/tests/Expression/Level4/ReservedTest.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class ReservedTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/Level4Test.php b/tests/Expression/Level4Test.php index 0a8799c..19f4e61 100644 --- a/tests/Expression/Level4Test.php +++ b/tests/Expression/Level4Test.php @@ -15,14 +15,14 @@ Str, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class Level4Test extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { @@ -50,7 +50,7 @@ public function testStringCast() public function testThrowWhenNegativeLimit() { $this - ->forAll(Generator\neg()) + ->forAll(Set\Integers::below(1)) ->then(function(int $int): void { $this->expectException(DomainException::class); diff --git a/tests/Expression/NameTest.php b/tests/Expression/NameTest.php index 6fcbeea..5e6c3c2 100644 --- a/tests/Expression/NameTest.php +++ b/tests/Expression/NameTest.php @@ -8,22 +8,23 @@ Exception\DomainException, }; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class NameTest extends TestCase { - use TestTrait; + use BlackBox; public function testInterface() { $this - ->forAll(Generator\string()) - ->when(static function(string $string): bool { - return (bool) preg_match('~[a-zA-Z0-9_]+~', $string); - }) + ->forAll( + Set\Strings::atLeast(1)->filter(static function(string $string): bool { + return (bool) \preg_match('~[a-zA-Z0-9_]+~', $string); + }), + ) ->then(function(string $string): void { $this->assertSame($string, (new Name($string))->toString()); }); @@ -32,10 +33,11 @@ public function testInterface() public function testThrowWhenInvalidName() { $this - ->forAll(Generator\string()) - ->when(static function(string $string): bool { - return !preg_match('~[a-zA-Z0-9_]+~', $string); - }) + ->forAll( + Set\Strings::any()->filter(static function(string $string): bool { + return (bool) !\preg_match('~[a-zA-Z0-9_]+~', $string); + }), + ) ->then(function(string $string): void { $this->expectException(DomainException::class); $this->expectExceptionMessage($string); diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index 75d1824..0927047 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -13,7 +13,6 @@ Map, Sequence, }; -use function Innmind\Immutable\first; use PHPUnit\Framework\TestCase; class TemplateTest extends TestCase diff --git a/tests/UrlEncodeTest.php b/tests/UrlEncodeTest.php index bc29c86..975dd73 100644 --- a/tests/UrlEncodeTest.php +++ b/tests/UrlEncodeTest.php @@ -5,30 +5,30 @@ use Innmind\UrlTemplate\UrlEncode; use PHPUnit\Framework\TestCase; -use Eris\{ - Generator, - TestTrait, +use Innmind\BlackBox\{ + PHPUnit\BlackBox, + Set, }; class UrlEncodeTest extends TestCase { - use TestTrait; + use BlackBox; public function testStandardEncode() { $this - ->forAll(Generator\string()) + ->forAll(Set\Strings::any()) ->then(function(string $string): void { $encode = new UrlEncode; - $this->assertSame(rawurlencode($string), $encode($string)); + $this->assertSame(\rawurlencode($string), $encode($string)); }); } public function testSafeCharactersAreNotEncoded() { $this - ->forAll(Generator\elements( + ->forAll(Set\Elements::of( ':', '/', '?',