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

EntityManager: add setRepository() method #1

Closed
wants to merge 1 commit into from
Closed

EntityManager: add setRepository() method #1

wants to merge 1 commit into from

Conversation

maxim-oleinik
Copy link

Goal is to have opportunity to set mocked repo.

// PHPUnit
$repo = $this->getMock('ArticleRepository', array('findActiveByAuthor'), array($em, $metadata));
$repo->expects($this->once())
     ->method('findActiveByAuthor');
$em->setRepository($entityName, $repo);

// Proxy call
$author->getArticles();

EntityManager::clear() resets all initialized repositories too
@beberlei
Copy link
Member

beberlei commented Sep 9, 2010

imho rejected. It only blows up the API.

You have to mock the entity manager for this, and testing proxy calls is nothing you should do. Proxies are a Doctrine feature, tested by doctrine, you should only functinoally test them.

@maxim-oleinik
Copy link
Author

Sorry, not D2 proxy. See:

$author->getArticles() {
    return $this->getEntityManager()
        ->getRepository('ArticleRepository')
        ->findActiveByAuthor($this);
}

@beberlei
Copy link
Member

I won't merge this. Adding setRepository() serves no other purpose than for testing reasons, yet there are other solutions.

You could also just mock the entity manager and have it return the repository mock. Its a bit more difficult, but thats a problem of the PHPUnit Mock complexity.

@maxim-oleinik
Copy link
Author

Ok, I'll try another ways. Thanks.

r0ssIV referenced this pull request in datasyntax/doctrine2 Apr 16, 2013
Ocramius pushed a commit that referenced this pull request Jul 31, 2014
Ocramius pushed a commit that referenced this pull request Jan 20, 2015
This was referenced Dec 6, 2015
aldisanta pushed a commit to aldisanta/doctrine2 that referenced this pull request Oct 31, 2016
@kirya-dev kirya-dev mentioned this pull request Apr 8, 2020
@tasselchof tasselchof mentioned this pull request Aug 2, 2023
This pull request was closed.
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 this pull request may close these issues.

2 participants