-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow server to be reset, HTTPS control when testing requests (#588)
* Trait to get the server reset between each run * Rename internal trait to be clearer with its intention * Allow HTTPS control with tests * Lint fix
- Loading branch information
Showing
9 changed files
with
153 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Prevent_Remote_Requests trait file | ||
* | ||
* @package Mantle | ||
*/ | ||
|
||
namespace Mantle\Testing\Concerns; | ||
|
||
use Mantle\Testing\Utils; | ||
|
||
/** | ||
* Reset the server for each test case. | ||
* | ||
* @mixin \Mantle\Testing\Test_Case | ||
*/ | ||
trait Reset_Server { | ||
/** | ||
* Setup the trait. | ||
*/ | ||
public function reset_server_set_up(): void { | ||
Utils::reset_server(); | ||
} | ||
|
||
/** | ||
* Tear down the trait after the test class. | ||
*/ | ||
public static function reset_server_tear_down_after_class(): void { | ||
Utils::reset_server(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
namespace Mantle\Tests\Testing\Concerns; | ||
|
||
use Mantle\Testing\Concerns\Reset_Server; | ||
use Mantle\Testing\Framework_Test_Case; | ||
use Mantle\Testing\Utils; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
/** | ||
* @group testing | ||
*/ | ||
#[Group( 'testing' )] | ||
class ResetServerTest extends Framework_Test_Case { | ||
use Reset_Server; | ||
|
||
public static function tearDownAfterClass(): void { | ||
parent::tearDownAfterClass(); | ||
|
||
Utils::reset_server(); | ||
} | ||
|
||
public function test_modify_server_http_host() { | ||
$this->assertSame( WP_TESTS_DOMAIN, $_SERVER['HTTP_HOST'] ); | ||
|
||
$_SERVER['HTTP_HOST'] = 'other.org'; | ||
|
||
$this->assertSame( 'other.org', $_SERVER['HTTP_HOST'] ); | ||
} | ||
|
||
public function test_modify_server_request_uri() { | ||
$this->assertEquals( WP_TESTS_DOMAIN, $_SERVER['HTTP_HOST'] ); | ||
} | ||
} |