test: fix integration tests
This commit is contained in:
Родитель
c083263a50
Коммит
bce9f19002
|
@ -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>
|
||||
|
|
14
phpunit.xml
14
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>
|
||||
|
|
|
@ -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
|
||||
{
|
|
@ -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
|
||||
{
|
|
@ -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
|
||||
{
|
|
@ -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()
|
|
@ -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;
|
|
@ -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
|
||||
{
|
|
@ -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;
|
||||
|
||||
/**
|
|
@ -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;
|
||||
|
|
@ -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(
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OJSXC;
|
||||
namespace OCA\OJSXC\Tests\Integration;
|
||||
|
||||
use OCA\OJSXC\AppInfo\Application;
|
||||
use OCA\OJSXC\Db\IQRosterPushMapper;
|
|
@ -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');
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче