Merge pull request #10112 from nupplaphil/feat/phpunit_upgrade

Enable PHP 8.0 Unit-Tests
This commit is contained in:
Hypolite Petovan 2021-04-05 07:24:24 -04:00 committed by GitHub
commit 49d80dc447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 282 additions and 1616 deletions

View File

@ -28,7 +28,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php-versions: ['7.2', '7.3', '7.4'] php-versions: ['7.3', '7.4', '8.0']
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -62,6 +62,9 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: composer install --prefer-dist run: composer install --prefer-dist
- name: Setup PHPUnit 8
run: bin/dev/setup-phpunit.sh
- name: Copy default Friendica config - name: Copy default Friendica config
run: cp config/local-sample.config.php config/local.config.php run: cp config/local-sample.config.php config/local.config.php
@ -83,7 +86,7 @@ jobs:
run: vendor/bin/parallel-lint --exclude vendor/ --exclude view/asset/ . run: vendor/bin/parallel-lint --exclude vendor/ --exclude view/asset/ .
- name: Test with phpunit - name: Test with phpunit
run: vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml run: $(git rev-parse --show-toplevel)/bin/phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml
env: env:
MYSQL_HOST: 127.0.0.1 MYSQL_HOST: 127.0.0.1
MYSQL_PORT: ${{ job.services.mariadb.ports[3306] }} MYSQL_PORT: ${{ job.services.mariadb.ports[3306] }}

3
.gitignore vendored
View File

@ -79,3 +79,6 @@ venv/
#Ignore log folder #Ignore log folder
/log /log
#Ignore temporary installed phpunit
/bin/phpunit

13
bin/dev/setup-phpunit.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
PHPUNIT="$(git rev-parse --show-toplevel)/bin/phpunit"
if ! [ -x "$PHPUNIT" ]; then
echo "Install PHPUnit 8"
cd /tmp/
curl -s -O -L https://phar.phpunit.de/phpunit-8.phar
chmod +x phpunit-8.phar
mv phpunit-8.phar $PHPUNIT
fi
echo "Using $PHPUNIT $($PHPUNIT --version)"

View File

@ -124,12 +124,9 @@
] ]
}, },
"require-dev": { "require-dev": {
"phpdocumentor/reflection-docblock": "^3.0.2", "php-parallel-lint/php-parallel-lint": "^1.2",
"phpunit/php-token-stream": "^1.4.2", "mockery/mockery": "^1.3",
"mikey179/vfsstream": "^1.6", "mikey179/vfsstream": "^1.6"
"mockery/mockery": "^1.2",
"johnkary/phpunit-speedtrap": "1.1",
"php-parallel-lint/php-parallel-lint": "^1.2"
}, },
"scripts": { "scripts": {
"test": "phpunit" "test": "phpunit"

1449
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -27,4 +27,18 @@ namespace Friendica\Test;
abstract class DatabaseTest extends MockedTest abstract class DatabaseTest extends MockedTest
{ {
use DatabaseTestTrait; use DatabaseTestTrait;
protected function setUp(): void
{
$this->setUpDb();
parent::setUp();
}
protected function tearDown(): void
{
$this->tearDownDb();
parent::tearDown();
}
} }

View File

@ -29,23 +29,23 @@ use Friendica\Test\Util\Database\StaticDatabase;
*/ */
trait DatabaseTestTrait trait DatabaseTestTrait
{ {
protected function setUp() protected function setUpDb()
{ {
StaticDatabase::statConnect($_SERVER); StaticDatabase::statConnect($_SERVER);
// Rollbacks every DB usage (in case the test couldn't call tearDown) // Rollbacks every DB usage (in case the test couldn't call tearDown)
StaticDatabase::statRollback(); StaticDatabase::statRollback();
// Start the first, outer transaction // Start the first, outer transaction
StaticDatabase::getGlobConnection()->beginTransaction(); StaticDatabase::getGlobConnection()->beginTransaction();
parent::setUp();
} }
protected function tearDown() protected function tearDownDb()
{ {
try {
// Rollbacks every DB usage so we don't commit anything into the DB // Rollbacks every DB usage so we don't commit anything into the DB
StaticDatabase::statRollback(); StaticDatabase::statRollback();
} catch (\PDOException $exception) {
parent::tearDown(); print_r("Found already rolled back transaction");
}
} }
/** /**

View File

@ -26,7 +26,7 @@ abstract class FixtureTest extends DatabaseTest
/** /**
* Create variables used by tests. * Create variables used by tests.
*/ */
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -28,7 +28,7 @@ use PHPUnit\Framework\TestCase;
*/ */
abstract class MockedTest extends TestCase abstract class MockedTest extends TestCase
{ {
protected function tearDown() protected function tearDown() : void
{ {
\Mockery::close(); \Mockery::close();

13
tests/README.md Normal file
View File

@ -0,0 +1,13 @@
# Using the Friendica tests
## Install PHPUnit
Please use [setup-phpunit.sh](https://github.com/friendica/friendica/bin/dev/setup-phpunit.sh) to install the necessary PHPUnit version.
It will temporarily install the `phpunit` phar file into the `bin/` subdirectory
Currently, Friendica uses PHPUnit 8.
## Supported PHP versions of these tests
The Unit-Tests of Friendica requires at least PHP 7.2.

View File

@ -67,8 +67,9 @@ class ExtendedPDO extends PDO
*/ */
public function beginTransaction() public function beginTransaction()
{ {
if($this->_transactionDepth == 0 || !$this->hasSavepoint()) { if($this->_transactionDepth <= 0 || !$this->hasSavepoint()) {
parent::beginTransaction(); parent::beginTransaction();
$this->_transactionDepth = $this->_transactionDepth < 0 ? 0 : $this->_transactionDepth;
} else { } else {
$this->exec("SAVEPOINT LEVEL{$this->_transactionDepth}"); $this->exec("SAVEPOINT LEVEL{$this->_transactionDepth}");
} }
@ -85,8 +86,9 @@ class ExtendedPDO extends PDO
{ {
$this->_transactionDepth--; $this->_transactionDepth--;
if($this->_transactionDepth == 0 || !$this->hasSavepoint()) { if($this->_transactionDepth <= 0 || !$this->hasSavepoint()) {
parent::commit(); parent::commit();
$this->_transactionDepth = $this->_transactionDepth < 0 ? 0 : $this->_transactionDepth;
} else { } else {
$this->exec("RELEASE SAVEPOINT LEVEL{$this->_transactionDepth}"); $this->exec("RELEASE SAVEPOINT LEVEL{$this->_transactionDepth}");
} }
@ -100,8 +102,7 @@ class ExtendedPDO extends PDO
*/ */
public function rollBack() public function rollBack()
{ {
if ($this->_transactionDepth <= 0) {
if ($this->_transactionDepth == 0) {
throw new PDOException('Rollback error : There is no transaction started'); throw new PDOException('Rollback error : There is no transaction started');
} }

View File

@ -24,6 +24,12 @@ use Dice\Dice;
use Friendica\DI; use Friendica\DI;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.');
}
require __DIR__ . '/../vendor/autoload.php';
// Backward compatibility // Backward compatibility
if (!class_exists(TestCase::class)) { if (!class_exists(TestCase::class)) {
class_alias(PHPUnit_Framework_TestCase::class, TestCase::class); class_alias(PHPUnit_Framework_TestCase::class, TestCase::class);

View File

@ -19,11 +19,43 @@
* *
*/ */
use Friendica\Core\Protocol;
use Friendica\Model\Contact;
return [ 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' => [ 'photo' => [
// move from data-attribute to storage backend // move from data-attribute to storage backend
[ [
'id' => 1, 'id' => 1,
'uid' => 42,
'contact-id' => 42,
'backend-class' => null, 'backend-class' => null,
'backend-ref' => 'f0c0d0i2', 'backend-ref' => 'f0c0d0i2',
'data' => 'without class', 'data' => 'without class',
@ -31,6 +63,8 @@ return [
// move from storage-backend to maybe filesystem backend, skip at database backend // move from storage-backend to maybe filesystem backend, skip at database backend
[ [
'id' => 2, 'id' => 2,
'uid' => 42,
'contact-id' => 42,
'backend-class' => 'Database', 'backend-class' => 'Database',
'backend-ref' => 1, 'backend-ref' => 1,
'data' => '', 'data' => '',
@ -38,6 +72,8 @@ return [
// move data if invalid storage // move data if invalid storage
[ [
'id' => 3, 'id' => 3,
'uid' => 42,
'contact-id' => 42,
'backend-class' => 'invalid!', 'backend-class' => 'invalid!',
'backend-ref' => 'unimported', 'backend-ref' => 'unimported',
'data' => 'invalid data moved', 'data' => 'invalid data moved',
@ -45,6 +81,8 @@ return [
// @todo Check failing test because of this (never loaded) fixture // @todo Check failing test because of this (never loaded) fixture
// [ // [
// 'id' => 4, // 'id' => 4,
// 'uid' => 42,
// 'contact-id' => 42,
// 'backend-class' => 'invalid!', // 'backend-class' => 'invalid!',
// 'backend-ref' => 'unimported', // 'backend-ref' => 'unimported',
// 'data' => '', // 'data' => '',

View File

@ -45,7 +45,7 @@ class DependencyCheckTest extends TestCase
*/ */
private $dice; private $dice;
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -22,6 +22,8 @@ require_once __DIR__ . '/../../include/api.php';
* *
* Functions that use header() need to be tested in a separate process. * Functions that use header() need to be tested in a separate process.
* @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
*
* @backupGlobals enabled
*/ */
class ApiTest extends FixtureTest class ApiTest extends FixtureTest
{ {
@ -48,7 +50,7 @@ class ApiTest extends FixtureTest
/** /**
* Create variables used by tests. * Create variables used by tests.
*/ */
protected function setUp() protected function setUp() : void
{ {
global $API, $called_api; global $API, $called_api;
$API = []; $API = [];
@ -108,10 +110,6 @@ class ApiTest extends FixtureTest
'authenticated' => true, 'authenticated' => true,
'uid' => $this->selfUser['id'] 'uid' => $this->selfUser['id']
]; ];
$_POST = [];
$_GET = [];
$_SERVER = [];
} }
/** /**
@ -140,7 +138,7 @@ class ApiTest extends FixtureTest
* *
* @return void * @return void
*/ */
private function assertOtherUser(array $user) private function assertOtherUser(array $user = [])
{ {
self::assertEquals($this->otherUser['id'], $user['id']); self::assertEquals($this->otherUser['id'], $user['id']);
self::assertEquals($this->otherUser['id'], $user['id_str']); self::assertEquals($this->otherUser['id'], $user['id_str']);
@ -157,10 +155,10 @@ class ApiTest extends FixtureTest
* *
* @return void * @return void
*/ */
private function assertStatus(array $status) private function assertStatus(array $status = [])
{ {
self::assertInternalType('string', $status['text']); self::assertInternalType('string', $status['text'] ?? '');
self::assertInternalType('int', $status['id']); self::assertInternalType('int', $status['id'] ?? '');
// We could probably do more checks here. // We could probably do more checks here.
} }
@ -171,7 +169,7 @@ class ApiTest extends FixtureTest
* *
* @return void * @return void
*/ */
private function assertList(array $list) private function assertList(array $list = [])
{ {
self::assertInternalType('string', $list['name']); self::assertInternalType('string', $list['name']);
self::assertInternalType('int', $list['id']); self::assertInternalType('int', $list['id']);
@ -188,7 +186,7 @@ class ApiTest extends FixtureTest
* *
* @return void * @return void
*/ */
private function assertXml($result, $root_element) private function assertXml($result = '', $root_element = '')
{ {
self::assertStringStartsWith('<?xml version="1.0"?>', $result); self::assertStringStartsWith('<?xml version="1.0"?>', $result);
self::assertContains('<' . $root_element, $result); self::assertContains('<' . $root_element, $result);
@ -302,8 +300,9 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_login() function without any login. * Test the api_login() function without any login.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
* @preserveGlobalState disabled
* @expectedException Friendica\Network\HTTPException\UnauthorizedException * @expectedException Friendica\Network\HTTPException\UnauthorizedException
*/ */
public function testApiLoginWithoutLogin() public function testApiLoginWithoutLogin()
@ -314,8 +313,9 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_login() function with a bad login. * Test the api_login() function with a bad login.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
* @preserveGlobalState disabled
* @expectedException Friendica\Network\HTTPException\UnauthorizedException * @expectedException Friendica\Network\HTTPException\UnauthorizedException
*/ */
public function testApiLoginWithBadLogin() public function testApiLoginWithBadLogin()
@ -347,8 +347,9 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_login() function with a correct login. * Test the api_login() function with a correct login.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
* @doesNotPerformAssertions
*/ */
public function testApiLoginWithCorrectLogin() public function testApiLoginWithCorrectLogin()
{ {
@ -360,8 +361,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_login() function with a remote user. * Test the api_login() function with a remote user.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
* @expectedException Friendica\Network\HTTPException\UnauthorizedException * @expectedException Friendica\Network\HTTPException\UnauthorizedException
*/ */
public function testApiLoginWithRemoteUser() public function testApiLoginWithRemoteUser()
@ -404,8 +405,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function. * Test the api_call() function.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCall() public function testApiCall()
{ {
@ -431,8 +432,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with the profiled enabled. * Test the api_call() function with the profiled enabled.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithProfiler() public function testApiCallWithProfiler()
{ {
@ -468,8 +469,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function without any result. * Test the api_call() function without any result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithNoResult() public function testApiCallWithNoResult()
{ {
@ -494,8 +495,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with an unimplemented API. * Test the api_call() function with an unimplemented API.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithUninplementedApi() public function testApiCallWithUninplementedApi()
{ {
@ -508,8 +509,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with a JSON result. * Test the api_call() function with a JSON result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithJson() public function testApiCallWithJson()
{ {
@ -534,8 +535,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with an XML result. * Test the api_call() function with an XML result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithXml() public function testApiCallWithXml()
{ {
@ -560,8 +561,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with an RSS result. * Test the api_call() function with an RSS result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithRss() public function testApiCallWithRss()
{ {
@ -587,8 +588,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with an Atom result. * Test the api_call() function with an Atom result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithAtom() public function testApiCallWithAtom()
{ {
@ -614,8 +615,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with an unallowed method. * Test the api_call() function with an unallowed method.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithWrongMethod() public function testApiCallWithWrongMethod()
{ {
@ -635,8 +636,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_call() function with an unauthorized user. * Test the api_call() function with an unauthorized user.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiCallWithWrongAuth() public function testApiCallWithWrongAuth()
{ {
@ -660,8 +661,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_error() function with a JSON result. * Test the api_error() function with a JSON result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiErrorWithJson() public function testApiErrorWithJson()
{ {
@ -674,8 +675,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_error() function with an XML result. * Test the api_error() function with an XML result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiErrorWithXml() public function testApiErrorWithXml()
{ {
@ -695,8 +696,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_error() function with an RSS result. * Test the api_error() function with an RSS result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiErrorWithRss() public function testApiErrorWithRss()
{ {
@ -716,8 +717,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_error() function with an Atom result. * Test the api_error() function with an Atom result.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiErrorWithAtom() public function testApiErrorWithAtom()
{ {
@ -859,8 +860,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_get_user() function with an user that is not allowed to use the API. * Test the api_get_user() function with an user that is not allowed to use the API.
* *
* @return void
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
*/ */
public function testApiGetUserWithoutApiUser() public function testApiGetUserWithoutApiUser()
{ {
@ -1312,8 +1313,8 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_media_upload() function. * Test the api_media_upload() function.
* * @runInSeparateProcess
* @return void * @preserveGlobalState disabled
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
public function testApiMediaUpload() public function testApiMediaUpload()
@ -1504,7 +1505,7 @@ class ApiTest extends FixtureTest
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertStatus($status);
self::assertContains('reply', $status['text'], null, true); self::assertContains('reply', $status['text'], '', true);
} }
} }
@ -1520,7 +1521,7 @@ class ApiTest extends FixtureTest
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertStatus($status);
self::assertContains('reply', $status['text'], null, true); self::assertContains('reply', $status['text'], '', true);
} }
} }
@ -1536,14 +1537,13 @@ class ApiTest extends FixtureTest
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertStatus($status);
self::assertContains('reply', $status['text'], null, true); self::assertContains('reply', $status['text'], '', true);
} }
} }
/** /**
* Test the api_search() function with an q parameter contains hashtag. * Test the api_search() function with an q parameter contains hashtag.
* * @doesNotPerformAssertions
* @return void
*/ */
public function testApiSearchWithHashtag() public function testApiSearchWithHashtag()
{ {
@ -1551,14 +1551,13 @@ class ApiTest extends FixtureTest
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertStatus($status);
self::assertContains('#friendica', $status['text'], null, true); self::assertContains('#friendica', $status['text'], '', true);
} }
} }
/** /**
* Test the api_search() function with an exclude_replies parameter. * Test the api_search() function with an exclude_replies parameter.
* * @doesNotPerformAssertions
* @return void
*/ */
public function testApiSearchWithExcludeReplies() public function testApiSearchWithExcludeReplies()
{ {
@ -2474,8 +2473,7 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_format_items() function. * Test the api_format_items() function.
* * @doesNotPerformAssertions
* @return void
*/ */
public function testApiFormatItems() public function testApiFormatItems()
{ {
@ -2500,8 +2498,7 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_format_items() function with an XML result. * Test the api_format_items() function with an XML result.
* * @doesNotPerformAssertions
* @return void
*/ */
public function testApiFormatItemsWithXml() public function testApiFormatItemsWithXml()
{ {
@ -2617,8 +2614,7 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_lists_statuses() function with a list ID. * Test the api_lists_statuses() function with a list ID.
* * @doesNotPerformAssertions
* @return void
*/ */
public function testApiListsStatusesWithListId() public function testApiListsStatusesWithListId()
{ {
@ -3271,8 +3267,6 @@ class ApiTest extends FixtureTest
/** /**
* Test the api_fr_photo_create_update() function. * Test the api_fr_photo_create_update() function.
*
* @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
public function testApiFrPhotoCreateUpdate() public function testApiFrPhotoCreateUpdate()

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit
bootstrap="bootstrap.php"
verbose="true">
<testsuite name='friendica'>
<directory suffix='.php'>functional/</directory>
<directory suffix='.php'>include/</directory>
<directory suffix='.php'>src/</directory>
<directory suffix='.php'>./</directory>
</testsuite>
<!-- Filters for Code Coverage -->
<filter>
<whitelist>
<directory suffix=".php">..</directory>
<exclude>
<directory suffix=".php">config/</directory>
<directory suffix=".php">doc/</directory>
<directory suffix=".php">images/</directory>
<directory suffix=".php">library/</directory>
<directory suffix=".php">spec/</directory>
<directory suffix=".php">tests/</directory>
<directory suffix=".php">view/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@ -1,29 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<phpunit <phpunit
bootstrap="bootstrap.php" bootstrap="bootstrap.php"
verbose="true"> verbose="true"
backupGlobals="false"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
timeoutForLargeTests="900">
<testsuite name='friendica'> <testsuite name='friendica'>
<directory suffix='.php'>functional/</directory> <directory suffix='.php'>functional/</directory>
<directory suffix='.php'>include/</directory> <directory suffix='.php'>include/</directory>
<directory suffix='.php'>src/</directory> <directory suffix='.php'>src/</directory>
<directory suffix='.php'>./</directory>
</testsuite> </testsuite>
<!-- Filters for Code Coverage --> <!-- Filters for Code Coverage -->
<filter> <filter>
<whitelist> <whitelist>
<directory suffix=".php">..</directory> <directory suffix=".php">..</directory>
<exclude> <exclude>
<directory suffix=".php">../config</directory> <directory suffix=".php">config/</directory>
<directory suffix=".php">../doc</directory> <directory suffix=".php">doc/</directory>
<directory suffix=".php">../images</directory> <directory suffix=".php">images/</directory>
<directory suffix=".php">../library</directory> <directory suffix=".php">library/</directory>
<directory suffix=".php">../spec</directory> <directory suffix=".php">spec/</directory>
<directory suffix=".php">../tests</directory> <directory suffix=".php">tests/</directory>
<directory suffix=".php">../view</directory> <directory suffix=".php">view/</directory>
<directory suffix=".php">vendor/</directory>
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
</phpunit> </phpunit>

View File

@ -53,7 +53,7 @@ class ModeTest extends MockedTest
*/ */
private $configCacheMock; private $configCacheMock;
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -40,7 +40,7 @@ class RouterTest extends TestCase
*/ */
private $cache; private $cache;
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -76,7 +76,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
*/ */
private $dice; private $dice;
public function setUp() public function setUp() : void
{ {
static::markTestSkipped('Needs class \'Installer\' as constructing argument for console tests'); static::markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');

View File

@ -38,7 +38,7 @@ class ConfigConsoleTest extends ConsoleTest
/** @var IConfig|LegacyMockInterface|MockInterface */ /** @var IConfig|LegacyMockInterface|MockInterface */
private $configMock; private $configMock;
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -32,7 +32,7 @@ abstract class ConsoleTest extends MockedTest
*/ */
protected $consoleArgv = [ 'consoleTest.php' ]; protected $consoleArgv = [ 'consoleTest.php' ];
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -40,7 +40,7 @@ class LockConsoleTest extends ConsoleTest
*/ */
private $lockMock; private $lockMock;
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -42,7 +42,7 @@ class ServerBlockConsoleTest extends ConsoleTest
*/ */
private $configMock; private $configMock;
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();

View File

@ -19,7 +19,7 @@ class SmiliesTest extends MockedTest
use VFSTrait; use VFSTrait;
use AppMockTrait; use AppMockTrait;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->setUpVfsDir(); $this->setUpVfsDir();

View File

@ -35,7 +35,7 @@ class BBCodeTest extends MockedTest
use VFSTrait; use VFSTrait;
use AppMockTrait; use AppMockTrait;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->setUpVfsDir(); $this->setUpVfsDir();

View File

@ -33,7 +33,7 @@ class HTMLTest extends MockedTest
use VFSTrait; use VFSTrait;
use AppMockTrait; use AppMockTrait;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->setUpVfsDir(); $this->setUpVfsDir();

View File

@ -32,7 +32,7 @@ class MarkdownTest extends MockedTest
use VFSTrait; use VFSTrait;
use AppMockTrait; use AppMockTrait;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->setUpVfsDir(); $this->setUpVfsDir();

View File

@ -28,7 +28,7 @@ use Friendica\Core\Cache\APCuCache;
*/ */
class APCuCacheTest extends MemoryCacheTest class APCuCacheTest extends MemoryCacheTest
{ {
protected function setUp() protected function setUp(): void
{ {
if (!APCuCache::isAvailable()) { if (!APCuCache::isAvailable()) {
static::markTestSkipped('APCu is not available'); static::markTestSkipped('APCu is not available');
@ -43,7 +43,7 @@ class APCuCacheTest extends MemoryCacheTest
return $this->cache; return $this->cache;
} }
protected function tearDown() protected function tearDown(): void
{ {
$this->cache->clear(false); $this->cache->clear(false);
parent::tearDown(); parent::tearDown();

View File

@ -31,7 +31,7 @@ class ArrayCacheTest extends MemoryCacheTest
return $this->cache; return $this->cache;
} }
protected function tearDown() protected function tearDown(): void
{ {
$this->cache->clear(false); $this->cache->clear(false);
parent::tearDown(); parent::tearDown();
@ -40,6 +40,7 @@ class ArrayCacheTest extends MemoryCacheTest
public function testTTL() public function testTTL()
{ {
// Array Cache doesn't support TTL // Array Cache doesn't support TTL
self::markTestSkipped("Array Cache doesn't support TTL");
return true; return true;
} }
} }

View File

@ -81,7 +81,7 @@ abstract class CacheTest extends MockedTest
abstract protected function getInstance(); abstract protected function getInstance();
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -36,10 +36,12 @@ class DatabaseCacheTest extends CacheTest
use DatabaseTestTrait; use DatabaseTestTrait;
use VFSTrait; use VFSTrait;
protected function setUp() protected function setUp(): void
{ {
$this->setUpVfsDir(); $this->setUpVfsDir();
$this->setUpDb();
parent::setUp(); parent::setUp();
} }
@ -60,9 +62,12 @@ class DatabaseCacheTest extends CacheTest
return $this->cache; return $this->cache;
} }
protected function tearDown() protected function tearDown(): void
{ {
$this->cache->clear(false); $this->cache->clear(false);
$this->tearDownDb();
parent::tearDown(); parent::tearDown();
} }
} }

View File

@ -56,7 +56,7 @@ class MemcacheCacheTest extends MemoryCacheTest
return $this->cache; return $this->cache;
} }
protected function tearDown() protected function tearDown(): void
{ {
$this->cache->clear(false); $this->cache->clear(false);
parent::tearDown(); parent::tearDown();

View File

@ -55,7 +55,7 @@ class MemcachedCacheTest extends MemoryCacheTest
return $this->cache; return $this->cache;
} }
protected function tearDown() protected function tearDown(): void
{ {
$this->cache->clear(false); $this->cache->clear(false);
parent::tearDown(); parent::tearDown();

View File

@ -31,7 +31,7 @@ abstract class MemoryCacheTest extends CacheTest
*/ */
protected $instance; protected $instance;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -65,7 +65,7 @@ class RedisCacheTest extends MemoryCacheTest
return $this->cache; return $this->cache;
} }
protected function tearDown() protected function tearDown(): void
{ {
$this->cache->clear(false); $this->cache->clear(false);
parent::tearDown(); parent::tearDown();

View File

@ -55,7 +55,7 @@ abstract class ConfigTest extends MockedTest
} }
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -45,7 +45,7 @@ class InstallerTest extends MockedTest
*/ */
private $dice; private $dice;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -64,6 +64,15 @@ class InstallerTest extends MockedTest
DI::init($this->dice); DI::init($this->dice);
} }
public static function tearDownAfterClass(): void
{
// Reset mocking
global $phpMock;
$phpMock = [];
parent::tearDownAfterClass();
}
private function mockL10nT(string $text, $times = null) private function mockL10nT(string $text, $times = null)
{ {
$this->l10nMock->shouldReceive('t')->with($text)->andReturn($text)->times($times); $this->l10nMock->shouldReceive('t')->with($text)->andReturn($text)->times($times);
@ -463,6 +472,7 @@ class InstallerTest extends MockedTest
/** /**
* Test the setup of the config cache for installation * Test the setup of the config cache for installation
* @doesNotPerformAssertions
*/ */
public function testSetUpCache() public function testSetUpCache()
{ {

View File

@ -29,7 +29,7 @@ use Friendica\Core\Lock\CacheLock;
*/ */
class APCuCacheLockTest extends LockTest class APCuCacheLockTest extends LockTest
{ {
protected function setUp() protected function setUp(): void
{ {
if (!APCuCache::isAvailable()) { if (!APCuCache::isAvailable()) {
static::markTestSkipped('APCu is not available'); static::markTestSkipped('APCu is not available');

View File

@ -33,7 +33,6 @@ class ArrayCacheLockTest extends LockTest
public function testLockTTL() public function testLockTTL()
{ {
// ArrayCache doesn't support TTL self::markTestSkipped("ArrayCache doesn't support TTL");
return true;
} }
} }

View File

@ -38,10 +38,12 @@ class DatabaseLockDriverTest extends LockTest
protected $pid = 123; protected $pid = 123;
protected function setUp() protected function setUp(): void
{ {
$this->setUpVfsDir(); $this->setUpVfsDir();
$this->setUpDb();
parent::setUp(); parent::setUp();
} }
@ -60,4 +62,11 @@ class DatabaseLockDriverTest extends LockTest
return new DatabaseLock($dba, $this->pid); return new DatabaseLock($dba, $this->pid);
} }
protected function tearDown(): void
{
$this->tearDownDb();
parent::tearDown();
}
} }

View File

@ -38,7 +38,7 @@ abstract class LockTest extends MockedTest
abstract protected function getInstance(); abstract protected function getInstance();
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -46,7 +46,7 @@ abstract class LockTest extends MockedTest
$this->instance->releaseAll(true); $this->instance->releaseAll(true);
} }
protected function tearDown() protected function tearDown(): void
{ {
$this->instance->releaseAll(true); $this->instance->releaseAll(true);
parent::tearDown(); parent::tearDown();

View File

@ -32,7 +32,7 @@ use Mockery\MockInterface;
class SemaphoreLockTest extends LockTest class SemaphoreLockTest extends LockTest
{ {
protected function setUp() protected function setUp(): void
{ {
/** @var MockInterface|Dice $dice */ /** @var MockInterface|Dice $dice */
$dice = Mockery::mock(Dice::class)->makePartial(); $dice = Mockery::mock(Dice::class)->makePartial();
@ -61,8 +61,7 @@ class SemaphoreLockTest extends LockTest
public function testLockTTL() public function testLockTTL()
{ {
// Semaphore doesn't work with TTL self::markTestSkipped("Semaphore doesn't work with TTL");
return true;
} }
/** /**

View File

@ -57,7 +57,7 @@ abstract class PConfigTest extends MockedTest
} }
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -57,7 +57,7 @@ class StorageManagerTest extends DatabaseTest
use VFSTrait; use VFSTrait;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -296,7 +296,7 @@ class StorageManagerTest extends DatabaseTest
public function testMoveStorage($name, $assert, $assertName, $userBackend) public function testMoveStorage($name, $assert, $assertName, $userBackend)
{ {
if (!$userBackend) { if (!$userBackend) {
return; self::markTestSkipped("No user backend");
} }
$this->loadFixture(__DIR__ . '/../../datasets/storage/database.fixture.php', $this->dba); $this->loadFixture(__DIR__ . '/../../datasets/storage/database.fixture.php', $this->dba);

View File

@ -10,7 +10,7 @@ use Friendica\Test\Util\Database\StaticDatabase;
class DBATest extends DatabaseTest class DBATest extends DatabaseTest
{ {
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -30,7 +30,7 @@ use Friendica\Test\Util\Database\StaticDatabase;
class DBStructureTest extends DatabaseTest class DBStructureTest extends DatabaseTest
{ {
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -18,7 +18,7 @@ class ProcessTest extends DatabaseTest
/** @var StaticDatabase */ /** @var StaticDatabase */
private $dba; private $dba;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -71,6 +71,9 @@ class ProcessTest extends DatabaseTest
self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1])); self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
} }
/**
* @doesNotPerformAssertions
*/
public function testWrongDelete() public function testWrongDelete()
{ {
$process = new Process($this->dba); $process = new Process($this->dba);

View File

@ -38,10 +38,12 @@ class DatabaseStorageTest extends StorageTest
use DatabaseTestTrait; use DatabaseTestTrait;
use VFSTrait; use VFSTrait;
protected function setUp() protected function setUp(): void
{ {
$this->setUpVfsDir(); $this->setUpVfsDir();
$this->setUpDb();
parent::setUp(); parent::setUp();
} }
@ -68,4 +70,11 @@ class DatabaseStorageTest extends StorageTest
{ {
self::assertEmpty($storage->getOptions()); self::assertEmpty($storage->getOptions());
} }
protected function tearDown(): void
{
$this->tearDownDb();
parent::tearDown();
}
} }

View File

@ -39,7 +39,7 @@ class FilesystemStorageTest extends StorageTest
/** @var MockInterface|IConfig */ /** @var MockInterface|IConfig */
protected $config; protected $config;
protected function setUp() protected function setUp(): void
{ {
$this->setUpVfsDir(); $this->setUpVfsDir();

View File

@ -35,7 +35,7 @@ class CookieTest extends MockedTest
/** @var MockInterface|BaseURL */ /** @var MockInterface|BaseURL */
private $baseUrl; private $baseUrl;
protected function setUp() protected function setUp(): void
{ {
StaticCookie::clearStatic(); StaticCookie::clearStatic();
@ -45,7 +45,7 @@ class CookieTest extends MockedTest
$this->baseUrl = \Mockery::mock(BaseURL::class); $this->baseUrl = \Mockery::mock(BaseURL::class);
} }
protected function tearDown() protected function tearDown(): void
{ {
StaticCookie::clearStatic(); StaticCookie::clearStatic();

View File

@ -37,7 +37,7 @@ class UserTest extends MockedTest
private $child; private $child;
private $manage; private $manage;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -31,7 +31,7 @@ use Psr\Log\NullLogger;
class CurlResultTest extends TestCase class CurlResultTest extends TestCase
{ {
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -3,11 +3,12 @@
namespace Friendica\Test\src\Security\TwoFactor\Factory; namespace Friendica\Test\src\Security\TwoFactor\Factory;
use Friendica\Security\TwoFactor\Factory\TrustedBrowser; use Friendica\Security\TwoFactor\Factory\TrustedBrowser;
use Friendica\Test\MockedTest;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Logger\VoidLogger; use Friendica\Util\Logger\VoidLogger;
use Friendica\Util\Strings; use Friendica\Util\Strings;
class TrustedBrowserTest extends \PHPUnit_Framework_TestCase class TrustedBrowserTest extends MockedTest
{ {
public function testCreateFromTableRowSuccess() public function testCreateFromTableRowSuccess()
{ {

View File

@ -3,10 +3,11 @@
namespace Friendica\Test\src\Security\TwoFactor\Model; namespace Friendica\Test\src\Security\TwoFactor\Model;
use Friendica\Security\TwoFactor\Model\TrustedBrowser; use Friendica\Security\TwoFactor\Model\TrustedBrowser;
use Friendica\Test\MockedTest;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings; use Friendica\Util\Strings;
class TrustedBrowserTest extends \PHPUnit_Framework_TestCase class TrustedBrowserTest extends MockedTest
{ {
public function test__construct() public function test__construct()
{ {

View File

@ -31,7 +31,7 @@ class ConfigFileLoaderTest extends MockedTest
{ {
use VFSTrait; use VFSTrait;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -29,6 +29,15 @@ use PHPUnit\Framework\TestCase;
class CryptoTest extends TestCase class CryptoTest extends TestCase
{ {
public static function tearDownAfterClass(): void
{
// Reset mocking
global $phpMock;
$phpMock = [];
parent::tearDownAfterClass();
}
/** /**
* Replaces random_int results with given mocks * Replaces random_int results with given mocks
* *

View File

@ -35,7 +35,7 @@ class EMailerTest extends MockedTest
/** @var BaseURL|MockInterface */ /** @var BaseURL|MockInterface */
private $baseUrl; private $baseUrl;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -53,7 +53,7 @@ class EMailerTest extends MockedTest
$this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local'); $this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
} }
protected function tearDown() protected function tearDown(): void
{ {
EmailerSpy::$MAIL_DATA = []; EmailerSpy::$MAIL_DATA = [];

View File

@ -51,7 +51,7 @@ class MailBuilderTest extends MockedTest
/** @var string */ /** @var string */
private $defaultHeaders; private $defaultHeaders;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -41,7 +41,7 @@ class SystemMailBuilderTest extends MockedTest
/** @var BaseURL */ /** @var BaseURL */
private $baseUrl; private $baseUrl;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -58,7 +58,7 @@ abstract class AbstractLoggerTest extends MockedTest
*/ */
abstract protected function getInstance($level = LogLevel::DEBUG); abstract protected function getInstance($level = LogLevel::DEBUG);
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -41,7 +41,7 @@ class ProfilerLoggerTest extends MockedTest
*/ */
private $profiler; private $profiler;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -52,6 +52,7 @@ class ProfilerLoggerTest extends MockedTest
/** /**
* Test if the profiler is profiling data * Test if the profiler is profiling data
* @dataProvider dataTests * @dataProvider dataTests
* @doesNotPerformAssertions
*/ */
public function testProfiling($function, $message, array $context) public function testProfiling($function, $message, array $context)
{ {
@ -64,6 +65,7 @@ class ProfilerLoggerTest extends MockedTest
/** /**
* Test the log() function * Test the log() function
* @doesNotPerformAssertions
*/ */
public function testProfilingLog() public function testProfilingLog()
{ {

View File

@ -42,7 +42,7 @@ class StreamLoggerTest extends AbstractLoggerTest
*/ */
private $fileSystem; private $fileSystem;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -31,7 +31,7 @@ class SyslogLoggerTest extends AbstractLoggerTest
*/ */
private $logger; private $logger;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -86,8 +86,13 @@ class SyslogLoggerTest extends AbstractLoggerTest
*/ */
public function testServerException() public function testServerException()
{ {
if (PHP_MAJOR_VERSION < 8) {
$this->expectException(\UnexpectedValueException::class); $this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessageRegExp("/Can\'t open syslog for ident \".*\" and facility \".*\": .* /"); $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 = new SyslogLoggerWrapper('test', $this->introspection, LogLevel::DEBUG, null, 'a string');
$logger->emergency('not working'); $logger->emergency('not working');
@ -95,6 +100,7 @@ class SyslogLoggerTest extends AbstractLoggerTest
/** /**
* Test the close() method * Test the close() method
* @doesNotPerformAssertions
*/ */
public function testClose() public function testClose()
{ {

View File

@ -32,6 +32,7 @@ class VoidLoggerTest extends MockedTest
/** /**
* Test if the profiler is profiling data * Test if the profiler is profiling data
* @dataProvider dataTests * @dataProvider dataTests
* @doesNotPerformAssertions
*/ */
public function testNormal($function, $message, array $context) public function testNormal($function, $message, array $context)
{ {
@ -41,6 +42,7 @@ class VoidLoggerTest extends MockedTest
/** /**
* Test the log() function * Test the log() function
* @doesNotPerformAssertions
*/ */
public function testProfilingLog() public function testProfilingLog()
{ {

View File

@ -35,7 +35,7 @@ class ProfilerTest extends MockedTest
*/ */
private $logger; private $logger;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();