Skip to content

Commit e833060

Browse files
PHP 8.5 compatibility
1 parent e3fac8b commit e833060

File tree

8 files changed

+143
-31
lines changed

8 files changed

+143
-31
lines changed

.github/workflows/static.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ on:
77
jobs:
88
phpstan:
99
name: PHPStan
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-24.04
1111

1212
steps:
1313
- name: Checkout code
14-
uses: actions/checkout@v4
14+
uses: actions/checkout@v5
1515

1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
@@ -23,14 +23,14 @@ jobs:
2323
update: true
2424

2525
- name: Install Dependencies
26-
uses: nick-invision/retry@v2
26+
uses: nick-invision/retry@v3
2727
with:
2828
timeout_minutes: 5
2929
max_attempts: 5
3030
command: composer update --no-interaction --no-progress
3131

3232
- name: Install PHPStan
33-
uses: nick-invision/retry@v2
33+
uses: nick-invision/retry@v3
3434
with:
3535
timeout_minutes: 5
3636
max_attempts: 5
@@ -41,11 +41,11 @@ jobs:
4141

4242
psalm:
4343
name: Psalm
44-
runs-on: ubuntu-22.04
44+
runs-on: ubuntu-24.04
4545

4646
steps:
4747
- name: Checkout code
48-
uses: actions/checkout@v4
48+
uses: actions/checkout@v5
4949

5050
- name: Setup PHP
5151
uses: shivammathur/setup-php@v2
@@ -57,14 +57,14 @@ jobs:
5757
update: true
5858

5959
- name: Install Dependencies
60-
uses: nick-invision/retry@v2
60+
uses: nick-invision/retry@v3
6161
with:
6262
timeout_minutes: 5
6363
max_attempts: 5
6464
command: composer update --no-interaction --no-progress
6565

6666
- name: Install Psalm
67-
uses: nick-invision/retry@v2
67+
uses: nick-invision/retry@v3
6868
with:
6969
timeout_minutes: 5
7070
max_attempts: 5

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ on:
77
jobs:
88
tests:
99
name: PHP ${{ matrix.php }}
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-24.04
1111

1212
strategy:
1313
matrix:
14-
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
14+
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
1515

1616
steps:
1717
- name: Checkout Code
18-
uses: actions/checkout@v4
18+
uses: actions/checkout@v5
1919

2020
- name: Setup PHP
2121
uses: shivammathur/setup-php@v2
@@ -30,7 +30,7 @@ jobs:
3030
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
3131

3232
- name: Install PHP Dependencies
33-
uses: nick-invision/retry@v2
33+
uses: nick-invision/retry@v3
3434
with:
3535
timeout_minutes: 5
3636
max_attempts: 5

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
install:
2-
@docker run -it -w /data -v ${PWD}:/data:delegated -v ~/.composer:/root/.composer:delegated --entrypoint composer --rm registry.gitlab.com/grahamcampbell/php:8.3-base update
3-
@docker run -it -w /data -v ${PWD}:/data:delegated -v ~/.composer:/root/.composer:delegated --entrypoint composer --rm registry.gitlab.com/grahamcampbell/php:8.3-base bin all update
2+
@docker run -it -w /data -v ${PWD}:/data:delegated -v ~/.composer:/root/.composer:delegated --entrypoint composer --rm registry.gitlab.com/grahamcampbell/php:8.4-base update
3+
@docker run -it -w /data -v ${PWD}:/data:delegated -v ~/.composer:/root/.composer:delegated --entrypoint composer --rm registry.gitlab.com/grahamcampbell/php:8.4-base bin all update
44

55
phpunit:
6-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit --rm registry.gitlab.com/grahamcampbell/php:8.3-cli
6+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit --rm registry.gitlab.com/grahamcampbell/php:8.4-cli
77

88
phpstan-analyze:
9-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan --rm registry.gitlab.com/grahamcampbell/php:8.3-cli analyze
9+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan --rm registry.gitlab.com/grahamcampbell/php:8.4-cli analyze
1010

1111
phpstan-baseline:
12-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan --rm registry.gitlab.com/grahamcampbell/php:8.3-cli analyze --generate-baseline
12+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan --rm registry.gitlab.com/grahamcampbell/php:8.4-cli analyze --generate-baseline
1313

1414
psalm-analyze:
15-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/psalm.phar --rm registry.gitlab.com/grahamcampbell/php:8.3-cli
15+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/psalm.phar --rm registry.gitlab.com/grahamcampbell/php:8.4-cli
1616

1717
psalm-baseline:
18-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/psalm.phar --rm registry.gitlab.com/grahamcampbell/php:8.3-cli --set-baseline=psalm-baseline.xml
18+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/psalm.phar --rm registry.gitlab.com/grahamcampbell/php:8.4-cli --set-baseline=psalm-baseline.xml
1919

2020
psalm-show-info:
21-
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/psalm.phar --rm registry.gitlab.com/grahamcampbell/php:8.3-cli --show-info=true
21+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/psalm.phar --rm registry.gitlab.com/grahamcampbell/php:8.4-cli --show-info=true
2222

2323
test: phpunit phpstan-analyze psalm-analyze
2424

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require-dev": {
2222
"bamarni/composer-bin-plugin": "^1.8.2",
23-
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
23+
"phpunit/phpunit": "^8.5.44 || ^9.6.25 || ^10.5.53 || ^11.5.34"
2424
},
2525
"autoload": {
2626
"psr-4": {

tests/PhpOption/Tests/EnsureTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
use PhpOption\Some;
88
use PHPUnit\Framework\TestCase;
99

10-
/**
11-
* Tests for Option::ensure() method.
12-
*
13-
* @covers Option::ensure
14-
*/
1510
class EnsureTest extends TestCase
1611
{
1712
private static function ensure($value, $noneValue = null): Option

tests/PhpOption/Tests/LazyOptionTest.php

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ public function testFoldLeftRight(): void
178178
$callback = function () {
179179
};
180180

181-
$option = self::getMockForAbstractClass(Option::class);
181+
// Use TestOption as a concrete implementation to test with
182+
$option = self::createPartialMock(TestOption::class, ['foldLeft', 'foldRight']);
182183
$option->expects(self::once())
183184
->method('foldLeft')
184185
->with(5, $callback)
185-
->will(self::returnValue(6));
186+
->willReturn(6);
186187
$lazyOption = new LazyOption(function () use ($option) {
187188
return $option;
188189
});
@@ -191,10 +192,126 @@ public function testFoldLeftRight(): void
191192
$option->expects(self::once())
192193
->method('foldRight')
193194
->with(5, $callback)
194-
->will(self::returnValue(6));
195+
->willReturn(6);
195196
$lazyOption = new LazyOption(function () use ($option) {
196197
return $option;
197198
});
198199
self::assertSame(6, $lazyOption->foldRight(5, $callback));
199200
}
200201
}
202+
203+
class TestOption extends Option
204+
{
205+
private $value;
206+
207+
public function __construct($value = null)
208+
{
209+
$this->value = $value;
210+
}
211+
212+
public function get()
213+
{
214+
return $this->value;
215+
}
216+
217+
public function getOrElse($default)
218+
{
219+
return $this->isDefined() ? $this->value : $default;
220+
}
221+
222+
public function getOrCall($callable)
223+
{
224+
return $this->isDefined() ? $this->value : call_user_func($callable);
225+
}
226+
227+
public function getOrThrow(\Exception $ex)
228+
{
229+
if ($this->isDefined()) {
230+
return $this->value;
231+
}
232+
throw $ex;
233+
}
234+
235+
public function isEmpty()
236+
{
237+
return $this->value === null;
238+
}
239+
240+
public function isDefined()
241+
{
242+
return $this->value !== null;
243+
}
244+
245+
public function orElse(Option $else)
246+
{
247+
return $this->isDefined() ? $this : $else;
248+
}
249+
250+
public function ifDefined($callable)
251+
{
252+
if ($this->isDefined()) {
253+
call_user_func($callable, $this->value);
254+
}
255+
}
256+
257+
public function forAll($callable)
258+
{
259+
if ($this->isDefined()) {
260+
call_user_func($callable, $this->value);
261+
}
262+
}
263+
264+
public function map($callable)
265+
{
266+
return $this->isDefined() ? new self(call_user_func($callable, $this->value)) : $this;
267+
}
268+
269+
public function flatMap($callable)
270+
{
271+
return $this->isDefined() ? call_user_func($callable, $this->value) : $this;
272+
}
273+
274+
public function filter($callable)
275+
{
276+
return $this->isDefined() && call_user_func($callable, $this->value) ? $this : None::create();
277+
}
278+
279+
public function filterNot($callable)
280+
{
281+
return $this->isDefined() && !call_user_func($callable, $this->value) ? $this : None::create();
282+
}
283+
284+
public function select($value)
285+
{
286+
return $this->isDefined() && $this->value === $value ? $this : None::create();
287+
}
288+
289+
public function reject($value)
290+
{
291+
return $this->isDefined() && $this->value !== $value ? $this : None::create();
292+
}
293+
294+
public function foldLeft($initialValue, $callable)
295+
{
296+
if ($this->isDefined()) {
297+
return call_user_func($callable, $initialValue, $this->value);
298+
}
299+
return $initialValue;
300+
}
301+
302+
public function foldRight($initialValue, $callable)
303+
{
304+
if ($this->isDefined()) {
305+
return call_user_func($callable, $this->value, $initialValue);
306+
}
307+
return $initialValue;
308+
}
309+
310+
public function getIterator(): \Traversable
311+
{
312+
if ($this->isDefined()) {
313+
return new \ArrayIterator([$this->value]);
314+
}
315+
return new \ArrayIterator([]);
316+
}
317+
}

vendor-bin/phpstan/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"phpstan/phpstan": "1.11.7"
3+
"phpstan/phpstan": "2.122"
44
},
55
"config": {
66
"preferred-install": "dist"

vendor-bin/psalm/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"psalm/phar": "5.25.0"
3+
"psalm/phar": "6.13.1"
44
},
55
"config": {
66
"preferred-install": "dist"

0 commit comments

Comments
 (0)