Skip to content

Commit f27a9f0

Browse files
zero-to-proddavid_smith
andauthored
maint/doc (#4)
* maint/doc Updated `.gitattributes`. * maint/doc Updated `.github/workflows/test.yml`. * maint/doc Updated `.gitignore`. * maint/doc Updated `README.md`. * maint/doc Renamed `logo.png` to `art/logo.png`. * maint/doc Created `art/socialcard.png`. * maint/doc Updated `phpunit.xml`. * Deleted unused files. * maint/doc Updated `.gitignore`. * maint/doc Updated `test.sh`. * maint/doc Created `dock`. * maint/doc Created `docker-compose.yml`. * maint/doc Created `docker/`. --------- Co-authored-by: david_smith <david_smith@sweetwater.com>
1 parent da09527 commit f27a9f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+615
-557
lines changed

.gitattributes

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,8 @@
77
/CONTRIBUTING.md export-ignore
88
/docker-compose.yml export-ignore
99
/LICENSE.md export-ignore
10-
/logo.png export-ignore
11-
/phpunit.xml export-ignore
12-
/phpunit71.xml export-ignore
13-
/phpunit72.xml export-ignore
14-
/phpunit73.xml export-ignore
15-
/phpunit74.xml export-ignore
16-
/phpunit80.xml export-ignore
17-
/phpunit81.xml export-ignore
18-
/phpunit82.xml export-ignore
19-
/phpunit83.xml export-ignore
20-
/phpunit84.xml export-ignore
10+
/art/ export-ignore
2111
/README.md export-ignore
2212
/SECURITY.md export-ignore
23-
/test.sh export-ignore
13+
/test.sh export-ignore
14+
/dock export-ignore

.github/workflows/test.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12-
services:
13-
docker:
14-
image: docker:20.10.7
15-
options: --privileged
1612

1713
strategy:
1814
matrix:
19-
php-version: [84, 83, 82, 81, 80, 74, 73, 72, 71]
15+
php-version: ["8.4", "8.3", "8.2", "8.1", "8.0", "7.4", "7.3", "7.2", "7.1"]
2016

2117
steps:
2218
- uses: actions/checkout@v4
2319

24-
- name: Install dependencies for PHP${{ matrix.php-version }}
25-
run: |
26-
docker compose run --rm php${{ matrix.php-version }}composer composer update --no-cache
20+
- name: Create .env
21+
run: touch .env
2722

28-
- name: Run PHPUnit tests for PHP${{ matrix.php-version }}
23+
- name: Set PHP version in .env
2924
run: |
30-
docker compose run --rm php${{ matrix.php-version }} vendor/bin/phpunit --configuration phpunit${{ matrix.php-version }}.xml
25+
echo "PHP_COMPOSER=${{ matrix.php-version }}" >> .env
26+
echo "PHP_VERSION=${{ matrix.php-version }}" >> .env
27+
28+
- name: Install dependencies (composer update) for PHP
29+
run: sh dock composer update
30+
31+
- name: Run PHPUnit tests for PHP
32+
run: sh dock test

.gitignore

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ composer.lock
44
.phpunit.result.cache
55
.php-cs-fixer.cache
66
/.phpunit.cache/
7-
/vendor-php71/
8-
/vendor-php72/
9-
/vendor-php73/
10-
/vendor-php74/
11-
/vendor-php80/
12-
/vendor-php81/
13-
/vendor-php82/
14-
/vendor-php83/
15-
/vendor-php84/
7+
8+
.vendor/
9+
.env

README.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Zerotoprod\Psr4Classname
22

3-
![](./logo.png)
3+
![](art/logo.png)
44

55
[![Repo](https://img.shields.io/badge/github-gray?logo=github)](https://github.com/zero-to-prod/psr4-classname)
66
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/zero-to-prod/psr4-classname/test.yml?label=tests)](https://github.com/zero-to-prod/psr4-classname/actions)
@@ -17,7 +17,11 @@
1717
- [Requirements](#requirements)
1818
- [Installation](#installation)
1919
- [Usage](#usage)
20-
- [Testing](#testing)
20+
- [Local Development](#local-development)
21+
- [Prerequisites](#prerequisites)
22+
- [Initializing](#initializing)
23+
- [Testing](#testing)
24+
- [Configuration](#configuration)
2125
- [Contributing](#contributing)
2226

2327
## Introduction
@@ -46,12 +50,57 @@ use Zerotoprod\Psr4Classname\Classname;
4650
Classname::generate('weird%characters*in^name', '.php'); // 'WeirdCharactersInName.php';
4751
```
4852

49-
## Testing
53+
## Local Development
54+
55+
This project provides a convenient [dock](https://github.com/zero-to-prod/dock) script to simplify local development workflows within Docker
56+
containers.
57+
58+
You can use this script to initialize the project, manage Composer dependencies, and run tests in a consistent PHP environment.
59+
60+
### Prerequisites
61+
62+
- Docker installed and running
63+
- A `.env` file (created automatically via the `dock init` command, if it doesn’t already exist)
64+
65+
### Initializing
66+
67+
Use the following commands to set up the project:
68+
69+
```shell
70+
sh dock init
71+
sh dock composer update
72+
```
73+
74+
### Testing
75+
76+
This command runs PHPUnit inside the Docker container, using the PHP version specified in your `.env` file.
77+
You can modify or extend this script to include additional tests or commands as needed.
5078

5179
```shell
52-
./vendor/bin/phpunit
80+
sh dock test
5381
```
5482

83+
Run the test suite with all versions of php:
84+
85+
```shell
86+
sh test.sh
87+
```
88+
89+
### Configuration
90+
91+
Before starting development, verify that your `.env` file contains the correct settings.
92+
93+
You can specify which PHP version to use for local development, debugging, and Composer operations by updating these variables in your `.env` file:
94+
95+
```dotenv
96+
PHP_VERSION=8.1
97+
PHP_DEBUG=8.1
98+
PHP_COMPOSER=8.1
99+
```
100+
101+
Make sure these values reflect the PHP versions you intend to use.
102+
If the `.env` file does not exist, run the `sh dock init` command to create one from the `.env.example` template.
103+
55104
## Contributing
56105

57106
Contributions, issues, and feature requests are welcome!

logo.png renamed to art/logo.png

File renamed without changes.

art/socialcard.png

64 KB
Loading

dock

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
usage() {
6+
cat <<EOF
7+
Usage: $0 <command> [options]
8+
9+
Commands:
10+
init Initialize the .env file from .env.example if it doesn't exist.
11+
test Run PHPUnit tests using the specified PHP version.
12+
composer Run Composer commands using the specified PHP version.
13+
<service> Run a specified Docker service with optional arguments.
14+
15+
Examples:
16+
$0 init
17+
$0 test --filter=MyTest
18+
$0 composer install
19+
$0 php8.1 bash
20+
EOF
21+
exit 1
22+
}
23+
24+
if [ "$#" -lt 1 ]; then
25+
usage
26+
fi
27+
28+
run_service() {
29+
local service=$1
30+
shift
31+
if ! docker compose run --rm "$service" "$@"; then
32+
exit 1
33+
fi
34+
}
35+
36+
case "$1" in
37+
init)
38+
if [ ! -f ".env" ]; then
39+
cp ".env.example" ".env"
40+
echo "cp '.env.example' '.env'"
41+
fi
42+
exit 0;
43+
;;
44+
esac
45+
46+
if [ ! -f ".env" ]; then
47+
echo "Project does not have a .env file. Please provide one or run: dock init"
48+
exit 0
49+
fi
50+
51+
PHP_VERSION=$(grep "^PHP_VERSION=" .env | cut -d '=' -f2-)
52+
53+
case "$1" in
54+
test)
55+
shift
56+
run_service "php${PHP_VERSION}" vendor/bin/phpunit "$@"
57+
;;
58+
build)
59+
shift
60+
docker compose build "php${PHP_VERSION}" "$@"
61+
docker compose build "debug${PHP_VERSION}" "$@"
62+
docker compose build "composer${PHP_VERSION}" "$@"
63+
;;
64+
composer)
65+
shift
66+
run_service "composer${PHP_VERSION}" composer "$@"
67+
;;
68+
*)
69+
run_service "$@"
70+
;;
71+
esac

0 commit comments

Comments
 (0)