-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdrupal-test-database.html
31 lines (31 loc) · 6.15 KB
/
drupal-test-database.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Using transactions in a separate database with Drupal PHPUnit tests - Pat Shaughnessy</title><meta name="description" content=""><meta name="author" content=""><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/assets/css/normalize.css"><link rel="stylesheet" href="/assets/css/skeleton.css"><link rel="alternate" type="application/atom+xml" title="Pat Shaughnessy - Feed" href="http://feeds2.feedburner.com/patshaughnessy"><link rel="icon" type="image/png" href="images/favicon.png"></head><body><div id="banner"><a href="/"><span id="title">Pat Shaughnessy</span><span id="tagline"> blogger, rubyist, aspiring author</span></a></div><div style="margin-top: 35px"><div class="ten columns"><div class="container"><div class="row"><article class="post"><header><h1>Using transactions in a separate database with Drupal PHPUnit tests</h1><div class="metadata">January 19th 2009 — <a href="#disqus_thread" data-disqus-identifier="https://patshaughnessy.net/drupal-test-database"> Comments and Reactions</a></div></header><section class="content"><p>
Update April 2009:<br/>
I’ve started working with <a href="http://markbennett.ca">Mark Bennett</a> on phpunit_setup.inc and moved it up to a <a href="http://github.com/patshaughnessy/drupal_tdd">github repository</a>. Mark has adapted it to work with Drupal 5, and we’re working on a number of other related ideas as well. I’ll post updates here about our progress.</p>
<p>This month I’ve been experimenting with using testing ideas from Ruby on Rails while developing a Drupal module. To read more, see:</p>
<ul>
<li><a href="https://patshaughnessy.net/2009/1/19/using-mysql-transactions-with-drupal-unit-tests">Using MySQL transactions with Drupal unit tests</a></li>
<li><a href="https://patshaughnessy.net/2009/1/16/using-a-test-database-with-drupal-unit-tests">Using a test database with Drupal unit tests</a></li>
</ul>
<p>If you want to try this out yourself, follow these instructions:</p>
<ol>
<li><p>Edit settings.php and use an array of two values for $db_url:</p>
<pre>$db_url["default"] = 'mysql://user:password@localhost/drupal;
$db_url["test"] = 'mysql://user:password@localhost/drupal_test';</pre></li>
<li><p>Create a new test database in MySQL:</p><pre>CREATE DATABASE drupal_test DEFAULT CHARACTER SET utf8
COLLATE utf8_unicode_ci;</pre></li>
<li>Download and save <a href="https://patshaughnessy.net/assets/code/drupal-tdd-4/phpunit_setup.inc">phpunit_setup.inc</a> somewhere in your Drupal application; for example in the “includes” folder.</li>
<li>Include <a href="https://patshaughnessy.net/assets/code/drupal-tdd-4/phpunit_setup.inc">phpunit_setup.inc</a> at the top of each of your PHPUnit test classes. See one of the two articles above for example PHPUnit tests.</li>
<li><p>Execute your PHPUnit test class from the root folder of your Drupal app:</p><pre>$ cd /path/to/your/drupal-site
$ phpunit YourClass modules/your_module/YourClassFileName.php
PHPUnit 3.2.21 by Sebastian Bergmann.
..
Time: 0 seconds
OK (2 tests)</pre></li>
</ol>
<p>For more information about how to run PHPUnit with Drupal, see: <a href="https://patshaughnessy.net/2008/12/12/writing-your-first-phpunit-test-in-drupal">Writing your first PHPUnit test in Drupal</a>.</p>
</section><section class="comments"><div id="disqus_thread"><script type="text/javascript">var disqus_identifier = 'https://patshaughnessy.net/drupal-test-database'; var disqus_shortname = 'patshaughnessy'; var disqus_title = 'Using transactions in a separate database with Drupal PHPUnit tests';</script></div><script type="text/javascript" src="https://disqus.com/forums/patshaughnessy/embed.js"></script><noscript><a href="https://patshaughnessy.disqus.com/?url=ref">View the discussion thread.</a></noscript></section></article></div></div></div><div class="two columns"><div id="sidebar"><img src="/assets/images/pat.jpg"></img><div class="header">Subscribe</div><div class="links"><ul><li><a id="feed" href="http://feeds.feedburner.com/patshaughnessy"><img src="/assets/images/feed-icon16x16B.png"></img></a><a href="http://twitter.com/pat_shaughnessy"><img width="20" height="20" src="/assets/images/twitter.svg"></img></a></li></ul></div><div class="header">Buy My Book</div><div class="links"><ul><li><a href="/ruby-under-a-microscope"><img src="/assets/images/book-cover.png"></img></a></li><li id="eBook"><a href="/ruby-under-a-microscope">Ruby Under a Microscope</a></li></ul></div><div class="header">More on Drupal</div><div class="links"><ul><li><a href="/2009/1/16/using-a-test-database-with-drupal-unit-tests">Using a test database with Drupal unit tests</a></li><li><a href="/2009/1/9/tdd-keeps-your-php-code-separate-from-drupal">TDD keeps your PHP code separate from Drupal</a></li><li><a href="/2008/12/19/using-tdd-to-write-a-drupal-module">Using TDD to write a Drupal module</a></li><li><a href="/2008/12/12/writing-your-first-phpunit-test-in-drupal">Writing your first PHPUnit test in Drupal</a></li></ul></div><div class="header">Popular</div><div class="links"><ul><li><a href="/2016/11/26/learning-to-read-x86-assembly-language">Learning to Read x86 Assembly Language</a></li><li><a href="/2012/1/4/never-create-ruby-strings-longer-than-23-characters">Never create Ruby strings longer than 23 characters</a></li><li><a href="/2012/3/23/why-you-should-be-excited-about-garbage-collection-in-ruby-2-0">Why You Should Be Excited About Garbage Collection in Ruby 2.0</a></li><li><a href="/2013/4/3/ruby-2-0-works-hard-so-you-can-be-lazy">Ruby 2.0 Works Hard So You Can Be Lazy</a></li></ul></div><div class="header"><a href="/">More...</a></div></div></div><script type="text/javascript">(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'https://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());</script></div><div id="footer" class="ten columns"><p>Content and UI design © 2008-2022 Pat Shaughnessy</p></div></body></html>