Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7696049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:41:23+00:00 2026-05-31T21:41:23+00:00

I have a PHPUnit test that’s using a Doctrine2 custom repository and Doctrine Fixtures.

  • 0

I have a PHPUnit test that’s using a Doctrine2 custom repository and Doctrine Fixtures. I wanted to test that a query gave me back an expected entity from my fixture.

But when I try $this->assertEquals($expectedEntity, $result);, I get Fatal error: out of memory. I’m guessing it is recursing into all the relations and the entity manager and whatnot.

Is there a good way to test this equality? Should I just assertEquals on the IDs of the entities?

Edit:
Here is the test code

<?php
use Liip\FunctionalTestBundle\Test\WebTestCase;

class AbstractRepositoryTestCase extends WebTestCase
{
    /**
     * @var Doctrine\ORM\EntityRepository 
     */
    protected $repo;

    /**
     * @var Doctrine\Common\DataFixtures\Executor\AbstractExecutor
     */
    protected $fixtureExecutor;

    /**
     * @var string Which repository to load, overriden by derived class
     */
    protected $repoName;

    /**
     * @var array Fixture classes to load on setup
     */
    protected $fixtures = array();

    public function setUp()
    {
        $kernel = static::createKernel();
        $this->repo = $kernel->boot();
        $this->repo = $kernel->getContainer()
                             ->get('doctrine.orm.entity_manager')
                             ->getRepository($this->repoName);

        $this->fixtureExecutor = $this->loadFixtures($this->getFixtures());
    }

    public function getFixtures()
    {
        return $this->fixtures;
    }
}

class ArticleRepositoryTest extends AbstractRepositoryTestCase
{
    /**
     * @var string Which repository to load, overriden by derived class
     */
    protected $repoName = 'MyMainBundle:Article';

    /**
     * @var array Fixture classes to load on setup
     */
    protected $fixtures = array(
        'My\MainBundle\DataFixtures\ORM\LoadUserData',
        'My\MainBundle\DataFixtures\ORM\LoadArticleData',
        'My\MainBundle\DataFixtures\ORM\LoadFeedsData',
        'My\MainBundle\DataFixtures\ORM\LoadFeedDataData',
        'My\MainBundle\DataFixtures\ORM\LoadUserReadArticleData',
    );
    public function testGetNextArticle_ExpectCorrect()
    {
        /** @var Doctrine\Common\DataFixtures\ReferenceRepository **/
        $refRepo = $this->fixtureExecutor->getReferenceRepository();

        /** @var FeedStream\MainBundle\Entity\Article **/
        $curr = $refRepo->getReference('feed-1-article-3');
        $expected = $refRepo->getReference('feed-1-article-2');
        $expected2 = $refRepo->getReference('feed-1-article-1');
        $next = $this->repo->getNextArticle($curr->getFeed()->getId(), $curr);

        $this->assertNotNull($next);
        // this is the part that doesn't work
        $this->assertEquals($expected, $next);
        // this is the code I've used instead
        $this->assertEquals($expected->getId(), $next->getId());
    }
}

Here is the entity (getters/setters omitted to save space)

<?php

namespace My\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * My\MainBundle\Entity\Article
 *
 * @ORM\Table(name="articles", uniqueConstraints={
 *   @ORM\UniqueConstraint(name="feed_guid", columns={"feed_id", "guid"}),
 *   @ORM\UniqueConstraint(name="article_slug_unique", columns={"feed_id", "slug"})
 * })
 * @ORM\Entity(repositoryClass="My\MainBundle\Repository\ArticleRepository")
 */
class Article
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $guid
     *
     * @ORM\Column(name="guid", type="string", length=255, nullable=false)
     */
    private $guid;

    /**
     * @var string $title
     *
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;

    /**
     * @var datetime $pubDate
     *
     * @ORM\Column(name="pub_date", type="datetime", nullable=true)
     */
    private $pubDate;

    /**
     * @var text $summary
     *
     * @ORM\Column(name="summary", type="text", nullable=true)
     */
    private $summary;

    /**
     * @var text $content
     *
     * @ORM\Column(name="content", type="text", nullable=false)
     */
    private $content;

    /**
     * @var string $sourceUrl
     *
     * @ORM\Column(name="source_url", type="string", length=255, nullable=true)
     */
    private $sourceUrl;

    /**
     * @var string $commentUrl
     *
     * @ORM\Column(name="comment_url", type="string", length=255, nullable=true)
     */
    private $commentUrl;

    /**
     * @var string $slug
     *
     * @ORM\Column(name="slug", type="string", length=64, nullable=false)
     */
    private $slug;

    /**
     * @var string $thumbnailFile
     *
     * @ORM\Column(name="thumbnail_file", type="string", length=64, nullable=true)
     */
    private $thumbnailFile;

    /**
     * @var My\MainBundle\Entity\ArticleEnclosure
     *
     * @ORM\ManyToOne(targetEntity="My\MainBundle\Entity\ArticleEnclosure")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="thumbnail_enclosure_id", referencedColumnName="id")
     * })
     */
    private $thumbnailEnclosure;

    /**
     * @var My\MainBundle\Entity\ArticleImageScrape
     *
     * @ORM\ManyToOne(targetEntity="My\MainBundle\Entity\ArticleImageScrape")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="thumbnail_scrape_id", referencedColumnName="id", unique=false)
     * })
     */
    private $thumbnailScrape;

    /**
     * @var My\MainBundle\Entity\ArticleBitly
     *
     * @ORM\OneToOne(targetEntity="My\MainBundle\Entity\ArticleBitly", mappedBy="article", orphanRemoval=true)
     */
    private $bitly;

    /**
     * @var My\MainBundle\Entity\ArticleEnclosure
     *
     * @ORM\OneToMany(targetEntity="My\MainBundle\Entity\ArticleEnclosure", mappedBy="article", orphanRemoval=true)
     */
    private $enclosures;

    /**
     * @var My\MainBundle\Entity\ArticleImageScrape
     *
     * @ORM\OneToMany(targetEntity="My\MainBundle\Entity\ArticleImageScrape", mappedBy="article", orphanRemoval=true)
     */
    private $scrapes;

    /**
     * @var My\MainBundle\Entity\ArticleLink
     *
     * @ORM\OneToMany(targetEntity="My\MainBundle\Entity\ArticleLink", mappedBy="article", orphanRemoval=true)
     */
    private $links;

    /**
     * @var My\MainBundle\Entity\Feed
     *
     * @ORM\ManyToOne(targetEntity="My\MainBundle\Entity\Feed", inversedBy="articles")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="feed_id", referencedColumnName="id", nullable=false)
     * })
     */
    private $feed;

    /**
     * @var My\MainBundle\Entity\ArticleAuthor
     *
     * @ORM\ManyToOne(targetEntity="My\MainBundle\Entity\ArticleAuthor", inversedBy="articles")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="author_id", referencedColumnName="id")
     * })
     */
    private $author;

    public function __construct()
    {
        $this->links = new \Doctrine\Common\Collections\ArrayCollection();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:41:24+00:00Added an answer on May 31, 2026 at 9:41 pm

    You should also test the class in addition to the ID.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHPUnit test suite that is currently causing a fatal error due
I have a PHPUnit Test class that I'd like to be ignored from a
I'm using PHPUnit to try to unit test some PHP files that are part
I would like to test a process that queries across multiple schemas using PHPUnit's
I'm writing unit tests for a project (written in PHP, using PHPUnit) that have
I have been using PHPUnit for a while now, but suddenly hit a big
I beginer programmer,and don't have any QA experience (only simple test that i write
I'm using PHPUnit (3.6.7) to test and provide code coverage reports on my application,
I have quite a fundamental problem that none of my selenium phpunit tests pass
I have a series of PHPUnit tests that will need to connect to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.