Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f993819
maint/dock Updated `.gitattributes`.
Jan 13, 2025
99a8ace
maint/dock Updated `.github/workflows/test.yml`.
Jan 13, 2025
d1da900
maint/dock Updated `.gitignore`.
Jan 13, 2025
0072a65
maint/dock Updated `README.md`.
Jan 13, 2025
2db8139
maint/dock Created `dock`.
Jan 13, 2025
0b5829b
maint/dock Updated `docker-compose.yml`.
Jan 13, 2025
0f7a3aa
maint/dock Created `docker/7.1/.gitignore`.
Jan 13, 2025
baa6507
maint/dock Created `docker/7.1/Dockerfile`.
Jan 13, 2025
7a3f8fa
maint/dock Created `docker/7.1/php.ini`.
Jan 13, 2025
06718e0
maint/dock Created `docker/7.2/.gitignore`.
Jan 13, 2025
c3fbf5d
maint/dock Created `docker/7.2/Dockerfile`.
Jan 13, 2025
16237fc
maint/dock Created `docker/7.2/php.ini`.
Jan 13, 2025
15b94d7
maint/dock Created `docker/7.3/.gitignore`.
Jan 13, 2025
0ec21b3
maint/dock Created `docker/7.3/Dockerfile`.
Jan 13, 2025
b1f917e
maint/dock Created `docker/7.3/php.ini`.
Jan 13, 2025
48c6c68
maint/dock Created `docker/7.4/.gitignore`.
Jan 13, 2025
f82caf1
maint/dock Created `docker/7.4/Dockerfile`.
Jan 13, 2025
1abc72d
maint/dock Created `docker/7.4/php.ini`.
Jan 13, 2025
dbf2a30
maint/dock Created `docker/8.0/.gitignore`.
Jan 13, 2025
58e6783
maint/dock Created `docker/8.0/Dockerfile`.
Jan 13, 2025
39a666b
maint/dock Created `docker/8.0/php.ini`.
Jan 13, 2025
eeee5b1
maint/dock Created `docker/8.1/.gitignore`.
Jan 13, 2025
c2746e4
maint/dock Created `docker/8.1/Dockerfile`.
Jan 13, 2025
40c3c41
maint/dock Created `docker/8.1/php.ini`.
Jan 13, 2025
68d5a32
maint/dock Created `docker/8.2/.gitignore`.
Jan 13, 2025
5a4f004
maint/dock Created `docker/8.2/Dockerfile`.
Jan 13, 2025
045354b
maint/dock Created `docker/8.2/php.ini`.
Jan 13, 2025
9033e49
maint/dock Created `docker/8.3/.gitignore`.
Jan 13, 2025
4d5be94
maint/dock Created `docker/8.3/Dockerfile`.
Jan 13, 2025
871be02
maint/dock Created `docker/8.3/php.ini`.
Jan 13, 2025
1dff834
maint/dock Created `docker/8.4/.gitignore`.
Jan 13, 2025
b513693
maint/dock Created `docker/8.4/Dockerfile`.
Jan 13, 2025
322101a
maint/dock Created `docker/8.4/php.ini`.
Jan 13, 2025
288d282
maint/dock Updated `phpunit.xml`.
Jan 13, 2025
5dd9484
maint/dock Updated `test.sh`.
Jan 13, 2025
e34f290
Delete unused files.
Jan 13, 2025
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
15 changes: 4 additions & 11 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@
/CONTRIBUTING.md export-ignore
/docker-compose.yml export-ignore
/LICENSE.md export-ignore
/logo.png export-ignore
/phpunit.xml export-ignore
/phpunit71.xml export-ignore
/phpunit72.xml export-ignore
/phpunit73.xml export-ignore
/phpunit74.xml export-ignore
/phpunit80.xml export-ignore
/phpunit81.xml export-ignore
/phpunit82.xml export-ignore
/phpunit83.xml export-ignore
/phpunit84.xml export-ignore
/README.md export-ignore
/SECURITY.md export-ignore
/test.sh export-ignore
/.env.example export-ignore
/dock export-ignore
/test.sh export-ignore
/art/ export-ignore
22 changes: 12 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ on:
jobs:
test:
runs-on: ubuntu-latest
services:
docker:
image: docker:20.10.7
options: --privileged

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

steps:
- uses: actions/checkout@v4

- name: Install dependencies for PHP${{ matrix.php-version }}
run: |
docker compose run --rm php${{ matrix.php-version }}composer composer update --no-cache
- name: Create .env
run: touch .env

- name: Run PHPUnit tests for PHP${{ matrix.php-version }}
- name: Set PHP version in .env
run: |
docker compose run --rm php${{ matrix.php-version }} vendor/bin/phpunit --configuration phpunit${{ matrix.php-version }}.xml
echo "PHP_COMPOSER=${{ matrix.php-version }}" >> .env
echo "PHP_VERSION=${{ matrix.php-version }}" >> .env

- name: Install dependencies (composer update) for PHP
run: sh dock composer update

- name: Run PHPUnit tests for PHP
run: sh dock test
11 changes: 2 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@ composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
/.phpunit.cache/
/vendor-php71/
/vendor-php72/
/vendor-php73/
/vendor-php74/
/vendor-php80/
/vendor-php81/
/vendor-php82/
/vendor-php83/
/vendor-php84/
.vendor/
.env
99 changes: 92 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,45 @@
[![wakatime](https://wakatime.com/badge/github/zero-to-prod/transformable.svg)](https://wakatime.com/badge/github/zero-to-prod/transformable)
[![Hits-of-Code](https://hitsofcode.com/github/zero-to-prod/transformable?branch=main)](https://hitsofcode.com/github/zero-to-prod/transformable/view?branch=main)

## Contents

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Additional Packages](#additional-packages)
- [Usage](#usage)
- [Methods](#methods)
- [Local Development](#local-development)
- [Prerequisites](#prerequisites)
- [Initializing](#initializing)
- [Testing](#testing)
- [Configuration](#configuration)
- [Contributing](#contributing)

## Introduction

Transform a class into different types.

## Requirements

- PHP 7.1 or higher.

## Installation

You can install the package via Composer:
Install `Zerotoprod\Transformable` via [Composer](https://getcomposer.org/):

```bash
composer require zero-to-prod/transformable
```

This will add the package to your project’s dependencies and create an autoloader entry for it.

### Additional Packages

- [DataModel](https://github.com/zero-to-prod/data-model): Transform data into a class.
- [DataModelHelper](https://github.com/zero-to-prod/data-model-helper): Helpers for a `DataModel`.
- [DataModelFactory](https://github.com/zero-to-prod/data-model-factory): A factory helper to set the value of your `DataModel`.

## Methods

- `toArray(): array` Converts the object’s properties into an associative array.
- `toJson(): string` Converts the object’s properties into a JSON string.

## Usage

To use the `Zerotoprod\Transformable\Transformable` trait in your class, simply include it:
Expand All @@ -51,4 +69,71 @@ $model->email = 'john.doe@example.com';

$array = $model->toArray();
$json = $model->toJson();
```
```

### Methods

- `toArray(): array` Converts the object’s properties into an associative array.
- `toJson(): string` Converts the object’s properties into a JSON string.

## Local Development

This project provides a convenient [dock](https://github.com/zero-to-prod/dock) script to simplify local development workflows within Docker
containers.

You can use this script to initialize the project, manage Composer dependencies, and run tests in a consistent PHP environment.

### Prerequisites

- Docker installed and running
- A `.env` file (created automatically via the `dock init` command, if it doesn’t already exist)

### Initializing

Use the following commands to set up the project:

```shell
sh dock init
sh dock composer update
```

### Testing

This command runs PHPUnit inside the Docker container, using the PHP version specified in your `.env` file.
You can modify or extend this script to include additional tests or commands as needed.

```shell
sh dock test
```

Run the test suite with all versions of php:

```shell
sh test.sh
```

### Configuration

Before starting development, verify that your `.env` file contains the correct settings.

You can specify which PHP version to use for local development, debugging, and Composer operations by updating these variables in your `.env` file:

```dotenv
PHP_VERSION=8.1
PHP_DEBUG=8.1
PHP_COMPOSER=8.1
```

Make sure these values reflect the PHP versions you intend to use.
If the `.env` file does not exist, run the `sh dock init` command to create one from the `.env.example` template.

## Contributing

Contributions, issues, and feature requests are welcome!
Feel free to check the [issues](https://github.com/zero-to-prod/transformable/issues) page if you want to contribute.

1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Commit changes (`git commit -m 'Add some feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Create a new Pull Request.
71 changes: 71 additions & 0 deletions dock
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

set -e

usage() {
cat <<EOF
Usage: $0 <command> [options]

Commands:
init Initialize the .env file from .env.example if it doesn't exist.
test Run PHPUnit tests using the specified PHP version.
composer Run Composer commands using the specified PHP version.
<service> Run a specified Docker service with optional arguments.

Examples:
$0 init
$0 test --filter=MyTest
$0 composer install
$0 php8.1 bash
EOF
exit 1
}

if [ "$#" -lt 1 ]; then
usage
fi

run_service() {
local service=$1
shift
if ! docker compose run --rm "$service" "$@"; then
exit 1
fi
}

case "$1" in
init)
if [ ! -f ".env" ]; then
cp ".env.example" ".env"
echo "cp '.env.example' '.env'"
fi
exit 0;
;;
esac

if [ ! -f ".env" ]; then
echo "Project does not have a .env file. Please provide one or run: dock init"
exit 0
fi

PHP_VERSION=$(grep "^PHP_VERSION=" .env | cut -d '=' -f2-)

case "$1" in
test)
shift
run_service "php${PHP_VERSION}" vendor/bin/phpunit "$@"
;;
build)
shift
docker compose build "php${PHP_VERSION}" "$@"
docker compose build "debug${PHP_VERSION}" "$@"
docker compose build "composer${PHP_VERSION}" "$@"
;;
composer)
shift
run_service "composer${PHP_VERSION}" composer "$@"
;;
*)
run_service "$@"
;;
esac
Loading
Loading