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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:28:43+00:00 2026-06-12T09:28:43+00:00

I have a test for testing data model: <?php namespace Tests\Model\SQL; /** * @group

  • 0

I have a test for testing data model:

<?php
namespace Tests\Model\SQL;

/**
 * @group Model_Users
 * @group Model
 */
class UsersTest extends TestCase {

/** @var Users */
private $model;

public function setUp() {
    parent::setUp();
    $this->connection->execute( file_get_contents(
        __DIR__ . '/fixtures/countries.sql' ) );
    $this->model = new \Users(
        $this->connection
    );
}

    public function testUserExists() {
            $exists = $this->model->userExists( 'johndoe' );
            $this->assertTrue( $exists );
    }

}

The Tests\Model\SQL\TestCase uses SQLite as a database to keep tests as fast as possible.
Anyway, as you may expect, SQLite is not the same database as Postgres, therefore there could be some specialites, which will fail on SQLite and pass on PostgreSQL and vice versa.

My question is:

How to effectively (when keeping DRY in mind) design the architecture to be able to run tests only with SQLite and then only with Postgres.

When I am saying DRY, I mean ideally case, when I write only one testcase for one model and the architecture of my tests will take care of that, so I will be able to run tests like this:

php tests/run.php --group=MockedDbWithSqlite # fast way, prefered, default

php tests/run.php --group=RealDb # slower way, but with more precise results
  • 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-12T09:28:44+00:00Added an answer on June 12, 2026 at 9:28 am

    So judging from the comment the issue is rather independent of any concrete storage issue and more about how one can pass a custom parameter to PHPUnit.

    Because, using this parameter, you’d switch out DB drivers.

    There are a couple of options to do this but no officially supported "custom parameters" objects or something. Even so it would be nice if someone would add this maybe 🙂

    My suggestion would be to use one of the following to options:

    Env variables

    Make the test/bootstrap code rely on $_ENV variables.

    $dbDriverFactory->getInstanceFor(getenv('DB'));
    

    and using one of the ways below to

    export DB=postgress
    phpunit
    

    or

    DB=postpress; phpunit;
    

    or using phpunits xml config to set the env or whatever you like.

    By doing so you could provide two xml configs phpunit-sqlite.xml & phpunit-pg.xml and run:

    phpunit -c phpunit-sqlite.xml
    

    It doesn’t have to be env. Any of the methods listed in the doc section Setting PHP INI settings, Constants and Global Variables will work.

    "Custom" cli parameters

    Calling phpunit like this:

    phpunit --colors --usePostgres
    

    and adding something like this in test cases or bootstrap code:

    if (in_array('--usePostgress', $_SERVER['argv'], true) {
        $db = $this->setupPG();
    } else {
        $db = $this->setupSqlite();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing some unit test and I have a unit testing base class
I have a Group model that I am testing using Request specs with Capybara
I have a model class that caches data in redis. The first time I
I am new to testing.I have to test some C# classes.Kindly let me know
I am new to junit testing and I have the following test - public
I'm stress testing a web app and have set up a windows test program
I have a project structure like: src/CMakeLists.txt src/test/component1/CMakeLists.txt src/test/component2/CMakeLists.txt For the testing, I'm using
I have a Test Class, that test the access of all page with different
I have a test sample about coherence lock-unlock mechanism like this: public class Test
I have been testing out pandas and pytables for some large financial data sets,

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.