Skip to content

Commit

Permalink
feat: add support for Symfony 7 and PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Feb 7, 2024
1 parent 92418eb commit b45fc5a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ on:

jobs:
php-tests:
name: Testing on PHP${{ matrix.php }}
name: Testing on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.2']
php: [8.2, 8.3]
fail-fast: false
steps:

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Foggy - Database scrubbing

Foggy is a package which creates a database dump of your database, but with scrubbed data.
Perfect for taking a production database and use locally.

## Installation
## Install

For installation via composer
````bash
$ composer require worksome/foggy
Expand All @@ -14,14 +16,16 @@ $ composer require worksome/foggy-laravel
```

## Usage
For usage with Laravel, read more in [Laravel Foggy docs](https://github.com/worksome/foggy-laravel#usage).

For usage with Laravel, read more in [Laravel Foggy docs](https://github.com/worksome/foggy-laravel#usage).

## Configuration

The configuration lies in a JSON file, which has to adhere to the `schema.json` file.
You can validate your configuration file on [jsonschemavalidator.net](https://www.jsonschemavalidator.net/) or directly in phpstorm.

For the most basic configuration, where all tables are dumped, but no data is scrubbed, we simply do
For the most basic configuration, where all tables are dumped, but no data is scrubbed, we simply do:

```json
{
"database": {
Expand All @@ -31,10 +35,12 @@ For the most basic configuration, where all tables are dumped, but no data is sc
}
}
```

Here we have specified that all tables and views (`*`) should be dumped with data by default.
A more secure default would be to set `withData` to `false`, so only schema definitions are exported, if nothing specific is specified.

### Defining rules for a table

All table definitions live inside `database` key in the json object.
Each table can have an array of rules. A rule consist of the following
- `column` - Which column to apply the rule to.
Expand All @@ -46,6 +52,7 @@ Each table can have an array of rules. A rule consist of the following

In the following snippet we have added some rules for the `users` table.
It shows a quick example of some rules and parameters.

```json
{
"database": {
Expand Down Expand Up @@ -78,10 +85,12 @@ It shows a quick example of some rules and parameters.
```

### Rules

Each table can have an array of rules. Rules are applied to a specific column and can modify
the values in that column per row.

#### Faker

The faker rule is to replace the value with a new fake value.
It uses the [faker library](https://github.com/fzaninotto/Faker) underneath, so all formatters
available in faker can be used here.
Expand Down Expand Up @@ -111,6 +120,7 @@ In the following example we specify that we only want to generate `female` names
```

#### Replacer

The replacer rule replaces a column with the given value.
It's a simple rule for when you just want all entries to have the same value. A great use-case is for
setting all passwords to the same value, so when using the scrubbed database, you can log in on all user's
Expand All @@ -126,6 +136,7 @@ In the following example we replace all passwords with `secret`, but a hashed ed
```

#### PHP

The PHP rule is a basic, but really powerful rule. It allows you to define a PHP string which will be applied
to the column.
This string has a few variables which can be accessed.
Expand All @@ -146,10 +157,12 @@ not needed to write `return`, as the statement is wrapped in a `return` automati
### Conditions

#### Times

It is possible to limit a column to only be applied `x` amount of times, by supplying an argument named
`times`. This will limit, so the rule is only applied until the `times` are hit.

### SQL Views

All views definitions live inside `database` key in the json object.
In opposition to tables, views do not have any particular rules applicable to them.

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
"php": "^8.2",
"ext-json": "*",
"ext-pdo": "*",
"doctrine/dbal": "^3.1",
"symfony/console": "^6.2",
"symfony/var-dumper": "^6.2",
"thecodingmachine/safe": "^2.0",
"doctrine/dbal": "^3.6",
"symfony/console": "^6.4 || ^7.0",
"symfony/var-dumper": "^6.4 || ^7.0",
"thecodingmachine/safe": "^2.5",
"fakerphp/faker": "^1.10"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"pestphp/pest": "^2.0",
"pestphp/pest": "^2.33",
"mockery/mockery": "^1.5.1",
"worksome/coding-style": "^2.5"
"worksome/coding-style": "^2.8"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function dumpNewLine(string $message = ''): void
}

/**
* Creates a instance of a progress bar in the specified console output interface.
* Creates an instance of a progress bar in the specified console output interface.
*/
public function createProgressBar(int $max = 1): ProgressBar
{
Expand Down Expand Up @@ -254,7 +254,7 @@ protected function getColumnsForTable(
}

/**
* @param array(string=>mixed) $cols
* @param array<string, mixed> $cols
*/
protected function insertValuesStatement($table, $cols): string
{
Expand Down

0 comments on commit b45fc5a

Please sign in to comment.