abstract class DatabaseTest extends MockedTest
{
use DatabaseTestTrait;
+
+ protected function setUp(): void
+ {
+ $this->setUpDb();
+
+ parent::setUp();
+ }
+
+ protected function tearDown(): void
+ {
+ $this->tearDownDb();
+
+ parent::tearDown();
+ }
}
*/
trait DatabaseTestTrait
{
- protected function setUp()
+ protected function setUpDb()
{
StaticDatabase::statConnect($_SERVER);
// Rollbacks every DB usage (in case the test couldn't call tearDown)
StaticDatabase::statRollback();
// Start the first, outer transaction
StaticDatabase::getGlobConnection()->beginTransaction();
-
- parent::setUp();
}
- protected function tearDown()
+ protected function tearDownDb()
{
- // Rollbacks every DB usage so we don't commit anything into the DB
- StaticDatabase::statRollback();
-
- parent::tearDown();
+ try {
+ // Rollbacks every DB usage so we don't commit anything into the DB
+ StaticDatabase::statRollback();
+ } catch (\PDOException $exception) {
+ print_r("Found already rolled back transaction");
+ }
}
/**
/**
* Create variables used by tests.
*/
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
*/
abstract class MockedTest extends TestCase
{
- protected function tearDown()
+ protected function tearDown() : void
{
\Mockery::close();
*/
public function beginTransaction()
{
- if($this->_transactionDepth == 0 || !$this->hasSavepoint()) {
+ if($this->_transactionDepth <= 0 || !$this->hasSavepoint()) {
parent::beginTransaction();
+ $this->_transactionDepth = $this->_transactionDepth < 0 ? 0 : $this->_transactionDepth;
} else {
$this->exec("SAVEPOINT LEVEL{$this->_transactionDepth}");
}
{
$this->_transactionDepth--;
- if($this->_transactionDepth == 0 || !$this->hasSavepoint()) {
+ if($this->_transactionDepth <= 0 || !$this->hasSavepoint()) {
parent::commit();
+ $this->_transactionDepth = $this->_transactionDepth < 0 ? 0 : $this->_transactionDepth;
} else {
$this->exec("RELEASE SAVEPOINT LEVEL{$this->_transactionDepth}");
}
*/
public function rollBack()
{
-
- if ($this->_transactionDepth == 0) {
+ if ($this->_transactionDepth <= 0) {
throw new PDOException('Rollback error : There is no transaction started');
}
*
*/
+use Friendica\Core\Protocol;
+use Friendica\Model\Contact;
+
return [
+ 'user' => [
+ [
+ 'uid' => 42,
+ 'username' => 'Test user',
+ 'nickname' => 'selfcontact',
+ 'verified' => 1,
+ 'password' => '$2y$10$DLRNTRmJgKe1cSrFJ5Jb0edCqvXlA9sh/RHdSnfxjbR.04yZRm4Qm',
+ 'theme' => 'frio',
+ ],
+ ],
+ 'contact' => [
+ [
+ 'id' => 42,
+ 'uid' => 42,
+ 'name' => 'Self contact',
+ 'nick' => 'selfcontact',
+ 'self' => 1,
+ 'nurl' => 'http://localhost/profile/selfcontact',
+ 'url' => 'http://localhost/profile/selfcontact',
+ 'about' => 'User used in tests',
+ 'pending' => 0,
+ 'blocked' => 0,
+ 'rel' => Contact::FOLLOWER,
+ 'network' => Protocol::DFRN,
+ 'location' => 'DFRN',
+ ],
+ ],
'photo' => [
// move from data-attribute to storage backend
[
'id' => 1,
+ 'uid' => 42,
+ 'contact-id' => 42,
'backend-class' => null,
'backend-ref' => 'f0c0d0i2',
'data' => 'without class',
// move from storage-backend to maybe filesystem backend, skip at database backend
[
'id' => 2,
+ 'uid' => 42,
+ 'contact-id' => 42,
'backend-class' => 'Database',
'backend-ref' => 1,
'data' => '',
// move data if invalid storage
[
'id' => 3,
+ 'uid' => 42,
+ 'contact-id' => 42,
'backend-class' => 'invalid!',
'backend-ref' => 'unimported',
'data' => 'invalid data moved',
// @todo Check failing test because of this (never loaded) fixture
// [
// 'id' => 4,
+// 'uid' => 42,
+// 'contact-id' => 42,
// 'backend-class' => 'invalid!',
// 'backend-ref' => 'unimported',
// 'data' => '',
*/
private $dice;
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
/**
* Create variables used by tests.
*/
- protected function setUp()
+ protected function setUp() : void
{
global $API, $called_api;
$API = [];
*/
private $configCacheMock;
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
*/
private $cache;
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
*/
private $dice;
- public function setUp()
+ public function setUp() : void
{
static::markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
/** @var IConfig|LegacyMockInterface|MockInterface */
private $configMock;
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
*/
protected $consoleArgv = [ 'consoleTest.php' ];
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
*/
private $lockMock;
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
*/
private $configMock;
- protected function setUp()
+ protected function setUp() : void
{
parent::setUp();
use VFSTrait;
use AppMockTrait;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
use VFSTrait;
use AppMockTrait;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
use VFSTrait;
use AppMockTrait;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
use VFSTrait;
use AppMockTrait;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
*/
class APCuCacheTest extends MemoryCacheTest
{
- protected function setUp()
+ protected function setUp(): void
{
if (!APCuCache::isAvailable()) {
static::markTestSkipped('APCu is not available');
return $this->cache;
}
- protected function tearDown()
+ protected function tearDown(): void
{
$this->cache->clear(false);
parent::tearDown();
return $this->cache;
}
- protected function tearDown()
+ protected function tearDown(): void
{
$this->cache->clear(false);
parent::tearDown();
abstract protected function getInstance();
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
use DatabaseTestTrait;
use VFSTrait;
- protected function setUp()
+ protected function setUp(): void
{
$this->setUpVfsDir();
+ $this->setUpDb();
+
parent::setUp();
}
return $this->cache;
}
- protected function tearDown()
+ protected function tearDown(): void
{
$this->cache->clear(false);
+
+ $this->tearDownDb();
+
parent::tearDown();
}
}
return $this->cache;
}
- protected function tearDown()
+ protected function tearDown(): void
{
$this->cache->clear(false);
parent::tearDown();
return $this->cache;
}
- protected function tearDown()
+ protected function tearDown(): void
{
$this->cache->clear(false);
parent::tearDown();
*/
protected $instance;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
return $this->cache;
}
- protected function tearDown()
+ protected function tearDown(): void
{
$this->cache->clear(false);
parent::tearDown();
}
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
*/
private $dice;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
DI::init($this->dice);
}
+ public static function tearDownAfterClass(): void
+ {
+ // Reset mocking
+ global $phpMock;
+ $phpMock = [];
+
+ parent::tearDownAfterClass();
+ }
+
private function mockL10nT(string $text, $times = null)
{
$this->l10nMock->shouldReceive('t')->with($text)->andReturn($text)->times($times);
*/
public function testSetUpCache()
{
- $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; })->times(5);
+ $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
$install = new Installer();
$configCache = Mockery::mock(Cache::class);
*/
class APCuCacheLockTest extends LockTest
{
- protected function setUp()
+ protected function setUp(): void
{
if (!APCuCache::isAvailable()) {
static::markTestSkipped('APCu is not available');
protected $pid = 123;
- protected function setUp()
+ protected function setUp(): void
{
$this->setUpVfsDir();
+ $this->setUpDb();
+
parent::setUp();
}
return new DatabaseLock($dba, $this->pid);
}
+
+ protected function tearDown(): void
+ {
+ $this->tearDownDb();
+
+ parent::tearDown();
+ }
}
abstract protected function getInstance();
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->instance->releaseAll(true);
}
- protected function tearDown()
+ protected function tearDown(): void
{
$this->instance->releaseAll(true);
parent::tearDown();
class SemaphoreLockTest extends LockTest
{
- protected function setUp()
+ protected function setUp(): void
{
/** @var MockInterface|Dice $dice */
$dice = Mockery::mock(Dice::class)->makePartial();
}
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
use VFSTrait;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
public function testMoveStorage($name, $assert, $assertName, $userBackend)
{
if (!$userBackend) {
- return;
+ self::markTestSkipped("No user backend");
}
$this->loadFixture(__DIR__ . '/../../datasets/storage/database.fixture.php', $this->dba);
class DBATest extends DatabaseTest
{
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
class DBStructureTest extends DatabaseTest
{
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
/** @var StaticDatabase */
private $dba;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
}
+ /**
+ * @doesNotPerformAssertions
+ */
public function testWrongDelete()
{
$process = new Process($this->dba);
use DatabaseTestTrait;
use VFSTrait;
- protected function setUp()
+ protected function setUp(): void
{
$this->setUpVfsDir();
+ $this->setUpDb();
+
parent::setUp();
}
{
self::assertEmpty($storage->getOptions());
}
+
+ protected function tearDown(): void
+ {
+ $this->tearDownDb();
+
+ parent::tearDown();
+ }
}
/** @var MockInterface|IConfig */
protected $config;
- protected function setUp()
+ protected function setUp(): void
{
$this->setUpVfsDir();
/** @var MockInterface|BaseURL */
private $baseUrl;
- protected function setUp()
+ protected function setUp(): void
{
StaticCookie::clearStatic();
$this->baseUrl = \Mockery::mock(BaseURL::class);
}
- protected function tearDown()
+ protected function tearDown(): void
{
StaticCookie::clearStatic();
private $child;
private $manage;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
class CurlResultTest extends TestCase
{
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
{
use VFSTrait;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
class CryptoTest extends TestCase
{
+ public static function tearDownAfterClass(): void
+ {
+ // Reset mocking
+ global $phpMock;
+ $phpMock = [];
+
+ parent::tearDownAfterClass();
+ }
+
/**
* Replaces random_int results with given mocks
*
/** @var BaseURL|MockInterface */
private $baseUrl;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
}
- protected function tearDown()
+ protected function tearDown(): void
{
EmailerSpy::$MAIL_DATA = [];
/** @var string */
private $defaultHeaders;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
/** @var BaseURL */
private $baseUrl;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
*/
abstract protected function getInstance($level = LogLevel::DEBUG);
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
*/
private $profiler;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
*/
private $fileSystem;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
*/
private $logger;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
*/
public function testServerException()
{
- $this->expectException(\UnexpectedValueException::class);
- $this->expectExceptionMessageRegExp("/Can\'t open syslog for ident \".*\" and facility \".*\": .* /");
+ if (PHP_MAJOR_VERSION < 8) {
+ $this->expectException(\UnexpectedValueException::class);
+ $this->expectExceptionMessageRegExp("/Can\'t open syslog for ident \".*\" and facility \".*\": .* /");
+ } else {
+ $this->expectException(\TypeError::class);
+ $this->expectExceptionMessage("openlog(): Argument #3 (\$facility) must be of type int, string given");
+ }
$logger = new SyslogLoggerWrapper('test', $this->introspection, LogLevel::DEBUG, null, 'a string');
$logger->emergency('not working');
*/
private $logger;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();