From d8c33fbff1e8ec3639c608538efe961c9a4a049e Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 14 Jun 2013 11:18:59 -0400 Subject: [PATCH] Separated integration tests requiring CI from unit tests that stand alone. Resolves VUFIND-663. --- build.xml | 4 +-- .../VuFind/src/VuFindTest/Unit/TestCase.php | 11 +++++++ .../src/VuFindTest/Auth/DatabaseTest.php | 29 ++++++++++++++++-- .../src/VuFindTest/Auth/ILSTest.php | 29 ++++++++++++++++-- .../src/VuFindTest/Auth/ShibbolethTest.php | 30 +++++++++++++++++-- .../src/VuFindTest/Connection/SolrTest.php | 13 ++++++++ .../VuFindTest/Db/Table/ChangeTrackerTest.php | 13 ++++++++ .../View/Helper/Root/ResultFeedTest.php | 13 ++++++++ 8 files changed, 133 insertions(+), 9 deletions(-) rename module/VuFind/tests/{unit-tests => integration-tests}/src/VuFindTest/Auth/DatabaseTest.php (90%) rename module/VuFind/tests/{unit-tests => integration-tests}/src/VuFindTest/Auth/ILSTest.php (88%) rename module/VuFind/tests/{unit-tests => integration-tests}/src/VuFindTest/Auth/ShibbolethTest.php (89%) rename module/VuFind/tests/{unit-tests => integration-tests}/src/VuFindTest/Db/Table/ChangeTrackerTest.php (92%) diff --git a/build.xml b/build.xml index f4ae9a76eca..3219f96d6f1 100644 --- a/build.xml +++ b/build.xml @@ -139,7 +139,7 @@ </if> <!-- start Solr (use restart in case of old PID files) --> - <exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${srcdir}/local JETTY_PID=${tmp}/vufindtest.pid JETTY_CONSOLE=/dev/null ${srcdir}/vufind.sh restart" outputProperty="LASTOUTPUT" /> + <exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${srcdir}/local JETTY_PID=${srcdir}/local/vufindtest.pid JETTY_CONSOLE=/dev/null ${srcdir}/vufind.sh restart" outputProperty="LASTOUTPUT" /> <echo message="${LASTOUTPUT}" /> <!-- wait for Solor to finish spinning up --> @@ -178,7 +178,7 @@ </if> <!-- stop Solr --> - <exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${srcdir}/local JETTY_PID=${tmp}/vufindtest.pid ${srcdir}/vufind.sh stop" outputProperty="LASTOUTPUT" /> + <exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${srcdir}/local JETTY_PID=${srcdir}/local/vufindtest.pid ${srcdir}/vufind.sh stop" outputProperty="LASTOUTPUT" /> <echo message="${LASTOUTPUT}" /> <!-- delete the configuration, sample index, logs and cache data --> diff --git a/module/VuFind/src/VuFindTest/Unit/TestCase.php b/module/VuFind/src/VuFindTest/Unit/TestCase.php index 35808d25809..6c53f6d9c75 100644 --- a/module/VuFind/src/VuFindTest/Unit/TestCase.php +++ b/module/VuFind/src/VuFindTest/Unit/TestCase.php @@ -245,4 +245,15 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase } return $sm->get('VuFind\AuthPluginManager'); } + + /** + * Is this test running in a continuous integration context? + * + * @return bool + */ + public function continuousIntegrationRunning() + { + // We'll assume that if the CI Solr PID is present, then CI is active: + return file_exists(__DIR__ . '/../../../../../local/vufindtest.pid'); + } } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/DatabaseTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/DatabaseTest.php similarity index 90% rename from module/VuFind/tests/unit-tests/src/VuFindTest/Auth/DatabaseTest.php rename to module/VuFind/tests/integration-tests/src/VuFindTest/Auth/DatabaseTest.php index d6b6664e902..4fde5afc0ef 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/DatabaseTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/DatabaseTest.php @@ -56,12 +56,31 @@ class DatabaseTest extends \VuFindTest\Unit\DbTestCase */ public static function setUpBeforeClass() { + // If CI is not running, all tests were skipped, so no work is necessary: + $test = new DatabaseTest(); + if (!$test->continuousIntegrationRunning()) { + return; + } // Fail if there are already users in the database (we don't want to run this // on a real system -- it's only meant for the continuous integration server) - $test = new DatabaseTest(); $userTable = $test->getTable('User'); if (count($userTable->select()) > 0) { - throw new \Exception('Test cannot run with pre-existing user data!'); + return $this->markTestSkipped( + 'Test cannot run with pre-existing user data!' + ); + } + } + + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); } } @@ -274,6 +293,12 @@ class DatabaseTest extends \VuFindTest\Unit\DbTestCase */ public static function tearDownAfterClass() { + // If CI is not running, all tests were skipped, so no work is necessary: + $test = new DatabaseTest(); + if (!$test->continuousIntegrationRunning()) { + return; + } + // Delete test user $test = new DatabaseTest(); $userTable = $test->getTable('User'); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ILSTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ILSTest.php similarity index 88% rename from module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ILSTest.php rename to module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ILSTest.php index 53745533b7e..58d9dc43549 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ILSTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ILSTest.php @@ -72,12 +72,31 @@ class ILSTest extends \VuFindTest\Unit\DbTestCase */ public static function setUpBeforeClass() { + // If CI is not running, all tests were skipped, so no work is necessary: + $test = new ILSTest(); + if (!$test->continuousIntegrationRunning()) { + return; + } // Fail if there are already users in the database (we don't want to run this // on a real system -- it's only meant for the continuous integration server) - $test = new ILSTest(); $userTable = $test->getTable('User'); if (count($userTable->select()) > 0) { - throw new \Exception('Test cannot run with pre-existing user data!'); + return $this->markTestSkipped( + 'Test cannot run with pre-existing user data!' + ); + } + } + + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); } } @@ -176,6 +195,12 @@ class ILSTest extends \VuFindTest\Unit\DbTestCase */ public static function tearDownAfterClass() { + // If CI is not running, all tests were skipped, so no work is necessary: + $test = new ILSTest(); + if (!$test->continuousIntegrationRunning()) { + return; + } + // Delete test user $test = new ILSTest(); $userTable = $test->getTable('User'); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ShibbolethTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ShibbolethTest.php similarity index 89% rename from module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ShibbolethTest.php rename to module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ShibbolethTest.php index 0041224dd6d..3b8d28e8ae7 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ShibbolethTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ShibbolethTest.php @@ -46,12 +46,31 @@ class ShibbolethTest extends \VuFindTest\Unit\DbTestCase */ public static function setUpBeforeClass() { + // If CI is not running, all tests were skipped, so no work is necessary: + $test = new ShibbolethTest(); + if (!$test->continuousIntegrationRunning()) { + return; + } // Fail if there are already users in the database (we don't want to run this // on a real system -- it's only meant for the continuous integration server) - $test = new ShibbolethTest(); $userTable = $test->getTable('User'); if (count($userTable->select()) > 0) { - throw new \Exception('Test cannot run with pre-existing user data!'); + return $this->markTestSkipped( + 'Test cannot run with pre-existing user data!' + ); + } + } + + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); } } @@ -215,8 +234,13 @@ class ShibbolethTest extends \VuFindTest\Unit\DbTestCase */ public static function tearDownAfterClass() { - // Delete test user + // If CI is not running, all tests were skipped, so no work is necessary: $test = new ShibbolethTest(); + if (!$test->continuousIntegrationRunning()) { + return; + } + + // Delete test user $userTable = $test->getTable('User'); $user = $userTable->getByUsername('testuser', false); if (empty($user)) { diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Connection/SolrTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Connection/SolrTest.php index 67a4a9fdc29..e114f441cbb 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Connection/SolrTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Connection/SolrTest.php @@ -38,6 +38,19 @@ namespace VuFindTest\Integration\Connection; */ class SolrTest extends \VuFindTest\Unit\TestCase { + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); + } + } + /** * Check AlphaBrowse "see also" functionality. * diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Db/Table/ChangeTrackerTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Db/Table/ChangeTrackerTest.php similarity index 92% rename from module/VuFind/tests/unit-tests/src/VuFindTest/Db/Table/ChangeTrackerTest.php rename to module/VuFind/tests/integration-tests/src/VuFindTest/Db/Table/ChangeTrackerTest.php index 20d1db89cfa..10f3900a30d 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Db/Table/ChangeTrackerTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Db/Table/ChangeTrackerTest.php @@ -39,6 +39,19 @@ use VuFind\Db\Table\ChangeTracker; */ class ChangeTrackerTest extends \VuFindTest\Unit\DbTestCase { + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); + } + } + /** * Test change tracking * diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php index 4dcc545c81a..cbcc6095574 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php @@ -39,6 +39,19 @@ use VuFind\View\Helper\Root\ResultFeed; */ class ResultFeedTest extends \VuFindTest\Unit\ViewHelperTestCase { + /** + * Standard setup method. + * + * @return void + */ + public function setUp() + { + // Give up if we're not running in CI: + if (!$this->continuousIntegrationRunning()) { + return $this->markTestSkipped('Continuous integration not running.'); + } + } + /** * Get plugins to register to support view helper being tested * -- GitLab