diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 1783b6a8..e2cc98ab 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -16,7 +16,7 @@ jobs: with: os: ubuntu-latest branch: master - package-name: laravel-package-tpl + package-name: laravel-paginator secrets: token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index f02e65e4..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,346 +0,0 @@ -# Changelog - -## [2.1.0](https://github.com/wayofdev/laravel-package-tpl/compare/v2.0.3...v2.1.0) (2023-06-04) - - -### Features - -* bump php version to 8.2 ([cbb5733](https://github.com/wayofdev/laravel-package-tpl/commit/cbb57332db249c74dbae4406f064943d5cd9896a)) -* split testing directory ([364acab](https://github.com/wayofdev/laravel-package-tpl/commit/364acabe8c5bef19e01434d65029a13218068a4d)) -* split testing directory ([e5f8e9d](https://github.com/wayofdev/laravel-package-tpl/commit/e5f8e9d0da949827b8e1590223917a4fd5c80063)) - -## [2.0.3](https://github.com/wayofdev/laravel-package-tpl/compare/v2.0.2...v2.0.3) (2023-06-02) - - -### Miscellaneous - -* **deps:** update dependency pestphp/pest to v2.6.2 ([9659689](https://github.com/wayofdev/laravel-package-tpl/commit/96596899abebe11423a0a5551f0b7018dcfe666b)) - -## [2.0.2](https://github.com/wayofdev/laravel-package-tpl/compare/v2.0.1...v2.0.2) (2023-06-02) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.7 ([1e989e0](https://github.com/wayofdev/laravel-package-tpl/commit/1e989e03168fc32e16a1a95cf847acd815dfc896)) - -## [2.0.1](https://github.com/wayofdev/laravel-package-tpl/compare/v2.0.0...v2.0.1) (2023-05-30) - - -### Miscellaneous - -* **deps:** update dependency orchestra/testbench to v8.5.5 ([c077ef0](https://github.com/wayofdev/laravel-package-tpl/commit/c077ef0a410f6755a137002d9ab828bc131686e2)) - -## [2.0.0](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.38...v2.0.0) (2023-05-30) - - -### ⚠ BREAKING CHANGES - -* update template - -### Features - -* update template ([9c83764](https://github.com/wayofdev/laravel-package-tpl/commit/9c837642abf47d7afdddfa280fd97121da902a36)) - - -### Bug Fixes - -* ci commands ([bb712eb](https://github.com/wayofdev/laravel-package-tpl/commit/bb712eb02d4c81af2f6d76e18dc033a478f58bc5)) - -## [1.1.38](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.37...v1.1.38) (2023-05-28) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.6 ([7299e55](https://github.com/wayofdev/laravel-package-tpl/commit/7299e553f23f58296701596b499cfe97f150353f)) - -## [1.1.37](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.36...v1.1.37) (2023-05-28) - - -### Miscellaneous - -* **deps:** update dependency phpstan/phpstan-phpunit to v1.3.13 ([514282a](https://github.com/wayofdev/laravel-package-tpl/commit/514282ab04d1dc2a6f531a35f3799f97a94b5b19)) - -## [1.1.36](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.35...v1.1.36) (2023-05-24) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.5 ([38ec8ef](https://github.com/wayofdev/laravel-package-tpl/commit/38ec8ef5cc5820ee7088c1cddf49cec0a9945ba7)) - -## [1.1.35](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.34...v1.1.35) (2023-05-24) - - -### Miscellaneous - -* **deps:** update dependency phpstan/extension-installer to v1.3.1 ([90887f1](https://github.com/wayofdev/laravel-package-tpl/commit/90887f1c24a454bae351ff680a5cf98f15574b9a)) - -## [1.1.34](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.33...v1.1.34) (2023-05-24) - - -### Miscellaneous - -* **deps:** update dependency orchestra/testbench to v8.5.4 ([88c8643](https://github.com/wayofdev/laravel-package-tpl/commit/88c86431122b67475b8f2a5e8f58269ac4ac5744)) - -## [1.1.33](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.32...v1.1.33) (2023-05-23) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.4 ([61d53b3](https://github.com/wayofdev/laravel-package-tpl/commit/61d53b37bbc4d913c755da9b9a3be707f74127b7)) - -## [1.1.32](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.31...v1.1.32) (2023-05-23) - - -### Miscellaneous - -* **deps:** update dependency phpstan/phpstan-phpunit to v1.3.12 ([98c67f2](https://github.com/wayofdev/laravel-package-tpl/commit/98c67f20fbdadfc2c3f4d705285e3d1c0f5c2281)) - -## [1.1.31](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.30...v1.1.31) (2023-05-23) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.3 ([6321dcc](https://github.com/wayofdev/laravel-package-tpl/commit/6321dcc816d9e45dbc580a175eb3e7b7a95163b9)) - -## [1.1.30](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.29...v1.1.30) (2023-05-17) - - -### Miscellaneous - -* **deps:** update dependency pestphp/pest to v2.6.1 ([fff3cc6](https://github.com/wayofdev/laravel-package-tpl/commit/fff3cc6c4741669811290f5aa2bf4c34e5121e3c)) - -## [1.1.29](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.28...v1.1.29) (2023-05-16) - - -### Miscellaneous - -* **deps:** update dependency orchestra/testbench to v8.5.3 ([f018848](https://github.com/wayofdev/laravel-package-tpl/commit/f018848a40774e981f54d326b3ffa9c5694a93b6)) - -## [1.1.28](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.27...v1.1.28) (2023-05-11) - - -### Miscellaneous - -* **deps:** update dependency phpunit/phpunit to v10.1.3 ([8e3baac](https://github.com/wayofdev/laravel-package-tpl/commit/8e3baac01881078ff0b33bc3930912a50654a09b)) -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.2 ([b177302](https://github.com/wayofdev/laravel-package-tpl/commit/b17730256d4c50d63cc405f5f9d87bbff043a4a5)) - -## [1.1.27](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.26...v1.1.27) (2023-05-09) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.1 ([ac84f45](https://github.com/wayofdev/laravel-package-tpl/commit/ac84f458fa72d2d06f641d949aae97fef470e08d)) - -## [1.1.26](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.25...v1.1.26) (2023-05-09) - - -### Miscellaneous - -* **deps:** update dependency phpstan/phpstan to v1.10.15 ([ec24a99](https://github.com/wayofdev/laravel-package-tpl/commit/ec24a9900515da8270c58c33cfb22133773dab3c)) - -## [1.1.25](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.24...v1.1.25) (2023-05-09) - - -### Miscellaneous - -* **deps:** update dependency orchestra/testbench to v8.5.2 ([ee85289](https://github.com/wayofdev/laravel-package-tpl/commit/ee85289388d964c14af4155244601681eba7e9b6)) - -## [1.1.24](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.23...v1.1.24) (2023-05-02) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.2.0 ([fd09205](https://github.com/wayofdev/laravel-package-tpl/commit/fd09205370a6c79b30746e15c2f7c4acf2a0b1fb)) - -## [1.1.23](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.22...v1.1.23) (2023-05-02) - - -### Miscellaneous - -* **deps:** update dependency ergebnis/composer-normalize to v2.31.0 ([06e34bc](https://github.com/wayofdev/laravel-package-tpl/commit/06e34bc9d780a75c2fd2050e0f825686a0d144d0)) - -## [1.1.22](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.21...v1.1.22) (2023-05-02) - - -### Miscellaneous - -* **deps:** update dependency pestphp/pest to v2.6.0 ([3629f93](https://github.com/wayofdev/laravel-package-tpl/commit/3629f93879a3aa6909b8657907edc5a9807ac1fe)) - -## [1.1.21](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.20...v1.1.21) (2023-05-01) - - -### Miscellaneous - -* **deps:** update dependency phpunit/phpunit to v10.1.2 ([aff909f](https://github.com/wayofdev/laravel-package-tpl/commit/aff909f430c31160c5fdd7c0c4eee5c7bb3ebfb1)) - -## [1.1.20](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.19...v1.1.20) (2023-04-28) - - -### Bug Fixes - -* **deps:** update dependency nunomaduro/collision to v7.5.2 ([f05ab29](https://github.com/wayofdev/laravel-package-tpl/commit/f05ab290cf39ed0e14eb200592db9a28e9295cb1)) - -## [1.1.19](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.18...v1.1.19) (2023-04-27) - - -### Bug Fixes - -* **deps:** update dependency spatie/laravel-package-tools to v1.15.0 ([f5c4389](https://github.com/wayofdev/laravel-package-tpl/commit/f5c43890cfa15b6a759dbe979bc49bcfa9f78b19)) - -## [1.1.18](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.17...v1.1.18) (2023-04-25) - - -### Bug Fixes - -* **deps:** update dependency spatie/laravel-package-tools to v1.14.3 ([f328fbe](https://github.com/wayofdev/laravel-package-tpl/commit/f328fbe9bc5686721f6681117bf8820b03099018)) - -## [1.1.17](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.16...v1.1.17) (2023-04-25) - - -### Miscellaneous - -* **deps:** update dependency orchestra/testbench to v8.5.1 ([d15054b](https://github.com/wayofdev/laravel-package-tpl/commit/d15054b10c0d21d2cd6aaba038a53b012ef3cc53)) - -## [1.1.16](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.15...v1.1.16) (2023-04-23) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.1.19 ([08a4ea7](https://github.com/wayofdev/laravel-package-tpl/commit/08a4ea736593ff8ca7f266e4824fbf937d0470e9)) - -## [1.1.15](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.14...v1.1.15) (2023-04-22) - - -### Miscellaneous - -* **deps:** update dependency pestphp/pest to v2.5.3 ([1912b0d](https://github.com/wayofdev/laravel-package-tpl/commit/1912b0d7eb3b4f882c667f1b24ea8369470ba445)) - -## [1.1.14](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.13...v1.1.14) (2023-04-22) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.1.18 ([819e524](https://github.com/wayofdev/laravel-package-tpl/commit/819e524ab91516a691993deb7f0e648b9bf94c1c)) - -## [1.1.13](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.12...v1.1.13) (2023-04-20) - - -### Miscellaneous - -* **deps:** update dependency nunomaduro/larastan to v2.6.0 ([ba08bf5](https://github.com/wayofdev/laravel-package-tpl/commit/ba08bf55cabc4cb198c7c23b171ab62658271b65)) - -## [1.1.12](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.11...v1.1.12) (2023-04-20) - - -### Miscellaneous - -* **deps:** update dependency nunomaduro/larastan to v2.5.2 ([ef0b16e](https://github.com/wayofdev/laravel-package-tpl/commit/ef0b16e8f323a370dcc8f9dc8dbaf4f339d533ea)) - -## [1.1.11](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.10...v1.1.11) (2023-04-19) - - -### Miscellaneous - -* **deps:** update dependency phpstan/phpstan to v1.10.14 ([2efbd9f](https://github.com/wayofdev/laravel-package-tpl/commit/2efbd9f29a702df70676a0334a49aaf1491839a8)) -* **deps:** update dependency wayofdev/cs-fixer-config to v1.1.17 ([c5dff1f](https://github.com/wayofdev/laravel-package-tpl/commit/c5dff1f7efbe4dee67b019d5a68052d4d8425b35)) - -## [1.1.10](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.9...v1.1.10) (2023-04-19) - - -### Miscellaneous - -* **deps:** update dependency pestphp/pest to v2.5.2 ([23a7395](https://github.com/wayofdev/laravel-package-tpl/commit/23a7395d6f46deb7fd030712098c9f8808810ee7)) - -## [1.1.9](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.8...v1.1.9) (2023-04-18) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.1.16 ([45dba9f](https://github.com/wayofdev/laravel-package-tpl/commit/45dba9f41b5f021b08cddf1a55c0d64691fc3dc2)) - -## [1.1.8](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.7...v1.1.8) (2023-04-18) - - -### Miscellaneous - -* **deps:** update dependency phpstan/extension-installer to v1.3.0 ([2624463](https://github.com/wayofdev/laravel-package-tpl/commit/2624463739d263f18c0af69115fb9eff5afd2fea)) - -## [1.1.7](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.6...v1.1.7) (2023-04-18) - - -### Miscellaneous - -* **deps:** update dependency orchestra/testbench to v8.5.0 ([bddc8c0](https://github.com/wayofdev/laravel-package-tpl/commit/bddc8c0b39b7a137cf4154279bd2d4c3cf49caab)) - -## [1.1.6](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.5...v1.1.6) (2023-04-18) - - -### Miscellaneous - -* **deps:** update dependency pestphp/pest to v2.5.1 ([215e0f3](https://github.com/wayofdev/laravel-package-tpl/commit/215e0f30ed749f6f6d481c8eaed9d6e2f30f081a)) - -## [1.1.5](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.4...v1.1.5) (2023-04-18) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.1.15 ([eb3f308](https://github.com/wayofdev/laravel-package-tpl/commit/eb3f3083b182e1763f01ad7009a2e0c14fd9ecc2)) - -## [1.1.4](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.3...v1.1.4) (2023-04-14) - - -### Bug Fixes - -* **deps:** update dependency nunomaduro/collision to v7.5.0 ([135bc20](https://github.com/wayofdev/laravel-package-tpl/commit/135bc20830ef05a90592cbf5a6adf38ccdd39bdc)) - -## [1.1.3](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.2...v1.1.3) (2023-04-14) - - -### Miscellaneous - -* **deps:** update dependency orchestra/testbench to v8.4.0 ([0c24a4a](https://github.com/wayofdev/laravel-package-tpl/commit/0c24a4acd1daa09456c23c3a8fc782292f845c00)) - -## [1.1.2](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.1...v1.1.2) (2023-04-14) - - -### Miscellaneous - -* **deps:** update dependency wayofdev/cs-fixer-config to v1.1.14 ([3014033](https://github.com/wayofdev/laravel-package-tpl/commit/30140331dbe5ca7488fc31acc1fdf038d005a2b7)) - -## [1.1.1](https://github.com/wayofdev/laravel-package-tpl/compare/v1.1.0...v1.1.1) (2023-04-14) - - -### Miscellaneous - -* **deps:** update dependency phpunit/phpunit to v10.1.0 ([a643e52](https://github.com/wayofdev/laravel-package-tpl/commit/a643e52e9763eae814e83e0e375252f0fb7480e7)) - -## [1.1.0](https://github.com/wayofdev/laravel-package-tpl/compare/v1.0.0...v1.1.0) (2023-04-13) - - -### Features - -* enable aut-merge ([cad52af](https://github.com/wayofdev/laravel-package-tpl/commit/cad52af89927500ae9320b9f2fd050d91d935dfb)) -* new github workflow ([2d4695f](https://github.com/wayofdev/laravel-package-tpl/commit/2d4695f148cbc99c9146ca2a9f8caa408825ce3a)) - - -### Bug Fixes - -* run against gh user ([95331ff](https://github.com/wayofdev/laravel-package-tpl/commit/95331ff6744dbb71af9773706f5256dfc02fbf10)) - - -### Miscellaneous - -* **deps:** update dependency phpstan/phpstan to v1.10.13 ([faba56b](https://github.com/wayofdev/laravel-package-tpl/commit/faba56bb758427db7b9a2b13da4d97ee8e3150ea)) -* **deps:** update dependency wayofdev/cs-fixer-config to v1.1.13 ([ee61cb2](https://github.com/wayofdev/laravel-package-tpl/commit/ee61cb2e0983105074cd26d195f2acc5da70d6bc)) - -## 1.0.0 (2022-07-16) - - -### Features - -* adding template code ([e758c21](https://github.com/wayofdev/laravel-package-tpl/commit/e758c218d71d637bd60a659254dd4eb9b82d5478)) - - -### Bug Fixes - -* stan fixes ([1982e4a](https://github.com/wayofdev/laravel-package-tpl/commit/1982e4a14171c5a867d0a7fe23dddc7741f28549)) diff --git a/Makefile b/Makefile index 7fd4b46e..4e703540 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ else WHITE := "" RST := "" endif -MAKE_LOGFILE = /tmpwayofdev-laravel-package-tpl.log +MAKE_LOGFILE = /tmpwayofdev-laravel-paginator.log MAKE_CMD_COLOR := $(BLUE) default: all @@ -47,7 +47,7 @@ help: @echo @echo ' 📑 Logs are stored in $(MAKE_LOGFILE)' @echo - @echo ' 📦 Package laravel-package-tpl (github.com/wayofdev/laravel-package-tpl)' + @echo ' 📦 Package laravel-paginator (github.com/wayofdev/laravel-paginator)' @echo ' 🤠 Author Andrij Orlenko (github.com/lotyp)' @echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}' .PHONY: help diff --git a/README.md b/README.md index 58999571..c71bcc18 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@
- - + +
@@ -11,11 +11,11 @@
-Build Status -Total Downloads -Latest Stable Version -Software License -Commits since latest release +Build Status +Total Downloads +Latest Stable Version +Software License +Commits since latest release

@@ -35,7 +35,7 @@ If you **like/use** this package, please consider **starring** it. Thanks! Require as dependency: ```bash -$ composer req wayofdev/laravel-package-tpl +$ composer req wayofdev/paginator ```
@@ -70,7 +70,7 @@ $ make cs-fix ## 🤝 License -[![Licence](https://img.shields.io/github/license/wayofdev/laravel-package-tpl?style=for-the-badge&color=blue)](./LICENSE) +[![Licence](https://img.shields.io/github/license/wayofdev/laravel-paginator?style=for-the-badge&color=blue)](./LICENSE)
diff --git a/composer.json b/composer.json index 4c977c64..a50d8573 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { - "name": "wayofdev/laravel-package-tpl", - "description": "PHP package template with GitHub Actions", + "name": "wayofdev/paginator", + "description": "Custom Laravel Paginator for Cycle-ORM implementing RFC 5988.", "type": "library", "license": "MIT", "homepage": "https://wayof.dev", "support": { - "issues": "https://github.com/wayofdev/laravel-package-tpl/issues", - "source": "https://github.com/wayofdev/laravel-package-tpl" + "issues": "https://github.com/wayofdev/laravel-paginator/issues", + "source": "https://github.com/wayofdev/laravel-paginator" }, "authors": [ { @@ -16,7 +16,9 @@ ], "require": { "php": "^8.2", - "illuminate/contracts": "^v10.13" + "illuminate/contracts": "^v10.13", + "spiral/pagination": "^3.7", + "symfony/web-link": "^6.3" }, "require-dev": { "ergebnis/composer-normalize": "^2.31", @@ -31,17 +33,18 @@ "phpstan/phpstan-strict-rules": "^1.5", "phpunit/phpunit": "^10.2", "roave/security-advisories": "dev-latest", + "tiagohillebrandt/php-parse-link-header": "^1.0", "wayofdev/cs-fixer-config": "^1.2" }, "autoload": { "psr-4": { - "WayOfDev\\Package\\": "src/" + "WayOfDev\\Paginator\\": "src/" } }, "autoload-dev": { "psr-4": { - "WayOfDev\\Package\\App\\": "tests/app/", - "WayOfDev\\Package\\Tests\\": "tests/src/" + "WayOfDev\\Paginator\\App\\": "tests/app/", + "WayOfDev\\Paginator\\Tests\\": "tests/src/" } }, "scripts": { @@ -61,11 +64,6 @@ } }, "extra": { - "laravel": { - "providers": [ - "WayOfDev\\Package\\Bridge\\Laravel\\Providers\\PackageServiceProvider" - ] - }, "composer-normalize": { "indent-size": 4, "indent-style": "space" diff --git a/composer.lock b/composer.lock index 7d8e075b..10bd6f1f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9018d73e2127dc57a68345793205136b", + "content-hash": "82637acbb01db902572a6fabf65bc8c6", "packages": [ { "name": "brick/math", @@ -1917,6 +1917,62 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/link", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/link.git", + "reference": "84b159194ecfd7eaa472280213976e96415433f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/link/zipball/84b159194ecfd7eaa472280213976e96415433f7", + "reference": "84b159194ecfd7eaa472280213976e96415433f7", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "suggest": { + "fig/link-util": "Provides some useful PSR-13 utilities" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Link\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for HTTP links", + "homepage": "https://github.com/php-fig/link", + "keywords": [ + "http", + "http-link", + "link", + "psr", + "psr-13", + "rest" + ], + "support": { + "source": "https://github.com/php-fig/link/tree/2.0.1" + }, + "time": "2021-03-11T23:00:27+00:00" + }, { "name": "psr/log", "version": "3.0.0", @@ -2199,6 +2255,69 @@ ], "time": "2023-04-15T23:01:58+00:00" }, + { + "name": "spiral/pagination", + "version": "3.7.1", + "source": { + "type": "git", + "url": "https://github.com/spiral/pagination.git", + "reference": "753d2604cda3363414c1a703bafb709d57a52918" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spiral/pagination/zipball/753d2604cda3363414c1a703bafb709d57a52918", + "reference": "753d2604cda3363414c1a703bafb709d57a52918", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "phpunit/phpunit": "^9.5.20", + "vimeo/psalm": "^5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Spiral\\Pagination\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anton Titov (wolfy-j)", + "email": "wolfy-j@spiralscout.com" + }, + { + "name": "Pavel Butchnev (butschster)", + "email": "pavel.buchnev@spiralscout.com" + }, + { + "name": "Aleksei Gagarin (roxblnfk)", + "email": "alexey.gagarin@spiralscout.com" + }, + { + "name": "Maksim Smakouz (msmakouz)", + "email": "maksim.smakouz@spiralscout.com" + } + ], + "description": "Common pagination interfaces", + "homepage": "https://spiral.dev", + "support": { + "issues": "https://github.com/spiral/framework/issues", + "source": "https://github.com/spiral/pagination" + }, + "time": "2023-04-20T16:06:33+00:00" + }, { "name": "symfony/console", "version": "v6.3.0", @@ -4442,6 +4561,89 @@ ], "time": "2023-05-25T13:09:35+00:00" }, + { + "name": "symfony/web-link", + "version": "v6.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/web-link.git", + "reference": "0989ca617d0703cdca501a245f10e194ff22315b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/web-link/zipball/0989ca617d0703cdca501a245f10e194ff22315b", + "reference": "0989ca617d0703cdca501a245f10e194ff22315b", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/link": "^1.1|^2.0" + }, + "conflict": { + "symfony/http-kernel": "<5.4" + }, + "provide": { + "psr/link-implementation": "1.0|2.0" + }, + "require-dev": { + "symfony/http-kernel": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\WebLink\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Dunglas", + "email": "dunglas@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Manages links between resources", + "homepage": "https://symfony.com", + "keywords": [ + "dns-prefetch", + "http", + "http2", + "link", + "performance", + "prefetch", + "preload", + "prerender", + "psr13", + "push" + ], + "support": { + "source": "https://github.com/symfony/web-link/tree/v6.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-04-21T14:41:17+00:00" + }, { "name": "tijsverkoyen/css-to-inline-styles", "version": "2.2.6", @@ -10678,6 +10880,54 @@ ], "time": "2021-07-28T10:34:58+00:00" }, + { + "name": "tiagohillebrandt/php-parse-link-header", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/tiagohillebrandt/php-parse-link-header.git", + "reference": "f59cefc8b8a17e0887c0bc36aafaaa1d1fe47b9d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tiagohillebrandt/php-parse-link-header/zipball/f59cefc8b8a17e0887c0bc36aafaaa1d1fe47b9d", + "reference": "f59cefc8b8a17e0887c0bc36aafaaa1d1fe47b9d", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "TiagoHillebrandt\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tiago Hillebrandt", + "email": "tiago@tiagohillebrandt.com", + "homepage": "https://tiagohillebrandt.com" + } + ], + "description": "Parses the Link HTTP header and returns the values as an array.", + "homepage": "https://github.com/tiagohillebrandt/php-parse-link-header", + "keywords": [ + "github", + "header", + "link", + "parse" + ], + "support": { + "issues": "https://github.com/tiagohillebrandt/php-parse-link-header/issues", + "source": "https://github.com/tiagohillebrandt/php-parse-link-header/tree/1.0.4" + }, + "time": "2020-04-15T22:58:44+00:00" + }, { "name": "wayofdev/cs-fixer-config", "version": "v1.2.7", diff --git a/config/package.php b/config/paginator.php similarity index 100% rename from config/package.php rename to config/paginator.php diff --git a/package.json b/package.json index e3582128..afd36912 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "version": "2.1.0", "repository": { - "url": "https://github.com/wayofdev/laravel-package-tpl.git" + "url": "https://github.com/wayofdev/laravel-paginator.git" } } diff --git a/src/Bridge/Laravel/Providers/PackageServiceProvider.php b/src/Bridge/Laravel/Providers/PaginatorServiceProvider.php similarity index 64% rename from src/Bridge/Laravel/Providers/PackageServiceProvider.php rename to src/Bridge/Laravel/Providers/PaginatorServiceProvider.php index 50ba6a70..c5a519fe 100644 --- a/src/Bridge/Laravel/Providers/PackageServiceProvider.php +++ b/src/Bridge/Laravel/Providers/PaginatorServiceProvider.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace WayOfDev\Package\Bridge\Laravel\Providers; +namespace WayOfDev\Paginator\Bridge\Laravel\Providers; use Illuminate\Support\ServiceProvider; -final class PackageServiceProvider extends ServiceProvider +final class PaginatorServiceProvider extends ServiceProvider { public function boot(): void { if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__ . '/../../../../config/package.php' => config_path('package.php'), + __DIR__ . '/../../../../config/paginator.php' => config_path('paginator.php'), ], 'config'); $this->registerConsoleCommands(); diff --git a/src/Concerns/NotRenders.php b/src/Concerns/NotRenders.php new file mode 100644 index 00000000..64e08665 --- /dev/null +++ b/src/Concerns/NotRenders.php @@ -0,0 +1,13 @@ +pages() as $rel => $page) { + $href = $this->url($page); + $linkProvider = $linkProvider->withLink(new Link($rel, $href)); + } + + return $linkProvider; + } + + public function toResponse(): JsonResponse + { + return (new JsonResponse($this->toArray())) + ->withHeaders($this->headers()); + } + + private function currentCount(): int + { + return $this->items->count(); + } + + private function pages(): array + { + $currentPage = $this->currentPage(); + $lastPage = $this->lastPage(); + $pages = ['first' => 1, 'last' => $lastPage]; + + if (1 < $currentPage) { + $pages['prev'] = $currentPage - 1; + } + if ($currentPage < $lastPage) { + $pages['next'] = $currentPage + 1; + } + + return $pages; + } +} diff --git a/src/CyclePaginator.php b/src/CyclePaginator.php new file mode 100644 index 00000000..785df463 --- /dev/null +++ b/src/CyclePaginator.php @@ -0,0 +1,83 @@ +paginator = $paginator; + $this->perPage = $paginator->getLimit(); + $this->currentPage = $paginator->getPage(); + $this->pageName = $pageName; + $this->items = $items; + } + + public function total(): int + { + return $this->paginator->count(); + } + + public function lastPage(): int + { + return $this->paginator->countPages(); + } + + public function nextPageUrl(): ?string + { + if ($this->hasMorePages()) { + return $this->url($this->currentPage() + 1); + } + + return null; + } + + public function hasMorePages(): bool + { + return $this->currentPage() < $this->lastPage(); + } + + public function toArray(): array + { + return array_values($this->items->toArray()); + } + + public function headers(): array + { + $linkProvider = $this->headerLinks(new GenericLinkProvider()); + + return [ + 'Link' => (new HttpHeaderSerializer())->serialize($linkProvider->getLinks()), + 'X-Page' => $this->currentPage(), + 'X-Per-Page' => $this->perPage(), + 'X-Total-Count' => $this->total(), + 'X-Count' => $this->currentCount(), + ]; + } + + private function currentCount(): int + { + return $this->items->count(); + } +} diff --git a/src/LengthAwarePaginator.php b/src/LengthAwarePaginator.php new file mode 100644 index 00000000..7b7f8bac --- /dev/null +++ b/src/LengthAwarePaginator.php @@ -0,0 +1,51 @@ +items(), + $paginator->total(), + $paginator->perPage(), + $paginator->currentPage(), + $options + ); + + $this->query = $paginator->query; + $this->path = $paginator->path; + $this->fragment = $paginator->fragment; + $this->pageName = $paginator->pageName; + } + + public function toArray(): array + { + return array_values($this->items->toArray()); + } + + public function headers(): array + { + $linkProvider = $this->headerLinks(new GenericLinkProvider()); + + return [ + 'Link' => (new HttpHeaderSerializer())->serialize($linkProvider->getLinks()), + 'X-Page' => $this->currentPage(), + 'X-Per-Page' => $this->perPage(), + 'X-Total-Count' => $this->total(), + 'X-Count' => $this->currentCount(), + ]; + } +} diff --git a/src/Paginator.php b/src/Paginator.php new file mode 100644 index 00000000..013a5f60 --- /dev/null +++ b/src/Paginator.php @@ -0,0 +1,48 @@ +items->toArray(); + } + + public function headers(): array + { + $linkProvider = $this->headerLinks(new GenericLinkProvider()); + + return [ + 'Link' => (new HttpHeaderSerializer())->serialize($linkProvider->getLinks()), + 'X-Page' => $this->currentPage(), + 'X-Per-Page' => $this->perPage(), + 'X-Total-Count' => $this->lastItem(), + ]; + } + + protected function pages(): array + { + $pages = []; + $pages['current'] = $this->currentPage(); + + if ($this->hasMorePages()) { + $pages['next'] = $this->currentPage() + 1; + } + + if ($this->currentPage() > 1) { + $pages['prev'] = $this->currentPage() - 1; + } + + return $pages; + } +} diff --git a/tests/app/items.php b/tests/app/items.php new file mode 100644 index 00000000..8cce3a57 --- /dev/null +++ b/tests/app/items.php @@ -0,0 +1,210 @@ + '8b60c843-fb13-4697-a24d-56256691b6f4', + 'code' => 'USD', + 'symbol' => '$', + 'name' => 'US Dollar', + ], + [ + 'id' => '28f1bf21-92cb-4cea-af69-8d4674d01077', + 'code' => 'CAD', + 'symbol' => 'CA$', + 'name' => 'Canadian Dollar', + ], + [ + 'id' => 'fe346b50-1b5c-4324-b27e-36123c73b133', + 'code' => 'EUR', + 'symbol' => '€', + 'name' => 'Euro', + ], + [ + 'id' => '95b1bf57-5896-49bc-88a6-7f1cb57bd9e5', + 'code' => 'AED', + 'symbol' => 'AED', + 'name' => 'United Arab Emirates Dirham', + ], + [ + 'id' => '8f5d7ed2-da3e-46b8-a690-56a2601d808e', + 'code' => 'AFN', + 'symbol' => 'Af', + 'name' => 'Afghan Afghani', + ], + [ + 'id' => '30b625e3-df5e-4905-970e-d0c37b5fa4b9', + 'code' => 'ALL', + 'symbol' => 'ALL', + 'name' => 'Albanian Lek', + ], + [ + 'id' => 'e6b86f76-8df5-4e4a-98da-5d202a87f565', + 'code' => 'AMD', + 'symbol' => 'AMD', + 'name' => 'Armenian Dram', + ], + [ + 'id' => 'f6a7524a-3cf8-499b-8de1-25f4f28e1083', + 'code' => 'ARS', + 'symbol' => 'AR$', + 'name' => 'Argentine Peso', + ], + [ + 'id' => 'b7ad07bc-e7fc-46fe-b7c7-04ec6f37c7b6', + 'code' => 'AUD', + 'symbol' => 'AU$', + 'name' => 'Australian Dollar', + ], + [ + 'id' => '7462f028-ac71-4420-b592-2276494a8cce', + 'code' => 'AZN', + 'symbol' => 'man.', + 'name' => 'Azerbaijani Manat', + ], + [ + 'id' => '6b721890-1943-45c0-a630-472b6018b8c4', + 'code' => 'BAM', + 'symbol' => 'KM', + 'name' => 'Bosnia-Herzegovina Convertible Mark', + ], + [ + 'id' => '876d13db-8e51-4513-b494-e9f30709a624', + 'code' => 'BDT', + 'symbol' => 'Tk', + 'name' => 'Bangladeshi Taka', + ], + [ + 'id' => 'f64a7cd0-21f2-43eb-9f69-68c685ffc061', + 'code' => 'BGN', + 'symbol' => 'BGN', + 'name' => 'Bulgarian Lev', + ], + [ + 'id' => 'bfcdd204-4be5-440b-8593-b5cd22c8499f', + 'code' => 'BHD', + 'symbol' => 'BD', + 'name' => 'Bahraini Dinar', + ], + [ + 'id' => '5115b096-9c0d-432a-b9d3-d591a187a2f9', + 'code' => 'BIF', + 'symbol' => 'FBu', + 'name' => 'Burundian Franc', + ], + [ + 'id' => '464a7c2e-558c-451c-a9c0-b8a766dbc551', + 'code' => 'BND', + 'symbol' => 'BN$', + 'name' => 'Brunei Dollar', + ], + [ + 'id' => 'facca107-8135-4619-9df1-cfc30d33b92a', + 'code' => 'BOB', + 'symbol' => 'Bs', + 'name' => 'Bolivian Boliviano', + ], + [ + 'id' => 'e016adf7-f19a-44b5-afaa-85969ada0600', + 'code' => 'BRL', + 'symbol' => 'R$', + 'name' => 'Brazilian Real', + ], + [ + 'id' => 'b8d372eb-c8e8-44f5-9f02-1935013df07e', + 'code' => 'BWP', + 'symbol' => 'BWP', + 'name' => 'Botswanan Pula', + ], + [ + 'id' => 'f7505c38-4737-4f5f-a376-e75caef37f1c', + 'code' => 'BYN', + 'symbol' => 'Br', + 'name' => 'Belarusian Ruble', + ], + [ + 'id' => '48f55ab7-34c3-4f73-bae0-5d0a7fad67bf', + 'code' => 'BZD', + 'symbol' => 'BZ$', + 'name' => 'Belize Dollar', + ], + [ + 'id' => 'ff60c8b9-fe4d-47c5-a4eb-83f255449b32', + 'code' => 'CDF', + 'symbol' => 'CDF', + 'name' => 'Congolese Franc', + ], + [ + 'id' => '50cdd5bf-fafa-49ea-b27b-197c973903a2', + 'code' => 'CHF', + 'symbol' => 'CHF', + 'name' => 'Swiss Franc', + ], + [ + 'id' => 'a19bd185-9fd5-4406-9281-27e2d1b86eab', + 'code' => 'CLP', + 'symbol' => 'CL$', + 'name' => 'Chilean Peso', + ], + [ + 'id' => 'ef66349d-8a88-49e1-8c24-80b060329049', + 'code' => 'CNY', + 'symbol' => 'CN¥', + 'name' => 'Chinese Yuan', + ], + [ + 'id' => 'ffa37ede-9633-464f-9320-bc6d86c7d2f8', + 'code' => 'COP', + 'symbol' => 'CO$', + 'name' => 'Colombian Peso', + ], + [ + 'id' => '42b60bf4-a8d9-4e23-aba7-d851385a9b01', + 'code' => 'CRC', + 'symbol' => '₡', + 'name' => 'Costa Rican Colón', + ], + [ + 'id' => '0842eab8-b290-429e-a528-3cf7f1a2bd58', + 'code' => 'CVE', + 'symbol' => 'CV$', + 'name' => 'Cape Verdean Escudo', + ], + [ + 'id' => 'b2d5eb9b-8630-407d-a4f5-d1fc5e45df12', + 'code' => 'CZK', + 'symbol' => 'Kč', + 'name' => 'Czech Republic Koruna', + ], + [ + 'id' => '4774baea-bf9a-4bf4-baa0-fbd4fd6c3d65', + 'code' => 'DJF', + 'symbol' => 'Fdj', + 'name' => 'Djiboutian Franc', + ], + [ + 'id' => 'cbddc430-fd05-4a3d-8034-a180489ef23d', + 'code' => 'DKK', + 'symbol' => 'Dkr', + 'name' => 'Danish Krone', + ], + [ + 'id' => '4775a923-ceeb-4ffc-83ab-ce8bce315060', + 'code' => 'DOP', + 'symbol' => 'RD$', + 'name' => 'Dominican Peso', + ], + [ + 'id' => 'da5df0ca-5ea5-4555-9b72-79098d0b96b3', + 'code' => 'DZD', + 'symbol' => 'DA', + 'name' => 'Algerian Dinar', + ], + [ + 'id' => '289a25cb-e65e-45ca-a4f7-9b274877ded1', + 'code' => 'EEK', + 'symbol' => 'Ekr', + 'name' => 'Estonian Kroon', + ], +]; diff --git a/tests/src/CyclePaginatorTest.php b/tests/src/CyclePaginatorTest.php new file mode 100644 index 00000000..640c1978 --- /dev/null +++ b/tests/src/CyclePaginatorTest.php @@ -0,0 +1,179 @@ +getPaginator()->total()); + } + + /** + * @test + */ + public function it_gets_last_page(): void + { + self::assertEquals(7, $this->getPaginator()->lastPage()); + } + + /** + * @test + */ + public function it_gets_next_page_url_when_it_exists(): void + { + self::assertEquals('/?page=3', $this->getPaginator()->nextPageUrl()); + } + + /** + * @test + */ + public function it_gets_next_page_url_when_it_not_exists(): void + { + self::assertNull( + $this->getPaginator(1, 200)->nextPageUrl() + ); + } + + /** + * @test + */ + public function it_gets_previous_page_url_when_it_exists(): void + { + self::assertEquals('/?page=1', $this->getPaginator()->previousPageUrl()); + } + + /** + * @test + */ + public function it_gets_previous_page_url_when_it_not_exists(): void + { + self::assertNull( + $this->getPaginator(1, 1)->previousPageUrl() + ); + } + + /** + * @test + */ + public function it_gets_items(): void + { + $items = array_slice($this->items, 5, 5, true); + + self::assertEquals($items, $this->getPaginator()->items()); + } + + /** + * @test + */ + public function it_gets_first_item(): void + { + self::assertEquals(6, $this->getPaginator()->firstItem()); + } + + /** + * @test + */ + public function it_gets_last_item(): void + { + self::assertEquals(10, $this->getPaginator()->lastItem()); + } + + /** + * @test + */ + public function it_gets_per_page(): void + { + self::assertEquals(5, $this->getPaginator()->perPage()); + } + + /** + * @test + */ + public function it_gets_current_page(): void + { + self::assertEquals(2, $this->getPaginator()->currentPage()); + } + + /** + * @test + */ + public function it_gets_page_name(): void + { + self::assertEquals('page', $this->getPaginator()->getPageName()); + } + + /** + * @test + */ + public function it_gets_count(): void + { + self::assertEquals(5, $this->getPaginator()->count()); + } + + /** + * @test + */ + public function it_returns_links(): void + { + $paginator = $this->getPaginator(); + $headers = $paginator->headers(); + + $links = (new ParseLinkHeader($headers['Link']))->toArray(); + + self::assertEquals('/?page=1', $links['first']['link']); + self::assertEquals('1', $links['first']['page']); + + self::assertEquals('/?page=7', $links['last']['link']); + self::assertEquals('7', $links['last']['page']); + + self::assertEquals('/?page=1', $links['prev']['link']); + self::assertEquals('1', $links['prev']['page']); + + self::assertEquals('/?page=3', $links['next']['link']); + self::assertEquals('3', $links['next']['page']); + } + + /** + * @test + */ + public function it_returns_response_headers(): void + { + $paginator = $this->getPaginator(); + $headers = $paginator->headers(); + + self::assertEquals(2, $headers['X-Page']); + self::assertEquals(5, $headers['X-Per-Page']); + self::assertEquals(34, $headers['X-Total-Count']); + self::assertEquals(5, $headers['X-Count']); + } + + protected function getPaginator(int $perPage = 5, int $currentPage = 2): CyclePaginator + { + $collection = collect($this->items)->forPage($this->page, $this->perPage); + + return new CyclePaginator( + (new SpiralPaginator($perPage)) + ->withPage($currentPage) + ->withCount(count($this->items)), + $collection, + 'page' + ); + } +} diff --git a/tests/src/LengthAwarePaginatorTest.php b/tests/src/LengthAwarePaginatorTest.php new file mode 100644 index 00000000..7b000817 --- /dev/null +++ b/tests/src/LengthAwarePaginatorTest.php @@ -0,0 +1,70 @@ +items)->forPage($this->page, $this->perPage); + $this->queryBuilderPaginator = new IlluminatePaginator( + $collection, + count($this->items), + $this->perPage, + $this->page + ); + } + + /** + * @test + */ + public function it_returns_links(): void + { + $paginator = new LengthAwarePaginator($this->queryBuilderPaginator); + $headers = $paginator->headers(); + + $links = (new ParseLinkHeader($headers['Link']))->toArray(); + + self::assertEquals('/?page=1', $links['first']['link']); + self::assertEquals('1', $links['first']['page']); + + self::assertEquals('/?page=7', $links['last']['link']); + self::assertEquals('7', $links['last']['page']); + + self::assertEquals('/?page=1', $links['prev']['link']); + self::assertEquals('1', $links['prev']['page']); + + self::assertEquals('/?page=3', $links['next']['link']); + self::assertEquals('3', $links['next']['page']); + } + + /** + * @test + */ + public function it_returns_response_headers(): void + { + $paginator = new LengthAwarePaginator($this->queryBuilderPaginator); + $headers = $paginator->headers(); + + self::assertEquals(2, $headers['X-Page']); + self::assertEquals(5, $headers['X-Per-Page']); + self::assertEquals(34, $headers['X-Total-Count']); + self::assertEquals(5, $headers['X-Count']); + } +} diff --git a/tests/src/PaginatorTest.php b/tests/src/PaginatorTest.php new file mode 100644 index 00000000..f1e2b076 --- /dev/null +++ b/tests/src/PaginatorTest.php @@ -0,0 +1,47 @@ +items, 5); + + $expectedHeaders = [ + 'Link' => '; rel="current",; rel="next"', + 'X-Page' => 1, + 'X-Per-Page' => 5, + 'X-Total-Count' => 5, + ]; + + $this::assertEquals($expectedHeaders, $paginator->headers()); + } + + /** + * @test + */ + public function it_returns_links(): void + { + $paginator = new Paginator($this->items, $this->perPage); + $headers = $paginator->headers(); + + $links = (new ParseLinkHeader($headers['Link']))->toArray(); + + self::assertEquals('/?page=1', $links['current']['link']); + self::assertEquals('1', $links['current']['page']); + + self::assertEquals('/?page=2', $links['next']['link']); + self::assertEquals('2', $links['next']['page']); + } +} diff --git a/tests/src/Pest.php b/tests/src/Pest.php index bce16ce8..84660bd7 100644 --- a/tests/src/Pest.php +++ b/tests/src/Pest.php @@ -2,6 +2,6 @@ declare(strict_types=1); -namespace WayOfDev\Package\Tests; +namespace WayOfDev\Paginator\Tests; uses(TestCase::class)->in(__DIR__); diff --git a/tests/src/TestCase.php b/tests/src/TestCase.php index 9182a262..fa018b40 100644 --- a/tests/src/TestCase.php +++ b/tests/src/TestCase.php @@ -2,17 +2,26 @@ declare(strict_types=1); -namespace WayOfDev\Package\Tests; +namespace WayOfDev\Paginator\Tests; use Orchestra\Testbench\TestCase as Orchestra; -use WayOfDev\Package\Bridge\Laravel\Providers\PackageServiceProvider; +use WayOfDev\Paginator\Bridge\Laravel\Providers\PaginatorServiceProvider; abstract class TestCase extends Orchestra { + protected array $items = []; + + public function setUp(): void + { + parent::setUp(); + + $this->items = require __DIR__ . '/../app/items.php'; + } + protected function getPackageProviders($app): array { return [ - PackageServiceProvider::class, + PaginatorServiceProvider::class, ]; } }