Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  use Stringable in Str to avoid manual type cast
  remove useless test
  add Str\Encoding
  remove support for php 8.0 and 8.1
  fix job name
  avoid re-testing blackbox
  use blackbox 5
  • Loading branch information
Baptouuuu committed Jul 8, 2023
2 parents 5b85b79 + 7523454 commit 16b1fd2
Show file tree
Hide file tree
Showing 32 changed files with 598 additions and 1,057 deletions.
59 changes: 55 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.0', '8.1', '8.2']
php-version: ['8.2']
name: 'PHPUnit'
steps:
- name: Checkout
Expand All @@ -25,12 +25,63 @@ jobs:
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']
dependency-versions: ['lowest', 'highest']
name: 'BlackBox'
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"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: BlackBox
run: php blackbox.php
blackbox_coverage:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.2']
dependency-versions: ['lowest', 'highest']
name: 'BlackBox 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"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: BlackBox
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.0', '8.1', '8.2']
php-version: ['8.2']
name: 'Coverage'
steps:
- name: Checkout
Expand All @@ -54,7 +105,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.0', '8.1', '8.2']
php-version: ['8.2']
name: 'Psalm'
steps:
- name: Checkout
Expand All @@ -72,7 +123,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.0']
php-version: ['8.2']
name: 'CS'
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return Innmind\CodingStandard\CodingStandard::config([
'proofs',
'tests',
'fixtures',
'properties',
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 4.15.0 - 2023-07-08

### Added

- `Innmind\Immutable\Str\Encoding`
- `Innmind\Immutable\Str` now implements `\Stringable`
- Most `Innmind\Immutable\Str` methods now also accept `\Stringable`

### Changed

- `innmind/black-box` updated to version `5`

### Removed

- Support for PHP `8.0` and `8.1`

## 4.14.1 - 2023-05-18

### Changed
Expand Down
27 changes: 27 additions & 0 deletions blackbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types = 1);

require 'vendor/autoload.php';

use Innmind\BlackBox\{
Application,
Runner\Load,
Runner\CodeCoverage,
};

Application::new($argv)
->codeCoverage(
CodeCoverage::of(
__DIR__.'/src/',
__DIR__.'/proofs/',
__DIR__.'/fixtures/',
)
->dumpTo('coverage.clover')
->enableWhen(\getenv('ENABLE_COVERAGE') !== false),
)
->scenariiPerProof(match (\getenv('ENABLE_COVERAGE')) {
false => 100,
default => 1,
})
->tryToProve(Load::everythingIn(__DIR__.'/proofs/'))
->exit();
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"issues": "http://github.com/Innmind/Immutable/issues"
},
"require": {
"php": "~8.0"
"php": "~8.2"
},
"autoload": {
"psr-4": {
Expand All @@ -30,18 +30,18 @@
}
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"phpunit/phpunit": "~10.0",
"vimeo/psalm": "~5.6",
"innmind/black-box": "^4.4",
"innmind/black-box": "~5.0",
"innmind/coding-standard": "~2.0"
},
"conflict": {
"innmind/black-box": "<4.4|~5.0"
"innmind/black-box": "<5.0|~6.0"
},
"suggest": {
"innmind/black-box": "For property based testing"
},
"provide": {
"innmind/black-box-sets": "4.4.0"
"innmind/black-box-sets": "5.0"
}
}
69 changes: 20 additions & 49 deletions docs/MONOIDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,29 @@ This library comes with a few monoids:

## Create your own

To make sure your own monoid follows the laws this library comes with properties you can use in your test like so:
To make sure your own monoid follows the laws this library comes with properties you can use (via [`innmind/black-box`](https://github.com/Innmind/BlackBox/)) in your test like so:

```php
use PHPUnit\Framework\TestCase;
use Innmind\BlackBox\{
PHPUnit\BlackBox,
Set,
};
use Innmind\BlackBox\Set;
use Properties\Innmind\Immutable\Monoid;

class YourMonoidTest extends TestCase
{
use BlackBox;

/**
* @dataProvider properties
*/
public function testHoldProperty($property)
{
$this
->forAll($property)
->then(static function($property) {
$property->ensureHeldBy(new YourMonoid);
});
}

public function testHoldProperties()
{
$this
->forAll(Monoid::properties($this->set(), $this->equals()))
->then(static function($properties) {
$properties->ensureHeldBy(new YourMonoid);
});
}

public function properties(): iterable
{
foreach (Monoid::list($this->set(), $this->equals()) as $property) {
yield [$property];
}
return static function() {
$equals = static fn($a, $b) => /* this callable is the way to check that 2 values are equal */;
// this Set must generate values that are of the type your monoid understands
$set = /* an instance of Set */;

yield properties(
'YourMonoid properties',
Monoid::properties($set, $equals),
Set\Elements::of(new YourMonoid),
);

foreach (Monoid::list($set, $equals) as $property) {
yield proof(
'YourMonoid property',
given($property),
static fn($assert, $property) => $property->ensureHeldBy($assert, new YourMonoid),
);
}

public function equals(): callable
{
return static fn($a, $b) => /* this callable is the way to check that 2 values are equal */;
}

private function set(): Set
{
// this Set must generate values that are of the type your monoid understands
return /* an instance of Set */
}
}

};
```
31 changes: 23 additions & 8 deletions fixtures/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

namespace Fixtures\Innmind\Immutable;

use Innmind\BlackBox\Set;
use Innmind\BlackBox\{
Set,
Random,
};
use Innmind\Immutable\{
Map as Structure,
Set as ISet,
Expand All @@ -13,6 +16,8 @@
final class Map
{
/**
* @deprecated Will be removed in the next major release
*
* @template I
* @template J
*
Expand All @@ -26,27 +31,37 @@ public static function of(
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(
new Set\Randomize( // forced to randomize as the composite will try to reuse the same key
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,
),
),
$sizes,
)->filter(static function(array $pairs): bool {
$keys = \array_column($pairs, 0);
)
->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();
}),
// checks unicity of values
return ISequence::mixed(...$keys)->size() === ISet::mixed(...$keys)->size();
}),
);
}
}
24 changes: 16 additions & 8 deletions fixtures/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

namespace Fixtures\Innmind\Immutable;

use Innmind\BlackBox\Set;
use Innmind\BlackBox\{
Set,
Random,
};
use Innmind\Immutable\Sequence as Structure;

final class Sequence
Expand All @@ -17,12 +20,17 @@ final class Sequence
*/
public static function of(Set $set, Set\Integers $sizes = null): Set
{
return Set\Decorate::immutable(
static fn(array $values): Structure => Structure::of(...$values),
Set\Sequence::of(
$set,
$sizes,
),
);
// 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\Sequence::of($set)
->between($min, $max)
->map(static fn(array $values): Structure => Structure::of(...$values));
}
}
Loading

0 comments on commit 16b1fd2

Please sign in to comment.