Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ jobs:

- name: Test
run: |
./phpunit --testsuite reset-database --bootstrap tests/bootstrap-reset-database.php
./phpunit --testsuite reset-database

# We should be able to run the tests twice in order to check if the second run also starts from a fresh db
# some bugs could be detected this way
./phpunit --testsuite reset-database --bootstrap tests/bootstrap-reset-database.php
./phpunit --testsuite reset-database
shell: bash
env:
SYMFONY_REQUIRE: 8.0.*
Expand Down
8 changes: 2 additions & 6 deletions config/persistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@
'command' => 'foundry:load-fixtures|foundry:load-stories|foundry:load-story',
'description' => 'Load stories which are marked with #[AsFixture] attribute.',
])
;

if (\PHP_VERSION_ID >= 80400) {
$container->services()->set('.foundry.persistence.objects_tracker', PersistedObjectsTracker::class)
->set('.foundry.persistence.objects_tracker', PersistedObjectsTracker::class)
->tag('kernel.reset', ['method' => 'refresh'])
->tag('kernel.event_listener', ['event' => TerminateEvent::class, 'method' => 'refresh'])
->tag('kernel.event_listener', ['event' => ConsoleTerminateEvent::class, 'method' => 'refresh'])
->tag('kernel.event_listener', ['event' => WorkerMessageHandledEvent::class, 'method' => 'refresh']) // @phpstan-ignore class.notFound
->tag('foundry.hook', ['class' => null, 'method' => 'afterPersistHook', 'event' => AfterPersist::class])
;
}
;
};
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ parameters:
- identifier: missingType.iterableValue
path: tests/

# PHPStan does not understand PHP version checks
- message: '#Comparison operation "(<|>|<=|>=)" between int<80\d+, 80\d+> and 80\d+ is always (false|true).#'

# Hydrator and Factory are annotated @immutable
- identifier: property.readOnlyByPhpDocDefaultValue
paths:
Expand Down
11 changes: 0 additions & 11 deletions phpunit-deprecation-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
<?xml version="1.0"?>
<files version="1">
<file path="vendor/symfony/deprecation-contracts/function.php">
<line number="25" hash="c6af5d66288d0667e424978000f29571e4954b81">
<issue><![CDATA[Since symfony/framework-bundle 6.4: Not setting the "framework.php_errors.log" config option is deprecated. It will default to "true" in 7.0.]]></issue>

<issue><![CDATA[Since doctrine/mongodb-odm 2.14: Not using native lazy objects is deprecated and will be impossible in Doctrine MongoDB ODM 3.0.]]></issue>
<issue><![CDATA[Since symfony/framework-bundle 7.3: Not setting the "property_info.with_constructor_extractor" option explicitly is deprecated because its default value will change in version 8.0.]]></issue>
<issue><![CDATA[Since symfony/console 7.4: The "Symfony\Component\Console\Application::add()" method is deprecated and will be removed in Symfony 8.0, use "Symfony\Component\Console\Application::addCommand()" instead.]]></issue>
<issue><![CDATA[Since doctrine/mongodb-odm 2.3: Document short namespace aliases are deprecated, use ::class constant instead.]]></issue>
</line>
</file>
<file path="vendor/doctrine/deprecations/src/Deprecation.php">
<line number="208" hash="815824609bbd80ce3a5cc8a6a19c2e6dd0c6985c">
<issue><![CDATA[Support for MySQL < 8 is deprecated and will be removed in DBAL 5 (AbstractMySQLDriver.php:70 called by AbstractDriverMiddleware.php:32, https://github.com/doctrine/dbal/pull/6343, package doctrine/dbal)]]></issue>
<issue><![CDATA[Support for MySQL < 8 is deprecated and will be removed in DBAL 5 (AbstractMySQLDriver.php:75 called by AbstractDriverMiddleware.php:32, https://github.com/doctrine/dbal/pull/6343, package doctrine/dbal)]]></issue>
</line>
</file>
Expand Down
6 changes: 3 additions & 3 deletions skeleton/Factory.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
{
}

<?php endif ?><?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?php endif ?>
<?php endif ?> #[\Override]
public static function class(): string
{
return <?php echo $makeFactoryData->getObjectShortName(); ?>::class;
Expand All @@ -33,7 +33,7 @@ public static function class(): string
*
* @todo add your default values here
*/
<?php endif ?><?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?php endif ?>
<?php endif ?> #[\Override]
protected function defaults(): array<?php if ($makeFactoryData->shouldAddHints()): ?>|callable<?php endif ?>
{
return [
Expand All @@ -48,7 +48,7 @@ protected function defaults(): array<?php if ($makeFactoryData->shouldAddHints()
<?php if ($makeFactoryData->shouldAddHints()): ?> /**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
<?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?php endif ?>
#[\Override]
protected function initialize(): static
{
return $this
Expand Down
12 changes: 0 additions & 12 deletions src/Maker/Factory/MakeFactoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ public function getDefaultProperties(): array

public function addEnumDefaultProperty(string $propertyName, string $enumClass): void
{
if (\PHP_VERSION_ID < 80100) {
throw new \LogicException('Cannot add enum for php version inferior than 8.1');
}

if (!\enum_exists($enumClass)) {
throw new \InvalidArgumentException("Enum of class \"{$enumClass}\" does not exist.");
}
Expand All @@ -179,14 +175,6 @@ public function shouldAddHints(): bool
return $this->addHints;
}

/**
* @phpstan-ignore return.tooWideBool
*/
public function shouldAddOverrideAttributes(): bool
{
return \PHP_VERSION_ID >= 80300;
}

private static function propertyInfo(): ReflectionExtractor
{
return self::$propertyInfo ??= new ReflectionExtractor();
Expand Down
2 changes: 1 addition & 1 deletion src/Maker/Factory/ObjectDefaultPropertiesGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(SymfonyStyle $io, MakeFactoryData $makeFactoryData, Mak

$value = \sprintf('null, // TODO add %svalue manually', $type ? "{$type} " : '');

if (\PHP_VERSION_ID >= 80100 && \enum_exists($type)) {
if (\enum_exists($type)) {
$makeFactoryData->addEnumDefaultProperty($property->getName(), $type);

continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\BeforeClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\Configuration;
use Zenstruck\Foundry\Persistence\PersistenceManager;
use Zenstruck\Foundry\Tests\Integration\RequiresORM;

/**
* @author Nicolas PHILIPPE <nikophil@gmail.com>
Expand All @@ -36,10 +36,16 @@
*/
trait ChangesEntityRelationshipCascadePersist
{
use RequiresORM;

private static string $methodName = '';

#[BeforeClass]
public static function _requiresORM(): void
{
if (!\getenv('DATABASE_URL')) {
self::markTestSkipped('SQL database not available.');
}
}

#[Before]
public function setUpCascadePersistMetadata(): void
{
Expand Down Expand Up @@ -82,9 +88,7 @@ public static function provideCascadeRelationshipsCombinations(): iterable
}

if (!\getenv('DATABASE_URL') || !self::$methodName) {
// this test requires the ORM, but trait RequiresORM is analysed after data provider are called
// then we need to return at least one empty array to avoid an error
// in PHPUnit 12, we will be able to use #[RequiresEnvironmentVariable('DATABASE_URL')] to prevent this
// data providers are resolved before #[RequiresEnvironmentVariable] is checked
yield []; // @phpstan-ignore generator.valueType

return;
Expand Down
8 changes: 0 additions & 8 deletions tests/Integration/ArrayFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Zenstruck\Foundry\Tests\Integration;

use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\LazyValue;
Expand All @@ -22,11 +21,7 @@
*/
final class ArrayFactoryTest extends KernelTestCase
{
/**
* @test
*/
#[Test]
#[IgnoreDeprecations]
public function can_create_with_defaults(): void
{
$this->assertSame(
Expand All @@ -40,9 +35,6 @@ public function can_create_with_defaults(): void
);
}

/**
* @test
*/
#[Test]
public function can_create_with_overrides(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Zenstruck\Foundry\Attribute\ResetDatabase;
use Zenstruck\Foundry\Attribute\WithStory;
use Zenstruck\Foundry\Tests\Fixture\Stories\EntityStory;
use Zenstruck\Foundry\Tests\Integration\RequiresORM;

/**
* @author Nicolas PHILIPPE <nikophil@gmail.com>
Expand All @@ -24,5 +23,4 @@
#[ResetDatabase]
abstract class ParentClassWithStoryAttributeTestCase extends KernelTestCase
{
use RequiresORM;
}
11 changes: 2 additions & 9 deletions tests/Integration/Attribute/WithStory/WithStoryOnClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,23 @@

namespace Zenstruck\Foundry\Tests\Integration\Attribute\WithStory;

use PHPUnit\Framework\Attributes\RequiresPhpunit;
use PHPUnit\Framework\Attributes\RequiresPhpunitExtension;
use PHPUnit\Framework\Attributes\RequiresEnvironmentVariable;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\Attribute\ResetDatabase;
use Zenstruck\Foundry\Attribute\WithStory;
use Zenstruck\Foundry\PHPUnit\FoundryExtension;
use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\GenericEntityFactory;
use Zenstruck\Foundry\Tests\Fixture\Stories\EntityPoolStory;
use Zenstruck\Foundry\Tests\Fixture\Stories\EntityStory;
use Zenstruck\Foundry\Tests\Integration\RequiresORM;

/**
* @author Nicolas PHILIPPE <nikophil@gmail.com>
* @requires PHPUnit >=11.0
*/
#[RequiresPhpunit('>=11.0')]
#[RequiresPhpunitExtension(FoundryExtension::class)]
#[WithStory(EntityStory::class)]
#[ResetDatabase]
#[RequiresEnvironmentVariable('DATABASE_URL')]
final class WithStoryOnClassTest extends KernelTestCase
{
use RequiresORM;

#[Test]
public function can_use_story_in_attribute(): void
{
Expand Down
11 changes: 2 additions & 9 deletions tests/Integration/Attribute/WithStory/WithStoryOnMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,23 @@

namespace Zenstruck\Foundry\Tests\Integration\Attribute\WithStory;

use PHPUnit\Framework\Attributes\RequiresPhpunit;
use PHPUnit\Framework\Attributes\RequiresPhpunitExtension;
use PHPUnit\Framework\Attributes\RequiresEnvironmentVariable;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\Attribute\ResetDatabase;
use Zenstruck\Foundry\Attribute\WithStory;
use Zenstruck\Foundry\PHPUnit\FoundryExtension;
use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\GenericEntityFactory;
use Zenstruck\Foundry\Tests\Fixture\Stories\EntityPoolStory;
use Zenstruck\Foundry\Tests\Fixture\Stories\EntityStory;
use Zenstruck\Foundry\Tests\Fixture\Stories\ServiceStory;
use Zenstruck\Foundry\Tests\Integration\RequiresORM;

/**
* @author Nicolas PHILIPPE <nikophil@gmail.com>
* @requires PHPUnit >=11.0
*/
#[RequiresPhpunit('>=11.0')]
#[RequiresPhpunitExtension(FoundryExtension::class)]
#[ResetDatabase]
#[RequiresEnvironmentVariable('DATABASE_URL')]
final class WithStoryOnMethodTest extends KernelTestCase
{
use RequiresORM;

#[Test]
#[WithStory(EntityStory::class)]
public function can_use_story_in_attribute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@

namespace Zenstruck\Foundry\Tests\Integration\Attribute\WithStory;

use PHPUnit\Framework\Attributes\RequiresPhpunit;
use PHPUnit\Framework\Attributes\RequiresPhpunitExtension;
use PHPUnit\Framework\Attributes\RequiresEnvironmentVariable;
use PHPUnit\Framework\Attributes\Test;
use Zenstruck\Foundry\Attribute\WithStory;
use Zenstruck\Foundry\PHPUnit\FoundryExtension;
use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\GenericEntityFactory;
use Zenstruck\Foundry\Tests\Fixture\Stories\EntityPoolStory;

/**
* @author Nicolas PHILIPPE <nikophil@gmail.com>
* @requires PHPUnit >=11.0
*/
#[RequiresPhpunit('>=11.0')]
#[RequiresPhpunitExtension(FoundryExtension::class)]
#[WithStory(EntityPoolStory::class)]
#[RequiresEnvironmentVariable('DATABASE_URL')]
final class WithStoryOnParentClassTest extends ParentClassWithStoryAttributeTestCase
{
#[Test]
Expand Down
Loading
Loading