Permalink
Browse files

Enhance test environment

=> run make test to run all tests

- forward Erfurt submodule
  • Loading branch information...
1 parent 32aa515 commit 5a2a632e30bde17fc6a02c7439e59266e5929871 @pfrischmuth pfrischmuth committed Sep 10, 2012
View
@@ -68,10 +68,14 @@ help-cs:
@echo " > OPTIONS=<option> ............. Run code checking with specific CodeSniffer options"
help-test:
- @echo " test ....................... Execute unit and integration tests"
- @echo " test-unit .................. Run OntoWiki unit tests"
- @echo " test-integration ........... Run OntoWiki integration tests"
- @echo " test-extensions ............ Run tests for extensions"
+ @echo " test ......................... Execute unit, integration and extension tests"
+ @echo " test-unit .................... Run OntoWiki unit tests"
+ @echo " test-unit-cc ................. Same as above plus code coverage report"
+ @echo " test-integration-virtuoso .... Run OntoWiki integration tests with virtuoso"
+ @echo " test-integration-virtuoso-cc . Same as above plus code coverage report"
+ @echo " test-integration-mysql ....... Run OntoWiki integration tests with mysql"
+ @echo " test-integration-mysql-cc .... Same as above plus code coverage report"
+ @echo " test-extensions .............. Run tests for extensions"
# top level target
@@ -160,21 +164,42 @@ rdfauthor:
# test stuff
-test-unit:
+test-unit: directories
+ @cd application/tests && phpunit --bootstrap Bootstrap.php unit/
+
+test-unit-cc: directories
@cd application/tests/unit && phpunit
-test-integration:
- @cd application/tests/integration && phpunit
+test-integration-virtuoso: directories
+ @cd application/tests && EF_STORE_ADAPTER=virtuoso phpunit --bootstrap Bootstrap.php integration/
+
+test-integration-virtuoso-cc: directories
+ @cd application/tests/integration && EF_STORE_ADAPTER=virtuoso phpunit
+
+test-integration-mysql: directories
+ @cd application/tests && EF_STORE_ADAPTER=zenddb phpunit --bootstrap Bootstrap.php integration/
-test-extensions:
+test-integration-mysql-cc: directories
+ @cd application/tests/integration && EF_STORE_ADAPTER=zenddb phpunit
+
+test-extensions: directories
@phpunit --bootstrap application/tests/Bootstrap.php extensions
test:
- @make test-unit
+ make test-unit
@echo ""
@echo "-----------------------------------"
@echo ""
- @make test-integration
+ make test-integration-virtuoso
+ @echo ""
+ @echo "-----------------------------------"
+ @echo ""
+ make test-integration-mysql
+ @echo ""
+ @echo "-----------------------------------"
+ @echo ""
+ make test-extensions
+
install-test-environment:
sudo apt-get install php-pear
@@ -94,6 +94,8 @@ public function _initExtensionManager()
// actionhelper
Zend_Controller_Action_HelperBroker::addPrefix('OntoWiki_Controller_ActionHelper_');
Zend_Controller_Action_HelperBroker::addHelper(new OntoWiki_Controller_ActionHelper_List());
+
+ return $extensionManager;
}
/**
@@ -0,0 +1,106 @@
+<?php
+/**
+ * Created by JetBrains PhpStorm.
+ * User: philipp
+ * Date: 08.09.12
+ * Time: 14:59
+ * To change this template use File | Settings | File Templates.
+ */
+class OntoWiki_Test_ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
+{
+ /** @var Erfurt_Ac_Test|Erfurt_Ac_Default */
+ protected $_ac = null;
+
+ /** @var Erfurt_Store_Adapter_Interface */
+ protected $_storeAdapter = null;
+
+ /** @var string|null */
+ protected $_extensionName = null;
+
+ public function setUpIntegrationTest()
+ {
+ $this->bootstrap = new Zend_Application(
+ 'integration_testing',
+ ONTOWIKI_ROOT . 'application/config/application.ini'
+ );
+
+ try {
+ parent::setUp();
+ } catch (Exception $e) {
+ // if we can't connect to the database, we skip the test
+ $this->markTestSkipped($e->getMessage());
+ }
+
+ // additional checks for database....
+ $this->_markTestNeedsDatabase();
+ }
+
+ public function setUpUnitTest()
+ {
+ $this->bootstrap = new Zend_Application(
+ 'unit_testing',
+ ONTOWIKI_ROOT . 'application/config/application.ini'
+ );
+
+ parent::setUp();
+ }
+
+ public function setUpExtensionUnitTest()
+ {
+ $this->bootstrap = new Zend_Application(
+ 'extension_unit_testing',
+ ONTOWIKI_ROOT . 'application/config/application.ini'
+ );
+ parent::setUp();
+
+ if (null !== $this->_extensionName) {
+ $extensionManager = OntoWiki::getInstance()->extensionManager;
+
+ if (!$extensionManager->isExtensionActive($this->_extensionName)) {
+ Erfurt_Event_Dispatcher::reset();
+ $this->markTestSkipped('extension is not active');
+ }
+ }
+
+ $this->_ac = Erfurt_App::getInstance(false)->getAc();
+ $this->_storeAdapter = Erfurt_App::getInstance(false)->getStore()->getBackendAdapter();
+ }
+
+ private function _markTestNeedsDatabase()
+ {
+ $config = Erfurt_App::getInstance(false)->getConfig();
+
+ $dbName = null;
+ if ($config->store->backend === 'virtuoso') {
+ if (isset($config->store->virtuoso->dsn)) {
+ $dbName = $config->store->virtuoso->dsn;
+ }
+ } else if ($config->store->backend === 'zenddb') {
+ if (isset($config->store->zenddb->dbname)) {
+ $dbName = $config->store->zenddb->dbname;
+ }
+ }
+
+ if ((null === $dbName) || (substr($dbName, -5) !== '_TEST')) {
+ $this->markTestSkipped('Invalid test database for tests: ' . $dbName); // make sure a test db was selected!
+ }
+
+ try {
+ $store = Erfurt_App::getInstance(false)->getStore();
+ $store->checkSetup();
+ $this->_dbWasUsed = true;
+ } catch (Erfurt_Store_Exception $e) {
+ if ($e->getCode() === 20) {
+ // Setup successful
+ $this->_dbWasUsed = true;
+ } else {
+ $this->markTestSkipped();
+ }
+ } catch (Erfurt_Exception $e2) {
+ $this->markTestSkipped();
+ }
+
+ $this->assertTrue(Erfurt_App::getInstance()->getStore()->isModelAvailable($config->sysont->modelUri, false));
+ $this->assertTrue(Erfurt_App::getInstance()->getStore()->isModelAvailable($config->sysont->schemaUri, false));
+ }
+}
@@ -0,0 +1,67 @@
+<?php
+require_once realpath(dirname(dirname(dirname(dirname(__FILE__))))). DIRECTORY_SEPARATOR . 'Bootstrap.php';
+
+/**
+ * This file is part of the {@link http://ontowiki.net OntoWiki} project.
+ *
+ * @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
+ * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
+ */
+
+/**
+ * OntoWiki bootstrap class.
+ *
+ * Provides on-demand loading of application resources.
+ *
+ * @category OntoWiki
+ * @package OntoWiki_Bootstrap
+ * @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
+ * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
+ * @author Philipp Frischmuth <pfrischmuth@googlemail.com>
+ */
+class OntoWiki_Test_ExtensionUnitTestBootstrap extends Bootstrap
+{
+ public function _initErfurt()
+ {
+ $erfurt = null;
+
+ // require Config
+ $this->bootstrap('Config');
+ $config = $this->getResource('Config');
+
+ // require OntoWiki
+ $this->bootstrap('OntoWiki');
+ $ontoWiki = $this->getResource('OntoWiki');
+
+ // require Logger, since Erfurt logger should write into OW logs dir
+ $this->bootstrap('Logger');
+
+ // Reset the Erfurt app for testability... needs to be refactored.
+ Erfurt_App::reset();
+
+ try {
+ $erfurt = Erfurt_App::getInstance(false)->start($config);
+ } catch (Erfurt_Exception $ee) {
+ throw new OntoWiki_Exception('Error loading Erfurt framework: ' . $ee->getMessage());
+ } catch (Exception $e) {
+ throw new OntoWiki_Exception('Unexpected error: ' . $e->getMessage());
+ }
+
+ $testAdapter = new Erfurt_Store_Adapter_Test();
+ $store = new Erfurt_Store(
+ array(
+ 'adapterInstance' => $testAdapter
+ ),
+ 'Test'
+ );
+ $erfurt->setStore($store);
+
+ $testAc = new Erfurt_Ac_Test();
+ Erfurt_App::getInstance()->setAc($testAc);
+
+ // make available
+ $ontoWiki->erfurt = $erfurt;
+
+ return $erfurt;
+ }
+}
@@ -0,0 +1,67 @@
+<?php
+require_once realpath(dirname(dirname(dirname(dirname(__FILE__))))). DIRECTORY_SEPARATOR . 'Bootstrap.php';
+
+/**
+ * This file is part of the {@link http://ontowiki.net OntoWiki} project.
+ *
+ * @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
+ * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
+ */
+
+/**
+ * OntoWiki bootstrap class.
+ *
+ * Provides on-demand loading of application resources.
+ *
+ * @category OntoWiki
+ * @package OntoWiki_Bootstrap
+ * @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
+ * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
+ * @author Philipp Frischmuth <pfrischmuth@googlemail.com>
+ */
+class OntoWiki_Test_IntegrationTestBootstrap extends Bootstrap
+{
+ /**
+ * Overwrite the config bootstrap method, such that the store backend can be set via an environment variable.
+ *
+ * @return void|Zend_Config_Ini
+ */
+ public function _initConfig()
+ {
+ $config = parent::_initConfig();
+
+ // Overwrite database settings from test config
+ // load user application configuration files
+ $tryDistConfig = false;
+ try {
+ $privateConfig = new Zend_Config_Ini(ONTOWIKI_ROOT . 'application/tests/config.ini', 'private', true);
+ $config->merge($privateConfig);
+ } catch (Zend_Config_Exception $e) {
+ $tryDistConfig = true;
+ }
+
+ if ($tryDistConfig === true) {
+ try {
+ $privateConfig = new Zend_Config_Ini(ONTOWIKI_ROOT . 'application/tests/config.ini.dist', 'private', true);
+ $config->merge($privateConfig);
+ } catch (Zend_Config_Exception $e) {
+ $message = 'Failed to find test config';
+ throw new OntoWiki_Exception($message);
+ }
+ }
+
+ // overwrite store adapter to use with environment variable if set
+ // this is useful, when we want to test with different stores without manually
+ // editing the config
+ if ($config instanceof Zend_Config) {
+ $storeAdapter = getenv('EF_STORE_ADAPTER');
+ if (($storeAdapter === 'virtuoso') || ($storeAdapter === 'zenddb')) {
+ $config->store->backend = $storeAdapter;
+ } else if ($storeAdapter !== false) {
+ throw new Exception('Invalid value of $EF_STORE_ADAPTER: ' . $storeAdapter);
+ }
+ }
+
+ return $config;
+ }
+}
@@ -1,5 +1,5 @@
<?php
-require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
+require_once realpath(dirname(dirname(dirname(dirname(__FILE__))))). DIRECTORY_SEPARATOR . 'Bootstrap.php';
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
@@ -19,7 +19,7 @@
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
* @author Philipp Frischmuth <pfrischmuth@googlemail.com>
*/
-class TestBootstrap extends Bootstrap
+class OntoWiki_Test_UnitTestBootstrap extends Bootstrap
{
public function _initExtensionManager()
{
@@ -27,7 +27,15 @@ includePaths.classes = APPLICATION_PATH "classes"
autoloaderNamespaces.ontoWiki = "OntoWiki_"
autoloaderNamespaces.erfurt = "Erfurt_"
-[testing : default]
-bootstrap.path = APPLICATION_PATH "tests/TestBootstrap.php"
-bootstrap.class = "TestBootstrap"
+[unit_testing : default]
+bootstrap.path = APPLICATION_PATH "classes/OntoWiki/Test/UnitTestBootstrap.php"
+bootstrap.class = "OntoWiki_Test_UnitTestBootstrap"
+
+[integration_testing : default]
+bootstrap.path = APPLICATION_PATH "classes/OntoWiki/Test/IntegrationTestBootstrap.php"
+bootstrap.class = "OntoWiki_Test_IntegrationTestBootstrap"
+
+[extension_unit_testing : default]
+bootstrap.path = APPLICATION_PATH "classes/OntoWiki/Test/ExtensionUnitTestBootstrap.php"
+bootstrap.class = "OntoWiki_Test_ExtensionUnitTestBootstrap"
@@ -7,8 +7,8 @@
store.backend = zenddb ; zenddb, virtuoso, multi
store.zenddb.dbname = erfurt_TEST ; needs to end with _TEST
-store.zenddb.username = ow
-store.zenddb.password = ow
+store.zenddb.username = php
+store.zenddb.password = php
store.zenddb.dbtype = mysql ; mysql
;store.zenddb.host = localhost ; default is localhost
@@ -13,10 +13,10 @@ protected function setUp()
{
$this->_resourcesDirectory = realpath(dirname(__FILE__)) . '/_files/';
- $this->markTestNeedsTestConfig();
+ $this->markTestNeedsDatabase();
$this->_bootstrap = new Zend_Application(
- 'testing',
+ 'integration_testing',
ONTOWIKI_ROOT . 'application/config/application.ini'
);
Oops, something went wrong. Retry.

0 comments on commit 5a2a632

Please sign in to comment.