generated from pestphp/pest-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add expectations for plugins and request pagination (#6)
- Loading branch information
Showing
11 changed files
with
116 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 jp | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Pest\Arch\Contracts\ArchExpectation; | ||
|
||
expect()->extend( | ||
'toBeSaloonPlugin', | ||
fn (): ArchExpectation => // @phpstan-ignore-next-line | ||
$this->toBeTrait() | ||
); |
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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
it('saloon plugin', function () { | ||
expect('Tests\Fixtures\Arch\ToBeSaloonPlugin\ToBeSaloonPlugin') | ||
->toBeSaloonPlugin(); | ||
}); |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Fixtures\Arch\ToBeSaloonPlugin; | ||
|
||
use Saloon\Http\PendingRequest; | ||
|
||
trait ToBeSaloonPlugin | ||
{ | ||
public function bootToBeSaloonPlugin(PendingRequest $pendingRequest): void | ||
{ | ||
$pendingRequest->headers()->add('Saloon', 'Plugin'); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Fixtures/Arch/ToUseRequestPagination/ToUseRequestPagination.php
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Fixtures\Arch\ToUseRequestPagination; | ||
|
||
use Saloon\Http\Connector; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
use Saloon\PaginationPlugin\Contracts\HasRequestPagination; | ||
use Saloon\PaginationPlugin\PagedPaginator; | ||
use Saloon\PaginationPlugin\Paginator; | ||
|
||
class ToUseRequestPagination extends Connector implements HasRequestPagination | ||
{ | ||
public function paginate(Connector $connector): Paginator | ||
{ | ||
return new class(connector: $connector, request: $this) extends PagedPaginator | ||
{ | ||
protected function isLastPage(Response $response): bool | ||
{ | ||
return is_null($response->json('next_page_url')); | ||
} | ||
|
||
protected function getPageItems(Response $response, Request $request): array | ||
{ | ||
return $response->json('items'); | ||
} | ||
}; | ||
} | ||
|
||
public function resolveBaseUrl(): string | ||
{ | ||
return ''; | ||
} | ||
} |