diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b4ae1c4..706acf5 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -40,7 +40,7 @@ Before submitting a pull request: If the project maintainer has any additional requirements, you will find them listed here. -- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). +- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). - **Add tests!** - Your patch won't be accepted if it doesn't have tests. diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 4484065..c162ae4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,16 +9,17 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.0, 7.4] - laravel: [8.*, 6.*, 7.*] + php: [8.1, 8.0, 7.4] + laravel: [9.*, 8.*] dependency-version: [prefer-lowest, prefer-stable] include: + - laravel: 9.* + testbench: 7.* - laravel: 8.* - testbench: 6.* - - laravel: 7.* - testbench: 5.* - - laravel: 6.* - testbench: 4.* + testbench: ^6.23 + exclude: + - laravel: 9.* + php: 7.4 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..fa56639 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/composer.json b/composer.json index 9b0aaed..49a2057 100644 --- a/composer.json +++ b/composer.json @@ -16,20 +16,20 @@ } ], "require": { - "php": "^7.3|^8.0", - "illuminate/support": "^6.0|^7.0|^8.0" + "php": "^7.4|^8.0", + "illuminate/support": "^8.0|^9.0" }, "require-dev": { - "laravel/legacy-factories": "^1.0.4", "league/iso3166": "^3.0", "myclabs/php-enum": "^1.6", - "orchestra/testbench": "^4.5|^5.0|^6.0", - "phpunit/phpunit": "^9.3", + "orchestra/testbench": "^6.23|^7.0", + "phpunit/phpunit": "^9.4", "spatie/enum": "^2.2|^3.0" }, "autoload": { "psr-4": { - "Spatie\\ValidationRules\\": "src" + "Spatie\\ValidationRules\\": "src", + "Spatie\\ValidationRules\\Database\\Factories\\": "database/factories" } }, "autoload-dev": { diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 0000000..2e916e6 --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,24 @@ + $this->faker->name, + 'email' => $this->faker->unique()->safeEmail, + 'password' => $password ?: $password = bcrypt('secret'), + 'remember_token' => Str::random(10), + ]; + } +} diff --git a/tests/Rules/AuthorizedTest.php b/tests/Rules/AuthorizedTest.php index a00aefc..b4bf420 100644 --- a/tests/Rules/AuthorizedTest.php +++ b/tests/Rules/AuthorizedTest.php @@ -2,7 +2,6 @@ namespace Spatie\ValidationRules\Tests\Rules; -use Illuminate\Foundation\Auth\User; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Lang; use Spatie\ValidationRules\Rules\Authorized; @@ -11,6 +10,7 @@ use Spatie\ValidationRules\Tests\TestClasses\Models\TestRouteKeyModel; use Spatie\ValidationRules\Tests\TestClasses\Policies\TestModelPolicy; use Spatie\ValidationRules\Tests\TestClasses\Policies\TestRouteKeyModelPolicy; +use Spatie\ValidationRules\Tests\TestModel\User; class AuthorizedTest extends TestCase { @@ -27,7 +27,7 @@ public function it_will_return_true_if_the_gate_returns_true_for_the_given_abili { $rule = new Authorized('edit', TestModel::class); - $user = factory(User::class)->create(['id' => 1]); + $user = User::factory()->create(['id' => 1]); TestModel::create([ 'id' => 1, 'user_id' => $user->id, @@ -43,7 +43,7 @@ public function it_will_return_false_if_noone_is_logged_in() { $rule = new Authorized('edit', TestModel::class); - $user = factory(User::class)->create(['id' => 1]); + $user = User::factory()->create(['id' => 1]); TestModel::create([ 'id' => 1, 'user_id' => $user->id, @@ -57,7 +57,7 @@ public function it_will_return_false_if_the_model_is_not_found() { $rule = new Authorized('edit', TestModel::class); - $user = factory(User::class)->create(['id' => 1]); + $user = User::factory()->create(['id' => 1]); TestModel::create([ 'id' => 1, 'user_id' => $user->id, @@ -71,7 +71,7 @@ public function it_will_return_false_if_the_gate_returns_false() { $rule = new Authorized('edit', TestModel::class); - $user = factory(User::class)->create(['id' => 1]); + $user = User::factory()->create(['id' => 1]); TestModel::create([ 'id' => 1, 'user_id' => 2, @@ -99,7 +99,7 @@ public function it_will_pass_when_using_alternate_route_key_name() { $rule = new Authorized('edit', TestRouteKeyModel::class); - $user = factory(User::class)->create(['id' => 1]); + $user = User::factory()->create(['id' => 1]); TestRouteKeyModel::create([ 'id' => 1, 'name' => 'abc123', @@ -116,7 +116,7 @@ public function it_will_pass_if_alternate_auth_guard_is_specified() { $rule = new Authorized('edit', TestModel::class, 'alternate'); - $user = factory(User::class)->create(['id' => 1]); + $user = User::factory()->create(['id' => 1]); TestModel::create([ 'id' => 1, 'user_id' => 1, @@ -132,7 +132,7 @@ public function it_will_return_false_if_auth_guard_is_incorrect() { $rule = new Authorized('edit', TestModel::class, 'web'); - $user = factory(User::class)->create(['id' => 1]); + $user = User::factory()->create(['id' => 1]); TestModel::create([ 'id' => 1, 'user_id' => 1, diff --git a/tests/Rules/ModelsExistTest.php b/tests/Rules/ModelsExistTest.php index abd2a72..1a8b3cb 100644 --- a/tests/Rules/ModelsExistTest.php +++ b/tests/Rules/ModelsExistTest.php @@ -2,10 +2,10 @@ namespace Spatie\ValidationRules\Tests\Rules; -use Illuminate\Foundation\Auth\User; use Illuminate\Support\Facades\Lang; use Spatie\ValidationRules\Rules\ModelsExist; use Spatie\ValidationRules\Tests\TestCase; +use Spatie\ValidationRules\Tests\TestModel\User; class ModelsExistTest extends TestCase { @@ -17,11 +17,11 @@ public function it_will_return_true_if_all_model_ids_exist() $this->assertTrue($rule->passes('userIds', [])); $this->assertFalse($rule->passes('userIds', [1])); - factory(User::class)->create(['id' => 1]); + User::factory()->create(['id' => 1]); $this->assertTrue($rule->passes('userIds', [1])); $this->assertFalse($rule->passes('userIds', [1, 2])); - factory(User::class)->create(['id' => 2]); + User::factory()->create(['id' => 2]); $this->assertTrue($rule->passes('userIds', [1, 2])); $this->assertTrue($rule->passes('userIds', [1])); } @@ -34,7 +34,7 @@ public function it_can_validate_existence_of_models_by_column() $this->assertTrue($rule->passes('userEmails', [])); $this->assertFalse($rule->passes('userEmails', ['user@example.com'])); - factory(User::class)->create(['email' => 'user@example.com']); + User::factory()->create(['email' => 'user@example.com']); $this->assertTrue($rule->passes('userEmails', ['user@example.com'])); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 311a7c0..999819f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,7 @@ namespace Spatie\ValidationRules\Tests; -use Illuminate\Database\Eloquent\Factory as EloquentFactory; +use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Orchestra\Testbench\TestCase as Orchestra; @@ -14,10 +14,16 @@ public function setUp(): void { parent::setUp(); + Factory::guessFactoryNamesUsing( + function (string $modelName) { + return 'Spatie\\ValidationRules\\Database\\Factories\\' . class_basename($modelName) . 'Factory'; + } + ); + + + $this->setUpDatabase(); $this->setUpGuard(); - - $this->app->make(EloquentFactory::class)->load(__DIR__.'/factories'); } protected function getPackageProviders($app) diff --git a/tests/TestModel/User.php b/tests/TestModel/User.php new file mode 100644 index 0000000..eb002e8 --- /dev/null +++ b/tests/TestModel/User.php @@ -0,0 +1,11 @@ +define(User::class, function (Faker\Generator $faker) { - static $password; - - return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'password' => $password ?: $password = bcrypt('secret'), - 'remember_token' => Str::random(10), - ]; -});