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

haveFakeRepository from Doctrine2 module doesn't work #44

Closed
olexp opened this issue Jun 25, 2021 · 2 comments · Fixed by #45
Closed

haveFakeRepository from Doctrine2 module doesn't work #44

olexp opened this issue Jun 25, 2021 · 2 comments · Fixed by #45

Comments

@olexp
Copy link
Contributor

olexp commented Jun 25, 2021

First, this issue is not related to Codeception/module-doctrine#20

Repository mock cannot be found by EntityManager because repositoryList property on DefaultRepositoryFactory implementation is keyed by hash and not by class name. So, code from Doctrine2 Codeception module

                $repositoryListProperty->setValue(
                    $repositoryFactory,
                    [$classname => $mock]
                );

should be replace with something like this for newer Doctrine ORM:

                $repositoryHash = $em->getClassMetadata($classname)->getName() . spl_object_hash($em);
                $repositoryListProperty->setValue(
                    $repositoryFactory,
                    [$repositoryHash => $mock]
                );

Installed components:

PHP 7.4.20
codeception/codeception                           4.1.20    BDD-style testing framework
codeception/lib-asserts                           1.13.2    Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser                      1.4.2     Parent library for all Codeception framework modules and PhpBrowser
codeception/module-asserts                        1.3.1     Codeception module containing various assertions
codeception/module-doctrine2                      1.1.1     Doctrine2 module for Codeception
codeception/module-laminas                        1.0.0     Codeception module for the Laminas Project
codeception/module-phpbrowser                     1.0.2     Codeception module for testing web application over HTTP
codeception/module-rest                           1.3.0     REST module for Codeception
codeception/module-webdriver                      1.2.0     WebDriver module for Codeception
codeception/phpunit-wrapper                       9.0.6     PHPUnit classes used by Codeception
codeception/stub                                  3.7.0     Flexible Stub wrapper for PHPUnit's Mock Builder
doctrine/orm                                      2.8.4     Object-Relational-Mapper for PHP
@Naktibalda
Copy link
Member

Naktibalda commented Jul 4, 2021

If you know how to fix the issue, please raise pull request.

@olexp
Copy link
Contributor Author

olexp commented Jul 6, 2021

Please check #45

@TavoNiievez TavoNiievez linked a pull request Jul 22, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants