Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 - 8.4 compatibility #21

Merged
merged 8 commits into from
Dec 1, 2024
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
2 changes: 1 addition & 1 deletion .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, windows-latest]
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
php-version: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
name: PHP ${{ matrix.php-version }} on ${{ matrix.os }}

steps:
Expand Down
6 changes: 3 additions & 3 deletions bin/update-tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file updates tests according to the phpunit library used for current php version, or php version in 1st argument.
# Usage:
# update-tests - to update tests according to the phpunit library used for current php version.
# update-tests x.x - to update tests according to the phpunit library used for specific php version x.x, where x.x = 5.6|7.0|7.1|7.2|7.3|7.4|8.0.
# update-tests x.x - to update tests according to the phpunit library used for specific php version x.x, where x.x = 5.6|7.0|7.1|7.2|7.3|7.4|8.0|8.1|8.2|8.3|8.4.

# Directory with phpunit tests.
TEST_DIR="tests"
Expand All @@ -14,7 +14,7 @@ else
fi

if [[ $1 == '' && $DEV_MODE != '1' ]]; then
echo "Script works with composer in dev mode only."
# Script works with composer in dev mode only.
exit 0
fi

Expand Down Expand Up @@ -52,7 +52,7 @@ elif [[ $PHP_VERSION == '7.1' ]]; then
PHP_UNIT='7.5'
elif [[ $PHP_VERSION == '7.2' ]]; then
PHP_UNIT='8.5'
elif [[ $PHP_VERSION == '7.3' || $PHP_VERSION == '7.4' || $PHP_VERSION == '8.0' ]]; then
elif [[ $PHP_VERSION == '7.3' || $PHP_VERSION == '7.4' || $PHP_VERSION == '8.0' || $PHP_VERSION == '8.1' || $PHP_VERSION == '8.2' || $PHP_VERSION == '8.3' || $PHP_VERSION == '8.4' ]]; then
PHP_UNIT='9.5'
fi

Expand Down
9 changes: 8 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. This projec

## [Unreleased][unreleased]

## [1.5.0]
### Added
- Support for PHP 8.4.

### Changed
- The minimum required PHP version is now 7.2.

## [1.4.0]
### Added
- PHP 8 compatibility and test coverage (thanks @kagg-design)
Expand All @@ -21,7 +28,7 @@ All notable changes to this project will be documented in this file. This projec

## [1.3.7]
### Fixed
- issue that would generate en excpetion when providing an empty configuration to the `FunctionMocker::init` method
- issue that would generate en exception when providing an empty configuration to the `FunctionMocker::init` method

## [1.3.6]
### Fixed
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
],
"minimum-stability": "stable",
"require": {
"phpunit/phpunit": "5.7 - 9.5",
"antecedent/patchwork": "^2.0",
"lucatume/args": "^1.0"
"php": ">=7.1",
"phpunit/phpunit": "7.5 - 9.6",
"antecedent/patchwork": "^2.2.0",
"lucatume/args": "^1.0.1"
},
"autoload": {
"psr-0": {
Expand Down
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @see \Patchwork\configure()
*
*/
function init(array $options = null) {
function init(?array $options = null) {
FunctionMocker::init($options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tad/FunctionMocker/Call/Logger/LoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
interface LoggerInterface
{

public function called(array $args = null);
public function called(?array $args = null);
}
4 changes: 2 additions & 2 deletions src/tad/FunctionMocker/Call/Logger/SpyCallLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function __construct()
: '\\PHPUnit\\Framework\\Constraint\\Constraint';
}

public function called(array $args = null)
public function called(?array $args = null)
{
$this->calls[] = CallTrace::fromArguments($args);
}

public function getCallTimes(array $args = null)
public function getCallTimes(?array $args = null)
{
$calls = $this->calls;
if ($args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function realWasCalledTimes( $times ) {
*
* @return array
*/
protected function getCallTimesWithArgs( $methodName, array $args = null ) {
protected function getCallTimesWithArgs( $methodName, ?array $args = null ) {
$invocations = $this->getInvocations();
$callTimes = 0;
array_map( function ( $invocation ) use ( &$callTimes, $args, $methodName ) {
Expand Down
2 changes: 1 addition & 1 deletion src/tad/FunctionMocker/CallTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CallTrace

protected $args;

public static function fromArguments(array $args = null)
public static function fromArguments(?array $args = null)
{
$instance = new self;
$instance->args = $args ? $args : array();
Expand Down
6 changes: 3 additions & 3 deletions src/tad/FunctionMocker/FunctionMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function setUp() {
*
* @see \Patchwork\configure()
*/
public static function init(array $options = null, $forceReinit = false) {
public static function init(?array $options = null, $forceReinit = false) {
if (!$forceReinit && self::$didInit) {
return;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ private static function getIndexedReplacements($return) {
*
* @return mixed
*/
public static function callOriginal(array $args = null) {
public static function callOriginal(?array $args = null) {
return \Patchwork\relay($args);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ public static function forge($class) {
*
* @throws \RuntimeException If the Patchwork configuration file or the checksum file could not be written.
*/
public static function writePatchworkConfig(array $options = null, $destinationFolder) {
public static function writePatchworkConfig(?array $options = null, $destinationFolder = '') {
$options = self::getPatchworkConfiguration($options, $destinationFolder);

$configFileContents = json_encode($options);
Expand Down
2 changes: 1 addition & 1 deletion src/tad/FunctionMocker/Method/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
{
}

public function __call($name, array $args = null)
public function __call($name, ?array $args = null)
{
return InstanceMethodCallVerifier::from($this->returnValue, $this->callLogger);
}
Expand Down
9 changes: 7 additions & 2 deletions src/tad/FunctionMocker/MockWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class MockWrapper
*/
protected $classTemplate;

public function __construct($originalClassName = '', ClassTemplateInterface $classTemplate = null, MethodCodeInterface $methodCode = null)
/**
* @var MethodCode|MethodCodeInterface
*/
private $methodCode;

public function __construct($originalClassName = '', ?ClassTemplateInterface $classTemplate = null, ?MethodCodeInterface $methodCode = null)
{
$this->originalClassName = $originalClassName;
$this->classTemplate = $classTemplate ?: new ClassTemplate();
Expand Down Expand Up @@ -66,7 +71,7 @@ public function wrap($mockObject, $invokedRecorder, ReplacementRequest $request)
* @throws \Exception
*
*/
protected function getWrappedInstance($object, ExtenderInterface $extender, $invokedRecorder = null, ReplacementRequest $request = null)
protected function getWrappedInstance($object, ExtenderInterface $extender, $invokedRecorder = null, ?ReplacementRequest $request = null)
{
$mockClassName = get_class($object);
$extendClassName = sprintf('%s_%s', uniqid('Extended_'), $mockClassName);
Expand Down
2 changes: 1 addition & 1 deletion src/tad/FunctionMocker/PHPUnitFrameworkAssertWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function getTestCase()
* @param array $args
* @return mixed
*/
public static function __callStatic($name, array $args = null)
public static function __callStatic($name, ?array $args = null)
{
return call_user_func_array([self::getTestCase(), $name], $args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tad/FunctionMocker/Replacers/InstanceForger.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getPHPUnitMockObjectFor($className, array $methods)
* @param $methodName
* @param ReturnValue|null $returnValue
*/
public function setMockObjectExpectation(&$mockObject, $methodName, ReturnValue $returnValue = null)
public function setMockObjectExpectation(&$mockObject, $methodName, ?ReturnValue $returnValue = null)
{
if ($returnValue->isCallable()) {
// callback
Expand Down