Skip to content

Commit bb24df1

Browse files
authored
Update for PHP 8.4 / PHPUnit 11.5 (#903)
1 parent cd3cc7c commit bb24df1

File tree

9 files changed

+49
-104
lines changed

9 files changed

+49
-104
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ updates:
99
interval: 'monthly'
1010
groups:
1111
github-actions:
12-
patterns: '*'
12+
patterns:
13+
- '*'
1314

1415
# Keep dependencies for Composer up-to-date
1516
- package-ecosystem: 'composer'
@@ -18,4 +19,5 @@ updates:
1819
interval: 'monthly'
1920
groups:
2021
composer:
21-
patterns: '*'
22+
patterns:
23+
- '*'

.github/workflows/exercise-lint-phpcs-psr-12.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
php-version: [8.2]
17+
php-version: [8.4]
1818
os: [ubuntu-24.04]
1919

2020
steps:

.github/workflows/exercise-tests-phpunit-10.yml

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

.github/workflows/exercise-tests-phpunit-11.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
# php-version: [8.2, 8.3, 8.4]
18-
# os: [ubuntu-24.04, windows-2022, macOS-14]
19-
php-version: [8.4]
20-
os: [ubuntu-24.04]
17+
php-version: [8.2, 8.3, 8.4]
18+
os: [ubuntu-24.04, windows-2022, macOS-14]
2119

2220
steps:
2321
- name: Set git line endings
@@ -40,7 +38,6 @@ jobs:
4038
chmod +x bin/phpunit-11.phar
4139
4240
- name: Test exercises
43-
continue-on-error: true
4441
shell: bash
4542
env:
4643
PHPUNIT_BIN: 'bin/phpunit-11.phar'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The following system dependencies are required:
1111

1212
- `composer`, as recommended in the [PHP track installation docs][exercism-track-installation-composer].
1313
- [`bash` shell][gnu-bash].
14-
- PHP V8.3+ CLI.
14+
- PHP V8.4+ CLI.
1515
- An active Internet connection for installing required tools / composer packages.
1616

1717
Run the following command to get started with this project:

docs/INSTALLATION.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Which version to chose?
44

55
We encourage to use a stable PHP release with active support.
6-
Currently this is **PHP 8.1, 8.2 and 8.3**.
6+
Currently this is **PHP 8.2, 8.3 and 8.4**.
77
Details on current releases and their timelines can be found in [the official PHP documentation](https://www.php.net/supported-versions.php).
88

99
## Install PHP
@@ -38,9 +38,9 @@ For further instructions, read the PHP manual on [Installation on Unix systems](
3838

3939
While PHP is often bundled with macOS, it is often outdated.
4040
We recommended installing PHP through [Homebrew](https://brew.sh/).
41-
You can install Homebrew following the instructions [here](https://brew.sh/#install).
41+
You can install Homebrew following the instructions [on their homepage](https://brew.sh/#install).
4242

43-
To confirm its installation try the following command, it should output Homebrew `4.2.x` at the time of this writing.
43+
To confirm its installation try the following command, it should output Homebrew `4.5.x` at the time of this writing.
4444

4545
```shell
4646
brew --version
@@ -49,10 +49,10 @@ brew --version
4949
Install PHP via homebrew
5050

5151
```shell
52-
brew install php@8.3
52+
brew install php@8.4
5353
```
5454

55-
This should display the now installed version of PHP, at least version `8.1.0`.
55+
This should display the now installed version of PHP, at least version `8.2.0`.
5656

5757
```shell
5858
php -v
@@ -77,12 +77,12 @@ You will also need [Docker](https://docs.docker.com/engine/install/).
7777

7878
If you want to use a different OS, see instruction on [php.net/manual/en/install](https://www.php.net/manual/en/install.php).
7979

80-
## Install Composer
81-
82-
Install [Composer](https://getcomposer.org) following your devices OS [installation instructions](https://getcomposer.org/doc/00-intro.md). We recommend installing it globally for ease of use.
83-
8480
## Install PHPUnit
8581

82+
~~~~exercism/note
83+
PHPUnit 12 is not supported, yet!
84+
~~~~
85+
8686
### Via PHP Archive (PHAR)
8787

8888
The easiest way to use PHPUnit for Exercism exercises is downloading a distribution that is packaged as a PHP Archive (PHAR), which is also the recommended way to use PHPUnit.
@@ -91,7 +91,7 @@ Store the PHAR where you stored the `exercism` CLI to run PHPUnit from wherever
9191
You can download a release of PHPUnit packages as a PHP archive:
9292

9393
```shell
94-
wget -O phpunit.phar https://phar.phpunit.de/phpunit-10.phar
94+
wget -O phpunit.phar https://phar.phpunit.de/phpunit-11.phar
9595
```
9696

9797
Then make the downloaded file executable:
@@ -114,20 +114,26 @@ phpunit --version
114114

115115
The output should look like this:
116116

117+
```text
118+
PHPUnit 11.5.45 by Sebastian Bergmann and contributors.
117119
```
118-
PHPUnit 10.5.45 by Sebastian Bergmann and contributors.
119120

120-
```
121+
You can also follow the official [Installing PHPUnit instructions](https://docs.phpunit.de/en/11.5/installation.html#installing-phpunit) to install PHPUnit.
121122

123+
### Via Composer
122124

123-
You can also follow the official [Installing PHPUnit instructions](https://docs.phpunit.de/en/10.5/installation.html#installing-phpunit) to install PHPUnit.
125+
PHPUnit version 11 can also be installed via [Composer](https://getcomposer.org).
124126

125-
### Via Composer
127+
#### Install Composer
128+
129+
Install [Composer](https://getcomposer.org) following your devices OS [installation instructions](https://getcomposer.org/doc/00-intro.md). We recommend installing it globally for ease of use.
130+
131+
#### Add PHPUnit as global tool
126132

127-
PHPUnit version 10 can also be installed globally via [Composer](https://getcomposer.org), using the following command:
133+
Using the following command:
128134

129135
```shell
130-
composer global require phpunit/phpunit ^10.5
136+
composer global require phpunit/phpunit ^11.5
131137
```
132138

133-
Please make sure you install version 10.5 or later.
139+
Please make sure you install version 11.5 or later.

exercises/practice/robot-name/RobotNameTest.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,42 +73,26 @@ public function testResetName(): void
7373
$this->assertMatchesRegularExpression('/\w{2}\d{3}/', $name2);
7474
}
7575

76-
/**
77-
* PHPUnit ^10.5 has an issue with
78-
* $this->assertArrayNotHasKey($name, $names, sprintf...
79-
* that leads to test timeouts. This is fixed in PHPUnit ^11.
80-
* Revert workaround
81-
* $this->assertFalse(isset($names[$name]), sprintf...
82-
* when upgrading.
83-
*/
84-
public function testNameArentRecycled(): void
76+
public function testNamesArentRecycled(): void
8577
{
8678
$names = [];
8779

8880
for ($i = 0; $i < 10000; $i++) {
8981
$name = $this->robot->getName();
90-
$this->assertFalse(isset($names[$name]), sprintf('Name %s reissued after Reset.', $name));
82+
$this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after Reset.', $name));
9183
$names[$name] = true;
9284
$this->robot->reset();
9385
}
9486
}
9587

96-
/**
97-
* PHPUnit ^10.5 has an issue with
98-
* $this->assertArrayNotHasKey($name, $names, sprintf...
99-
* that leads to test timeouts. This is fixed in PHPUnit ^11.
100-
* Revert workaround
101-
* $this->assertFalse(isset($names[$name]), sprintf...
102-
* when upgrading.
103-
*/
10488
// This test is optional.
10589
public function testNameUniquenessManyRobots(): void
10690
{
10791
$names = [];
10892

10993
for ($i = 0; $i < 10000; $i++) {
11094
$name = (new Robot())->getName();
111-
$this->assertFalse(isset($names[$name]), sprintf('Name %s reissued after %d robots', $name, $i));
95+
$this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after %d robots', $name, $i));
11296
$names[$name] = true;
11397
}
11498
}

exercises/shared/.docs/help.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Help
22

3-
To get help if you're having trouble, you can use one of the following resources:
3+
To get help if you're having trouble, you can use one of the following resources:
44

5-
- [/r/php](https://www.reddit.com/r/php) is the PHP subreddit.
6-
- [StackOverflow](https://stackoverflow.com/questions/tagged/php) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
5+
- [/r/php](https://www.reddit.com/r/php) is the PHP subreddit.
6+
- [StackOverflow](https://stackoverflow.com/questions/tagged/php) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

exercises/shared/.docs/tests.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
1. Go to the root of your PHP exercise directory, which is `<EXERCISM_WORKSPACE>/php`.
44
To find the Exercism workspace run
55

6-
exercism debug | grep Workspace
6+
```shell
7+
exercism workspace
8+
```
79

8-
2. Get [PHPUnit] if you don't have it already.
10+
2. Install [PHPUnit] if you don't have it already.
11+
3. Execute the tests with:
912

10-
wget -O phpunit https://phar.phpunit.de/phpunit-10.phar
11-
chmod +x phpunit
12-
./phpunit --version
13-
14-
3. Execute the tests:
15-
16-
./phpunit test_file.php
13+
```shell
14+
phpunit test_file.php
15+
```
1716

1817
For example, to run the tests for the Hello World exercise, you would run:
1918

20-
./phpunit HelloWorldTest.php
19+
```shell
20+
phpunit HelloWorldTest.php
21+
```
2122

22-
[PHPUnit]: https://phpunit.de
23+
[PHPUnit]: https://exercism.org/docs/tracks/php/installation#h-via-php-archive-phar

0 commit comments

Comments
 (0)