Releases: zenstruck/foundry
v2.3.1
v2.3.0
Features
0867ad6 feat: add #[WithStory]
attribute (#728) by @nikophil
You can use the #[WithStory]
attribute to load stories in your tests:
use App\Story\CategoryStory;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\Attribute\WithStory;
// You can use the attribute on the class...
#[WithStory(CategoryStory::class)]
final class NeedsCategoriesTest extends KernelTestCase
{
// ... or on the method
#[WithStory(CategoryStory::class)]
public function testThatNeedStories(): void
{
// ...
}
}
If used on the class, the story will be loaded before each test method.
Fixes
af64c35 fix: detect if relation is oneToOne (#732) by @nikophil
c8f5046 fix: fix PHPUnit constraint requirement in FoundryExtension (#735) by @HypeMC
403d9e9 fix: Fix the parameter name of the first and last methods (#730) by @marien-probesys
c5d0bdd fix: can create inversed one to one with non nullable (#726) by @nikophil
f48ffd1 fix: can create inversed one to one (#659) by @nikophil
6d08784 fix: bug with one to many (#722) by @nikophil
Minor
b16b227 docs: Update index.rst (#740) by @OskarStark, @nikophil
854220f docs: fix highlighting and use CPP (#740) by @OskarStark
dfe6bab tests: add paratest permutation (#736) by @nikophil
59867c3 tests: change versions requirements (#737) by @nikophil
4cb7447 docs: Typo in Immutable section (#731) by @franckranaivo
0e7ac6f docs: Fix Story phpdocs (#727) by @simondaigre, @nikophil
efadea8 docs:fix code blocks not showing up (#723) by @AndreasA
edf287e minor: Add templated types to flush_after (#719) by @BackEndTea
v2.2.2
v2.2.1
v2.2.0
Main features
Factory::create()
and factory service in data providers
2014ed9 feature: allow to use Factory::create()
and factory service in data providers (#648) by @nikophil
From version 2.2, Foundry provides an extension for PHPUnit.
You can install it by modifying you phpunit.xml.dist
:
<phpunit>
<extensions>
<bootstrap class="Zenstruck\Foundry\PHPUnit\FoundryExtension"/>
</extensions>
</phpunit>
Warning
This PHPUnit extension requires at least PHPUnit 11.4.
Using this extension will allow to use your factories in your data providers the same way you're using them in tests.
Thanks to it, you can:
- Call
->create()
or::createOne()
or any other method which creates objects in unit tests
(usingPHPUnit\Framework\TestCase
) and functional tests (Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
) - Use "Factories as Services" in functional tests
- Use
faker()
normally, without wrapping its call in a callable
Make "database reset" mechanism extendable
df568da refactor: make "database reset" mechanism extendable (#690) by @nikophil
The reset mechanism can now be extended thanks to decoration:
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\When;
use Symfony\Component\HttpKernel\KernelInterface;
use Zenstruck\Foundry\ORM\ResetDatabase\OrmResetter;
// The decorator should be declared in test environment only.
#[When('test')]
// You can also decorate `MongoResetter::class`.
#[AsDecorator(OrmResetter::class)]
final readonly class DecorateDatabaseResetter implements OrmResetter
{
public function __construct(
private OrmResetter $decorated
) {}
public function resetBeforeFirstTest(KernelInterface $kernel): void
{
// do something once per test suite (for instance: install a PostgreSQL extension)
$this->decorated->resetBeforeFirstTest($kernel);
}
public function resetBeforeEachTest(KernelInterface $kernel): void
{
// do something once per test case (for instance: restart PostgreSQL sequences)
$this->decorated->resetBeforeEachTest($kernel);
}
}
Add a Psalm Extension
0d570cc refactor: fix proxy system and introduce psalm extension (#704) by @nikophil
A Psalm extension is now shipped with the library and makes Psalm happy with your factories.
You can enable it with:
.. code-block:: terminal
$ vendor/bin/psalm-plugin enable zenstruck/foundry
Minor PRs
a549c10 docs: using factories in data providers (#707) by @nikophil
470d927 docs: how to extend database reset mechanism (#706) by @nikophil
4fb0b25 docs: add missing docs (#703) by @nikophil
fa1d527 minor: misc fixes for sca (#705) by @nikophil
v2.1.0
v2.0.9
v2.0.8
3eebbf9 Have flush_after()
return the callback's return (#691) by @HypeMC
33d5870 doc: Fix range call instead of many (#688) by @ternel
33595b9 chore: add a wrapper for PHPUnit binary (#683) by @nikophil
8bf8c4c docs: Fix CategoryStory codeblock (#681) by @smnandre
f89d43e doc: Minor fixes (#679) by @smnandre
65c1cc2 fix: add phpdoc to improve proxy factories autocompletion (#675) by @nikophil
v2.0.7
5c44991 fix: handle proxies when refreshing entity in Proxy::getState() (#672) by @nikophil
49f5e1d Fix faker php urls (#671) by @BackEndTea
7719b0d chore(CI): Enable documentation linter (#657) by @cezarpopa