mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
Improve test isolation
To ensure tests don't step on each others toes, make sure we back up the static properties of the global App class before running tests that modify any of these properties.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\Attributes\BackupStaticProperties;
|
||||
use Zotlabs\Tests\Unit\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests for the Zotlabs\Lib\Config class.
|
||||
*
|
||||
@@ -8,6 +11,7 @@ declare(strict_types=1);
|
||||
* method for now. This should be improved once the database test framework is
|
||||
* merged.
|
||||
*/
|
||||
#[BackupStaticProperties(true)]
|
||||
class ConfigTest extends Zotlabs\Tests\Unit\UnitTestCase {
|
||||
/*
|
||||
* Hardcode a config that we can test against, and that we can
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
|
||||
namespace Zotlabs\Tests\Unit\Lib;
|
||||
|
||||
use App;
|
||||
use phpmock\phpunit\PHPMock;
|
||||
use PHPUnit\Framework\Attributes\BackupStaticProperties;
|
||||
use Zotlabs\Tests\Unit\UnitTestCase;
|
||||
use Zotlabs\Lib\PermissionDescription;
|
||||
|
||||
@@ -56,6 +58,7 @@ class PermissionDescriptionTest extends UnitTestCase {
|
||||
/**
|
||||
* Test fetching permission descriptions for the current channel.
|
||||
*/
|
||||
#[BackupStaticProperties(App::class)]
|
||||
public function testFromGlobalPermission() {
|
||||
// Initiate the global App with a channel_id
|
||||
\App::$channel = array(
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace Zotlabs\Tests\Unit\Module;
|
||||
|
||||
use App;
|
||||
use PHPUnit\Framework\Attributes\BackupStaticProperties;
|
||||
use PHPUnit\Framework\Attributes\Before;
|
||||
|
||||
class AdminAccountsTest extends TestCase {
|
||||
@@ -76,6 +77,7 @@ class AdminAccountsTest extends TestCase {
|
||||
$this->assertEquals('2 accounts blocked/unblocked', $this->notice[0]);
|
||||
}
|
||||
|
||||
#[BackupStaticProperties(App::class)]
|
||||
public function test_deleting_accounts_remove_them_from_db(): void {
|
||||
$params = [
|
||||
'user' => [ 42, 44 ],
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\Attributes\BackupStaticProperties;
|
||||
|
||||
class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase {
|
||||
|
||||
use \phpmock\phpunit\PHPMock;
|
||||
@@ -103,6 +105,7 @@ class HelpTest extends \Zotlabs\Tests\Unit\Module\TestCase {
|
||||
$this->get('help/first');
|
||||
}
|
||||
|
||||
#[BackupStaticProperties(App::class)]
|
||||
public function test_fall_back_to_english_if_localized_topic_dont_exist(): void {
|
||||
\App::$language = 'nb';
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\Attributes\BackupStaticProperties;
|
||||
|
||||
class RpostTest extends \Zotlabs\Tests\Unit\Module\TestCase {
|
||||
|
||||
/**
|
||||
@@ -59,6 +61,7 @@ class RpostTest extends \Zotlabs\Tests\Unit\Module\TestCase {
|
||||
*
|
||||
* @param array $query An associative array of query parameters.
|
||||
*/
|
||||
#[BackupStaticProperties(App::class)]
|
||||
private function get_authenticated(array $query = []): void {
|
||||
// Mock `local_chanel()` to emulate a valid logged in channel
|
||||
$lc_mock = $this->getFunctionMock('Zotlabs\Module', 'local_channel')
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
namespace Zotlabs\Tests\Unit\includes;
|
||||
|
||||
use App;
|
||||
use PHPUnit\Framework\Attributes\BackupStaticProperties;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Zotlabs\Tests\Unit\UnitTestCase;
|
||||
|
||||
class BBCodeTest extends UnitTestCase {
|
||||
@@ -38,9 +40,9 @@ class BBCodeTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Test the `[observer]` BBCode tags.
|
||||
*
|
||||
* @dataProvider bbcode_observer_provider
|
||||
*/
|
||||
#[BackupStaticProperties(App::class)]
|
||||
#[DataProvider('bbcode_observer_provider')]
|
||||
public function test_bbcode_observer(string $src, bool $logged_in, string $lang, string $expected): void {
|
||||
if ($logged_in) {
|
||||
App::set_observer([
|
||||
@@ -64,6 +66,7 @@ class BBCodeTest extends UnitTestCase {
|
||||
/**
|
||||
* Test parsing the `[channel]` tag.
|
||||
*/
|
||||
#[BackupStaticProperties(App::class)]
|
||||
public function test_bbcode_channel(): void {
|
||||
$src = '[channel=1]This is only for channels[/channel][channel=0]This is for everyone else[/channel]';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user