Skip to content

Commit 6cf21c5

Browse files
committed
Optimize IndexTest - only instantiate a webserver once
1 parent 6acdea0 commit 6cf21c5

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

tests/www/IndexTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@ class IndexTest extends TestCase
2424
/**
2525
* @var \SimpleSAML\TestUtils\BuiltInServer
2626
*/
27-
protected BuiltInServer $server;
27+
protected static BuiltInServer $server;
2828

2929
/**
3030
* @var string
3131
*/
32-
protected string $server_addr;
32+
protected static string $server_addr;
3333

3434
/**
3535
* @var int
3636
*/
37-
protected int $server_pid;
37+
protected static int $server_pid;
3838

3939
/**
4040
* @var string
4141
*/
42-
protected string $shared_file;
42+
protected static string $shared_file;
4343

4444

4545
/**
4646
* The setup method that is run before any tests in this class.
4747
*/
48-
protected function setup(): void
48+
public static function setupBeforeClass(): void
4949
{
50-
$this->server = new BuiltInServer('configLoader');
51-
$this->server_addr = $this->server->start();
52-
$this->server_pid = $this->server->getPid();
50+
self::$server = new BuiltInServer('configLoader');
51+
self::$server_addr = self::$server->start();
52+
self::$server_pid = self::$server->getPid();
5353

54-
$this->shared_file = sys_get_temp_dir() . '/' . $this->server_pid . '.lock';
55-
@unlink($this->shared_file); // remove it if it exists
54+
self::$shared_file = sys_get_temp_dir() . '/' . self::$server_pid . '.lock';
55+
@unlink(self::$shared_file); // remove it if it exists
5656
}
5757

5858

@@ -61,9 +61,9 @@ protected function setup(): void
6161
*/
6262
protected function updateConfig(array $config): void
6363
{
64-
@unlink($this->shared_file);
64+
@unlink(self::$shared_file);
6565
$config = "<?php\n\$config = " . var_export($config, true) . ";\n";
66-
file_put_contents($this->shared_file, $config);
66+
file_put_contents(self::$shared_file, $config);
6767
}
6868

6969

@@ -76,7 +76,7 @@ public function testRedirection(): void
7676
$this->updateConfig([
7777
'baseurlpath' => 'http://example.org/simplesaml/'
7878
]);
79-
$resp = $this->server->get('/index.php', [], [
79+
$resp = self::$server->get('/index.php', [], [
8080
CURLOPT_FOLLOWLOCATION => 0,
8181
]);
8282
$this->assertEquals('303', $resp['code']);
@@ -89,7 +89,7 @@ public function testRedirection(): void
8989
$this->updateConfig([
9090
'baseurlpath' => 'https://example.org/'
9191
]);
92-
$resp = $this->server->get('/index.php', [], [
92+
$resp = self::$server->get('/index.php', [], [
9393
CURLOPT_FOLLOWLOCATION => 0,
9494
]);
9595
$this->assertEquals('303', $resp['code']);
@@ -102,12 +102,12 @@ public function testRedirection(): void
102102
$this->updateConfig([
103103
'baseurlpath' => '/simplesaml/'
104104
]);
105-
$resp = $this->server->get('/index.php', [], [
105+
$resp = self::$server->get('/index.php', [], [
106106
CURLOPT_FOLLOWLOCATION => 0,
107107
]);
108108
$this->assertEquals('303', $resp['code']);
109109
$this->assertEquals(
110-
'http://' . $this->server_addr . '/simplesaml/module.php/core/welcome',
110+
'http://' . self::$server_addr . '/simplesaml/module.php/core/welcome',
111111
$resp['headers']['Location']
112112
);
113113
}
@@ -120,7 +120,7 @@ public function testRedirectionFrontpageRedirectOption(): void
120120
$this->updateConfig([
121121
'frontpage.redirect' => 'https://www.example.edu/'
122122
]);
123-
$resp = $this->server->get('/index.php', [], [
123+
$resp = self::$server->get('/index.php', [], [
124124
CURLOPT_FOLLOWLOCATION => 0,
125125
]);
126126
$this->assertEquals('303', $resp['code']);
@@ -133,9 +133,9 @@ public function testRedirectionFrontpageRedirectOption(): void
133133
/**
134134
* The tear down method that is executed after all tests in this class.
135135
*/
136-
protected function tearDown(): void
136+
public static function tearDownAfterClass(): void
137137
{
138-
unlink($this->shared_file);
139-
$this->server->stop();
138+
unlink(self::$shared_file);
139+
self::$server->stop();
140140
}
141141
}

0 commit comments

Comments
 (0)