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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:52:30+00:00 2026-06-08T15:52:30+00:00

I am trying to use PHPUnit/DBUnit to test my Zend Framework DbTable models. I

  • 0

I am trying to use PHPUnit/DBUnit to test my Zend Framework DbTable models. I am getting tripped up with tables that have a timestamp.

I am trying to use assertDataSetsEqual to compare an the actual results of an insert to the expected results. Of course, when I insert a record into a table with a timestamp, the timestamp field get populated with the current date/time. The dataset that represents the expected data is static so the timestamp won’t match.

How can I handle this situation? Can I make the assertion ignore the timestamp column?

  • 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-08T15:52:31+00:00Added an answer on June 8, 2026 at 3:52 pm

    I just found a much better solution to this thanks to this blog post.

    I created a function to allow me to easily assert my two datasets are equal.

    protected function assertDataSetEquals(
            $ExpectedXMLFileName,
            array $options = array()) {
    
        $model  = (isset($options['model'])) ?
            $options['model'] :
            $this->_object;
        $excludeColumns = (isset($options['excludeColumns'])) ?
            $options['excludeColumns'] :
            null;
    
        $ds = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
        $ds->addTable($model);
    
        $dsFiltered = (isset($excludeColumns)) ?
            $this->filterColumns($model, $ds, $excludeColumns) :
            $ds;
    
        $this->assertDataSetsEqual(
            $this->createFlatXmlDataSet(
                APPLICATION_PATH 
                . '/../tests/fixtures/models/'
                    . $ExpectedXMLFileName . '.xml'
            ),
            $dsFiltered
        );
    }
    

    And a private function to return the filtered dataset.

    private function filterColumns(
            $model,
            $dataSet,
            $excludeColumns) {
    
        $dsFiltered = 
            new PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet);
        $dsFiltered->setExcludeColumnsForTable(
                $model->getName(),
                $excludeColumns
            );
    
        return $dsFiltered;
    }
    

    Now to compare two datasets while excluding any columns I just do this.

        $this->assertDataSetEquals(
                'TableWithTimestampIWantToIgnoreUpdate',
                array('excludeColumns'=>array('timestamp','id'))
            );
    

    This makes for a much easier/cleaner way to test models that correspond to tables with a timestamp column.

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

Sidebar

Related Questions

I have been trying to use PHPUnit to test an application. I have it
I'm trying to use PHPUnit to unit test some class methods that return SQL.
I am trying to work out how to configure PHPUnit to use the test
I am trying use gem tire to search in my application. I have tables
I have been getting into Unit Testing with Zend Framework. I am getting used
I have a regex that I'm trying use to validate against strings. Trying to
I have a 3rd party DLL that I am trying to use in a
I'm trying to test dynamic id's with PHPUnit so i choose to use xpath
I am trying to create my first unit test. I use Zend Studio, and
I'm currently trying to use PHPUnit to learn about Test Driven Development (TDD) and

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.