-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Roots\Acorn\Tests\Integration\Routing; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
uses(RoutingTestCase::class); | ||
|
||
it('should return a 200 status code for WordPress homepage', function () { | ||
$client = new Client([ | ||
'verify' => false, | ||
]); | ||
|
||
$response = $client->request('GET', 'http://web:8080/'); | ||
expect($response->getStatusCode())->toBe(200); | ||
}); | ||
|
||
it('should return a 200 status code for Acorn test route', function () { | ||
$client = new Client([ | ||
'verify' => false, | ||
]); | ||
|
||
$response = $client->request('GET', 'http://web:8080/test'); | ||
expect($response->getStatusCode())->toBe(200); | ||
expect((string) $response->getBody())->toBe('Howdy'); | ||
}); |
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,72 @@ | ||
<?php | ||
|
||
namespace Roots\Acorn\Tests\Integration\Routing; | ||
|
||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests; | ||
use Roots\Acorn\Tests\Test\Concerns\SupportsGlobalStubs; | ||
use Roots\Acorn\Tests\Test\Concerns\SupportsScopedFixtures; | ||
|
||
class RoutingTestCase extends MockeryTestCase | ||
{ | ||
use MakesHttpRequests; | ||
use SupportsGlobalStubs; | ||
use SupportsScopedFixtures; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->clearStubs(); | ||
|
||
// Ensure routes directory exists | ||
if (!is_dir('/roots/app/public/routes')) { | ||
mkdir('/roots/app/public/routes', 0777, true); | ||
} | ||
|
||
// Create web.php routes file | ||
$webRoutes = <<<'PHP' | ||
<?php | ||
use Illuminate\Support\Facades\Route; | ||
Route::middleware(['web'])->group(function () { | ||
Route::get('/test', fn() => 'Howdy')->name('test'); | ||
}); | ||
PHP; | ||
|
||
file_put_contents('/roots/app/public/routes/web.php', $webRoutes); | ||
|
||
// Ensure mu-plugins directory exists | ||
if (!is_dir('/roots/app/public/content/mu-plugins')) { | ||
mkdir('/roots/app/public/content/mu-plugins', 0777, true); | ||
} | ||
|
||
// Create or update the Acorn boot mu-plugin | ||
$bootPlugin = <<<'PHP' | ||
<?php | ||
/* | ||
Plugin Name: Acorn Boot | ||
*/ | ||
use Roots\Acorn\Application; | ||
use Roots\Acorn\Configuration\Exceptions; | ||
use Roots\Acorn\Configuration\Middleware; | ||
add_action('after_setup_theme', function () { | ||
Application::configure() | ||
->withMiddleware(function (Middleware $middleware) { | ||
// | ||
}) | ||
->withExceptions(function (Exceptions $exceptions) { | ||
// | ||
}) | ||
->withRouting( | ||
web: '/roots/app/public/routes/web.php' | ||
) | ||
->boot(); | ||
}, 0); | ||
PHP; | ||
|
||
file_put_contents('/roots/app/public/content/mu-plugins/01-acorn-boot.php', $bootPlugin); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Roots\Acorn\Tests\Test\Concerns; | ||
|
||
use Roots\Acorn\Application; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
trait SupportsRouting | ||
{ | ||
protected function setUpRouting() | ||
{ | ||
// The application will be booted by the mu-plugin | ||
$this->app = Application::getInstance(); | ||
|
||
// Set up facades | ||
Route::setFacadeApplication($this->app); | ||
} | ||
} |