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

Different results if I run one test and all test in same time #17

Open
ilijastojkovic opened this issue Jan 10, 2019 · 6 comments
Open

Comments

@ilijastojkovic
Copy link

What are you trying to achieve?

Right now, I have some strange behaviour while running functional tests. If I run one file codecept run functional /FunctionalFolder/Services/ServiceOneCest, all tests are success - as expected. But in secound case, when I run all created tests codecept run functional /FunctionalFolder, some tests are finished as expected, while some others are failed.

Somehow, in _before() section, are not executed all dependeces.

class ServiceOneCest
{
public function _before(FunctionalTester $I)
 {
            $this->entityManager = $I->grabServiceFromContainer(EntityManager::class);
            $this->entity = $this->entityManager->getRepository(Entity::class)
            ->findOneBy([
                'name' => 'test'
            ]);
         
        if (!$this->entity) {
            $this->entity = $I->have(Entity::class, ['name' => 'test']);
        }
}

public function testSomething(FunctionalTester $I)
{
      $I->assertEquals('test', $this->entity->getName());
      // here I catch error message [Error] Call to a member function getName() on null
      // it only happend when I run more then one test file
}
}

//also exist some other test file

class ServiceTwoCest
{
}

I expect same results if I run one test file or more. I need to say, don't have any dependece between test data created in _before()

Please, if you see any reason or my bad code/configuration anything, give me handsup. If you have some other questions, please feel free to contact me.

Details

  • Codeception version: 2.5.1
  • PHP Version:PHP 7.1.25
  • Operating System: ubuntu16.04.1 (on vagrant)
  • Installation type: Phar || Composer
  • List of installed packages (composer show)
  • Suite configuration:
actor: FunctionalTester
modules:
    enabled:
        - ZF2
        - Asserts
        - \Helper\Functional
        - Doctrine2:
            depends: ZF2
        - DataFactory:
            depends: Doctrine2
        - \Helper\Factories
    config:
        Doctrine2:
            cleanup: true
@Naktibalda
Copy link
Member

if (!$entity) {

Check $this->entity instead.

@ilijastojkovic
Copy link
Author

thanks for the hint, but this is a typo.

@Naktibalda
Copy link
Member

Have you made another typo in this line?

$this->entity = $I->have(Entity::class, ['name' => 'test']);

If you actually used haveInRepository there, this method does not return entity, so null is assigned to $this->entity.

@ilijastojkovic
Copy link
Author

I don't think so. $I->have() return

    * [!] Method is generated. Documentation taken from corresponding module.
    *
    * Generates and saves a record,.
    *
    * ```php
    * $I->have('User'); // creates user
    * $I->have('User', ['is_active' => true]); // creates active user
    * ```
    *
    * Returns an instance of created user.
    *
    * @param string $name
    * @param array $extraAttrs
    *
    * @return object
    * @see \Codeception\Module\DataFactory::have()
    */
   public function have($name, $extraAttrs = null) {
       return $this->getScenario()->runStep(new \Codeception\Step\Action('have', func_get_args()));
   }

So $this->entity is instance of provided Entity::class

@SeCoBremen
Copy link

Did you have a solution? I have the same problem right now

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 4, 2021
@Clasyc
Copy link

Clasyc commented Aug 5, 2023

Same problem for me: Codeception/Codeception#6682

@TavoNiievez TavoNiievez transferred this issue from Codeception/module-doctrine2 Feb 17, 2024
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

4 participants