Skip to content

Commit

Permalink
do a global config rollback at the end of every test
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Feb 10, 2025
1 parent 16c3622 commit 1564098
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 42 deletions.
8 changes: 6 additions & 2 deletions core/testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ abstract class ShimmiePHPUnitTestCase extends TestBase
protected static string $admin_name = "demo";
protected static string $user_name = "test";
protected string $wipe_time = "test";
/** @var array<string, string> */
private array $config_snapshot = [];

/**
* Start a DB transaction for each test class
Expand All @@ -41,7 +43,7 @@ public static function setUpBeforeClass(): void
*/
public function setUp(): void
{
global $database, $_tracer, $page;
global $database, $_tracer, $page, $config;
$_tracer->begin($this->name());
$_tracer->begin("setUp");
$class = str_replace("Test", "", get_class($this));
Expand All @@ -60,15 +62,17 @@ public function setUp(): void
send_event(new ImageDeletionEvent(Image::by_id_ex((int)$image_id), true));
}
$page = new Page();
$this->config_snapshot = $config->values;

$_tracer->end(); # setUp
$_tracer->begin("test");
}

public function tearDown(): void
{
global $_tracer, $database;
global $_tracer, $config, $database;
$database->execute("ROLLBACK TO test_start");
$config->values = $this->config_snapshot;
$_tracer->end(); # test
$_tracer->end(); # $this->getName()
}
Expand Down
7 changes: 0 additions & 7 deletions ext/approval/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,4 @@ public function testApprovalNeeded(): void
$this->log_in_as_user();
$this->assert_search_results(["some_tag"], [$image_id]);
}

public function tearDown(): void
{
global $config;
$config->set_bool(ApprovalConfig::IMAGES, false);
parent::tearDown();
}
}
7 changes: 0 additions & 7 deletions ext/comment/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ public function setUp(): void
$this->log_out();
}

public function tearDown(): void
{
global $config;
$config->set_int(CommentConfig::LIMIT, 10);
parent::tearDown();
}

public function testCommentsPage(): void
{
global $user;
Expand Down
7 changes: 0 additions & 7 deletions ext/downtime/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

class DowntimeTest extends ShimmiePHPUnitTestCase
{
public function tearDown(): void
{
global $config;
$config->set_bool("downtime", false);
parent::tearDown();
}

public function testDowntime(): void
{
global $config;
Expand Down
4 changes: 1 addition & 3 deletions ext/rating/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ public function testCountImages(): void
// that it doesn't mess with other unrelated tests
public function tearDown(): void
{
global $config, $user_config;
$config->set_array("ext_rating_user_privs", ["?", "s", "q", "e"]);
$config->set_array("ext_rating_anonymous_privs", ["?", "s", "q", "e"]);
global $user_config;

$this->log_in_as_user();
$user_config->set_array(RatingsConfig::USER_DEFAULTS, ["?", "s", "q", "e"]);
Expand Down
3 changes: 1 addition & 2 deletions ext/ratings_blur/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ private function delete_test_user(string $username): void
// that it doesn't mess with other unrelated tests
public function tearDown(): void
{
global $config, $user_config;
$config->set_array(RatingsBlurConfig::GLOBAL_DEFAULTS, RatingsBlurConfig::DEFAULT_OPTIONS);
global $user_config;

$this->log_in_as_user();
$user_config->set_array(RatingsBlurConfig::USER_DEFAULTS, RatingsBlurConfig::DEFAULT_OPTIONS);
Expand Down
14 changes: 0 additions & 14 deletions ext/res_limit/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,4 @@ public function testResLimitRatio(): void
});
$this->assertEquals("Post needs to be in one of these ratios: 16:9", $e->getMessage());
}

# reset to defaults, otherwise this can interfere with
# other extensions' test suites
public function tearDown(): void
{
global $config;
$config->delete("upload_min_height");
$config->delete("upload_min_width");
$config->delete("upload_max_height");
$config->delete("upload_max_width");
$config->delete("upload_ratios");

parent::tearDown();
}
}

0 comments on commit 1564098

Please sign in to comment.