So, you want to start running local tests on Postgres. Of course you do. Everybody wants that, right?
Wait, why would you want to do that? Well in my case, I tend to break Drupal Core on Postgres and then it's nice to be able to fix things without having to try to figure things out by posting patches to Drupal.org.
So, what we need is a local environment that runs its tests on Postgres. Problem is, I know very little about Postgres. And to be honest, I’m not really interested in learning all about it just to set up a testing environment.
Luckily, you don’t really need to. The tools are all available on OSX and really easy to install, and then it’s just about pointing your testing environment in the right direction.
I didn’t shop around for the best available tools, I just wanted to get it up and running fast. And if you are not on OSX, good luck to you!
I used the Postgres.app and installed that.
Then I downloaded the PgAdmin tool and installed that too.
Start the Postgres app then start the PgAdmin tool. Connect to your server in PgAdmin (default user is 'postgres' and password is ‘root’), right click Databases and choose ‘create’. Create a database named something like d8test and that is all there is to setting Postgres up.
If you want to run any Webtestbase based tests (so Simpletest tests) on this, just do a Drupal install on this database, enable the Testing module and run your tests.
Now if you want to run PHPUnit based tests (BrowserTestBase, Kerneltestbase extending tests), open phpunit.xml in /core. If that doesn’t exist, copy phpunit.xml.dist and paste it as phpunit.xml.
Find the line that starts with:
and replace it with
<env name="SIMPLETEST_DB" value="pgsql://postgres:root@localhost:5432/d8test"/>
where d8test is the name of the database you created.
Now if you have set up the rest of your local testing environment correctly, you are good to go! If not, read the setup docs on Drupal.org
In my case, go into PHPStorm, right click the test I want to run, choose Run and wait for the fails!
About the author
Len Swaneveld (Lendude) is one of the subsystem maintainers of the Views module in Drupal 8 core.