Created
March 22, 2020 16:52
-
-
Save lstrojny/a8675b47cc182101e088057ce8962122 to your computer and use it in GitHub Desktop.
SF functional test example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function testSomething(): void | |
{ | |
$client = static::createClient(); | |
$entity = self::$container->get('em')->find(…, 1); | |
$entity->setState(1); | |
self::$container->get('em')->persist($entity); | |
self::$container->get('em')->flush(); | |
$client->request(…, …); | |
$entity->setState(2); | |
self::$container->get('em')->persist($entity); | |
self::$container->get('em')->persist($entity); | |
// Boom | |
self::$container->get('em')->flush(); | |
} |
@tdomarkas exactly the opposite advice of https://twitter.com/Ocramius/status/1241770426218557441 😄
Just to clarify: avoid $this->em->clear();
in a HTTP request IF you want to introspect and operate on the same entities after $client->request()
is over. 🙂
EDIT: But if that can't be done or you don't want to care what happens inside a request, indeed - just refresh the entity.
ServiceResetter
during Kernel boot will clear the EM no matter what, so not too much one can do
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
self::assertSame($client->getContainer()->get('em'), self::$container->get('em'));
$this->em->clear();
in a HTTP request.