Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
86 changes: 6 additions & 80 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Create release

on:
push:
tags:
- '*'

jobs:
release:
uses: innmind/github-workflows/.github/workflows/release.yml@main
secrets: inherit
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
composer.lock
vendor
.phpunit.result.cache
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 26 additions & 0 deletions blackbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types = 1);

require 'vendor/autoload.php';

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

Application::new($argv)
->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();
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
22 changes: 0 additions & 22 deletions phpunit.xml.dist

This file was deleted.

5 changes: 1 addition & 4 deletions src/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

namespace Innmind\Reflection;

use Innmind\Immutable\{
Map,
Set,
};
use Innmind\Immutable\Set;

/**
* @template T of object
Expand Down
18 changes: 0 additions & 18 deletions src/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
}
}
22 changes: 11 additions & 11 deletions tests/ExtractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
Map,
Set,
};
use PHPUnit\Framework\TestCase;
use Innmind\BlackBox\{
PHPUnit\Framework\TestCase,
PHPUnit\BlackBox,
Set as DataSet,
};
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
30 changes: 15 additions & 15 deletions tests/InstanciateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Loading