Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use PHPUnit 12 #810

Merged
merged 1 commit into from
Feb 24, 2025
Merged
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ MONGO_URL="mongodb://127.0.0.1:27018/dbName?compressors=disabled&gssapiServi

USE_DAMA_DOCTRINE_TEST_BUNDLE="0"
USE_FOUNDRY_PHPUNIT_EXTENSION="0"
PHPUNIT_VERSION="9" # allowed values: 9, 10, 11
PHPUNIT_VERSION="9" # allowed values: 9, 10, 11, 12
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,35 @@ jobs:
php: [ 8.2, 8.3, 8.4 ]
symfony: [ 6.4.*, 7.1.*, 7.2.* ]
database: [ mysql|mongo ]
phpunit: [ 11 ]
phpunit: [ 11, 12 ]

# default values:
# deps: [ highest ]
# use-phpunit-extension: [ 0 ]

exclude:
- {php: 8.1, symfony: 7.1.*}
- {php: 8.1, symfony: 7.2.*}
- {php: 8.2, phpunit: 12}
- {php: 8.3, phpunit: 11}
- {php: 8.4, phpunit: 11}

include:
# php 8.1
- {php: 8.1, symfony: 6.4.*, phpunit: 9, database: mysql}

# old PHPUnit versions
- {php: 8.3, symfony: '*', phpunit: 9, database: mysql}
- {php: 8.3, symfony: '*', phpunit: 10, database: mysql}
- {php: 8.4, symfony: '*', phpunit: 10, database: mysql}
- {php: 8.4, symfony: '*', phpunit: 11, database: mysql}

# test with no database (PHPUnit 9 is used to prevent some problems with empty data providers)
- {php: 8.3, symfony: '*', phpunit: 9, database: none}
- {php: 8.3, symfony: '*', phpunit: 9, database: none, deps: lowest}

# One permutation per DBMS
- {php: 8.3, symfony: '*', phpunit: 11, database: mongo}
- {php: 8.3, symfony: '*', phpunit: 11, database: pgsql}
- {php: 8.3, symfony: '*', phpunit: 11, database: sqlite}
- {php: 8.3, symfony: '*', phpunit: 11, database: mysql}
- {php: 8.4, symfony: '*', phpunit: 12, database: mongo}
- {php: 8.4, symfony: '*', phpunit: 12, database: pgsql}
- {php: 8.4, symfony: '*', phpunit: 12, database: sqlite}
- {php: 8.4, symfony: '*', phpunit: 12, database: mysql}

# lowest deps (one per DBMS)
- {php: 8.3, symfony: '*', phpunit: 9, database: mysql|mongo, deps: lowest}
Expand All @@ -51,7 +54,7 @@ jobs:
- {php: 8.3, symfony: '*', phpunit: 9, database: mysql, deps: lowest}

# using Foundry's PHPUnit extension
- {php: 8.3, symfony: '*', phpunit: 11, database: mysql|mongo, use-phpunit-extension: 1}
- {php: 8.4, symfony: '*', phpunit: 12, database: mysql|mongo, 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' || contains(matrix.database, 'sqlite') && 'sqlite:///%kernel.project_dir%/var/data.db' || '' }}
MONGO_URL: ${{ contains(matrix.database, 'mongo') && 'mongodb://127.0.0.1:27017/dbName?compressors=disabled&gssapiServiceName=mongodb' || '' }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"doctrine/mongodb-odm-bundle": "^4.6|^5.0",
"doctrine/mongodb-odm": "^2.4",
"doctrine/orm": "^2.16|^3.0",
"phpunit/phpunit": "^9.5.0 || ^10.0 || ^11.0",
"phpunit/phpunit": "^9.5.0 || ^10.0 || ^11.0 || ^12.0",
"symfony/console": "^6.4|^7.0",
"symfony/dotenv": "^6.4|^7.0",
"symfony/maker-bundle": "^1.55",
Expand Down
6 changes: 3 additions & 3 deletions phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fi
### <<

### >> update PHPUnit if needed
if [[ " 9 10 11 " != *" ${PHPUNIT_VERSION-9} "* ]]; then
echo "❌ PHPUNIT_VERSION should be one of 9, 10, 11";
if [[ " 9 10 11 12 " != *" ${PHPUNIT_VERSION-9} "* ]]; then
echo "❌ PHPUNIT_VERSION should be one of 9, 10, 11, 12";
exit 1;
fi

Expand Down Expand Up @@ -62,7 +62,7 @@ case ${PHPUNIT_VERSION} in
PHPUNIT_EXEC="${PHPUNIT_EXEC} -c phpunit-10.xml.dist"
;;

"11")
"11"|"12")
PHPUNIT_EXEC="${PHPUNIT_EXEC} -c phpunit-10.xml.dist --extension Zenstruck\Foundry\Tests\Fixture\DoctrineCascadeRelationship\PhpUnitTestExtension"

if [ "${USE_DAMA_DOCTRINE_TEST_BUNDLE:-0}" = "1" ]; then
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/ProxyRepositoryDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @template I of ObjectRepository
* @extends RepositoryDecorator<T&Proxy<T>, I>
*/
final class ProxyRepositoryDecorator extends RepositoryDecorator // @phpstan-ignore class.extendsFinalByPhpDoc
final class ProxyRepositoryDecorator extends RepositoryDecorator
{
/**
* @return T|Proxy<T>|null
Expand Down
2 changes: 0 additions & 2 deletions src/Persistence/RepositoryDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
* @implements \IteratorAggregate<array-key, T>
* @mixin I
*
* @final
*
* @phpstan-import-type Parameters from Factory
*/
class RepositoryDecorator implements ObjectRepository, \IteratorAggregate, \Countable
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/ArrayFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Zenstruck\Foundry\Tests\Integration;

use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\LazyValue;
use Zenstruck\Foundry\Test\Factories;
Expand All @@ -26,6 +27,7 @@ final class ArrayFactoryTest extends KernelTestCase
/**
* @test
*/
#[Test]
public function can_create_with_defaults(): void
{
$this->assertSame(
Expand All @@ -42,6 +44,7 @@ public function can_create_with_defaults(): void
/**
* @test
*/
#[Test]
public function can_create_with_overrides(): void
{
$this->assertSame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ final class WithStoryOnClassTest extends KernelTestCase
{
use Factories, RequiresORM, ResetDatabase;

/**
* @test
*/
#[Test]
public function can_use_story_in_attribute(): void
{
Expand All @@ -49,19 +46,13 @@ public function can_use_story_in_attribute(): void
$this->assertSame('foo', EntityStory::get('foo')->getProp1());
}

/**
* @test
*/
#[Test]
#[WithStory(EntityStory::class)]
public function can_use_story_in_attribute_multiple_times(): void
{
GenericEntityFactory::assert()->count(2);
}

/**
* @test
*/
#[Test]
#[WithStory(EntityPoolStory::class)]
public function can_use_another_story_at_level_class(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ final class WithStoryOnMethodTest extends KernelTestCase
{
use Factories, RequiresORM, ResetDatabase;

/**
* @test
*/
#[Test]
#[WithStory(EntityStory::class)]
public function can_use_story_in_attribute(): void
Expand All @@ -50,9 +47,6 @@ public function can_use_story_in_attribute(): void
$this->assertSame('foo', EntityStory::get('foo')->getProp1());
}

/**
* @test
*/
#[Test]
#[WithStory(EntityStory::class)]
#[WithStory(EntityPoolStory::class)]
Expand All @@ -61,9 +55,6 @@ public function can_use_multiple_story_in_attribute(): void
GenericEntityFactory::assert()->count(5);
}

/**
* @test
*/
#[Test]
#[WithStory(ServiceStory::class)]
public function can_use_service_story(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
#[WithStory(EntityPoolStory::class)]
final class WithStoryOnParentClassTest extends ParentClassWithStoryAttributeTestCase
{
/**
* @test
*/
#[Test]
public function can_use_story_in_attribute_from_parent_class(): void
{
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Zenstruck\Foundry\Tests\Integration;

use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
Expand All @@ -25,6 +26,7 @@ final class EventsTest extends KernelTestCase
/**
* @test
*/
#[Test]
public function it_can_call_hooks(): void
{
$address = FactoryWithEventListeners::createOne(['name' => 'events']);
Expand Down
27 changes: 27 additions & 0 deletions tests/Integration/Maker/MakeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Zenstruck\Foundry\Tests\Integration\Maker;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -29,6 +32,7 @@
* @author Kevin Bond <[email protected]>
* @group maker
*/
#[Group('maker')]
final class MakeFactoryTest extends MakerTestCase
{
private const PHPSTAN_PATH = __DIR__.'/../../..'.FactoryGenerator::PHPSTAN_PATH;
Expand Down Expand Up @@ -59,6 +63,7 @@ protected function tearDown(): void
/**
* @test
*/
#[Test]
public function can_create_factory(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -79,6 +84,7 @@ public function can_create_factory(): void
/**
* @test
*/
#[Test]
public function can_create_factory_interactively(): void
{
if (!\getenv('DATABASE_URL')) {
Expand Down Expand Up @@ -106,6 +112,7 @@ public function can_create_factory_interactively(): void
/**
* @test
*/
#[Test]
public function can_create_factory_in_test_dir(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -123,6 +130,8 @@ public function can_create_factory_in_test_dir(): void
* @test
* @dataProvider scaToolProvider
*/
#[Test]
#[DataProvider('scaToolProvider')]
public function can_create_factory_with_static_analysis_annotations(string $scaTool): void
{
if (!\getenv('DATABASE_URL')) {
Expand Down Expand Up @@ -150,6 +159,7 @@ public static function scaToolProvider(): iterable
/**
* @test
*/
#[Test]
public function can_create_factory_for_entity_with_repository(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -166,6 +176,7 @@ public function can_create_factory_for_entity_with_repository(): void
/**
* @test
*/
#[Test]
public function invalid_entity_throws_exception(): void
{
$tester = $this->makeFactoryCommandTester();
Expand All @@ -185,6 +196,7 @@ public function invalid_entity_throws_exception(): void
/**
* @test
*/
#[Test]
public function can_create_factory_for_not_persisted_class(): void
{
$tester = $this->makeFactoryCommandTester();
Expand All @@ -197,6 +209,7 @@ public function can_create_factory_for_not_persisted_class(): void
/**
* @test
*/
#[Test]
public function can_create_factory_for_not_persisted_class_interactively(): void
{
$tester = $this->makeFactoryCommandTester();
Expand All @@ -215,6 +228,7 @@ public function can_create_factory_for_not_persisted_class_interactively(): void
/**
* @test
*/
#[Test]
public function can_customize_namespace(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -234,6 +248,7 @@ public function can_customize_namespace(): void
/**
* @test
*/
#[Test]
public function can_customize_namespace_with_test_flag(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -253,6 +268,7 @@ public function can_customize_namespace_with_test_flag(): void
/**
* @test
*/
#[Test]
public function can_customize_namespace_with_root_namespace_prefix(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -272,6 +288,7 @@ public function can_customize_namespace_with_root_namespace_prefix(): void
/**
* @test
*/
#[Test]
public function can_customize_namespace_with_test_flag_with_root_namespace_prefix(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -292,6 +309,8 @@ public function can_customize_namespace_with_test_flag_with_root_namespace_prefi
* @test
* @dataProvider documentProvider
*/
#[Test]
#[DataProvider('documentProvider')]
public function can_create_factory_for_odm(string $class, string $file): void
{
if (!\getenv('MONGO_URL')) {
Expand All @@ -318,6 +337,7 @@ public static function documentProvider(): iterable
/**
* @test
*/
#[Test]
public function can_create_all_factories_for_doctrine_objects(): void
{
if (!\getenv('MONGO_URL') && !\getenv('DATABASE_URL')) {
Expand Down Expand Up @@ -350,6 +370,7 @@ public function can_create_all_factories_for_doctrine_objects(): void
/**
* @test
*/
#[Test]
public function can_create_factory_with_auto_activated_not_persisted_option(): void
{
if (\getenv('MONGO_URL') || \getenv('DATABASE_URL')) {
Expand All @@ -369,6 +390,7 @@ public function can_create_factory_with_auto_activated_not_persisted_option(): v
/**
* @test
*/
#[Test]
public function can_create_factory_with_all_fields(): void
{
if (!\getenv('DATABASE_URL')) {
Expand All @@ -386,6 +408,8 @@ public function can_create_factory_with_all_fields(): void
* @test
* @dataProvider objectsWithEmbeddableProvider
*/
#[Test]
#[DataProvider('objectsWithEmbeddableProvider')]
public function can_create_factory_with_embeddable(string $objectClass, string $objectFactoryName): void
{
$tester = $this->makeFactoryCommandTester();
Expand Down Expand Up @@ -413,6 +437,7 @@ public static function objectsWithEmbeddableProvider(): iterable
/**
* @test
*/
#[Test]
public function can_create_factory_with_default_enum(): void
{
$tester = $this->makeFactoryCommandTester();
Expand All @@ -425,6 +450,7 @@ public function can_create_factory_with_default_enum(): void
/**
* @test
*/
#[Test]
public function does_not_initialize_non_settable(): void
{
$tester = $this->makeFactoryCommandTester();
Expand All @@ -437,6 +463,7 @@ public function does_not_initialize_non_settable(): void
/**
* @test
*/
#[Test]
public function does_force_initialization_of_non_settable_with_always_force(): void
{
$tester = $this->makeFactoryCommandTester(['environment' => 'always_force']);
Expand Down
Loading
Loading