diff --git a/.gitattributes b/.gitattributes index 4160131..05f17e3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,3 @@ /.gitattributes export-ignore /.gitignore export-ignore -/phpunit.xml.dist export-ignore /tests export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f329fde..2f3eecb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,86 +3,12 @@ name: CI on: [push, pull_request] jobs: - phpunit: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macOS-latest] - php-version: ['8.2', '8.3'] - 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_DETAILED_PROPERTIES: 1 + blackbox: + uses: innmind/github-workflows/.github/workflows/black-box-matrix.yml@main coverage: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macOS-latest] - php-version: ['8.2', '8.3'] - 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: - token: ${{ secrets.CODECOV_TOKEN }} + uses: innmind/github-workflows/.github/workflows/coverage-matrix.yml@main + secrets: inherit psalm: - runs-on: ubuntu-latest - strategy: - matrix: - php-version: ['8.2', '8.3'] - name: 'Psalm' - 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: Composer - uses: "ramsey/composer-install@v2" - - name: Psalm - run: vendor/bin/psalm --shepherd + uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main cs: - runs-on: ubuntu-latest - strategy: - matrix: - php-version: ['8.2'] - 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: Composer - uses: "ramsey/composer-install@v2" - - name: CS - run: vendor/bin/php-cs-fixer fix --diff --dry-run + uses: innmind/github-workflows/.github/workflows/cs.yml@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b25ad8a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,11 @@ +name: Create release + +on: + push: + tags: + - '*' + +jobs: + release: + uses: innmind/github-workflows/.github/workflows/release.yml@main + secrets: inherit diff --git a/.gitignore b/.gitignore index e96516b..987e2a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ composer.lock vendor -.phpunit.result.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aba420..b787481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires PHP `8.4` +- Requires `innmind/immutable:~6.0` + +### Fixed + +- Deprecations related to the use of `\ReflectionProperty::setAccessible()` + ## 5.2.0 - 2023-09-16 ### Added diff --git a/blackbox.php b/blackbox.php new file mode 100644 index 0000000..dcc7e0b --- /dev/null +++ b/blackbox.php @@ -0,0 +1,26 @@ +when( + \getenv('ENABLE_COVERAGE') !== false, + static fn(Application $app) => $app + ->codeCoverage( + CodeCoverage::of( + __DIR__.'/src/', + __DIR__.'/tests/', + ) + ->dumpTo('coverage.clover') + ->enableWhen(true), + ), + ) + ->tryToProve(Load::directory(__DIR__.'/tests/')) + ->exit(); diff --git a/composer.json b/composer.json index 08655de..8912a35 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "issues": "http://github.com/Innmind/Reflection/issues" }, "require": { - "php": "~8.2", - "innmind/immutable": "~4.0|~5.0", + "php": "~8.4", + "innmind/immutable": "~6.0", "innmind/type": "~1.0" }, "autoload": { @@ -31,9 +31,8 @@ } }, "require-dev": { - "phpunit/phpunit": "~10.2", - "vimeo/psalm": "~5.13", + "innmind/static-analysis": "~1.3", "innmind/coding-standard": "~2.0", - "innmind/black-box": "~5.1" + "innmind/black-box": "~6.5" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 7141a4d..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - ./tests - - - - - . - - - ./tests - ./vendor - - - diff --git a/src/ReflectionClass.php b/src/ReflectionClass.php index c88b7f8..2d1513b 100644 --- a/src/ReflectionClass.php +++ b/src/ReflectionClass.php @@ -3,10 +3,7 @@ namespace Innmind\Reflection; -use Innmind\Immutable\{ - Map, - Set, -}; +use Innmind\Immutable\Set; /** * @template T of object diff --git a/src/ReflectionProperty.php b/src/ReflectionProperty.php index 6a2e0e5..d277a25 100644 --- a/src/ReflectionProperty.php +++ b/src/ReflectionProperty.php @@ -83,17 +83,8 @@ public function inject(object $object, mixed $value): Maybe } $reflection = new \ReflectionProperty($this->class, $this->name); - - if (!$reflection->isPublic()) { - $reflection->setAccessible(true); - } - $reflection->setValue($object, $value); - if (!$reflection->isPublic()) { - $reflection->setAccessible(false); - } - return Maybe::just($object); } @@ -103,18 +94,9 @@ public function inject(object $object, mixed $value): Maybe public function extract(object $object): mixed { $reflection = new \ReflectionProperty($this->class, $this->name); - - if (!$reflection->isPublic()) { - $reflection->setAccessible(true); - } - /** @var mixed */ $value = $reflection->getValue($object); - if (!$reflection->isPublic()) { - $reflection->setAccessible(false); - } - return $value; } } diff --git a/tests/ExtractTest.php b/tests/ExtractTest.php index ca8e6cf..d7831ee 100644 --- a/tests/ExtractTest.php +++ b/tests/ExtractTest.php @@ -11,8 +11,8 @@ Map, Set, }; -use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ + PHPUnit\Framework\TestCase, PHPUnit\BlackBox, Set as DataSet, }; @@ -22,14 +22,14 @@ class ExtractTest extends TestCase { use BlackBox; - public function testExtract() + public function testExtract(): BlackBox\Proof { - $this + return $this ->forAll( - DataSet\Type::any(), - DataSet\Type::any(), + DataSet::type(), + DataSet::type(), ) - ->then(function($a, $b) { + ->prove(function($a, $b) { $instanciate = new Instanciate; $object = $instanciate(WithConstructor::class, Map::of(['a', $a], ['b', $b]))->match( @@ -58,14 +58,14 @@ public function testExtract() }); } - public function testReturnNothingWhenFailingToExtractAProperty() + public function testReturnNothingWhenFailingToExtractAProperty(): BlackBox\Proof { - $this + return $this ->forAll( - DataSet\Type::any(), - DataSet\Type::any(), + DataSet::type(), + DataSet::type(), ) - ->then(function($a, $b) { + ->prove(function($a, $b) { $instanciate = new Instanciate; $object = $instanciate(WithConstructor::class, Map::of(['a', $a], ['b', $b]))->match( diff --git a/tests/InstanciateTest.php b/tests/InstanciateTest.php index d56b6d9..ab12543 100644 --- a/tests/InstanciateTest.php +++ b/tests/InstanciateTest.php @@ -5,8 +5,8 @@ use Innmind\Reflection\Instanciate; use Innmind\Immutable\Map; -use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ + PHPUnit\Framework\TestCase, PHPUnit\BlackBox, Set, }; @@ -19,11 +19,11 @@ class InstanciateTest extends TestCase { use BlackBox; - public function testInvoke() + public function testInvoke(): BlackBox\Proof { - $this - ->forAll(Set\Type::any()) - ->then(function($value) { + return $this + ->forAll(Set::type()) + ->prove(function($value) { $instanciate = new Instanciate; $object = $instanciate(NoConstructor::class, Map::of(['a', $value]))->match( @@ -36,14 +36,14 @@ public function testInvoke() }); } - public function testPartialInstance() + public function testPartialInstance(): BlackBox\Proof { - $this + return $this ->forAll( - Set\Integers::any(), - Set\Elements::of(true, false), + Set::integers(), + Set::of(true, false), ) - ->then(function($value, $bool) { + ->prove(function($value, $bool) { $instanciate = new Instanciate; $object = $instanciate(ManyTypes::class, Map::of(['a', $value], ['d', $bool]))->match( @@ -67,15 +67,15 @@ public function testPartialInstance() }); } - public function testReturnNothingWhenFailingToInjectAProperty() + public function testReturnNothingWhenFailingToInjectAProperty(): BlackBox\Proof { - $this + return $this ->forAll( - Set\Integers::any(), - Set\Type::any(), + Set::integers(), + Set::type(), ) ->filter(static fn($value, $invalid) => !\is_bool($invalid)) - ->then(function($value, $invalid) { + ->prove(function($value, $invalid) { $instanciate = new Instanciate; $object = $instanciate(ManyTypes::class, Map::of(['a', $value], ['d', $invalid]))->match( diff --git a/tests/ReflectionClassTest.php b/tests/ReflectionClassTest.php index 03566ce..e6a5abd 100644 --- a/tests/ReflectionClassTest.php +++ b/tests/ReflectionClassTest.php @@ -3,28 +3,16 @@ namespace Tests\Innmind\Reflection; -use Innmind\Reflection\{ - ReflectionClass, - InjectionStrategy, - InjectionStrategy\InjectionStrategies, - InjectionStrategy\NamedMethodStrategy, - InjectionStrategy\ReflectionStrategy, - InjectionStrategy\SetterStrategy, - Instanciator\ReflectionInstanciator, - Instanciator, -}; +use Innmind\Reflection\ReflectionClass; use Fixtures\Innmind\Reflection\{ NoConstructor, WithConstructor, ManyTypes, Attr, }; -use Innmind\Immutable\{ - Set, - Map, -}; -use PHPUnit\Framework\TestCase; +use Innmind\Immutable\Set; use Innmind\BlackBox\{ + PHPUnit\Framework\TestCase, PHPUnit\BlackBox, Set as DataSet, }; @@ -88,12 +76,12 @@ public function testPropertiesType() $types = \array_combine(\array_column($types, 0), \array_column($types, 1)); $this - ->forAll(DataSet\Integers::any()) + ->forAll(DataSet::integers()) ->then(function($int) use ($types) { $this->assertTrue($types['a']->allows($int)); }); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_int($type)) { return; @@ -102,7 +90,7 @@ public function testPropertiesType() $this->assertFalse($types['a']->allows($type)); }); $this - ->forAll(DataSet\RealNumbers::any()) + ->forAll(DataSet::realNumbers()) ->then(function($value) use ($types) { if (\is_int($value)) { return; @@ -111,7 +99,7 @@ public function testPropertiesType() $this->assertTrue($types['b']->allows($value)); }); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_float($type)) { return; @@ -120,12 +108,12 @@ public function testPropertiesType() $this->assertFalse($types['b']->allows($type)); }); $this - ->forAll(DataSet\Unicode::strings()) + ->forAll(DataSet::strings()->unicode()) ->then(function($value) use ($types) { $this->assertTrue($types['c']->allows($value)); }); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_string($type)) { return; @@ -134,12 +122,12 @@ public function testPropertiesType() $this->assertFalse($types['c']->allows($type)); }); $this - ->forAll(DataSet\Elements::of(true, false)) + ->forAll(DataSet::of(true, false)) ->then(function($value) use ($types) { $this->assertTrue($types['d']->allows($value)); }); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_bool($type)) { return; @@ -148,12 +136,12 @@ public function testPropertiesType() $this->assertFalse($types['d']->allows($type)); }); $this - ->forAll(DataSet\Sequence::of(DataSet\Type::any())) + ->forAll(DataSet::sequence(DataSet::type())) ->then(function($value) use ($types) { $this->assertTrue($types['e']->allows($value)); }); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_array($type)) { return; @@ -165,7 +153,7 @@ public function testPropertiesType() })); $this->assertTrue($types['f']->allows(new \stdClass)); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_object($type)) { return; @@ -175,7 +163,7 @@ public function testPropertiesType() }); $this->assertTrue($types['g']->allows(static fn() => null)); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_callable($type)) { return; @@ -185,12 +173,12 @@ public function testPropertiesType() }); $this->assertTrue($types['h']->allows(new NoConstructor)); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { $this->assertFalse($types['h']->allows($type)); }); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { $this->assertTrue($types['i']->allows($type)); $this->assertTrue($types['j']->allows($type)); @@ -198,15 +186,15 @@ public function testPropertiesType() $this->assertTrue($types['k']->allows(new NoConstructor)); $this->assertTrue($types['k']->allows(null)); $this - ->forAll(DataSet\Either::any( - DataSet\Integers::any(), - DataSet\Unicode::strings(), + ->forAll(DataSet::either( + DataSet::integers(), + DataSet::strings()->unicode(), )) ->then(function($value) use ($types) { $this->assertTrue($types['union']->allows($value)); }); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if (\is_int($type) || \is_string($type)) { return; @@ -216,7 +204,7 @@ public function testPropertiesType() }); $this->assertTrue($types['intersection']->allows(new \ArrayIterator([]))); $this - ->forAll(DataSet\Type::any()) + ->forAll(DataSet::type()) ->then(function($type) use ($types) { if ($type instanceof \Countable) { return;