diff options
author | sualko <klaus@jsxc.org> | 2020-06-30 15:53:20 +0300 |
---|---|---|
committer | sualko <klaus@jsxc.org> | 2020-06-30 15:53:20 +0300 |
commit | bce9f1900271a9af7ba2fcac30c12f2ea37c2b64 (patch) | |
tree | 822750b67829d835397c75129e5f026d59099cd9 | |
parent | c083263a500ae1664377d94b38528e7c10e570f2 (diff) |
test: fix integration tests
-rw-r--r-- | phpunit.integration.xml | 11 | ||||
-rw-r--r-- | phpunit.xml | 14 | ||||
-rw-r--r-- | tests/Integration/ContactsStoreUserProviderTest.php (renamed from tests/integration/ContactsStoreUserProviderTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/Db/IqRosterPushTest.php (renamed from tests/integration/db/IqRosterPushTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/Db/IqRosterTest.php (renamed from tests/integration/db/IqRosterTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/Db/MessageMapperTest.php (renamed from tests/integration/db/MessageMapperTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/Db/PresenceMapperTest.php (renamed from tests/integration/db/PresenceMapperTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/Db/PresenceTest.php (renamed from tests/integration/db/PresenceTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/Db/StanzaMapperTest.php (renamed from tests/integration/db/StanzaMapperTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/DbLockTest.php (renamed from tests/integration/DbLockTest.php) | 4 | ||||
-rw-r--r-- | tests/Integration/MemLockTest.php (renamed from tests/integration/MemLockTest.php) | 12 | ||||
-rw-r--r-- | tests/Integration/RosterPushTest.php (renamed from tests/integration/RosterPushTest.php) | 2 | ||||
-rw-r--r-- | tests/Integration/UserTest.php | 20 | ||||
-rw-r--r-- | tests/Utility/MapperTestUtility.php (renamed from utility/mappertestutility.php) | 28 | ||||
-rw-r--r-- | tests/Utility/TestCase.php (renamed from utility/testcase.php) | 28 | ||||
-rw-r--r-- | tests/bootstrap-integration.php | 12 |
16 files changed, 82 insertions, 77 deletions
diff --git a/phpunit.integration.xml b/phpunit.integration.xml index 07fb64e..e57bc4b 100644 --- a/phpunit.integration.xml +++ b/phpunit.integration.xml @@ -2,21 +2,16 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" + colors="true" > <testsuites> <testsuite name="integration"> - <directory>./tests/integration</directory> + <directory>tests/Integration</directory> </testsuite> </testsuites> <filter> <whitelist processUncoveredFilesFromWhitelist="true"> - <directory suffix=".php">lib/db</directory> - <file>lib/dblock.php</file> - <file>lib/memlock.php</file> - <file>lib/User.php</file> - <file>lib/ContactsStoreUserProvider.php</file> - <file>lib/UserManagerUserProvider.php</file> - <file>lib/rosterpush.php</file> + <directory suffix=".php">lib</directory> </whitelist> </filter> </phpunit> diff --git a/phpunit.xml b/phpunit.xml index b6bced8..09b416d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,26 +2,16 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" + colors="true" > <testsuites> <testsuite name="unit"> - <directory>./tests/unit</directory> + <directory>tests/unit</directory> </testsuite> </testsuites> <filter> <whitelist processUncoveredFilesFromWhitelist="true"> <directory suffix=".php">lib</directory> - <exclude> - <directory suffix=".php">lib/ContactsMenu</directory> - <directory suffix=".php">lib/db</directory> - <!-- The following three files are tested in the integration test suite --> - <file>lib/ilock.php</file> - <file>lib/memlock.php</file> - <file>lib/dblock.php</file> - <!-- The following two files are simple wrappers around other code --> - <file>lib/command/refreshroster.php</file> - <file>lib/Migration/RefreshRoster.php</file> - </exclude> </whitelist> </filter> </phpunit> diff --git a/tests/integration/ContactsStoreUserProviderTest.php b/tests/Integration/ContactsStoreUserProviderTest.php index 0073c17..1c9bb91 100644 --- a/tests/integration/ContactsStoreUserProviderTest.php +++ b/tests/Integration/ContactsStoreUserProviderTest.php @@ -1,6 +1,6 @@ <?php -namespace OCA\OJSXC; +namespace OCA\OJSXC\Tests\Integration; use OC\Contacts\ContactsMenu\ContactsStore; use OCA\DAV\CardDAV\AddressBookImpl; @@ -15,7 +15,7 @@ use OCA\DAV\AppInfo\Application as DavApp; use OCA\DAV\CardDAV\CardDavBackend; use PHPUnit\Framework\Constraint\IsEqual; use Sabre\VObject\Component\VCard; -use OCA\OJSXC\Utility\TestCase; +use OCA\OJSXC\Tests\Utility\TestCase; class ContactsStoreUserProviderTest extends TestCase { diff --git a/tests/integration/db/IqRosterPushTest.php b/tests/Integration/Db/IqRosterPushTest.php index 02ecbb9..88a3099 100644 --- a/tests/integration/db/IqRosterPushTest.php +++ b/tests/Integration/Db/IqRosterPushTest.php @@ -1,8 +1,8 @@ <?php -namespace OCA\OJSXC\Db; +namespace OCA\OJSXC\Tests\Integration\Db; use Sabre\Xml\Writer; -use OCA\OJSXC\Utility\TestCase; +use OCA\OJSXC\Tests\Utility\TestCase; class IqRosterPushTest extends TestCase { diff --git a/tests/integration/db/IqRosterTest.php b/tests/Integration/Db/IqRosterTest.php index 377acc8..6d1a7d7 100644 --- a/tests/integration/db/IqRosterTest.php +++ b/tests/Integration/Db/IqRosterTest.php @@ -1,8 +1,8 @@ <?php -namespace OCA\OJSXC\Db; +namespace OCA\OJSXC\Tests\Integration\Db; use Sabre\Xml\Writer; -use OCA\OJSXC\Utility\TestCase; +use OCA\OJSXC\Tests\Utility\TestCase; class IqRosterTest extends TestCase { diff --git a/tests/integration/db/MessageMapperTest.php b/tests/Integration/Db/MessageMapperTest.php index 52ca3b4..7a3b7ef 100644 --- a/tests/integration/db/MessageMapperTest.php +++ b/tests/Integration/Db/MessageMapperTest.php @@ -1,9 +1,9 @@ <?php -namespace OCA\OJSXC\Db; +namespace OCA\OJSXC\Tests\Integration\Db; use OCA\OJSXC\AppInfo\Application; -use OCA\OJSXC\Utility\MapperTestUtility; +use OCA\OJSXC\Tests\Utility\MapperTestUtility; use OCP\AppFramework\Db\DoesNotExistException; function uniqid() diff --git a/tests/integration/db/PresenceMapperTest.php b/tests/Integration/Db/PresenceMapperTest.php index 866b132..a81f2d6 100644 --- a/tests/integration/db/PresenceMapperTest.php +++ b/tests/Integration/Db/PresenceMapperTest.php @@ -1,11 +1,11 @@ <?php -namespace OCA\OJSXC\Db; +namespace OCA\OJSXC\Tests\Integration\Db; use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\Db\Presence as PresenceEntity; use OCA\OJSXC\NewContentContainer; -use OCA\OJSXC\Utility\MapperTestUtility; +use OCA\OJSXC\Tests\Utility\MapperTestUtility; use OCA\DAV\AppInfo\Application as DavApp; $time = 0; diff --git a/tests/integration/db/PresenceTest.php b/tests/Integration/Db/PresenceTest.php index 55b3dd3..0aa26f8 100644 --- a/tests/integration/db/PresenceTest.php +++ b/tests/Integration/Db/PresenceTest.php @@ -1,12 +1,12 @@ <?php -namespace OCA\OJSXC\Db; +namespace OCA\OJSXC\Tests\Integration\Db; use Sabre\Xml\Reader; use Sabre\Xml\Writer; use Sabre\Xml\LibXMLException; use Sabre\Xml\ParseException; -use OCA\OJSXC\Utility\TestCase; +use OCA\OJSXC\Tests\Utility\TestCase; class PresenceTest extends TestCase { diff --git a/tests/integration/db/StanzaMapperTest.php b/tests/Integration/Db/StanzaMapperTest.php index d07e830..f951707 100644 --- a/tests/integration/db/StanzaMapperTest.php +++ b/tests/Integration/Db/StanzaMapperTest.php @@ -1,8 +1,8 @@ <?php -namespace OCA\OJSXC\Db; +namespace OCA\OJSXC\Tests\Integration\Db; -use OCA\OJSXC\Utility\MapperTestUtility; +use OCA\OJSXC\Tests\Utility\MapperTestUtility; use OCP\AppFramework\Db\DoesNotExistException; /** diff --git a/tests/integration/DbLockTest.php b/tests/Integration/DbLockTest.php index e071990..576281e 100644 --- a/tests/integration/DbLockTest.php +++ b/tests/Integration/DbLockTest.php @@ -1,8 +1,8 @@ <?php -namespace OCA\OJSXC; +namespace OCA\OJSXC\Tests\Integration; use OCP\AppFramework\Db\DoesNotExistException; -use Test\TestCase; +use PHPUnit\Framework\TestCase; use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\DbLock; diff --git a/tests/integration/MemLockTest.php b/tests/Integration/MemLockTest.php index 728c2ec..0c0171f 100644 --- a/tests/integration/MemLockTest.php +++ b/tests/Integration/MemLockTest.php @@ -1,8 +1,8 @@ <?php -namespace OCA\OJSXC; +namespace OCA\OJSXC\Tests\Integration; use OCP\AppFramework\Db\DoesNotExistException; -use Test\TestCase; +use PHPUnit\Framework\TestCase; use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\MemLock; @@ -43,11 +43,6 @@ class MemLockTest extends TestCase parent::setUp(); $app = new Application(); $this->container = $app->getContainer(); - - $version = \OC::$server->getSession()->get('OC_Version'); - if ($version[0] === 8 && $version[1] == 0) { - $this->markTestSkipped(); - } } /** @@ -62,7 +57,8 @@ class MemLockTest extends TestCase if ($cache->isAvailable()) { $this->memCache = $cache->create('ojsxc'); } else { - die('No memcache available'); + $this->markTestSkipped(); + return; } $this->memLock = new MemLock( diff --git a/tests/integration/RosterPushTest.php b/tests/Integration/RosterPushTest.php index b6b9e43..c9c5fe9 100644 --- a/tests/integration/RosterPushTest.php +++ b/tests/Integration/RosterPushTest.php @@ -1,6 +1,6 @@ <?php -namespace OCA\OJSXC; +namespace OCA\OJSXC\Tests\Integration; use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\Db\IQRosterPushMapper; diff --git a/tests/Integration/UserTest.php b/tests/Integration/UserTest.php new file mode 100644 index 0000000..cf61cc7 --- /dev/null +++ b/tests/Integration/UserTest.php @@ -0,0 +1,20 @@ +<?php +namespace OCA\OJSXC\Tests\Integration; + +use OCA\OJSXC\User; +use PHPUnit\Framework\TestCase; + +class UserTest extends TestCase +{ + public function test() + { + $user1 = new User(" test @ 'abc", 'Test123', null); + + $this->assertEquals($user1->getFullName(), 'Test123'); + $this->assertEquals($user1->getUid(), '_ojsxc_esc_space_test_ojsxc_esc_space__ojsxc_esc_at__ojsxc_esc_space__ojsxc_squote_space_abc'); + $user1->setUid('test1'); + $user1->setFullName('test2'); + $this->assertEquals($user1->getUid(), 'test1'); + $this->assertEquals($user1->getFullName(), 'test2'); + } +} diff --git a/utility/mappertestutility.php b/tests/Utility/MapperTestUtility.php index bcfc41c..ef07d03 100644 --- a/utility/mappertestutility.php +++ b/tests/Utility/MapperTestUtility.php @@ -1,13 +1,14 @@ <?php -namespace OCA\OJSXC\Utility; +namespace OCA\OJSXC\Tests\Utility; use OCA\OJSXC\AppInfo\Application; /** * @group DB */ -class MapperTestUtility extends TestCase { +class MapperTestUtility extends TestCase +{ /** * @var \OCP\AppFramework\IAppContainer @@ -26,7 +27,7 @@ class MapperTestUtility extends TestCase { { parent::setUp(); $app = new Application(); - $this->overwriteApplicationService($app, 'Host','localhost'); + $this->overwriteApplicationService($app, 'Host', 'localhost'); $this->overwriteApplicationService($app, 'UserId', 'admin'); $this->container = $app->getContainer(); $this->mapper = $this->container[$this->mapperName]; @@ -38,18 +39,21 @@ class MapperTestUtility extends TestCase { $con->executeQuery('DELETE FROM ' . $this->mapper->getTableName()); } - protected function tearDown(): void { + protected function tearDown(): void + { $con = $this->container->getServer()->getDatabaseConnection(); $con->executeQuery('DELETE FROM ' . $this->mapper->getTableName()); } - protected function fetchAll(){ + protected function fetchAll() + { $con = $this->container->getServer()->getDatabaseConnection(); $stmt = $con->executeQuery('SELECT * FROM ' . $this->mapper->getTableName()); $entities = []; - while($row = $stmt->fetch()){ - $entities[] = call_user_func($this->entityName . '::fromRow', $row);; + while ($row = $stmt->fetch()) { + $entities[] = call_user_func($this->entityName . '::fromRow', $row); + ; } $stmt->closeCursor(); @@ -57,7 +61,8 @@ class MapperTestUtility extends TestCase { return $entities; } - protected function fetchAllAsArray($tableName = null){ + protected function fetchAllAsArray($tableName = null) + { if (is_null($tableName)) { $tableName = $this->mapper->getTableName(); } else { @@ -66,7 +71,7 @@ class MapperTestUtility extends TestCase { $stmt = $con->executeQuery('SELECT * FROM ' . $tableName); $result = []; - while($row = $stmt->fetch()){ + while ($row = $stmt->fetch()) { $result[] = $row; } $stmt->closeCursor(); @@ -74,9 +79,8 @@ class MapperTestUtility extends TestCase { return $result; } - public function getLastInsertedId() { + public function getLastInsertedId() + { return $this->container->getServer()->getDatabaseConnection()->lastInsertId(); - } - } diff --git a/utility/testcase.php b/tests/Utility/TestCase.php index d733e52..a5caa8e 100644 --- a/utility/testcase.php +++ b/tests/Utility/TestCase.php @@ -1,22 +1,22 @@ <?php -namespace OCA\OJSXC\Utility; +namespace OCA\OJSXC\Tests\Utility; use OCA\OJSXC\AppInfo\Application; use OCP\AppFramework\Db\Entity; use Sabre\Xml\Service; -use Test\TestCase as CoreTestCase; +use PHPUnit\Framework\TestCase as CoreTestCase; -class TestCase extends CoreTestCase { - - public static function assertSabreXmlEqualsXml($expected, $actual) { +class TestCase extends CoreTestCase +{ + public static function assertSabreXmlEqualsXml($expected, $actual) + { $service = new Service(); $parsedExpected = $service->parse("<?xml version=\"1.0\" encoding=\"utf-8\"?><unit-wrapper>" . $expected . "</unit-wrapper>"); $parsedActual = $service->parse("<?xml version=\"1.0\" encoding=\"utf-8\"?><unit-wrapper>" . $actual . "</unit-wrapper>"); self::assertEquals($parsedExpected, $parsedActual, 'Failed asserting that two XML strings are equal.'); - } /** @@ -24,7 +24,8 @@ class TestCase extends CoreTestCase { * @param Entity[] $actual * @param array $fields Use camelCase for this instead of snake_case! */ - public static function assertObjectDbResultsEqual($expected, $actual, array $fields) { + public static function assertObjectDbResultsEqual($expected, $actual, array $fields) + { $expectedArray = []; $actualArray = []; @@ -39,7 +40,8 @@ class TestCase extends CoreTestCase { self::assertArrayDbResultsEqual($expectedArray, $actualArray, $fields); } - public static function assertArrayDbResultsEqual(array $expected, array $actual, array $fields) { + public static function assertArrayDbResultsEqual(array $expected, array $actual, array $fields) + { $expectedFiltered = []; $actualFiltered = []; @@ -64,10 +66,10 @@ class TestCase extends CoreTestCase { self::assertCount(count($expected), $actual); self::assertEquals($expectedFiltered, $actualFiltered); - } - public function overwriteApplicationService(Application $app, $name, $newService) { + public function overwriteApplicationService(Application $app, $name, $newService) + { $app->getContainer()->registerService($name, function () use ($newService) { return $newService; }); @@ -79,12 +81,12 @@ class TestCase extends CoreTestCase { * @param $name * @param $newValue */ - public function setValueOfPrivateProperty($obj, $name, $newValue) { + public function setValueOfPrivateProperty($obj, $name, $newValue) + { $refl = new \ReflectionObject($obj); $p = $refl->getProperty($name); $p->setAccessible(true); $p->setValue($obj, $newValue); $p->setAccessible(false); } - -}
\ No newline at end of file +} diff --git a/tests/bootstrap-integration.php b/tests/bootstrap-integration.php index f415af9..a5aebe5 100644 --- a/tests/bootstrap-integration.php +++ b/tests/bootstrap-integration.php @@ -1,13 +1,11 @@ <?php +define('PHPUNIT_RUN', 1); + $nc_root = __DIR__ . '/../../..'; @include 'bootstrap-config.development.php'; -echo "Using ".realpath($nc_root)." as Nextcloud root.\n\n"; - -try { - require_once $nc_root . '/tests/bootstrap.php'; -} catch (Exception $ex) { - require_once $nc_root . '/lib/base.php'; -} +require_once $nc_root . '/lib/base.php'; require_once __DIR__ . '/../vendor/autoload.php'; + +\OC::$composerAutoloader->addPsr4('OCA\\OJSXC\\Tests\\', __DIR__, true); |