Skip to content

Commit

Permalink
Support only PHP 8.3 (#44)
Browse files Browse the repository at this point in the history
* Breaking Changes:
- Only support PHP 8.3
    - Make classes read-only when possible
	- Add types to constants
    - Upgrade PHPUnit to v11.3
		- Use static versions of asserts and expectations of invocations
    - Change CI pipeline to use PHP 8.3
- Changes to `AbstractFileLoaderFixture`:
	- Add `LoadMode` enumeration to define load modes of files
	- Change `getLoadMode` to return a `LoadMode` enumeration value instead of a string
	- Change derived classes to conform with new `getLoadMode` definition
- Changes to `ConnectionPurger`:
    - Add `PurgeMode` enumeration to define purge modes
    - Remove `setPurgeMode` and `getPurgeMode`
    - The purge mode must be set in the constuctor with a `PurgeMode` enumeration value (which defaults to `PurgeMode::Delete`)
    - Remove `InvalidConnectionPurgeModeException`
- Update documentation
  • Loading branch information
hugo-goncalves-kununu authored Sep 18, 2024
1 parent 227b09d commit c41d2df
Show file tree
Hide file tree
Showing 56 changed files with 369 additions and 476 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-version:
- 8.1
- 8.3
dependencies:
- lowest
- highest
Expand All @@ -30,7 +30,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
coverage: pcov

- name: Install Composer Dependencies
uses: ramsey/composer-install@v3
Expand All @@ -39,12 +39,13 @@ jobs:
composer-options: "--prefer-stable"

- name: Run PHPUnit
run: vendor/bin/phpunit
run: vendor/bin/phpunit --log-junit tests/.results/tests-junit.xml --coverage-clover tests/.results/tests-clover.xml

- name: Upload coverage files
uses: actions/upload-artifact@v4
with:
name: ${{ github.job }}-${{ matrix.php-version }}-${{ matrix.dependencies }}-coverage
include-hidden-files: true
path: tests/.results/

sonarcloud:
Expand All @@ -58,7 +59,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: build-8.1-highest-coverage
name: build-8.3-highest-coverage
path: tests/.results/

- name: Fix Code Coverage Paths
Expand All @@ -68,7 +69,7 @@ jobs:
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' tests-junit.xml
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
uses: sonarsource/sonarcloud-github-action@v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
58 changes: 34 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ This package provides a simple way to manage and execute the loading of data fix

Currently, this package supports the following types of fixtures:

- *[Doctrine DBAL Connection Fixtures](/docs/FixtureTypes/doctrine-dbal-connection-fixtures.md)* which relies on [Doctrine DBAL](https://github.com/doctrine/dbal) by using the [Connection](https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php) implementation
- *[Cache Pool Fixtures](/docs/FixtureTypes/cache-pool-fixtures.md)* which relies on implementations of the [PSR-6](https://github.com/php-fig/cache) standard
- *[Elasticsearch Fixtures](/docs/FixtureTypes/elasticsearch.md)* which relies on the [Elasticsearch-PHP client](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)
- *[Symfony Http Client Fixtures](/docs/FixtureTypes/symfony-http-client.md)* which relies on the [Symfony Http Client](https://github.com/symfony/http-client) and [Symfony Http Foundation](https://github.com/symfony/http-foundation).
- *[Doctrine DBAL Connection Fixtures](docs/FixtureTypes/doctrine-dbal-connection-fixtures.md)* which relies on [Doctrine DBAL](https://github.com/doctrine/dbal) by using the [Connection](https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php) implementation
- *[Cache Pool Fixtures](docs/FixtureTypes/cache-pool-fixtures.md)* which relies on implementations of the [PSR-6](https://github.com/php-fig/cache) standard
- *[Elasticsearch Fixtures](docs/FixtureTypes/elasticsearch.md)* which relies on the [Elasticsearch-PHP client](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)
- *[Symfony Http Client Fixtures](docs/FixtureTypes/symfony-http-client.md)* which relies on the [Symfony Http Client](https://github.com/symfony/http-client) and [Symfony Http Foundation](https://github.com/symfony/http-foundation).

Also check [Directory Loader](/docs/FixtureTypes/directory-loader.md) to check how to load fixtures from files in a directory.
Also check [Directory Loader](docs/FixtureTypes/directory-loader.md) to check how to load fixtures from files in a directory.

If you are interested in knowing more about the concepts of the package, or you need to create a new fixture type check out [How to create a new Fixture Type](/docs/how-to-create-new-fixture-type.md).
If you are interested in knowing more about the concepts of the package, or you need to create a new fixture type check out [How to create a new Fixture Type](docs/how-to-create-new-fixture-type.md).

--------------------------
## Install
Expand All @@ -31,18 +31,18 @@ Before installing this package be aware:
- **You own the fixtures you load**
- **This package should not be used in production mode!**

```bash
```shell
composer require --dev kununu/data-fixtures
```

#### 2. Enable any fixture type

In order to enable the fixture types that you are interested, check out their documentation:

- [Doctrine DBAL Connection Fixtures](/docs/FixtureTypes/doctrine-dbal-connection-fixtures.md)
- [Cache Pool Fixtures](/docs/FixtureTypes/cache-pool-fixtures.md)
- [Elasticsearch Fixtures](/docs/FixtureTypes/elasticsearch.md)
- [Symfony Http Client Fixtures](/docs/FixtureTypes/symfony-http-client.md)
- [Doctrine DBAL Connection Fixtures](docs/FixtureTypes/doctrine-dbal-connection-fixtures.md)
- [Cache Pool Fixtures](docs/FixtureTypes/cache-pool-fixtures.md)
- [Elasticsearch Fixtures](docs/FixtureTypes/elasticsearch.md)
- [Symfony Http Client Fixtures](docs/FixtureTypes/symfony-http-client.md)

--------------------

Expand All @@ -61,15 +61,20 @@ $executor->execute($loader->getFixtures(), true);

## Load Fixtures

In order to load fixtures the default [Loader](/src/Loader/Loader.php) provides a couple of options:
In order to load fixtures the default [Loader](src/Loader/Loader.php) provides a couple of options:

1) loadFromDirectory(string $dir)
2) loadFromFile(string $fileName)
3) loadFromClassName(string $className)
4) addFixture(FixtureInterface $fixture)
1) `loadFromDirectory(string $dir)`
2) `loadFromFile(string $fileName)`
3) `loadFromClassName(string $className)`
4) `addFixture(FixtureInterface $fixture)`

```php
$loader = new Kununu\DataFixtures\Loader\ConnectionFixturesLoader();
<?php
declare(strict_types=1);

use Kununu\DataFixtures\Loader\ConnectionFixturesLoader;

$loader = new ConnectionFixturesLoader();
$loader->loadFromDirectory('/your/directory/');
$loader->loadFromFile('/your/file.php');
$loader->loadFromClassName(MyFixtureSql::class);
Expand All @@ -83,13 +88,18 @@ $loader->addFixture(new MyFixtureSql());
If you want your Fixture classes to be initialized you can implement the `InitializableFixtureInterface`

```php
public function initializeFixture(...$args): void;
public function initializeFixture(mixed ...$args): void;
```

Then before loading the fixtures you need to register them in the Loader:

```php
$loader = new Kununu\DataFixtures\Loader\ConnectionFixturesLoader();
<?php
declare(strict_types=1);

use Kununu\DataFixtures\Loader\ConnectionFixturesLoader;

$loader = new ConnectionFixturesLoader();

$this->loader->registerInitializableFixture(
YourFixtureClass::class,
Expand All @@ -114,32 +124,32 @@ $loader->addFixture(new YourFixtureClass());

## Contribute

If you are interested in contributing read our [contributing guidelines](/CONTRIBUTING.md).
If you are interested in contributing read our [contributing guidelines](CONTRIBUTING.md).

------------------------------

## Tests

If not yet, first install composer dependencies:

```bash
```shell
composer install
```

Run the tests by doing:

```bash
```shell
vendor/bin/phpunit
```

To run tests without coverage report:
```bash
```shell
composer install
composer test
```

To run tests with coverage report:
```bash
```shell
composer install
composer test-coverage
```
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
}
],
"require": {
"php": ">=8.1",
"php": ">=8.3",
"ext-json": "*"
},
"require-dev": {
"doctrine/dbal": "^3.8",
"doctrine/dbal": "^3.9",
"elasticsearch/elasticsearch": "^7.1",
"kununu/scripts": ">=5.0",
"phpunit/phpunit": "^10.5",
"kununu/scripts": ">=5.1",
"phpunit/phpunit": "^11.3",
"psr/cache": "^2.0",
"symfony/http-client": "^6.4",
"symfony/http-foundation": "^6.4"
Expand All @@ -54,7 +54,7 @@
},
"scripts": {
"test": "phpunit --no-coverage --no-logging --no-progress",
"test-coverage": "XDEBUG_MODE=coverage phpunit"
"test-coverage": "XDEBUG_MODE=coverage phpunit --log-junit tests/.results/tests-junit.xml --coverage-clover tests/.results/tests-clover.xml --coverage-html tests/.results/html"
},
"scripts-descriptions": {
"test": "Run all tests",
Expand Down
8 changes: 4 additions & 4 deletions docs/FixtureTypes/cache-pool-fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ The `Cache Pool Fixtures` allows you to load data fixtures for any implementatio

Before starting loading Cache Pool Fixtures make sure to add [PSR-6](https://github.com/php-fig/cache) as a dependency of your project.

```bash
```shell
composer require psr/cache
```

## How to load Cache Pool Fixtures?

### 1. Create fixture classes

The first step to load Cache Pool Fixtures is to create fixtures classes. This classes must implement the [CachePoolFixtureInterface](/src/Adapter/CachePoolFixtureInterface.php).
The first step to load Cache Pool Fixtures is to create fixtures classes. This classes must implement the [CachePoolFixtureInterface](../../src/Adapter/CachePoolFixtureInterface.php).

```php
<?php
Expand Down Expand Up @@ -65,11 +65,11 @@ $executor->execute($loader->getFixtures());
$executor->execute($loader->getFixtures(), true);
```

If you want to know more options on how you can load fixtures in the Loader checkout *[Load Fixtures](/README.md#loading-fixtures)*.
If you want to know more options on how you can load fixtures in the Loader checkout *[Load Fixtures](../../README.md#load-fixtures)*.

### 3. Append Fixtures

By default, when loading fixtures the cache storage is purged. If you want to change this behavior and instead append the fixtures, you can pass *true* as second argument to the CachePoolExecutor.
By default, when loading fixtures the cache storage is purged. If you want to change this behavior and instead append the fixtures, you can pass *true* as second argument to the `CachePoolExecutor`.

```php
<?php
Expand Down
17 changes: 9 additions & 8 deletions docs/FixtureTypes/doctrine-dbal-connection-fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The `Doctrine DBAL Connection Fixtures` allows you to load data fixtures for any

Before starting loading Connection Fixtures make sure to add [Doctrine DBAL](https://github.com/doctrine/dbal) as a dependency of your project.

```bash
```shell
composer require doctrine/dbal
```

Expand All @@ -16,7 +16,7 @@ composer require doctrine/dbal

The first step to load *Connection Fixtures* is to create fixtures classes.

This classes must implement the [ConnectionFixtureInterface](/src/Adapter/ConnectionFixtureInterface.php) or extend the class [ConnectionSqlFixture](/src/Adapter/ConnectionSqlFixture.php) which allows you to define fixtures using *Sql* files.
This classes must implement the [ConnectionFixtureInterface](../../src/Adapter/ConnectionFixtureInterface.php) or extend the class [ConnectionSqlFixture](../../src/Adapter/ConnectionSqlFixture.php) which allows you to define fixtures using *Sql* files.

```php
<?php
Expand Down Expand Up @@ -100,7 +100,7 @@ $loader->addFixture(new MyFixture());
$executor->execute($loader->getFixtures());
```

If you want to know more options on how you can load fixtures in the Loader checkout *[Load Fixtures](/README.md#loading-fixtures)*.
If you want to know more options on how you can load fixtures in the Loader checkout *[Load Fixtures](../../README.md#load-fixtures)*.

### 3. Append Fixtures

Expand Down Expand Up @@ -141,19 +141,20 @@ $executor->execute($loader->getFixtures());
### 5. Purge mode

The Purger allows you to change the *Sql* statement used to purge the tables.
By default, the Purger will run a *DELETE* statement to purge the tables but you can change it to use a *TRUNCATE* statement instead.
By default, the Purger will run a *DELETE* statement to purge the tables, but you can change it to use a *TRUNCATE* statement instead, by specifying the `purgeMode` parameter.

```php
<?php
declare(strict_types=1);

use Kununu\DataFixtures\Purger\ConnectionPurger;
use Kununu\DataFixtures\Purger\PurgeMode;

$purger = new ConnectionPurger($conn, $excludedTables);
// Just passing here as an example, as the default is already PurgeMode::Delete
$purger = new ConnectionPurger($conn, $excludedTables, purgeMode: PurgeMode::Delete);

// If you want you can change the Purge Mode
$purger->setPurgeMode(1); // PURGE_MODE_DELETE
$purger->setPurgeMode(2); // PURGE_MODE_TRUNCATE
// If you want to use truncate mode
$purger = new ConnectionPurger($conn, $excludedTables, purgeMode: PurgeMode::Truncate);
```

## Notes
Expand Down
20 changes: 11 additions & 9 deletions docs/FixtureTypes/elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ The `Elasticsearch Fixtures` allows you to load data fixtures for any Elasticsea

Before starting loading Elasticsearch Fixtures make sure to add [Elasticsearch](https://github.com/elastic/elasticsearch) as a dependency of your project.

```bash
```shell
composer require elastic/elasticsearch
```

## How to load Elasticsearch Fixtures?

### 1. Create fixture classes

The first step to load Elasticsearch Fixtures is to create fixtures classes. This classes must implement the [ElasticsearchFixtureInterface](/src/Adapter/ElasticsearchFixtureInterface.php) or if you want to easily use *bulk* inserts on your fixtures you can extend the class [ElasticsearchFixture](/src/Adapter/ElasticsearchFixture.php).
The first step to load Elasticsearch Fixtures is to create fixtures classes. This classes must implement the [ElasticsearchFixtureInterface](../../src/Adapter/ElasticsearchFixtureInterface.php) or if you want to easily use *bulk* inserts on your fixtures you can extend the class [ElasticsearchFixture](../../src/Adapter/ElasticsearchFixture.php).


#### Inserting a single document
Expand Down Expand Up @@ -135,11 +135,11 @@ Get the files to load

Get the file extension (should return `php` for PHP array files or `json` for JSON file)

- `protected function getLoadMode(): string;`
- `protected function getLoadMode(): LoadMode;`

The load method to use.
- `AbstractFileLoaderFixture::LOAD_MODE_INCLUDE` to include the PHP array files
- `AbstractFileLoaderFixture::LOAD_MODE_LOAD_JSON` to load and convert the JSON files to array
- `LoadMode::Include` to include the PHP array files
- `LoadMode:LoadJson` to load and convert the JSON files to array

Example:

Expand All @@ -149,6 +149,7 @@ declare(strict_types=1);

use Elasticsearch\Client;
use Kununu\DataFixtures\Adapter\ElasticsearchFileFixture;
use Kununu\DataFixtures\Adapter\LoadMode;

final class MyFixture extends ElasticsearchFileFixture
{
Expand All @@ -166,10 +167,10 @@ final class MyFixture extends ElasticsearchFileFixture
return 'php';
}

protected function getLoadMode(): string
protected function getLoadMode(): LoadMode
{
// Load the php files as includes
return self::LOAD_MODE_INCLUDE;
return LoadMode::Include;
}

/**
Expand Down Expand Up @@ -214,6 +215,7 @@ declare(strict_types=1);

use Elasticsearch\Client;
use Kununu\DataFixtures\Adapter\ElasticsearchFileFixture;
use Kununu\DataFixtures\Adapter\LoadMode;

final class MyFixture extends ElasticsearchFileFixture
{
Expand All @@ -234,7 +236,7 @@ final class MyFixture extends ElasticsearchFileFixture
protected function getLoadMode(): string
{
// Load the json files contents as arrays
return self::LOAD_MODE_LOAD_JSON;
return LoadMode::LoadJson;
}

/**
Expand Down Expand Up @@ -338,7 +340,7 @@ $executor->execute($loader->getFixtures());
$executor->execute($loader->getFixtures(), true);
```

If you want to know more options on how you can load fixtures in the Loader checkout *[Load Fixtures](/README.md#loading-fixtures)*.
If you want to know more options on how you can load fixtures in the Loader checkout *[Load Fixtures](../../README.md#load-fixtures)*.

### 3. Append Fixtures

Expand Down
Loading

0 comments on commit c41d2df

Please sign in to comment.