Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior with a test #113

Open
dimzerawww opened this issue Sep 5, 2016 · 1 comment
Open

Strange behavior with a test #113

dimzerawww opened this issue Sep 5, 2016 · 1 comment

Comments

@dimzerawww
Copy link

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

@sroze sroze closed this as completed Oct 28, 2016
@sroze sroze reopened this Oct 28, 2016
@froozeify
Copy link

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants