From 91c35361fac4d3b7bb054828ef06372452d50698 Mon Sep 17 00:00:00 2001 From: Felix Huber Date: Sat, 19 Mar 2022 20:42:04 +0100 Subject: [PATCH 1/3] Update to support v1.0 of seatplus * update tests --- composer.json | 15 +++++++++------ phpunit.xml.dist | 5 +++++ tests/Integration/ApiUser.php | 2 +- tests/Integration/Endpoints.php | 7 ++++++- tests/Pest.php | 4 ++++ tests/Stubs/Kernel.php | 2 +- tests/Stubs/mix-manifest.json | 6 ++++++ tests/TestCase.php | 20 +++++++------------- 8 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 tests/Stubs/mix-manifest.json diff --git a/composer.json b/composer.json index d55454d..c3bb214 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,14 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "laravel/sanctum": "^2.11", - "seatplus/web": "^0.9" + "seatplus/web": "^1.0" }, "require-dev": { - "nunomaduro/collision": "^5.3", - "orchestra/testbench": "^6.15", - "pestphp/pest-plugin-laravel": "^1.1" + "nunomaduro/collision": "^6.1", + "orchestra/testbench": "^7.1", + "pestphp/pest-plugin-laravel": "^1.2" }, "autoload": { "psr-4": { @@ -41,7 +41,10 @@ "test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } }, "extra": { "laravel": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d16872c..d91fa17 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -35,6 +35,11 @@ + + + + + diff --git a/tests/Integration/ApiUser.php b/tests/Integration/ApiUser.php index c8aed8c..cebbc84 100644 --- a/tests/Integration/ApiUser.php +++ b/tests/Integration/ApiUser.php @@ -21,7 +21,7 @@ it('user can access api view', function () { $response = actingAs($this->test_user)->get(route('api.index')) - ->assertInertia(fn (Assert $page) => $page + ->assertInertia(fn (\Inertia\Testing\AssertableInertia $page) => $page ->component('Api/Index')); }); diff --git a/tests/Integration/Endpoints.php b/tests/Integration/Endpoints.php index fe63d66..93ae675 100644 --- a/tests/Integration/Endpoints.php +++ b/tests/Integration/Endpoints.php @@ -14,7 +14,11 @@ }); test('/api/v1/users/1', function () { - $this->get('api/v1/users/1')->assertOk(); + + expect(\Seatplus\Auth\Models\User::all())->toHaveCount(1); + $user_id = \Seatplus\Auth\Models\User::first()->id; + + $this->get("api/v1/users/$user_id")->assertOk(); }); test('/api/v1/characters/{character_id}/skills', function () { @@ -37,6 +41,7 @@ test('/api/v1/characters/{character_id}/corporationhistory', function () { \Seatplus\Eveapi\Models\Character\CorporationHistory::factory() ->create([ + 'start_date' => faker()->dateTime, 'character_id' => $this->test_character->character_id, ]); diff --git a/tests/Pest.php b/tests/Pest.php index 7f910eb..544ea3a 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -58,3 +58,7 @@ function using($test): TestCase { return $test; } + +function faker() { + return \Faker\Factory::create(); +} diff --git a/tests/Stubs/Kernel.php b/tests/Stubs/Kernel.php index 00da345..9a52c4c 100644 --- a/tests/Stubs/Kernel.php +++ b/tests/Stubs/Kernel.php @@ -6,7 +6,7 @@ use Orchestra\Testbench\Http\Middleware\RedirectIfAuthenticated; use Seatplus\Web\Http\Middleware\Authenticate; -class Kernel extends \Orchestra\Testbench\Http\Kernel +class Kernel extends \Orchestra\Testbench\Foundation\Http\Kernel { /** * The application's route middleware. diff --git a/tests/Stubs/mix-manifest.json b/tests/Stubs/mix-manifest.json new file mode 100644 index 0000000..50be220 --- /dev/null +++ b/tests/Stubs/mix-manifest.json @@ -0,0 +1,6 @@ +{ + "/js/app.js": "/js/app.js", + "/js/manifest.js": "/js/manifest.js", + "/css/app.css": "/css/app.css", + "/js/vendor.js": "/js/vendor.js" +} diff --git a/tests/TestCase.php b/tests/TestCase.php index d4b702b..f2f165c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,6 +3,7 @@ namespace Seatplus\Api\Tests; use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Queue; use Inertia\Inertia; @@ -19,6 +20,9 @@ class TestCase extends Orchestra { + + use LazilyRefreshDatabase; + protected function setUp(): void { parent::setUp(); @@ -43,7 +47,7 @@ protected function setUp(): void $this->test_character = $this->test_user->characters->first(); - $this->app->instance('path.public', __DIR__ .'/../vendor/seatplus/web/src/public'); + $this->app->instance('path.public', __DIR__ .'/Stubs'); Permission::findOrCreate('superuser'); } @@ -62,20 +66,10 @@ protected function getPackageProviders($app) public function getEnvironmentSetUp($app) { - config()->set('database.default', 'testing'); - - // Use memory SQLite, cleans it self up - $app['config']->set('database.default', 'testbench'); - $app['config']->set('database.connections.testbench', [ - 'driver' => 'sqlite', - 'database' => ':memory:', - 'prefix' => '', - ]); + config()->set('database.default', 'mysql'); config(['app.debug' => true]); - //$app['router']->aliasMiddleware('auth', Authenticate::class); - // Use test User model for users provider $app['config']->set('auth.providers.users.model', User::class); @@ -109,6 +103,6 @@ private function setupDatabase($app) { // Path to our migrations to load //$this->loadMigrationsFrom(__DIR__ . '/database/migrations'); - $this->artisan('migrate', ['--database' => 'testbench']); + $this->artisan('migrate'); } } From 4df97e9b442333034ec51444182047530e6b0f95 Mon Sep 17 00:00:00 2001 From: herpaderpaldent Date: Sat, 19 Mar 2022 19:42:40 +0000 Subject: [PATCH 2/3] Fix styling --- tests/Integration/ApiUser.php | 1 - tests/Integration/Endpoints.php | 1 - tests/Pest.php | 3 ++- tests/TestCase.php | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Integration/ApiUser.php b/tests/Integration/ApiUser.php index cebbc84..9b694c1 100644 --- a/tests/Integration/ApiUser.php +++ b/tests/Integration/ApiUser.php @@ -1,6 +1,5 @@ toHaveCount(1); $user_id = \Seatplus\Auth\Models\User::first()->id; diff --git a/tests/Pest.php b/tests/Pest.php index 544ea3a..6610653 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -59,6 +59,7 @@ function using($test): TestCase return $test; } -function faker() { +function faker() +{ return \Faker\Factory::create(); } diff --git a/tests/TestCase.php b/tests/TestCase.php index f2f165c..750acb6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,7 +20,6 @@ class TestCase extends Orchestra { - use LazilyRefreshDatabase; protected function setUp(): void From 399249928b703881027e11f449983f3a1f553ae5 Mon Sep 17 00:00:00 2001 From: Felix Huber Date: Sat, 19 Mar 2022 20:44:30 +0100 Subject: [PATCH 3/3] update workflow --- .github/workflows/run-tests.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index de4e09e..a6e6573 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,9 +16,16 @@ jobs: - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: - php-version: '8.0' + php-version: '8.1' extensions: mbstring, dom, fileinfo coverage: xdebug #optional + - uses: getong/mariadb-action@v1.1 + with: + host port: 3308 # Optional, default value is 3306. The port of host + mariadb version: '10.3' # Optional, default value is "latest". The version of the MariaDB + mysql database: 'testbench' # Optional, default value is "test". The specified database which will be create + mysql user: 'default' # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Can use secrets, too + mysql password: 'secret' # Required if "mysql user" exists. The password for the "mysql user" - name: Redis Server in GitHub Actions uses: supercharge/redis-github-action@1.1.0 with: @@ -27,11 +34,4 @@ jobs: - name: Install Dependencies run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Run test & coverage - run: vendor/bin/pest --coverage --min=85 -# - name: Test & publish code coverage -# uses: paambaati/codeclimate-action@v2.6.0 -# env: -# CC_TEST_REPORTER_ID: fe3081a529c6c268974ebebb2f0137c3b3f6351cdc8a2712d8eb86ec78f7bf22 -# with: -# coverageCommand: vendor/bin/phpunit --coverage-clover build/logs/clover.xml -# debug: false + run: vendor/bin/pest --coverage --ci --min=85