Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ USE_DAMA_DOCTRINE_TEST_BUNDLE="0"
USE_FOUNDRY_PHPUNIT_EXTENSION="0"
USE_PHP_84_LAZY_OBJECTS="0"
PHPUNIT_VERSION="12" # allowed values: 9, 10, 11, 12

# Only relevant for "reset-database" testsuite
DATABASE_RESET_MODE="schema" # allowed values: schema, migrate
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
shell: bash

test-reset-database:
name: Reset DB - D:${{ matrix.database }} ${{ matrix.use-dama == 1 && ' (dama)' || '' }} ${{ matrix.reset-database-mode == 'migrate' && ' (migrate)' || '' }} ${{ contains(matrix.with-migration-configuration-file, 'transactional') && '(configuration file transactional)' || contains(matrix.with-migration-configuration-file, 'configuration') && '(configuration file)' || '' }}${{ matrix.deps == 'lowest' && ' (lowest)' || '' }}
name: Reset DB - D:${{ matrix.database }} ${{ matrix.use-dama == 1 && ' (dama)' || '' }} ${{ matrix.reset-database-mode == 'migrate' && ' (migrate)' || '' }} ${{ contains(matrix.with-migration-configuration-file, 'transactional') && '(configuration file transactional)' || contains(matrix.with-migration-configuration-file, 'configuration') && '(configuration file)' || '' }}${{ matrix.deps == 'lowest' && ' (lowest)' || '' }}${{ matrix.use-phpunit-extension == 0 && ' (no phpunit extension)' || '' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -122,17 +122,21 @@ jobs:
reset-database-mode: [ schema, migrate ]
migration-configuration-file: ['no']
deps: [ highest, lowest ]
use-phpunit-extension: [ 1 ]
include:
- { database: mongo, migration-configuration-file: 'no', use-dama: 0, reset-database-mode: schema }
- { database: pgsql, migration-configuration-file: 'migration-configuration', use-dama: 0, reset-database-mode: migration }
- { database: pgsql, migration-configuration-file: 'migration-configuration-transactional', use-dama: 0, reset-database-mode: migration }
- { database: mongo, use-dama: 0, reset-database-mode: schema, use-phpunit-extension: 1 }
- { database: pgsql, use-dama: 1, reset-database-mode: schema, use-phpunit-extension: 0 }
- { database: pgsql, use-dama: 0, reset-database-mode: schema, use-phpunit-extension: 0 }
- { database: pgsql, migration-configuration-file: 'migration-configuration', use-dama: 0, reset-database-mode: migration, use-phpunit-extension: 1 }
- { database: pgsql, migration-configuration-file: 'migration-configuration-transactional', use-dama: 0, reset-database-mode: migration, use-phpunit-extension: 1 }
env:
DATABASE_URL: ${{ contains(matrix.database, 'mysql') && 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42' || contains(matrix.database, 'pgsql') && 'postgresql://root:root@localhost:5432/foundry?serverVersion=15' || 'sqlite:///%kernel.project_dir%/var/data.db' }}
MONGO_URL: ${{ contains(matrix.database, 'mongo') && 'mongodb://127.0.0.1:27017/dbName?compressors=disabled&gssapiServiceName=mongodb' || '' }}
USE_DAMA_DOCTRINE_TEST_BUNDLE: ${{ matrix.use-dama == 1 && 1 || 0 }}
DATABASE_RESET_MODE: ${{ matrix.reset-database-mode == 1 && 1 || 0 }}
MIGRATION_CONFIGURATION_FILE: ${{ matrix.migration-configuration-file == 'no' && '' || format('tests/Fixture/MigrationTests/configs/{0}.php', matrix.migration-configuration-file) }}
PHPUNIT_VERSION: 11
PHPUNIT_VERSION: 12
USE_FOUNDRY_PHPUNIT_EXTENSION: ${{ matrix.use-phpunit-extension }}
services:
postgres:
image: ${{ contains(matrix.database, 'pgsql') && 'postgres:15' || '' }}
Expand Down Expand Up @@ -189,7 +193,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.1, 8.2, 8.3, 8.4 ]
php: [ 8.2, 8.3, 8.4 ]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test-rector-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ jobs:
composer update phpunit/phpunit:^11 brianium/paratest -W

composer bin phpstan install
composer bin rector install

- name: Test
run: vendor/bin/phpunit -c phpunit-rector.xml.dist
shell: bash

- name: Static analysis
run: bin/tools/rector/vendor/phpstan/phpstan/phpstan analyse -c utils/rector/phpstan.neon
run: bin/tools/phpstan/vendor/phpstan/phpstan/phpstan analyse -c utils/rector/phpstan.neon
shell: bash
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $ composer update
# run main testsuite (with "schema" reset database strategy)
$ ./phpunit

# run "migrate" testsuite (with "migrate" reset database strategy)
# run "reset-database" testsuite
$ ./phpunit --testsuite reset-database
```

Expand All @@ -73,6 +73,7 @@ PHPUNIT_VERSION="11" # possible values: 9, 10, 11, 11.4

# test reset database with migrations,
# only relevant for "reset-database" testsuite
DATABASE_RESET_MODE="migrate"
MIGRATION_CONFIGURATION_FILE="tests/Fixture/MigrationTests/configs/migration-configuration.php"

# run test suite with postgreSQL
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-2.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return RectorConfig::configure()
'src',
'tests'
])
->withSets([FoundrySetList::REMOVE_PROXIES])
->withSets([FoundrySetList::FOUNDRY_2_7])
;
```

Expand Down
53 changes: 53 additions & 0 deletions UPGRADE-2.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Migration guide from Foundry 2.7 to 2.8

The main feature of Foundry 2.8 is the deprecation of the `Factories` trait, in favor of the [PHPUnit extension](https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#phpunit-extension)
shipped by Foundry. It was necessary to remember to add the trait in every test class. And in some cases, Foundry could
still work even if the trait wasn’t added to the test, which could lead to subtle bugs. Now, Foundry is globally enabled
once for all.

The trait will be removed in Foundry 3.0, and the extension will be mandatory.

> [!WARNING]
> The PHPUnit extension mechanism was introduced in PHPUnit 10. This means that Foundry 3 won't be compatible
> with PHPUnit 9 anymore (but Foundry 2 will remain compatible with PHPUnit 9).

## How to

> [!IMPORTANT]
> If you're still not using PHPUnit 10 or grater, there is nothing to do (yet!)

Enable Foundry's [PHPUnit extension](https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#phpunit-extension)
in your `phpunit.xml` file:

```xml
<phpunit>
<extensions>
<bootstrap class="Zenstruck\Foundry\PHPUnit\FoundryExtension"/>
</extensions>
</phpunit>
```

And then, remove all the `use Factories;` statements from your factories.

## Rector rules

A Rector set is available to automatically remove the usage of the trait in all your tests.

First, you'll need to install `rector/rector`:
```shell
composer require --dev rector/rector
```

Then, create a `rector.php` file:

```php
<?php

use Rector\Config\RectorConfig;
use Zenstruck\Foundry\Utils\Rector\FoundrySetList;

return RectorConfig::configure()
->withPaths(['tests'])
->withSets([FoundrySetList::FOUNDRY_2_8])
;
```
53 changes: 53 additions & 0 deletions UPGRADE-2.9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Migration guide from Foundry 2.8 to 2.9

The main feature of Foundry 2.9 is the deprecation of the `ResetDatabase` trait, in favor of a `#[ResetDatabase]` attribute,
along with the [PHPUnit extension](https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#phpunit-extension)
shipped by Foundry.

The trait will be removed in Foundry 3.0, and the usage of the attribute will be mandatory to reset the database in your tests.

> [!WARNING]
> The PHPUnit extension mechanism was introduced in PHPUnit 10. This means that Foundry 3 won't be compatible
> with PHPUnit 9 anymore (but Foundry 2 will remain compatible with PHPUnit 9).

## How to

> [!IMPORTANT]
> If you're still not using PHPUnit 10 or grater, there is nothing to do (yet!)

Enable Foundry's [PHPUnit extension](https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#phpunit-extension)
in your `phpunit.xml` file:

```xml
<phpunit>
<extensions>
<bootstrap class="Zenstruck\Foundry\PHPUnit\FoundryExtension"/>
</extensions>
</phpunit>
```

And then, replace all the `use ResetDatabase;` statements by a `#[\Zenstruck\Foundry\Attribute\ResetDatabase]` attribute
on your test classes. Note that you can put the attribute on a parent class, it will be inherited by all its children.

## Rector rules

A Rector set is available to automatically replace the trait by the attribute in all your tests.

First, you'll need to install `rector/rector`:
```shell
composer require --dev rector/rector
```

Then, create a `rector.php` file:

```php
<?php

use Rector\Config\RectorConfig;
use Zenstruck\Foundry\Utils\Rector\FoundrySetList;

return RectorConfig::configure()
->withPaths(['tests'])
->withSets([FoundrySetList::FOUNDRY_2_9])
;
```
Loading