-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Static warm: recheck whether page is cached for queued requests (…
- Loading branch information
1 parent
2623efe
commit 1462c27
Showing
4 changed files
with
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Statamic\Console\Commands; | ||
|
||
use Illuminate\Http\Request; | ||
use Statamic\StaticCaching\Cacher; | ||
|
||
class StaticWarmUncachedJob extends StaticWarmJob | ||
{ | ||
public function handle() | ||
{ | ||
$cacher = app(Cacher::class); | ||
|
||
if ($cacher->hasCachedPage(Request::create($this->request->getUri()))) { | ||
return; | ||
} | ||
|
||
parent::handle(); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace Tests\Console\Commands; | ||
|
||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use Mockery; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Console\Commands\StaticWarmUncachedJob; | ||
use Statamic\StaticCaching\Cacher; | ||
use Tests\TestCase; | ||
|
||
class StaticWarmUncachedJobTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_sends_a_get_request() | ||
{ | ||
$mock = new MockHandler([ | ||
new Response(200), | ||
]); | ||
|
||
$handlerStack = HandlerStack::create($mock); | ||
|
||
$job = new StaticWarmUncachedJob(new Request('GET', '/about'), ['handler' => $handlerStack]); | ||
|
||
$job->handle(); | ||
|
||
$this->assertEquals('/about', $mock->getLastRequest()->getUri()->getPath()); | ||
} | ||
|
||
#[Test] | ||
public function it_does_not_send_a_request_if_the_page_is_cached() | ||
{ | ||
$mockCacher = Mockery::mock(Cacher::class); | ||
$mockCacher->shouldReceive('hasCachedPage')->once()->andReturn(true); | ||
$mockCacher->allows('isExcluded')->andReturn(false); | ||
app()->instance(Cacher::class, $mockCacher); | ||
|
||
$mock = new MockHandler([ | ||
new Response(200), | ||
]); | ||
|
||
$handlerStack = HandlerStack::create($mock); | ||
|
||
$job = new StaticWarmUncachedJob(new Request('GET', '/about'), ['handler' => $handlerStack]); | ||
|
||
$job->handle(); | ||
|
||
$this->assertNull($mock->getLastRequest()); | ||
} | ||
} |