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
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ updates:
interval: 'monthly'
groups:
github-actions:
patterns: '*'
patterns:
- '*'

# Keep dependencies for Composer up-to-date
- package-ecosystem: 'composer'
Expand All @@ -18,4 +19,5 @@ updates:
interval: 'monthly'
groups:
composer:
patterns: '*'
patterns:
- '*'
2 changes: 1 addition & 1 deletion .github/workflows/exercise-lint-phpcs-psr-12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [8.2]
php-version: [8.4]
os: [ubuntu-24.04]

steps:
Expand Down
45 changes: 0 additions & 45 deletions .github/workflows/exercise-tests-phpunit-10.yml

This file was deleted.

7 changes: 2 additions & 5 deletions .github/workflows/exercise-tests-phpunit-11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
# php-version: [8.2, 8.3, 8.4]
# os: [ubuntu-24.04, windows-2022, macOS-14]
php-version: [8.4]
os: [ubuntu-24.04]
php-version: [8.2, 8.3, 8.4]
os: [ubuntu-24.04, windows-2022, macOS-14]

steps:
- name: Set git line endings
Expand All @@ -40,7 +38,6 @@ jobs:
chmod +x bin/phpunit-11.phar

- name: Test exercises
continue-on-error: true
shell: bash
env:
PHPUNIT_BIN: 'bin/phpunit-11.phar'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The following system dependencies are required:

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

Run the following command to get started with this project:
Expand Down
40 changes: 23 additions & 17 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Which version to chose?

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

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

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

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

```shell
brew --version
Expand All @@ -49,10 +49,10 @@ brew --version
Install PHP via homebrew

```shell
brew install php@8.3
brew install php@8.4
```

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

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

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

## Install Composer

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.

## Install PHPUnit

~~~~exercism/note
PHPUnit 12 is not supported, yet!
~~~~

### Via PHP Archive (PHAR)

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.
Expand All @@ -91,7 +91,7 @@ Store the PHAR where you stored the `exercism` CLI to run PHPUnit from wherever
You can download a release of PHPUnit packages as a PHP archive:

```shell
wget -O phpunit.phar https://phar.phpunit.de/phpunit-10.phar
wget -O phpunit.phar https://phar.phpunit.de/phpunit-11.phar
```

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

The output should look like this:

```text
PHPUnit 11.5.45 by Sebastian Bergmann and contributors.
```
PHPUnit 10.5.45 by Sebastian Bergmann and contributors.

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

### Via Composer

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

### Via Composer
#### Install Composer

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.

#### Add PHPUnit as global tool

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

```shell
composer global require phpunit/phpunit ^10.5
composer global require phpunit/phpunit ^11.5
```

Please make sure you install version 10.5 or later.
Please make sure you install version 11.5 or later.
22 changes: 3 additions & 19 deletions exercises/practice/robot-name/RobotNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,26 @@ public function testResetName(): void
$this->assertMatchesRegularExpression('/\w{2}\d{3}/', $name2);
}

/**
* PHPUnit ^10.5 has an issue with
* $this->assertArrayNotHasKey($name, $names, sprintf...
* that leads to test timeouts. This is fixed in PHPUnit ^11.
* Revert workaround
* $this->assertFalse(isset($names[$name]), sprintf...
* when upgrading.
*/
public function testNameArentRecycled(): void
public function testNamesArentRecycled(): void
{
$names = [];

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

/**
* PHPUnit ^10.5 has an issue with
* $this->assertArrayNotHasKey($name, $names, sprintf...
* that leads to test timeouts. This is fixed in PHPUnit ^11.
* Revert workaround
* $this->assertFalse(isset($names[$name]), sprintf...
* when upgrading.
*/
// This test is optional.
public function testNameUniquenessManyRobots(): void
{
$names = [];

for ($i = 0; $i < 10000; $i++) {
$name = (new Robot())->getName();
$this->assertFalse(isset($names[$name]), sprintf('Name %s reissued after %d robots', $name, $i));
$this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after %d robots', $name, $i));
$names[$name] = true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions exercises/shared/.docs/help.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Help

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

- [/r/php](https://www.reddit.com/r/php) is the PHP subreddit.
- [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.
- [/r/php](https://www.reddit.com/r/php) is the PHP subreddit.
- [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.
23 changes: 12 additions & 11 deletions exercises/shared/.docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
1. Go to the root of your PHP exercise directory, which is `<EXERCISM_WORKSPACE>/php`.
To find the Exercism workspace run

exercism debug | grep Workspace
```shell
exercism workspace
```

2. Get [PHPUnit] if you don't have it already.
2. Install [PHPUnit] if you don't have it already.
3. Execute the tests with:

wget -O phpunit https://phar.phpunit.de/phpunit-10.phar
chmod +x phpunit
./phpunit --version

3. Execute the tests:

./phpunit test_file.php
```shell
phpunit test_file.php
```

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

./phpunit HelloWorldTest.php
```shell
phpunit HelloWorldTest.php
```

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