DatabaseTestCase.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\test\lib;
12 
15 
16 /**
17  * DatabaseTestCase is the base class for test cases that need database support.
18  *
19  * @author ingo herwig <ingo@wemove.com>
20  */
21 abstract class DatabaseTestCase extends \PHPUnit_Extensions_Database_TestCase {
22  private static $frameworkReady = false;
23 
24  // only instantiate PHPUnit_Extensions_Database_DB_IDatabaseConnection once per test
25  private $conn = null;
26 
27  public final function getConnection() {
28  if (!self::$frameworkReady) {
29  TestUtil::initFramework(WCMF_BASE.'app/config/');
30  self::$frameworkReady = true;
31  }
32  if ($this->conn === null) {
33  $params = TestUtil::createDatabase();
34  $this->conn = $this->createDefaultDBConnection($params['connection'], $params['dbName']);
35  }
36  return $this->conn;
37  }
38 
39  protected function setUp() {
40  if (!self::$frameworkReady) {
41  TestUtil::initFramework(WCMF_BASE.'app/config/');
42  self::$frameworkReady = true;
43  }
44  parent::setUp();
45  $logger = LogManager::getLogger(__CLASS__);
46  $logger->info("Running: ".get_class($this).".".$this->getName());
47  }
48 
49  protected function tearDown() {
50  self::$frameworkReady = false;
51  }
52 }
53 ?>
static getLogger($name)
Get the logger with the given name.
Definition: LogManager.php:35
DatabaseTestCase is the base class for test cases that need database support.
static createDatabase()
Create the test database, if sqlite is configured.
Definition: TestUtil.php:63
Test support classes.
Definition: namespaces.php:100
static initFramework($configPath)
Set up the wcmf framework.
Definition: TestUtil.php:36