DatabaseTestCase.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 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  use TestTrait;
23 
24  private static $frameworkReady = false;
25 
26  public final function getConnection() {
27  if (!self::$frameworkReady) {
28  TestUtil::initFramework(WCMF_BASE.'app/config/');
29  self::$frameworkReady = true;
30  }
31  $params = TestUtil::createDatabase();
32  return $this->createDefaultDBConnection($params['connection'], $params['dbName']);
33  }
34 
35  public function run(\PHPUnit_Framework_TestResult $result=null) {
36  $this->setPreserveGlobalState(false);
37  return parent::run($result);
38  }
39 
40  protected function setUp() {
41  if (!self::$frameworkReady) {
42  TestUtil::initFramework(WCMF_BASE.'app/config/');
43  self::$frameworkReady = true;
44  }
45  parent::setUp();
46  $this->getLogger(__CLASS__)->info("Running: ".get_class($this).".".$this->getName());
47  }
48 
49  protected function tearDown() {
50  self::$frameworkReady = false;
51  }
52 
53  protected function executeSql($type, $sql, $parameters=[]) {
54  return ObjectFactory::getInstance('persistenceFacade')->getMapper($type)->executeSql($sql, $parameters);
55  }
56 }
57 ?>
run(\PHPUnit_Framework_TestResult $result=null)
Test support classes.
Definition: namespaces.php:100
DatabaseTestCase is the base class for test cases that need database support.
static initFramework($configPath)
Set up the wcmf framework.
Definition: TestUtil.php:35
static getInstance($name, $dynamicConfiguration=[])
static createDatabase()
Create the test database, if sqlite is configured.
Definition: TestUtil.php:65
TestUtil provides helper methods for testing wCMF functionality.
Definition: TestUtil.php:25
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...
executeSql($type, $sql, $parameters=[])