diff --git a/.env.example b/.env.example index 2a4a8b7..f486079 100644 --- a/.env.example +++ b/.env.example @@ -19,12 +19,12 @@ LOG_STACK=single LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug -DB_CONNECTION=sqlite -# DB_HOST=127.0.0.1 -# DB_PORT=3306 -# DB_DATABASE=laravel -# DB_USERNAME=root -# DB_PASSWORD= +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laravel +DB_USERNAME=root +DB_PASSWORD= SESSION_DRIVER=database SESSION_LIFETIME=120 diff --git a/.github/actions/setup-tooling/action.yml b/.github/actions/setup-tooling/action.yml new file mode 100644 index 0000000..d4bbc5a --- /dev/null +++ b/.github/actions/setup-tooling/action.yml @@ -0,0 +1,61 @@ +name: Setup Tooling + +description: Sets up PHP with and Composer with caching. + +inputs: + php-version: + description: The version(s) of PHP you want to configure. + required: false + default: '8.3' + php-extensions: + description: The PHP extensions to install. + required: false + default: dom, curl, libxml, mbstring, zip, pcntl, pdo, gd, redis, igbinary, msgpack, lzf, zstd, lz4, memcached, gmp, :php-psr + php-tools: + description: Any tools you want to include with PHP + required: false + default: composer:v2 + +runs: + using: composite + steps: + - name: Get extension cache hash + id: extension-cache-hash + env: + PHP_EXTENSIONS: ${{ inputs.php-extensions }} + run: echo hash=$(echo $PHP_EXTENSIONS | md5sum) >> $GITHUB_OUTPUT + shell: bash + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ inputs.php-version }} + extensions: ${{ inputs.php-extensions }} + key: php-extensions-${{ steps.extension-cache-hash.outputs.hash }} + + - name: Cache extensions + uses: actions/cache@v4 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + + - name: Setup PHP and Composer + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + extensions: ${{ inputs.php-extensions }} + tools: ${{ inputs.php-tools }} + + - name: Get Composer cache dir + id: composer-cache-dir + run: echo dir=$(composer config cache-files-dir) >> $GITHUB_OUTPUT + shell: bash + + - name: Cache dependencies + uses: actions/cache@v4.0.2 + with: + key: composer-cache-${{ hashFiles('**/composer.lock') }} + path: ${{ steps.composer-cache-dir.outputs.dir }} + restore-keys: composer-cache- diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d2692d1..03e5da1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,45 +1,44 @@ -name: Tests +name: Run Tests on: - pull_request + pull_request: + branches: + - main jobs: - run-tests: + tests: runs-on: ubuntu-latest - env: - DB_NAME: tests services: + redis: + image: redis:7.4 + ports: + - 6379:6379 mysql: image: mysql:8.0 ports: - 3306:3306 env: + MYSQL_DATABASE: laravel MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: ${{ env.DB_NAME }} steps: - name: Checkout Code uses: actions/checkout@v4.1.7 - - name: Setup PHP and Composer - uses: shivammathur/setup-php@v2 + - name: Setup tooling + uses: ./.github/actions/setup-tooling with: php-version: '8.3' - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, igbinary, msgpack, lzf, zstd, lz4, memcached, gmp, :php-psr - tools: composer:v2 - - name: Install Dependencies - run: composer install -q --no-interaction + - name: Install Project Dependencies + run: composer install -q --no-interaction --no-progress + + - name: Copy Environment File + run: cp .env.example .env - - name: Prep Application - run: | - cp .env.example .env - php artisan key:generate + - name: Generate Application Key + run: php artisan key:generate - name: Run Tests - env: - DB_CONNECTION: mysql - DB_DATABASE: ${{ env.DB_NAME }} - DB_USERNAME: root run: php artisan test --compact diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index 985e9f5..0b6e1fe 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -6,6 +6,7 @@ use App\Models\User; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Validator; use Laravel\Fortify\Contracts\CreatesNewUsers; use Laravel\Jetstream\Jetstream; @@ -21,7 +22,6 @@ class CreateNewUser implements CreatesNewUsers */ public function create(array $input): User { - // A new comment! Validator::make($input, [ 'name' => ['required', 'string', 'max:255', 'nullable'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], diff --git a/composer.json b/composer.json index f682f4d..a631a85 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "laravel/jetstream": "^5.1", "laravel/sanctum": "^4.0", "laravel/tinker": "^2.9", - "livewire/livewire": "^3.0" + "livewire/livewire": "^3.0", + "ext-redis": "*" }, "require-dev": { "fakerphp/faker": "^1.23", diff --git a/composer.lock b/composer.lock index 4ffe482..fe0eb2f 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": "fa0497b37466ebb0abba82a4374235ea", + "content-hash": "b3b3787540f181f6c5b1d7065abc7b09", "packages": [ { "name": "bacon/bacon-qr-code", @@ -191,23 +191,23 @@ }, { "name": "dasprid/enum", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/DASPRiD/Enum.git", - "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016" + "reference": "8dfd07c6d2cf31c8da90c53b83c026c7696dda90" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/6faf451159fb8ba4126b925ed2d78acfce0dc016", - "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/8dfd07c6d2cf31c8da90c53b83c026c7696dda90", + "reference": "8dfd07c6d2cf31c8da90c53b83c026c7696dda90", "shasum": "" }, "require": { "php": ">=7.1 <9.0" }, "require-dev": { - "phpunit/phpunit": "^7 | ^8 | ^9", + "phpunit/phpunit": "^7 || ^8 || ^9 || ^10 || ^11", "squizlabs/php_codesniffer": "*" }, "type": "library", @@ -235,9 +235,9 @@ ], "support": { "issues": "https://github.com/DASPRiD/Enum/issues", - "source": "https://github.com/DASPRiD/Enum/tree/1.0.5" + "source": "https://github.com/DASPRiD/Enum/tree/1.0.6" }, - "time": "2023-08-25T16:18:39+00:00" + "time": "2024-08-09T14:30:48+00:00" }, { "name": "dflydev/dot-access-data", @@ -8309,16 +8309,16 @@ }, { "name": "sebastian/comparator", - "version": "5.0.1", + "version": "5.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2db5010a484d53ebf536087a70b4a5423c102372" + "reference": "2d3e04c3b4c1e84a5e7382221ad8883c8fbc4f53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372", - "reference": "2db5010a484d53ebf536087a70b4a5423c102372", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2d3e04c3b4c1e84a5e7382221ad8883c8fbc4f53", + "reference": "2d3e04c3b4c1e84a5e7382221ad8883c8fbc4f53", "shasum": "" }, "require": { @@ -8329,7 +8329,7 @@ "sebastian/exporter": "^5.0" }, "require-dev": { - "phpunit/phpunit": "^10.3" + "phpunit/phpunit": "^10.4" }, "type": "library", "extra": { @@ -8374,7 +8374,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", "security": "https://github.com/sebastianbergmann/comparator/security/policy", - "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1" + "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.2" }, "funding": [ { @@ -8382,7 +8382,7 @@ "type": "github" } ], - "time": "2023-08-14T13:18:12+00:00" + "time": "2024-08-12T06:03:08+00:00" }, { "name": "sebastian/complexity", @@ -9242,7 +9242,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.2" + "php": "^8.2", + "ext-redis": "*" }, "platform-dev": [], "plugin-api-version": "2.6.0" diff --git a/phpunit.xml b/phpunit.xml index 506b9a3..7aa98ed 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -22,8 +22,8 @@ - - + + diff --git a/routes/web.php b/routes/web.php index 0b90255..9377536 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,9 +1,17 @@ rand(0, 100)); + + return view('welcome', [ + 'users' => User::inRandomOrder($seed)->paginate(3), + ]); }); Route::middleware([ diff --git a/tests/Feature/WelcomeTest.php b/tests/Feature/WelcomeTest.php new file mode 100644 index 0000000..dbce79b --- /dev/null +++ b/tests/Feature/WelcomeTest.php @@ -0,0 +1,23 @@ +get('/'); + $this->get('/'); + $this->get('/'); + + expect(Redis::get('landing-page-views'))->toEqual(3); +}); + +it('provides users in random paginated order', function () { + $users = User::factory(4)->create(); + + $users = collect($this->get('/')->viewData('users')->items()) + ->merge($this->get('/?page=2')->viewData('users')->items()); + + expect($users->count())->toBe($users->unique('id')->count()); +})->repeat(3);