Skip to content

Commit

Permalink
Fix some other uses of namespace in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Feb 14, 2023
1 parent ce51937 commit 288c295
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/mantle/application/class-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Mantle\Support\Environment;
use Mantle\Support\Service_Provider;
use Mantle\View\View_Service_Provider;
use RuntimeException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand Down Expand Up @@ -590,8 +591,14 @@ public function is_environment( ...$environments ): bool {
* Get the application namespace.
*
* @return string
*
* @throws RuntimeException If the config is not set yet.
*/
public function get_namespace(): string {
if ( ! isset( $this['config'] ) ) {
throw new RuntimeException( 'Configurations not set yet.' );
}

return (string) $this['config']->get( 'app.namespace', 'App' );
}

Expand Down
9 changes: 7 additions & 2 deletions tests/framework/blocks/test-block-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ protected function setUp(): void {
parent::setUp();

// Mock a true Mantle application.
Environment::get_repository()->set( 'APP_NAMESPACE', 'Mantle\\Tests' );
$this->app->set_app_path( dirname( __DIR__, 2 ) );

$this->app['config']->set( 'app.namespace', 'Mantle\\Tests' );
}

protected function tearDown(): void {
Environment::get_repository()->clear( 'APP_NAMESPACE' );
$this->app['config']->set( 'app.namespace', 'App' );
$this->app->set_app_path( $this->app->get_base_path( 'app' ) );

parent::tearDown();
}

/**
Expand Down Expand Up @@ -58,6 +61,8 @@ public function testBlockProviderRegistersBlocks() {
$app->set_base_path( getcwd() );
$app->set_app_path( __DIR__ . '/fixtures' );

$app['config'] = $this->app['config'];

$this->assertEquals( 'Mantle\\Tests', $app->get_namespace() );

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/framework/events/test-discover-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ protected function setUp(): void {
parent::setUp();

// Mock a true Mantle application.
Environment::get_repository()->set( 'APP_NAMESPACE', 'Mantle\\Tests' );
$this->app['config']->set( 'app.namespace', 'Mantle\\Tests' );
$this->app->set_app_path( dirname( __DIR__, 2 ) );
}

protected function tearDown(): void {
Environment::get_repository()->clear( 'APP_NAMESPACE' );
$this->app->set_app_path( $this->app->get_base_path( 'app' ) );
$this->app['config']->set( 'app.namespace', 'App' );

parent::tearDown();
}

public function test_events_can_be_discovered() {
Expand Down
5 changes: 3 additions & 2 deletions tests/http/routing/test-post-model-routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class Test_Post_Model_Routing extends Framework_Test_Case {
protected function setUp(): void {
parent::setUp();

update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
flush_rewrite_rules();
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );

add_filter( 'deprecated_file_trigger_error', '__return_false' );
}

public function test_post_type() {
Expand Down

0 comments on commit 288c295

Please sign in to comment.