diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 294b48c..88b99a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,34 +3,12 @@ name: CI on: [push] jobs: - phpunit: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macOS-latest] - php-version: ['8.2'] - name: 'PHPUnit' - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: none - - name: Composer - uses: "ramsey/composer-install@v2" - - name: PHPUnit - run: vendor/bin/phpunit - env: - BLACKBOX_SET_SIZE: 20 blackbox: runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['8.2'] + php-version: ['8.2', '8.3'] dependency-versions: ['lowest', 'highest'] name: 'BlackBox' steps: @@ -48,14 +26,16 @@ jobs: dependency-versions: ${{ matrix.dependencies }} - name: BlackBox run: php blackbox.php - blackbox_coverage: + env: + BLACKBOX_SET_SIZE: 20 + coverage: runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['8.2'] + php-version: ['8.2', '8.3'] dependency-versions: ['lowest', 'highest'] - name: 'BlackBox Coverage' + name: 'Coverage' steps: - name: Checkout uses: actions/checkout@v2 @@ -73,30 +53,6 @@ jobs: run: php blackbox.php env: ENABLE_COVERAGE: 'true' - - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - coverage: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macOS-latest] - php-version: ['8.2'] - name: 'Coverage' - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: xdebug - - name: Composer - uses: "ramsey/composer-install@v2" - - name: PHPUnit - run: vendor/bin/phpunit --coverage-clover=coverage.clover - env: BLACKBOX_SET_SIZE: 1 - uses: codecov/codecov-action@v1 with: @@ -105,7 +61,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.2'] + php-version: ['8.2', '8.3'] name: 'Psalm' steps: - name: Checkout diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml deleted file mode 100644 index 9f64211..0000000 --- a/.github/workflows/documentation.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Documentation - -on: - push: - branches: [master] - -jobs: - publish: - runs-on: ubuntu-latest - name: 'Publish documentation' - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - - name: Install halsey/journal - run: composer global require halsey/journal - - name: Generate - run: composer global exec 'journal generate' - - name: Push - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./.tmp_journal/ diff --git a/.gitignore b/.gitignore index 3ccfb21..987e2a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ composer.lock vendor -.phpunit.result.cache -.couscous -.php-cs-fixer.cache diff --git a/.journal b/.journal deleted file mode 100644 index 5167faf..0000000 --- a/.journal +++ /dev/null @@ -1,83 +0,0 @@ -package('innmind', 'immutable', null, 'Immutable') - ->locatedAt(Path::of('docs/')) - ->menu( - Entry::markdown( - 'Getting started', - Path::of('README.md'), - ), - Entry::section( - 'Structures', - Entry::markdown( - 'Sequence', - Path::of('SEQUENCE.md'), - ), - Entry::markdown( - 'Set', - Path::of('SET.md'), - ), - Entry::markdown( - 'Map', - Path::of('MAP.md'), - ), - Entry::markdown( - 'Str', - Path::of('STR.md'), - ), - Entry::markdown( - 'RegExp', - Path::of('REGEXP.md'), - ), - Entry::markdown( - 'Maybe', - Path::of('MAYBE.md'), - ), - Entry::markdown( - 'Either', - Path::of('EITHER.md'), - ), - Entry::markdown( - 'State', - Path::of('STATE.md'), - ), - Entry::markdown( - 'Fold', - Path::of('FOLD.md'), - ), - Entry::markdown( - 'Monoids', - Path::of('MONOIDS.md'), - ), - )->alwaysOpen(), - Entry::section( - 'Use cases', - Entry::markdown( - 'How to read a file', - Path::of('LAZY_FILE.md'), - ), - Entry::markdown( - 'Parsing strings', - Path::of('PARSING.md'), - ), - )->alwaysOpen(), - Entry::markdown( - 'Blackbox', - Path::of('BLACKBOX.md'), - ), - Entry::markdown( - 'Philosophy', - Path::of('PHILOSOPHY.md'), - ), - ); -}; diff --git a/CHANGELOG.md b/CHANGELOG.md index b041e44..357110d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 5.0.0 - 2023-09-16 + +### Changed + +- `Innmind\Immutable\Str` only use `Innmind\Immutable\Str\Encoding` to represent the encoding to work with + +### Removed + +- `Fixtures\Innmind\Immutable\Map` + ## 4.15.0 - 2023-07-08 ### Added diff --git a/README.md b/README.md index f3ac552..a18c096 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,19 @@ A set of classes to wrap PHP primitives to build immutable data. +[Documentation](docs/) + +## Installation + +```sh +composer require innmind/immutable +``` + +## Usage + Here are some examples of what you can do: -## Sequence +### Sequence To be used to wrap an ordered list of elements (elements can be of mixed types). @@ -38,7 +48,7 @@ $lines->foreach(fn($line) => echo($line)); For a complete list of methods check [`Sequence`](src/Sequence.php). -## Set +### Set To be used as a collection of unordered elements (elements must be of the same type). @@ -52,7 +62,7 @@ $set->add(42.0); // psalm will raise an error For a complete list of methods check [`Set`](src/Set.php). -## Map +### Map To be used as a collection of key/value pairs (both keys and values must be of the same type). @@ -72,7 +82,7 @@ $map->values()->toList(); // [42, 66] For a complete list of methods check [`Map`](src/Map.php). -## Strings +### Strings ```php use Innmind\Immutable\Str; @@ -100,9 +110,9 @@ $regexp->matches(Str::of('foobar')); // false $regexp->capture(Str::of('foo123bar')); // Map with index `i` set to Str::of('123') ``` -## [BlackBox](https://github.com/innmind/blackbox/) +### [BlackBox](https://github.com/innmind/blackbox/) -This library provides 3 `Set`s that can be used with [`innmind/black-box`](https://packagist.org/packages/innmind/black-box). +This library provides 2 `Set`s that can be used with [`innmind/black-box`](https://packagist.org/packages/innmind/black-box). You can use them as follow: @@ -121,10 +131,6 @@ class SomeTest extends \PHPUnit\Framework\TestCase { $this ->forAll( - Immutable\Map::of( - Set\Integers::any(), - Set\Strings::any(), - ), Immutable\Set::of( Set\RealNumbers::any(), ), @@ -132,8 +138,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase Set\Uuid::any(), ), ) - ->then(function($map, $set, $sequence) { - // $map is an instance of \Innmind\Immutable\Map + ->then(function($set, $sequence) { // $set is an instance of \Innmind\Immutable\Set // $sequence is an instance of \Innmind\Immutable\Sequence diff --git a/blackbox.php b/blackbox.php index a8cd695..bf1804d 100644 --- a/blackbox.php +++ b/blackbox.php @@ -10,18 +10,19 @@ }; Application::new($argv) - ->codeCoverage( - CodeCoverage::of( - __DIR__.'/src/', - __DIR__.'/proofs/', - __DIR__.'/fixtures/', - ) - ->dumpTo('coverage.clover') - ->enableWhen(\getenv('ENABLE_COVERAGE') !== false), + ->when( + \getenv('ENABLE_COVERAGE') !== false, + static fn(Application $app) => $app + ->codeCoverage( + CodeCoverage::of( + __DIR__.'/src/', + __DIR__.'/proofs/', + __DIR__.'/fixtures/', + ) + ->dumpTo('coverage.clover') + ->enableWhen(true), + ) + ->scenariiPerProof(1), ) - ->scenariiPerProof(match (\getenv('ENABLE_COVERAGE')) { - false => 100, - default => 1, - }) ->tryToProve(Load::everythingIn(__DIR__.'/proofs/')) ->exit(); diff --git a/composer.json b/composer.json index fd11042..90bc86c 100644 --- a/composer.json +++ b/composer.json @@ -30,9 +30,8 @@ } }, "require-dev": { - "phpunit/phpunit": "~10.0", "vimeo/psalm": "~5.6", - "innmind/black-box": "~5.0", + "innmind/black-box": "^5.5.1", "innmind/coding-standard": "~2.0" }, "conflict": { diff --git a/docs/EITHER.md b/docs/EITHER.md index bd9a13c..92453df 100644 --- a/docs/EITHER.md +++ b/docs/EITHER.md @@ -32,7 +32,8 @@ function accessResource(User $user): Either { } ``` -> **Note** `ServerRequest`, `User`, `Resource` and `Error` are imaginary classes. +> **Note** +> `ServerRequest`, `User`, `Resource` and `Error` are imaginary classes. ## `::left()` @@ -42,7 +43,8 @@ This builds an `Either` instance with the given value in the left hand side. $either = Either::left($anyValue); ``` -> **Note** usually this side is used for errors. +> **Note** +> usually this side is used for errors. ## `::right()` @@ -52,7 +54,8 @@ This builds an `Either` instance with the given value in the right hand side. $either = Either::right($anyValue); ``` -> **Note** usually this side is used for valid values. +> **Note** +> usually this side is used for valid values. ## `::defer()` @@ -110,7 +113,8 @@ $response = identify($serverRequest) ); ``` -> **Note** `Response` is an imaginary class. +> **Note** +> `Response` is an imaginary class. ## `->otherwise()` diff --git a/docs/MAP.md b/docs/MAP.md index 1f9fcef..86c2dc7 100644 --- a/docs/MAP.md +++ b/docs/MAP.md @@ -177,7 +177,8 @@ $values = Map::of([24, 1], [42, 2])->values(); $values->equals(Sequence::of(1, 2)); // true ``` -> **Note** it returns a `Sequence` because it can contain duplicates, the order is not guaranteed as a map is not ordered. +> **Note** +> it returns a `Sequence` because it can contain duplicates, the order is not guaranteed as a map is not ordered. ## `->map()` diff --git a/docs/MAYBE.md b/docs/MAYBE.md index a724dea..f96bcd5 100644 --- a/docs/MAYBE.md +++ b/docs/MAYBE.md @@ -190,7 +190,8 @@ $vars = Sequence::of('DB_URL', 'MAILER_URL', /* and so on */) ->flatMap(static fn($var) => env($var)->toSequence()); ``` -> **Note** this example uses the `env` function defined at the start of this documentation. +> **Note** +> this example uses the `env` function defined at the start of this documentation. This is equivalent to: diff --git a/docs/README.md b/docs/README.md index 9107033..2c72926 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,13 +2,15 @@ This project brings a set of immutable data structure to bring a uniformity on how to handle data. +Before diving in the documentation you may want to read about the [philosophy](PHILOSOPHY.md) behind the structures design. + ## Installation ```sh composer require innmind/immutable ``` -## Usage +## Structures This library provides the 7 following structures: @@ -25,3 +27,12 @@ This library provides the 7 following structures: See the documentation for each structure to understand how to use them. All structures are typed with [`vimeo/psalm`](https://psalm.dev), you must use it in order to verify that you use this library correctly. + +## Use cases + +- [How to read a file](LAZY_FILE.md) +- [Parsing strings](PARSING.md) + +## Testing + +This package provides sets that can be used with [BlackBox](BLACKBOX.md). diff --git a/docs/SEQUENCE.md b/docs/SEQUENCE.md index 6e9b657..07863e8 100644 --- a/docs/SEQUENCE.md +++ b/docs/SEQUENCE.md @@ -49,7 +49,8 @@ Same as `::lazy()` except you don't need to manually build the generator. $sequence = Sequence::lazyStartingWith(1, 2, 3); ``` -> **Note** this is useful when you know the first items of the sequence and you'll `append` another lazy sequence at the end. +> **Note** +> this is useful when you know the first items of the sequence and you'll `append` another lazy sequence at the end. ## `::mixed()` @@ -551,7 +552,8 @@ $lines = Sequence::of(...$chunks) $lines; // ['foo', 'bar', 'baz', ''] ``` -> **Note** The `flatMap` is here in case there is only one chunk in the sequence, in which case the `aggregate` is not called +> **Note** +> The `flatMap` is here in case there is only one chunk in the sequence, in which case the `aggregate` is not called ## `->memoize()` diff --git a/docs/STR.md b/docs/STR.md index 9315c00..079ef77 100644 --- a/docs/STR.md +++ b/docs/STR.md @@ -16,11 +16,14 @@ $str instanceof Str; // true You can also specify the encoding to use for manupilating the string. ```php -$str = Str::of('πŸ‘‹', 'UTF-8'); +$str = Str::of('πŸ‘‹', Str\Encoding::utf8); $str->length(); // 1 Str::of('πŸ‘‹')->length(); // 4 ``` +> **Note** +> `Str\Encoding::utf8` is the default value when not specified + ## `->toString()` This will return the encapsulated string. @@ -34,7 +37,7 @@ Str::of('whataver')->toString(); // 'whatever' This will return the encoding used to manipulate the string. ```php -Str::of('', 'UTF-8')->encoding()->equals(Str::of('UTF-8')); // true +Str::of('', 'UTF-8')->encoding() === Str\Encoding::utf8; // true ``` ## `->toEncoding()` @@ -42,7 +45,7 @@ Str::of('', 'UTF-8')->encoding()->equals(Str::of('UTF-8')); // true Use this method to change the encoding used to manipulate the string. ```php -Str::of('πŸ‘‹')->toEncoding('UTF-8'); +Str::of('πŸ‘‹')->toEncoding(Str\Encoding::utf8); ``` ## `->split()` @@ -112,7 +115,7 @@ Str::of('FOOBAR')->toUpper()->equals(Str::of('foobar')); Returns the length of the string depending on the used encoding. ```php -Str::of('πŸ‘‹', 'UTF-8')->length(); // 1 +Str::of('πŸ‘‹', Str\Encoding::utf8)->length(); // 1 Str::of('πŸ‘‹')->length(); // 4 ``` @@ -122,7 +125,7 @@ Check if the string is an empty string. ```php Str::of('')->empty(); // true -Str::of('', 'UTF-8')->empty(); // true +Str::of('', Str\Encoding::utf8)->empty(); // true Str::of('null')->empty(); // false Str::of('0')->empty(); // false Str::of('false')->empty(); // false @@ -336,7 +339,7 @@ Check if the 2 strings are equal. ```php Str::of('foo')->equals(Str::of('foo')); // true -Str::of('foo')->equals(Str::of('foo', 'UTF-8')); // true +Str::of('foo')->equals(Str::of('foo', Str\Encoding::utf8)); // true Str::of('foo')->equals(Str::of('bar')); // false ``` diff --git a/fixtures/Map.php b/fixtures/Map.php deleted file mode 100644 index aa47176..0000000 --- a/fixtures/Map.php +++ /dev/null @@ -1,67 +0,0 @@ - $keys - * @param Set $values - * - * @return Set> - */ - public static function of( - Set $keys, - Set $values, - Set\Integers $sizes = null, - ): Set { - // this is not optimal but it allows to avoid a BC break - $sizes ??= Set\Integers::between(0, 100); - $range = [ - $sizes->values(Random::default)->current()->unwrap(), - $sizes->values(Random::default)->current()->unwrap(), - ]; - $min = \min($range); - $max = \max($range); - - return Set\Decorate::immutable( - static fn(array $pairs): Structure => \array_reduce( - $pairs, - static fn(Structure $map, array $pair): Structure => ($map)($pair[0], $pair[1]), - Structure::of(), - ), - Set\Sequence::of( - Set\Randomize::of( // forced to randomize as the composite will try to reuse the same key - Set\Composite::immutable( - static fn($key, $value): array => [$key, $value], - $keys, - $values, - ), - ), - ) - ->between($min, $max) - ->filter(static function(array $pairs): bool { - $keys = \array_column($pairs, 0); - - // checks unicity of values - return ISequence::mixed(...$keys)->size() === ISet::mixed(...$keys)->size(); - }), - ); - } -} diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 2c4d515..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - ./tests - - - - - . - - - ./tests - ./vendor - ./benchmarks - - - diff --git a/proofs/monoid/mergeMap.php b/proofs/monoid/mergeMap.php index ce8fe7e..0c0b52a 100644 --- a/proofs/monoid/mergeMap.php +++ b/proofs/monoid/mergeMap.php @@ -1,18 +1,33 @@ $a->equals($b); - $set = Map::of( - Set\Integers::between(0, 200), - Set\Integers::between(0, 200), - Set\Integers::between(1, 10), - ); + $set = Set\Sequence::of( + Set\Randomize::of( // forced to randomize as the composite will try to reuse the same key + Set\Composite::immutable( + static fn($key, $value): array => [$key, $value], + Set\Integers::between(0, 200), + Set\Integers::between(0, 200), + ), + ), + ) + ->between(1, 10) + ->filter(static function(array $pairs): bool { + $keys = \array_column($pairs, 0); + + // checks unicity of values + return Sequence::of(...$keys)->size() === Sequence::of(...$keys)->distinct()->size(); + }) + ->map(static fn($pairs) => Map::of(...$pairs)); yield properties( 'MergeMap properties', diff --git a/proofs/phpunit.php b/proofs/phpunit.php new file mode 100644 index 0000000..a1ef0da --- /dev/null +++ b/proofs/phpunit.php @@ -0,0 +1,8 @@ +pattern, $string->toString()); if ($value === false) { @@ -56,6 +58,7 @@ public function matches(Str $string): bool public function capture(Str $string): Map { $matches = []; + /** @psalm-suppress ArgumentTypeCoercion */ $value = \preg_match($this->pattern, $string->toString(), $matches); if ($value === false) { @@ -72,7 +75,7 @@ public function capture(Str $string): Map $key, Str::of( (string) $match, - $string->encoding()->toString(), + $string->encoding(), ), ); } diff --git a/src/Sequence/Defer.php b/src/Sequence/Defer.php index fc04f3d..392f3e1 100644 --- a/src/Sequence/Defer.php +++ b/src/Sequence/Defer.php @@ -413,6 +413,7 @@ public function slice(int $from, int $until): Implementation return new self( (static function(\Iterator $values, int $from, int $until): \Generator { $index = 0; + /** @var T $value */ foreach ($values as $value) { if ($index >= $from && $index < $until) { @@ -434,6 +435,7 @@ public function take(int $size): Implementation return new self( (static function(\Iterator $values, int $size): \Generator { $taken = 0; + /** @var T $value */ foreach ($values as $value) { if ($taken >= $size) { diff --git a/src/Str.php b/src/Str.php index 992efd0..3a169f1 100644 --- a/src/Str.php +++ b/src/Str.php @@ -11,16 +11,12 @@ final class Str implements \Stringable { private string $value; - private string $encoding; + private Str\Encoding $encoding; - private function __construct(string $value, string $encoding = null) + private function __construct(string $value, Str\Encoding $encoding = null) { $this->value = $value; - /** - * @psalm-suppress ImpureFunctionCall - * @var string - */ - $this->encoding = $encoding ?? \mb_internal_encoding(); + $this->encoding = $encoding ?? Str\Encoding::utf8; } public function __toString(): string @@ -30,15 +26,9 @@ public function __toString(): string /** * @psalm-pure - * - * @param string|Str\Encoding|null $encoding $encoding Strings will no longer be accepted in the next major release */ - public static function of(string $value, string|Str\Encoding $encoding = null): self + public static function of(string $value, Str\Encoding $encoding = null): self { - if ($encoding instanceof Str\Encoding) { - $encoding = $encoding->toString(); - } - return new self($value, $encoding); } @@ -60,15 +50,12 @@ public function toString(): string return $this->value; } - public function encoding(): self + public function encoding(): Str\Encoding { - return new self($this->encoding); + return $this->encoding; } - /** - * @param string|Str\Encoding $encoding $encoding Strings will no longer be accepted in the next major release - */ - public function toEncoding(string|Str\Encoding $encoding): self + public function toEncoding(Str\Encoding $encoding): self { return self::of($this->value, $encoding); } @@ -116,7 +103,7 @@ public function chunk(int $size = 1): Sequence { /** @var Sequence */ $sequence = Sequence::of(); - $parts = \mb_str_split($this->value, $size, $this->encoding); + $parts = \mb_str_split($this->value, $size, $this->encoding->toString()); foreach ($parts as $value) { $sequence = ($sequence)(new self($value, $this->encoding)); @@ -134,7 +121,7 @@ public function chunk(int $size = 1): Sequence */ public function position(string|\Stringable $needle, int $offset = 0): Maybe { - $position = \mb_strpos($this->value, (string) $needle, $offset, $this->encoding); + $position = \mb_strpos($this->value, (string) $needle, $offset, $this->encoding->toString()); if ($position === false) { /** @var Maybe<0|positive-int> */ @@ -184,7 +171,7 @@ public function toLower(): self */ public function length(): int { - return \mb_strlen($this->value, $this->encoding); + return \mb_strlen($this->value, $this->encoding->toString()); } public function empty(): bool @@ -296,6 +283,7 @@ public function words(string|\Stringable $charlist = ''): Map */ public function pregSplit(string|\Stringable $regex, int $limit = -1): Sequence { + /** @psalm-suppress ArgumentTypeCoercion */ $strings = \preg_split((string) $regex, $this->value, $limit); /** @var Sequence */ $sequence = Sequence::of(); @@ -339,6 +327,7 @@ public function pregReplace( string|\Stringable $replacement, int $limit = -1, ): self { + /** @psalm-suppress ArgumentTypeCoercion */ $value = \preg_replace( (string) $regex, (string) $replacement, @@ -365,7 +354,7 @@ public function substring(int $start, int $length = null): self return $this; } - $sub = \mb_substr($this->value, $start, $length, $this->encoding); + $sub = \mb_substr($this->value, $start, $length, $this->encoding->toString()); return new self($sub, $this->encoding); } @@ -508,7 +497,7 @@ public function leftTrim(string $mask = null): self */ public function contains(string|\Stringable $value): bool { - return \mb_strpos($this->value, (string) $value, 0, $this->encoding) !== false; + return \mb_strpos($this->value, (string) $value, 0, $this->encoding->toString()) !== false; } /** @@ -520,7 +509,7 @@ public function startsWith(string|\Stringable $value): bool return true; } - return \mb_strpos($this->value, (string) $value, 0, $this->encoding) === 0; + return \mb_strpos($this->value, (string) $value, 0, $this->encoding->toString()) === 0; } /** @@ -548,7 +537,7 @@ public function pregQuote(string|\Stringable $delimiter = ''): self } /** - * @param callable(string, string): string $map Second string is the encoding + * @param callable(string, Str\Encoding): string $map Second string is the encoding */ public function map(callable $map): self { @@ -557,7 +546,7 @@ public function map(callable $map): self } /** - * @param callable(string, string): self $map Second string is the encoding + * @param callable(string, Str\Encoding): self $map Second string is the encoding */ public function flatMap(callable $map): self { diff --git a/tests/AccumulateTest.php b/tests/AccumulateTest.php index 4882d18..d1638e4 100644 --- a/tests/AccumulateTest.php +++ b/tests/AccumulateTest.php @@ -4,7 +4,7 @@ namespace Tests\Innmind\Immutable; use Innmind\Immutable\Accumulate; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class AccumulateTest extends TestCase { diff --git a/tests/EitherTest.php b/tests/EitherTest.php index 527c176..50e9eb3 100644 --- a/tests/EitherTest.php +++ b/tests/EitherTest.php @@ -4,9 +4,9 @@ namespace Tests\Innmind\Immutable; use Innmind\Immutable\Either; -use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ PHPUnit\BlackBox, + PHPUnit\Framework\TestCase, Set, }; diff --git a/tests/Fixtures/MapTest.php b/tests/Fixtures/MapTest.php deleted file mode 100644 index d92d65b..0000000 --- a/tests/Fixtures/MapTest.php +++ /dev/null @@ -1,42 +0,0 @@ -assertInstanceOf( - Set::class, - Map::of( - Set\Strings::madeOf(Set\Chars::any())->between(1, 2), - Set\Strings::madeOf(Set\Chars::any())->between(1, 2), - ), - ); - } - - public function testGenerate() - { - $this - ->forAll(Map::of( - Set\Strings::madeOf(Set\Chars::any())->between(1, 2), - Set\Strings::madeOf(Set\Chars::any())->between(1, 2), - Set\Integers::between(0, 5), - )) - ->then(function($map) { - $this->assertInstanceOf(Structure::class, $map); - $this->assertLessThanOrEqual(5, $map->size()); - }); - } -} diff --git a/tests/Fixtures/SequenceTest.php b/tests/Fixtures/SequenceTest.php index a78f004..eabbe9a 100644 --- a/tests/Fixtures/SequenceTest.php +++ b/tests/Fixtures/SequenceTest.php @@ -6,10 +6,10 @@ use Innmind\Immutable\Sequence as Structure; use Innmind\BlackBox\{ PHPUnit\BlackBox, + PHPUnit\Framework\TestCase, Set, }; use Fixtures\Innmind\Immutable\Sequence; -use PHPUnit\Framework\TestCase; class SequenceTest extends TestCase { diff --git a/tests/Fixtures/SetTest.php b/tests/Fixtures/SetTest.php index f478cf8..058b088 100644 --- a/tests/Fixtures/SetTest.php +++ b/tests/Fixtures/SetTest.php @@ -6,10 +6,10 @@ use Innmind\Immutable\Set as Structure; use Innmind\BlackBox\{ PHPUnit\BlackBox, + PHPUnit\Framework\TestCase, Set as DataSet, }; use Fixtures\Innmind\Immutable\Set; -use PHPUnit\Framework\TestCase; class SetTest extends TestCase { diff --git a/tests/FoldTest.php b/tests/FoldTest.php index 777e2a1..3660b80 100644 --- a/tests/FoldTest.php +++ b/tests/FoldTest.php @@ -4,9 +4,9 @@ namespace Tests\Innmind\Immutable; use Innmind\Immutable\Fold; -use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ PHPUnit\BlackBox, + PHPUnit\Framework\TestCase, Set, }; diff --git a/tests/Map/DoubleIndexTest.php b/tests/Map/DoubleIndexTest.php index 82826cb..132ee16 100644 --- a/tests/Map/DoubleIndexTest.php +++ b/tests/Map/DoubleIndexTest.php @@ -12,7 +12,7 @@ Set, Sequence, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class DoubleIndexTest extends TestCase { diff --git a/tests/Map/ObjectKeysTest.php b/tests/Map/ObjectKeysTest.php index 48cee09..a4ce325 100644 --- a/tests/Map/ObjectKeysTest.php +++ b/tests/Map/ObjectKeysTest.php @@ -13,7 +13,7 @@ Set, Sequence, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class ObjectKeysTest extends TestCase { diff --git a/tests/Map/PrimitiveTest.php b/tests/Map/PrimitiveTest.php index 760c007..dcd3a01 100644 --- a/tests/Map/PrimitiveTest.php +++ b/tests/Map/PrimitiveTest.php @@ -12,7 +12,7 @@ Set, Sequence, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class PrimitiveTest extends TestCase { diff --git a/tests/MapTest.php b/tests/MapTest.php index 31e826e..434e295 100644 --- a/tests/MapTest.php +++ b/tests/MapTest.php @@ -10,7 +10,7 @@ Set, Sequence, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class MapTest extends TestCase { diff --git a/tests/MaybeTest.php b/tests/MaybeTest.php index 2cf3c26..1f361e1 100644 --- a/tests/MaybeTest.php +++ b/tests/MaybeTest.php @@ -8,9 +8,9 @@ Either, Predicate, }; -use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ PHPUnit\BlackBox, + PHPUnit\Framework\TestCase, Set, }; diff --git a/tests/Monoid/AppendTest.php b/tests/Monoid/AppendTest.php index d6ee095..072712b 100644 --- a/tests/Monoid/AppendTest.php +++ b/tests/Monoid/AppendTest.php @@ -8,7 +8,7 @@ Monoid, Sequence, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class AppendTest extends TestCase { diff --git a/tests/Monoid/ConcatTest.php b/tests/Monoid/ConcatTest.php index 3f1a277..5ddbca1 100644 --- a/tests/Monoid/ConcatTest.php +++ b/tests/Monoid/ConcatTest.php @@ -8,7 +8,7 @@ Monoid, Str, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class ConcatTest extends TestCase { diff --git a/tests/Monoid/MergeMapTest.php b/tests/Monoid/MergeMapTest.php index 2baf5b0..81d24ad 100644 --- a/tests/Monoid/MergeMapTest.php +++ b/tests/Monoid/MergeMapTest.php @@ -8,7 +8,7 @@ Monoid, Map, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class MergeMapTest extends TestCase { diff --git a/tests/Monoid/MergeSetTest.php b/tests/Monoid/MergeSetTest.php index 0411677..877c627 100644 --- a/tests/Monoid/MergeSetTest.php +++ b/tests/Monoid/MergeSetTest.php @@ -8,7 +8,7 @@ Monoid, Set, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class MergeSetTest extends TestCase { diff --git a/tests/PairTest.php b/tests/PairTest.php index 792afc6..7211714 100644 --- a/tests/PairTest.php +++ b/tests/PairTest.php @@ -4,7 +4,7 @@ namespace Tests\Innmind\Immutable; use Innmind\Immutable\Pair; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class PairTest extends TestCase { diff --git a/tests/RegExpTest.php b/tests/RegExpTest.php index b998653..ad1a6c4 100644 --- a/tests/RegExpTest.php +++ b/tests/RegExpTest.php @@ -7,9 +7,9 @@ RegExp, Str, Map, - Exception\LogicException + Exception\LogicException, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class RegExpTest extends TestCase { diff --git a/tests/Sequence/DeferTest.php b/tests/Sequence/DeferTest.php index df87b43..a591b9c 100644 --- a/tests/Sequence/DeferTest.php +++ b/tests/Sequence/DeferTest.php @@ -12,7 +12,7 @@ Set, SideEffect, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class DeferTest extends TestCase { diff --git a/tests/Sequence/LazyTest.php b/tests/Sequence/LazyTest.php index 619b73b..465bcde 100644 --- a/tests/Sequence/LazyTest.php +++ b/tests/Sequence/LazyTest.php @@ -12,7 +12,7 @@ Set, SideEffect, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class LazyTest extends TestCase { diff --git a/tests/Sequence/PrimitiveTest.php b/tests/Sequence/PrimitiveTest.php index 263ce36..da3f75e 100644 --- a/tests/Sequence/PrimitiveTest.php +++ b/tests/Sequence/PrimitiveTest.php @@ -12,7 +12,7 @@ Set, SideEffect, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class PrimitiveTest extends TestCase { diff --git a/tests/SequenceTest.php b/tests/SequenceTest.php index 414a74f..a7babe4 100644 --- a/tests/SequenceTest.php +++ b/tests/SequenceTest.php @@ -14,9 +14,9 @@ }; use Innmind\BlackBox\{ PHPUnit\BlackBox, + PHPUnit\Framework\TestCase, Set as DataSet, }; -use PHPUnit\Framework\TestCase; class SequenceTest extends TestCase { diff --git a/tests/Set/DeferTest.php b/tests/Set/DeferTest.php index 94146f3..aa02f97 100644 --- a/tests/Set/DeferTest.php +++ b/tests/Set/DeferTest.php @@ -12,7 +12,7 @@ Sequence, SideEffect, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class DeferTest extends TestCase { diff --git a/tests/Set/LazyTest.php b/tests/Set/LazyTest.php index 8aaa6fd..2612e66 100644 --- a/tests/Set/LazyTest.php +++ b/tests/Set/LazyTest.php @@ -12,7 +12,7 @@ Sequence, SideEffect, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class LazyTest extends TestCase { diff --git a/tests/Set/PrimitiveTest.php b/tests/Set/PrimitiveTest.php index a4c8d86..d2d00f8 100644 --- a/tests/Set/PrimitiveTest.php +++ b/tests/Set/PrimitiveTest.php @@ -12,7 +12,7 @@ Sequence, SideEffect, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class PrimitiveTest extends TestCase { diff --git a/tests/SetTest.php b/tests/SetTest.php index a454651..1418b61 100644 --- a/tests/SetTest.php +++ b/tests/SetTest.php @@ -10,7 +10,7 @@ Sequence, Predicate, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class SetTest extends TestCase { diff --git a/tests/StateTest.php b/tests/StateTest.php index 7235194..647636c 100644 --- a/tests/StateTest.php +++ b/tests/StateTest.php @@ -7,9 +7,9 @@ State, State\Result, }; -use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ PHPUnit\BlackBox, + PHPUnit\Framework\TestCase, Set, }; diff --git a/tests/StrTest.php b/tests/StrTest.php index 8e7a724..1490ea3 100644 --- a/tests/StrTest.php +++ b/tests/StrTest.php @@ -10,7 +10,7 @@ Set, Exception\InvalidRegex, }; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class StrTest extends TestCase { @@ -23,7 +23,7 @@ public function testInterfaces() public function testOf() { - $str = S::of('foo', 'ASCII'); + $str = S::of('foo', S\Encoding::ascii); $this->assertInstanceOf(S::class, $str); $this->assertSame('foo', $str->toString()); @@ -32,24 +32,20 @@ public function testOf() public function testEncoding() { - $this->assertInstanceOf(S::class, S::of('')->encoding()); - $this->assertSame('UTF-8', S::of('')->encoding()->toString()); + $this->assertSame(S\Encoding::utf8, S::of('')->encoding()); } public function testToEncoding() { $str = S::of('fooπŸ™bar'); - $str2 = $str->toEncoding('ASCII'); - $str3 = $str->toEncoding(S\Encoding::ascii); + $str2 = $str->toEncoding(S\Encoding::ascii); $this->assertInstanceOf(S::class, $str2); $this->assertNotSame($str, $str2); - $this->assertSame('UTF-8', $str->encoding()->toString()); - $this->assertSame('ASCII', $str2->encoding()->toString()); - $this->assertSame('ASCII', $str3->encoding()->toString()); + $this->assertSame(S\Encoding::utf8, $str->encoding()); + $this->assertSame(S\Encoding::ascii, $str2->encoding()); $this->assertSame(7, $str->length()); $this->assertSame(10, $str2->length()); - $this->assertSame(10, $str3->length()); } public function testSplit() @@ -68,14 +64,14 @@ public function testSplit() $this->assertSame('o', $this->get($sequence, 1)->toString()); $this->assertSame('o', $this->get($sequence, 2)->toString()); - $parts = S::of('πŸ€©πŸ‘πŸ€”', 'UTF-8')->split(); + $parts = S::of('πŸ€©πŸ‘πŸ€”', S\Encoding::utf8)->split(); $this->assertSame('🀩', $this->get($parts, 0)->toString()); $this->assertSame('πŸ‘', $this->get($parts, 1)->toString()); $this->assertSame('πŸ€”', $this->get($parts, 2)->toString()); $this->assertNotSame( '🀩', - $this->get(S::of('πŸ€©πŸ‘πŸ€”', 'ASCII')->split(), 0)->toString(), + $this->get(S::of('πŸ€©πŸ‘πŸ€”', S\Encoding::ascii)->split(), 0)->toString(), ); $sequence = $str->split(''); @@ -127,7 +123,7 @@ public function testSplitUtf8ManipulatedAsAscii() $this->assertSame('a', $this->get($splits, 5)->toString()); $this->assertSame('r', $this->get($splits, 6)->toString()); - $splits = $str->toEncoding('ASCII')->split(); + $splits = $str->toEncoding(S\Encoding::ascii)->split(); $this->assertSame('f', $this->get($splits, 0)->toString()); $this->assertSame('o', $this->get($splits, 1)->toString()); @@ -149,12 +145,12 @@ public function testSplitUtf8ManipulatedAsAsciiWithDelimiter() $this->assertSame('foo', $this->get($splits, 0)->toString()); $this->assertSame('bar', $this->get($splits, 1)->toString()); - $splits = $str->toEncoding('ASCII')->split('πŸ™'); + $splits = $str->toEncoding(S\Encoding::ascii)->split('πŸ™'); $this->assertSame('foo', $this->get($splits, 0)->toString()); $this->assertSame('bar', $this->get($splits, 1)->toString()); - $splits = $str->toEncoding('ASCII')->split( + $splits = $str->toEncoding(S\Encoding::ascii)->split( \mb_substr('πŸ™', 0, 1, 'ASCII'), ); @@ -182,7 +178,7 @@ public function testChunk() public function testChunkUtf8ManipulatedAsAscii() { $splits = S::of('fooπŸ™bar') - ->toEncoding('ASCII') + ->toEncoding(S\Encoding::ascii) ->chunk(); $this->assertSame('f', $this->get($splits, 0)->toString()); @@ -197,7 +193,7 @@ public function testChunkUtf8ManipulatedAsAscii() $this->assertSame('r', $this->get($splits, 9)->toString()); $splits = S::of('fooπŸ™bar') - ->toEncoding('ASCII') + ->toEncoding(S\Encoding::ascii) ->chunk(3); $this->assertSame('foo', $this->get($splits, 0)->toString()); @@ -249,7 +245,7 @@ public function testPosition() ); $this->assertSame( 7, - $emoji->toEncoding('ASCII')->position('bar')->match( + $emoji->toEncoding(S\Encoding::ascii)->position('bar')->match( static fn($value) => $value, static fn() => null, ), @@ -301,7 +297,7 @@ public function testReplaceWithDifferentEncoding() $str2->toString(), ); - $str3 = $str->toEncoding('ASCII')->replace( + $str3 = $str->toEncoding(S\Encoding::ascii)->replace( \mb_substr('πŸ™', 0, 1, 'ASCII'), 'baz', ); @@ -340,14 +336,14 @@ public function testToLower() public function testLength() { $this->assertSame(4, S::of('fooπŸ™')->length()); - $this->assertSame(7, S::of('fooπŸ™')->toEncoding('ASCII')->length()); + $this->assertSame(7, S::of('fooπŸ™')->toEncoding(S\Encoding::ascii)->length()); } public function testEmpty() { $this->assertTrue(S::of('')->empty()); $this->assertFalse(S::of('πŸ™')->empty()); - $this->assertFalse(S::of('πŸ™', 'ASCII')->substring(0, 1)->empty()); + $this->assertFalse(S::of('πŸ™', S\Encoding::ascii)->substring(0, 1)->empty()); } public function testReverse() @@ -361,7 +357,7 @@ public function testReverse() $this->assertSame('fooπŸ™', $str->toString()); $this->assertSame( \strrev('πŸ™').'oof', - $str->toEncoding('ASCII')->reverse()->toString(), + $str->toEncoding(S\Encoding::ascii)->reverse()->toString(), ); } @@ -373,7 +369,7 @@ public function testReverseKeepTheGivenEncoding() ); $this->assertSame( 'ASCII', - S::of('foo', 'ASCII')->reverse()->encoding()->toString(), + S::of('foo', S\Encoding::ascii)->reverse()->encoding()->toString(), ); } @@ -413,7 +409,7 @@ public function testRepeat() $this->assertSame('foofoofoo', $str2->toString()); $this->assertSame('foo', $str->toString()); $this->assertSame('πŸ™πŸ™', S::of('πŸ™')->repeat(2)->toString()); - $this->assertSame('πŸ™πŸ™', S::of('πŸ™')->toEncoding('ASCII')->repeat(2)->toString()); + $this->assertSame('πŸ™πŸ™', S::of('πŸ™')->toEncoding(S\Encoding::ascii)->repeat(2)->toString()); } public function testStripSlashes() @@ -511,7 +507,7 @@ public function testMatches() $this->assertTrue($str->matches('/^abc/')); $this->assertTrue(S::of('fooπŸ™bar')->matches('/πŸ™/')); - $this->assertTrue(S::of('fooπŸ™bar')->toEncoding('ASCII')->matches('/πŸ™/')); + $this->assertTrue(S::of('fooπŸ™bar')->toEncoding(S\Encoding::ascii)->matches('/πŸ™/')); $this->assertTrue(S::of('fooπŸ™bar')->matches(S::of('/πŸ™/'))); } @@ -636,7 +632,7 @@ public function testDropEnd() public function testSubstringUtf8ManipulatedAsAscii() { - $str = S::of('fooπŸ™bar')->toEncoding('ASCII'); + $str = S::of('fooπŸ™bar')->toEncoding(S\Encoding::ascii); $this->assertSame('πŸ™bar', $str->substring(3)->toString()); $this->assertSame('πŸ™', $str->substring(3, 4)->toString()); @@ -817,7 +813,7 @@ public function testMap() $a = S::of('foo'); $b = $a->map(function($string, $encoding) use ($a) { $this->assertSame('foo', $string); - $this->assertSame($a->encoding()->toString(), $encoding); + $this->assertSame($a->encoding(), $encoding); return 'bar'; }); @@ -833,7 +829,7 @@ public function testFlatMap() $a = S::of('foo'); $b = $a->flatMap(function($string, $encoding) use ($a, $expected) { $this->assertSame('foo', $string); - $this->assertSame($a->encoding()->toString(), $encoding); + $this->assertSame($a->encoding(), $encoding); return $expected; });