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 8348435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:41:16+00:00 2026-06-09T07:41:16+00:00

I’m trying to set up my PHPUnit tests with Doctrine 2 ORM. However, I

  • 0

I’m trying to set up my PHPUnit tests with Doctrine 2 ORM. However, I am getting strange issues which I can only assume are down to some sort of caching (on Doctrine’s end), which I cannot figure out how to overcome. This is what I’ve got:

A setUp function:

public function setUp() 
{
    $front = Zend_Controller_Front::getInstance();
    $bootstrap = $front->getParam("bootstrap");

    if(!$boostrap) {
        $application = Zend_Registry::get("application");
        $bootstrap = $application->getBootstrap();
    }
    $bootstrap->bootstrap('doctrine');

    $this->em   = $bootstrap->getResource('doctrine');
    $tool       = new \Doctrine\ORM\Tools\SchemaTool($this->em);
    $classes    = $this->em->getMetaDataFactory()->getAllMetaData();

    $tool->dropSchema($classes);
    $tool->createSchema($classes);

    parent::setUp();
}

This basically aims to reset the doctrine instance for every test. I haven’t got a tearDown() function as, at the moment, this takes care of resetting the schema as illustrated. I should mention here that I am using SQLite.

I have two tests in one class that I am trying to run, with no dependencies. The first test inserts a record like so:

$value = 5;
$model = new Model();
$model->setUserId($rater->getId());
$model->setValue($value);

$this->em->persist($model);
$this->em->flush();

So far, so good. I have a new record in the database with a value of 5.

Onto the next test. This time I want to run:

$value = 3;
$model = new Model();
$model->setUserId($rater->getId());
$model->setValue($value);

$this->em->persist($model);
$this->em->flush();

Dumping all records from the relevant table gives me one result; a record with a value of 5 again. In other words, the second test is taking the $value from the first test.
I’ve double checked by dumping all records at the start of the second test and this returns nothing. It seems there are some caching issues in Doctrine somewhere that I’m not aware of.

I’ve tried clearing various caches that I’m aware Doctrine can potentially make sure of, such as:

$cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
$cacheDriver->deleteAll();

Can anybody suggest anything else I can try? Or is there some errant code somewhere in the way I have implemented Doctrine.

Thanks

  • 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-06-09T07:41:18+00:00Added an answer on June 9, 2026 at 7:41 am

    So I’m not entirely sure where or what the issue was, but it seems that Doctrine must have been caching somewhere down the line. After all, I ensured that my object had the correct value post-persist but pre-flush. Post-flush it suddenly had a different value than expected.

    Anyhow, to fix the issue I added the following line:

    $this->em->clear();
    

    just after getting the doctrine resource from my Bootstrap. This ensures that all managed entities are completely cleared from the Entity Manager before dropping and re-creating the schema.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

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.