Skip to content

Commit 6afea09

Browse files
Merge pull request #3 from mll-lab/improve-project-setup
Improvements to the project setup
2 parents e57e75c + 2b9f1fc commit 6afea09

11 files changed

Lines changed: 66 additions & 86 deletions

Dockerfile

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,24 @@ FROM php:${PHP_VERSION}cli
44
# Increase memory limit
55
RUN echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
66

7-
# install Composer
8-
COPY ./docker/composer.sh /root/
9-
7+
# Install Composer
8+
COPY --from=composer /usr/bin/composer /usr/bin/composer
109
RUN <<EOF
11-
set -eux;
12-
apt-get update;
13-
apt-get install -y \
14-
git \
15-
zip;
16-
rm -rf /var/lib/apt/lists/*;
17-
cd /root/;
18-
chmod 755 composer.sh;
19-
/root/composer.sh;
20-
mv /root/composer.phar /usr/local/bin/composer;
21-
rm /root/composer.sh;
10+
set -eux
11+
apt-get update
12+
apt-get install --yes git zip
13+
rm -rf /var/lib/apt/lists/*
2214
EOF
2315

24-
# install Xdebug
16+
# Install Xdebug
2517
ARG XDEBUG_ENABLED=1
26-
2718
RUN <<EOF
2819
if [ $XDEBUG_ENABLED -eq 1 ]; then
29-
pecl install xdebug;
30-
docker-php-ext-enable xdebug;
20+
pecl install xdebug
21+
docker-php-ext-enable xdebug
3122
fi
3223
EOF
3324

3425
# Sort out git
3526
RUN git config --global --add safe.directory /app
36-
37-
WORKDIR /app/
27+
WORKDIR /app

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88
[![Continuous Integration](https://github.com/DaveLiddament/test-splitter/workflows/Checks/badge.svg)](https://github.com/DaveLiddament/test-splitter/actions)
99
[![Psalm level 1](https://img.shields.io/badge/Psalm-%20level%201-brightgreen.svg)](https://github.com/DaveLiddament/test-splitter/blob/master/psalm.xml)
1010

11+
Have you got a slow running test suite?
12+
Are existing test parallelisation tools (e.g. [paratest](https://github.com/paratestphp/paratest)) not suitable as you need separate database instances?
1113

12-
13-
Have you got a slow running test suite? Are existing test parallelisation tools (e.g. [paratest](https://github.com/paratestphp/paratest)) not suitable as you need separate database instances?
14-
15-
If so PHPUnit test case splitter might help. This splits tests into batches in a deterministic way. Each batch of tests can run in separate instances (e.g. by using a matrix in github actions).
14+
If so, PHPUnit test case splitter might help.
15+
It splits tests into batches in a deterministic way.
16+
Each batch of tests can run in separate instances (e.g. by using a matrix in GitHub actions).
1617

1718
## Usage
1819

19-
To use. Install:
20+
Install via [Composer](https://getcomposer.org):
2021

21-
```bash
22+
```shell
2223
composer require --dev dave-liddament/test-splitter
2324
```
2425

25-
Test splitter (`tsplit`) takes two arguments: batch, and number of batches. The list of tests is piped into `stdin`.
26+
This package provides an executable under `vendor/bin/tsplit` that takes two arguments: batch, and number of batches.
27+
It accepts a list of tests piped into `stdin` and outputs the tests for the specified batch to `stdout`.
2628

2729
To split the tests into 4 batches and run the first batch you can do:
2830

29-
```
31+
```shell
3032
vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit 1 4`
3133
```
3234

33-
To run the second batch you'd use:
35+
To run the second batch out of 4 you'd use:
3436

35-
36-
```
37+
```shell
3738
vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit 2 4`
3839
```
3940

41+
## GitHub actions
4042

41-
## Github actions
42-
43-
Add this to your github actions:
43+
Add this to your GitHub actions:
4444

4545
```yaml
4646
jobs:
@@ -52,7 +52,7 @@ jobs:
5252
test-batch: [1, 2, 3, 4]
5353

5454
steps:
55-
# Steps to checkout code, setup environment, etc
55+
# Steps to checkout code, setup environment, etc.
5656

5757
- name: "Tests batch ${{ matrix.test--batch }}"
5858
run: vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit ${{ matrix.test-batch }} 4`
@@ -63,4 +63,4 @@ This will split the tests over 4 different jobs.
6363
## Additional documentation
6464
6565
- [Code of Conduct](docs/CodeOfConduct.md)
66-
- [Contributing](docs/Contributing.md)
66+
- [Contributing](docs/Contributing.md)

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dave-liddament/test-splitter",
3-
"description": "Splits up PHPUnit tests so they can be ran in parallel (e.g. on github actions)",
3+
"description": "Splits up PHPUnit tests so they can be ran in parallel (e.g. on GitHub actions)",
44
"type": "project",
55
"require": {
66
"php": "8.1.*|8.2.*|8.3.*|8.4.*"
@@ -42,8 +42,8 @@
4242
],
4343
"composer-validate" : "@composer validate --no-check-all --strict",
4444
"lint" : "parallel-lint src tests",
45-
"cs" : "php-cs-fixer fix -v --dry-run",
46-
"cs-fix" : "php-cs-fixer fix -v",
45+
"cs" : "php-cs-fixer fix --verbose --dry-run",
46+
"cs-fix" : "php-cs-fixer fix --verbose",
4747
"psalm" : "psalm --shepherd",
4848
"test" : "phpunit"
4949
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ services:
55
PHP_VERSION: ""
66
tty: true
77
volumes:
8-
- .:/app/:delegated
8+
- .:/app:delegated
9+
networks: []
910
php81:
1011
build:
1112
args:

docker/composer.sh

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

docs/Contributing.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,64 @@
22

33
Contributions are welcome.
44

5-
65
## Requirements for code created
76

87
test-splitter MUST support all PHP versions that are either in [active or security](https://www.php.net/supported-versions.php) support.
98

109
The maintainer will aim to add support for new PHP versions within 6 weeks of the official release.
1110

12-
1311
## Code checks
1412

15-
After writing your code run code style fixer, this will automatically format the code to the project style:
13+
After writing your code, format it according to the project style:
1614

17-
```
15+
```shell
1816
composer cs-fix
1917
```
2018

19+
Perform all quality assurance tasks that are run for continuous integration:
2120

22-
Check all the CI tasks would run.
23-
```
21+
```shell
2422
composer ci
2523
```
2624

25+
## Docker setup
2726

28-
## Docker
27+
[Dockerfile](/Dockerfile) and [docker-compose.yml](/docker-compose.yml) have been provided to help with development.
2928

30-
A docker file has been provided to help with development.
29+
### Install dependencies
3130

32-
#### Build
33-
Build the image:
31+
Run the following to install dependencies in the PHP version of your choice (e.g. 8.4):
3432

3533
```shell
36-
docker compose build
34+
docker compose run --rm php84 composer install
3735
```
3836

39-
#### Run the services
37+
### Run composer scripts
38+
39+
You can run composer scripts in any supported PHP version through Docker:
4040

41-
Start the services
4241
```shell
43-
docker compose up -d
42+
docker compose run --rm php<version> composer <script>
4443
```
4544

46-
You can run composer command. E.g. To run `composer cs-fix` on PHP 8.2
45+
For example, to run `cs-fix` on PHP 8.2:
4746

4847
```shell
49-
docker compose exec php82 composer cs-fix
48+
docker compose run --rm php82 composer cs-fix
5049
```
5150

52-
See the composer scripts section for all scripts available.
53-
54-
You can also get shell access. E.g. to get shell access on PHP 8.3:
51+
To run all validations in every supported PHP version, you can use the following command:
5552

5653
```shell
57-
docker compose exec php82 bash
54+
for v in 81 82 83 84; do docker compose run --rm php$v composer ci || break; done
5855
```
5956

57+
See [composer.json](/composer.json) section `scripts` for all available scripts.
58+
59+
### Shell access
60+
61+
You can get interactive shell access in any PHP version, e.g. on PHP 8.3:
62+
63+
```shell
64+
docker compose run --rm php83 bash
65+
```

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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/9.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
cacheResultFile=".phpunit.cache/test-results"
66
executionOrder="depends,defects"

psalm.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
<directory name="vendor"/>
1414
</ignoreFiles>
1515
</projectFiles>
16-
<plugins><pluginClass class="Psalm\PhpUnitPlugin\Plugin"/></plugins></psalm>
16+
<plugins>
17+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
18+
</plugins>
19+
</psalm>

src/CliArgumentParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(array $args)
2626
$this->denominator = $this->asInt($args[2]);
2727

2828
if ($this->numerator > $this->denominator) {
29-
throw new InvalidArgumentsException("Numerator must be less than Demoninator ({$this->denominator})");
29+
throw new InvalidArgumentsException("Numerator {$this->numerator} must be less than Denominator {$this->denominator}");
3030
}
3131
}
3232

tests/CliArgumentParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function invalidArgumentsDataProvider(): array
4949
'2',
5050
],
5151
],
52-
'denoninator is float' => [
52+
'denominator is float' => [
5353
[
5454
self::SCRIPT_NAME,
5555
'1',

0 commit comments

Comments
 (0)