Symfony2Extension icon indicating copy to clipboard operation
Symfony2Extension copied to clipboard

Strange behavior with a test

Open dimzerawww opened this issue 9 years ago • 1 comments

Hello,

I have a strange behavior with POST tests with my API and Behat.

My project is a symfony2 project. I have an entity with a token field which is the identifier (with a customid generator which generates random token).

To simplify the tests, i force the idgenerator of entity to an other which generate id (1, 2, 3 ...) in the FeatureContext of Behat. It works on every test (GET, PUT, POST, ... of my API). In one of my post tests, i try to do 3 posts in one scenario and get the entity with GET /entity/1, entity/2, entity/3. On the first post, the entity is created and the token is an id generated by the generator defined in FeatureContext. On the second and third post, entity is created but the token is generated by the generator defined in entity and not in FeatureContext.

My entity :

class Booking
{
    /**
     * @var string
     *
     * @ORM\Column(name="token", type="string", length=8)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class="ApiBundle\Doctrine\Generator\Token")
     *
     */
    private $token;
}

The construct function of FeatureContext loaded :

    public function __construct(ManagerRegistry $doctrine)
    {
        $this->doctrine = $doctrine;
        $this->manager = $doctrine->getManager();

        // Disable auto token assignment on Booking class (to use auto id for tests)
        $bookingClassMetaData = $this->manager->getClassMetaData('ApiBundle\Entity\Booking');
        $bookingClassMetaData->setIdGenerator(new FakeToken());

        $this->schemaTool = new SchemaTool($this->manager);
        $this->classes = $this->manager->getMetadataFactory()->getAllMetadata();
    }

I know it's really specific but i want to know if you have similar issues.

Thanks you, Best regards, Dimitri

dimzerawww avatar Sep 05 '16 08:09 dimzerawww

Hey, did you have any luck to find a solution ?

I've got a similar issue, if i do bin2hex(random_bytes(16)) and dump them, between 2 api calls they'll be the same values...

froozeify avatar Mar 31 '21 09:03 froozeify