Skip to content

Commit 6410a3f

Browse files
authored
Merge pull request #18 from lucatume/wrap-kagg-design-php8
Wrap PR #17
2 parents 925d699 + 1f36a40 commit 6410a3f

38 files changed

Lines changed: 299 additions & 144 deletions

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
run:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
matrix:
10+
os: [ubuntu-latest, windows-latest]
11+
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
12+
name: PHP ${{ matrix.php-version }} on ${{ matrix.os }}
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Install PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: ${{ matrix.php-version }}
22+
23+
- name: Install dependencies
24+
run: composer install
25+
26+
- name: PHPUnit tests
27+
run: "vendor/bin/phpunit"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ composer.lock
1313
patchwork.json
1414
cache/*
1515
pw-cs-*.yml
16+
.phpunit.result.cache

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
*A [Patchwork](http://antecedent.github.io/patchwork/) powered function mocker.*
44

5-
[![Build Status](https://travis-ci.org/lucatume/function-mocker.svg?branch=master)](https://travis-ci.org/lucatume/function-mocker)
5+
![Build Status](https://github.com/lucatume/function-mocker/actions/workflows/ci.yml/badge.svg)
66

77
## Show me the code
88
This can be written in a [PHPUnit](http://phpunit.de/) test suite

bin/update-tests

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
# This file updates tests according to the phpunit library used for current php version, or php version in 1st argument.
3+
# Usage:
4+
# update-tests - to update tests according to the phpunit library used for current php version.
5+
# 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.
6+
7+
# Directory with phpunit tests.
8+
TEST_DIR="tests"
9+
10+
if grep -q Microsoft /proc/version; then
11+
DEV_MODE=$(cmd.exe /c echo %COMPOSER_DEV_MODE% | sed -nr 's/\r//p')
12+
else
13+
DEV_MODE=$COMPOSER_DEV_MODE
14+
fi
15+
16+
if [[ $1 == '' && $DEV_MODE != '1' ]]; then
17+
echo "Script works with composer in dev mode only."
18+
exit 0
19+
fi
20+
21+
if [[ $1 == '' ]]; then
22+
PHP_VERSION=$(php -v | sed -nr "s/PHP ([^.]*?\.[^.]*?)\..*/\1/p")
23+
else
24+
if [[ $1 == 'revert' ]]; then
25+
# Restore test files to the current branch version.
26+
git checkout -- $TEST_DIR
27+
echo "Tests reverted to the initial state."
28+
exit 0
29+
fi
30+
PHP_VERSION=$1
31+
fi
32+
33+
echo "PHP_VERSION: $PHP_VERSION"
34+
35+
VERSION_FILE="vendor/phpunit/phpunit/src/Runner/Version.php"
36+
CURRENT_PHP_UNIT=''
37+
38+
RESULT=$(test -f $VERSION_FILE && sed -nr "s/.*new Version.+'(.+\..+)\..*'.*/\1/p" $VERSION_FILE)
39+
40+
if [[ $? == 0 ]]; then
41+
CURRENT_PHP_UNIT=$RESULT
42+
echo "CURRENT_PHP_UNIT: $CURRENT_PHP_UNIT"
43+
else
44+
echo "CURRENT_PHP_UNIT: Not found."
45+
fi
46+
47+
if [[ $PHP_VERSION == '5.6' ]]; then
48+
PHP_UNIT='5.7'
49+
elif [[ $PHP_VERSION == '7.0' ]]; then
50+
PHP_UNIT='6.5'
51+
elif [[ $PHP_VERSION == '7.1' ]]; then
52+
PHP_UNIT='7.5'
53+
elif [[ $PHP_VERSION == '7.2' ]]; then
54+
PHP_UNIT='8.5'
55+
elif [[ $PHP_VERSION == '7.3' || $PHP_VERSION == '7.4' || $PHP_VERSION == '8.0' ]]; then
56+
PHP_UNIT='9.5'
57+
fi
58+
59+
if [[ $PHP_UNIT == '' ]]; then
60+
echo "Wrong PHP version: $PHP_VERSION"
61+
exit 1
62+
fi
63+
64+
if [[ $1 == '' && $CURRENT_PHP_UNIT == "$PHP_UNIT" ]]; then
65+
# Do nothing if current version of phpunit is the same as required. Important on CI.
66+
# Anytime force update available specifying the first argument like 'update-phpunit 7.0'
67+
echo "Nothing to do with phpunit."
68+
exit 0
69+
fi
70+
71+
# Restore test files to the current branch version.
72+
git checkout -- $TEST_DIR
73+
74+
if [[ $PHP_UNIT == '5.7' || $PHP_UNIT == '6.5' || $PHP_UNIT == '7.5' ]]; then
75+
echo "Preparing tests for phpunit-$PHP_UNIT"
76+
find $TEST_DIR -type f -exec sed -i "s/: void//g" {} \;
77+
fi
78+
79+
exit 0

changelog.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. This projec
33

44
## [Unreleased][unreleased]
55

6+
## [1.4.0]
7+
### Added
8+
- PHP 8 compatibility and test coverage (thanks @kagg-design)
9+
10+
### Fixed
11+
- Windows compatibility issues (thanks @kagg-design)
12+
613
## [1.3.9]
714
### Added
815
- the `FunctionMocker::replaceInOrder` method to return values from a set from a replaced function or static method, thanks @wppunk, fixes #11
@@ -75,7 +82,9 @@ All notable changes to this project will be documented in this file. This projec
7582
### Fixed
7683
- issue where verifying the same instance replacement would result in double instance creations
7784

78-
[unreleased]: https://github.com/lucatume/function-mocker/compare/1.3.8...HEAD
85+
[unreleased]: https://github.com/lucatume/function-mocker/compare/1.4.0...HEAD
86+
[1.4.0]: https://github.com/lucatume/function-mocker/compare/1.3.9...1.4.0
87+
[1.3.9]: https://github.com/lucatume/function-mocker/compare/1.3.8...1.3.9
7988
[1.3.8]: https://github.com/lucatume/function-mocker/compare/1.3.7...1.3.8
8089
[1.3.7]: https://github.com/lucatume/function-mocker/compare/1.3.6...1.3.7
8190
[1.3.6]: https://github.com/lucatume/function-mocker/compare/1.3.5...1.3.6

composer.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@
1010
],
1111
"minimum-stability": "stable",
1212
"require": {
13-
"php": ">=5.6.0",
14-
"phpunit/phpunit": ">=5.7",
13+
"phpunit/phpunit": "5.7 - 9.5",
1514
"antecedent/patchwork": "^2.0",
1615
"lucatume/args": "^1.0"
1716
},
18-
"require-dev": {
19-
"phpunit/phpunit": "^5.7"
20-
},
2117
"autoload": {
2218
"psr-0": {
2319
"tad\\FunctionMocker": "src"
2420
},
2521
"files": [
26-
"src/shims.php",
2722
"src/functions.php"
2823
]
24+
},
25+
"bin": [
26+
"bin/update-tests"
27+
],
28+
"scripts": {
29+
"pre-update-cmd": "update-tests",
30+
"update-tests": "update-tests",
31+
"revert-tests": "composer update-tests revert",
32+
"phpcs": "phpcs --colors --standard=phpcs.xml",
33+
"unit": "phpunit"
2934
}
3035
}

phpunit.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.1/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
44
bootstrap="tests/_bootstrap.php"
5-
forceCoversAnnotation="true"
5+
forceCoversAnnotation="false"
66
beStrictAboutCoversAnnotation="true"
77
beStrictAboutOutputDuringTests="true"
88
beStrictAboutTodoAnnotatedTests="true"
99
colors="true"
1010
verbose="true">
11-
<testsuite>
11+
<testsuite name="function-mocker">
1212
<directory suffix="Test.php">tests</directory>
1313
</testsuite>
14-
15-
<filter>
16-
<whitelist processUncoveredFilesFromWhitelist="true">
17-
<directory suffix=".php">src</directory>
18-
</whitelist>
19-
</filter>
2014
</phpunit>

src/shims.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/tad/FunctionMocker/Call/CallHandlerInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
namespace tad\FunctionMocker\Call;
44

55

6-
use PHPUnit_Framework_MockObject_Matcher_InvokedRecorder;
6+
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
77
use tad\FunctionMocker\ReplacementRequest;
88

99
interface CallHandlerInterface
1010
{
1111

1212
/**
13-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $invokedRecorder
13+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder|InvocationOrder $invokedRecorder
1414
*
1515
* @return mixed
1616
*/
17-
public function setInvokedRecorder(PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $invokedRecorder);
17+
public function setInvokedRecorder($invokedRecorder);
1818

1919
/**
2020
* @param ReplacementRequest $request

0 commit comments

Comments
 (0)