Skip to content

Commit b8c32fd

Browse files
committed
minor: make "in-memory" classes experimental (#895)
1 parent 0032460 commit b8c32fd

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

docs/index.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,11 @@ applications or with `hexagonal architecture <https://en.wikipedia.org/wiki/Hexa
21332133
repositories in the domain are usually interfaces for which main implementations are a Doctrine one. You can tell Foundry to
21342134
use the "in-memory" version of these repositories.
21352135

2136+
.. versionadded:: 2.5
2137+
2138+
The "in-memory" behavior is experimental. Experimental features are not
2139+
covered by the backward compatibility promise.
2140+
21362141
First, you need to create an "in-memory" version of your repository. This repository must implement the
21372142
``Zenstruck\Foundry\InMemory\InMemoryRepository`` interface. You can use the trait
21382143
``Zenstruck\Foundry\InMemory\InMemoryRepositoryTrait`` to help you with this:
@@ -2160,7 +2165,7 @@ First, you need to create an "in-memory" version of your repository. This reposi
21602165
}
21612166

21622167
Then, the "in-memory" repository should be used in Symfony's container, as the main repository implementation. For this
2163-
purpose, you can either use a new environment ``test-in-memory``, or declare use ``InMeMemoryKernel``.
2168+
purpose, you can either use a new environment ``test-in-memory``, or use a ``InMeMemoryKernel``.
21642169

21652170
In your tests, use the ``#[AsInMemoryTest]`` attribute, which will disable persistence of the factories, and register an
21662171
"after instantiate" hook, which will store the objects in their respective "in memory" repositories:
@@ -2185,6 +2190,13 @@ In your tests, use the ``#[AsInMemoryTest]`` attribute, which will disable persi
21852190
$address = AddressFactory::createOne();
21862191

21872192
self::assertSame([$address], $this->addressRepository->_all());
2193+
2194+
// The following assertion is also true, `YourFactory::repository()` returns a special "in-memory" repository
2195+
// no request to the database will be made.
2196+
self::assertSame(1, AddressFactory::repository()->count(1));
2197+
2198+
// You can even use `YourFactory::repository()->assert()`
2199+
AddressFactory::repository()->assert()->count(1);
21882200
}
21892201
}
21902202

src/InMemory/AsInMemoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/**
1717
* @author Nicolas PHILIPPE <[email protected]>
18+
* @experimental
1819
*/
1920
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
2021
final class AsInMemoryTest

src/InMemory/GenericInMemoryRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @template T of object
1818
* @implements InMemoryRepository<T>
1919
* @author Nicolas PHILIPPE <[email protected]>
20+
* @experimental
2021
*
2122
* This class will be used when a specific "in-memory" repository does not exist for a given class.
2223
*/

src/InMemory/InMemoryRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @author Nicolas PHILIPPE <[email protected]>
1818
*
1919
* @template T of object
20+
* @experimental
2021
*/
2122
interface InMemoryRepository
2223
{

src/InMemory/InMemoryRepositoryTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/**
1717
* @template T of object
1818
* @phpstan-require-implements InMemoryRepository
19+
* @experimental
1920
*
2021
* @author Nicolas PHILIPPE <[email protected]>
2122
*/

0 commit comments

Comments
 (0)