Skip to content

Commit

Permalink
[5.x] Laravel 11 (#9434)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Mar 6, 2024
1 parent 24864fc commit dae2639
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 121 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1, 8.2, 8.3]
laravel: [9.*, 10.*]
php: [8.1, 8.2, 8.3]
laravel: [10.*, 11.*]
stability: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]
include:
- os: windows-latest
php: 8.1
laravel: 9.*
php: 8.3
laravel: 10.*
stability: prefer-stable
- os: windows-latest
php: 8.1
laravel: 10.*
php: 8.3
laravel: 11.*
stability: prefer-stable
exclude:
- php: 8.0
laravel: 10.*
- php: 8.3
laravel: 9.*
- php: 8.1
laravel: 11.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down Expand Up @@ -80,6 +78,16 @@ jobs:
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install Laravel 11
uses: nick-invision/retry@v2
if: steps.should-run-tests.outputs.result == 'true' && matrix.laravel == '11.*'
with:
timeout_minutes: 5
max_attempts: 5
command: |
composer config minimum-stability dev
composer config prefer-stable true
- name: Install dependencies
uses: nick-invision/retry@v2
if: steps.should-run-tests.outputs.result == 'true'
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@
"require": {
"ext-json": "*",
"ajthinking/archetype": "^1.0.3",
"composer/composer": "^1.10.22 || ^2.2.22",
"composer/composer": "^2.2.22",
"facade/ignition-contracts": "^1.0",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"james-heinrich/getid3": "^1.9.21",
"laravel/framework": "^9.50.0 || ^10.0",
"laravel/framework": "^10.0 || ^11.0",
"laravel/helpers": "^1.1",
"league/commonmark": "^2.2",
"league/csv": "^9.0",
"league/glide": "^1.1 || ^2.0",
"league/glide": "^2.0",
"maennchen/zipstream-php": "^2.2",
"michelf/php-smartypants": "^1.8.1",
"nesbot/carbon": "^2.62.1",
"pixelfear/composer-dist-plugin": "^0.1.4",
"rebing/graphql-laravel": "^6.5 || ^8.0",
"rebing/graphql-laravel": "^9.5",
"rhukster/dom-sanitizer": "^1.0.6",
"spatie/blink": "^1.3",
"statamic/stringy": "^3.1.2",
"symfony/http-foundation": "^4.3.3 || ^5.1.4 || ^6.0",
"symfony/lock": "^5.4",
"symfony/var-exporter": "^4.3 || ^5.1 || ^6.0",
"symfony/yaml": "^4.1 || ^5.1 || ^6.0",
"symfony/lock": "^6.4",
"symfony/var-exporter": "^6.0",
"symfony/yaml": "^6.0 || ^7.0",
"ueberdosis/tiptap-php": "^1.1",
"voku/portable-ascii": "^1.6.1 || ^2.0",
"voku/portable-ascii": "^2.0",
"wilderborn/partyline": "^1.0"
},
"require-dev": {
Expand All @@ -42,7 +41,7 @@
"google/cloud-translate": "^1.6",
"laravel/pint": "^1.0",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^7.0 || ^8.0",
"orchestra/testbench": "^8.0 || ^9.x-dev",
"phpunit/phpunit": "^9.0 || ^10.0"
},
"config": {
Expand Down
5 changes: 5 additions & 0 deletions src/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public function getAuthPassword()
return $this->password();
}

public function getAuthPasswordName()
{
return 'password';
}

/**
* Get or set the blueprint.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Auth/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ public function validateCredentials(Authenticatable $user, array $credentials)
{
return Hash::check($credentials['password'], $user->getAuthPassword());
}

public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false)
{
if (! Hash::needsRehash($user->getAuthPassword()) && ! $force) {
return;
}

$user->password($credentials['password'])->save();
}
}
4 changes: 1 addition & 3 deletions src/Console/Please/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ public function resolve($command)
/**
* Finds a command by name or alias. If doesn't exist, resolve deferred artisan commands and try again.
*
* @param string $name
* @return \Illuminate\Console\Command
*
* @throws CommandNotFoundException
*/
public function find($name)
public function find(string $name): Command
{
try {
return parent::find($name);
Expand Down
6 changes: 2 additions & 4 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2178,18 +2178,16 @@ public function shrug()
*/
public function shuffle($value, array $params)
{
$seed = Arr::get($params, 0);

if (Compare::isQueryBuilder($value)) {
$value = $value->get();
}

if (is_array($value)) {
return collect($value)->shuffle($seed)->all();
return collect($value)->shuffle()->all();
}

if ($value instanceof Collection) {
return $value->shuffle($seed);
return $value->shuffle();
}

return Stringy::shuffle($value);
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/CacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function extendFileStore()
$this->app['files'],
$this->app['config']['cache.stores.file']['path'],
$this->app['config']['cache.stores.file']['permission'] ?? null
));
), $this->app['config']['cache.stores.file']);
});

if (config('cache.default') === 'file') {
Expand Down
2 changes: 1 addition & 1 deletion tests/Antlers/Runtime/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2448,7 +2448,7 @@ public function it_uses_entries_as_conditions($object)
]));
}

public function objectInConditionProvider()
public static function objectInConditionProvider()
{
return [
'with __toString' => [new class()
Expand Down
59 changes: 12 additions & 47 deletions tests/Modifiers/RandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Modifiers;

use Illuminate\Support\Collection;
use Mockery;
use Statamic\Contracts\Query\Builder;
use Statamic\Modifiers\Modify;
Expand All @@ -13,57 +12,23 @@ class RandomTest extends TestCase
/**
* @test
*
* @group array
* @dataProvider inputsProvider
*/
public function it_returns_one_random_item_from_an_array(): void
public function it_returns_one_random_item($input): void
{
$orderOfCeremony = [
'Sonic',
'Knuckles',
'Tails',
];

srand(1234);

$modified = $this->modify($orderOfCeremony);
$expected = $this->modify($orderOfCeremony);
$this->assertEquals($expected, $modified);
}

/**
* @test
*
* @group array
*/
public function it_returns_one_random_item_from_a_collection(): void
{
$orderOfCeremony = collect([
'Sonic',
'Knuckles',
'Tails',
]);

srand(1234);

$modified = $this->modify($orderOfCeremony);
$expected = $this->modify($orderOfCeremony);
$this->assertEquals($expected, $modified);
$this->assertFalse(
$this->modify($input) === $this->modify($input) && $this->modify($input) === $this->modify($input),
'The same value was returned multiple times.',
);
}

/** @test */
public function it_returns_one_random_item_from_a_query_builder()
public static function inputsProvider()
{
$builder = Mockery::mock(Builder::class);
$builder->shouldReceive('get')->andReturn(Collection::make([
'Sonic',
'Knuckles',
'Tails',
]));

srand(1234);
$modified = $this->modify($builder);
$expected = $this->modify($builder);
$this->assertEquals($expected, $modified);
return [
'array' => [range('a', 'z')],
'collection' => [collect(range('a', 'z'))],
'query builder' => [Mockery::mock(Builder::class)->shouldReceive('get')->andReturn(collect(range('a', 'z')))->getMock()],
];
}

private function modify($value)
Expand Down
68 changes: 27 additions & 41 deletions tests/Modifiers/ShuffleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,41 @@ class ShuffleTest extends TestCase
/**
* @test
*
* @group array
* @dataProvider inputsProvider
*/
public function it_shuffles_the_items_of_an_array(): void
public function it_shuffles_the_items($input, $expectedType): void
{
$orderOfCeremony = [
'Sonic',
'Knuckles',
'Tails',
];
$modified = $this->modify($orderOfCeremony, [1234]);
$expected = $this->modify($orderOfCeremony, [1234]);
$this->assertEquals($expected, $modified);
}
$this->assertFalse(
$this->modify($input) === $this->modify($input) && $this->modify($input) === $this->modify($input),
'The same value was returned multiple times.',
);

/**
* @test
*
* @group array
*/
public function it_shuffles_the_items_of_a_collection(): void
{
$orderOfCeremony = collect([
'Sonic',
'Knuckles',
'Tails',
]);
$modified = $this->modify($orderOfCeremony, [1234]);
$expected = $this->modify($orderOfCeremony, [1234]);
$this->assertEquals($expected, $modified);
$this->assertTrue(
$expectedType($this->modify($input)),
'The modified value is not of the expected type.'
);
}

/** @test */
public function it_shuffles_values_from_query_builder()
public static function inputsProvider()
{
$builder = Mockery::mock(Builder::class);
$builder->shouldReceive('get')->andReturn(Collection::make([
'Sonic',
'Knuckles',
'Tails',
]));

$modified = $this->modify($builder, [1234]);
$expected = $this->modify($builder, [1234]);
$this->assertInstanceOf(Collection::class, $modified);
$this->assertEquals($expected, $modified);
return [
'array' => [
range('a', 'z'),
fn ($value) => is_array($value),
],
'collection' => [
collect(range('a', 'z')),
fn ($value) => $value instanceof Collection,
],
'query builder' => [
Mockery::mock(Builder::class)->shouldReceive('get')->andReturn(collect(range('a', 'z')))->getMock(),
fn ($value) => $value instanceof Collection,
],
];
}

private function modify($value, $params)
private function modify($value)
{
return Modify::value($value)->shuffle($params)->fetch();
return Modify::value($value)->shuffle()->fetch();
}
}
24 changes: 20 additions & 4 deletions tests/Support/Concerns/TestsIlluminateArr.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,14 +831,30 @@ public function testSet()
$this->assertEquals([1 => 'hAz'], Arr::set($array, 1, 'hAz'));
}

public function testShuffleWithSeed()
public function testShuffle()
{
$this->assertEquals(
Arr::shuffle(range(0, 100, 10), 1234),
Arr::shuffle(range(0, 100, 10), 1234)
$input = ['a', 'b', 'c', 'd', 'e', 'f'];

$this->assertNotEquals(
$input,
Arr::shuffle($input)
);

$this->assertNotEquals(
Arr::shuffle($input),
Arr::shuffle($input)
);
}

public function testShuffleKeepsSameValues()
{
$input = ['a', 'b', 'c', 'd', 'e', 'f'];
$shuffled = Arr::shuffle($input);
sort($shuffled);

$this->assertEquals($input, $shuffled);
}

public function testEmptyShuffle()
{
$this->assertEquals([], Arr::shuffle([]));
Expand Down

0 comments on commit dae2639

Please sign in to comment.