Skip to content

Commit

Permalink
Fix spaces (#45105)
Browse files Browse the repository at this point in the history
* Fix spaces

* fix
  • Loading branch information
michaelnabil230 authored Nov 27, 2022
1 parent 2071b04 commit 11edbfe
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Concerns/CompilesJsonPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function wrapJsonPath($value, $delimiter = '->')
$value = preg_replace("/([\\\\]+)?\\'/", "''", $value);

$jsonPath = collect(explode($delimiter, $value))
->map(fn ($segment) => $this->wrapJsonPathSegment($segment))
->map(fn ($segment) => $this->wrapJsonPathSegment($segment))
->join('.');

return "'$".(str_starts_with($jsonPath, '[') ? '' : '.').$jsonPath."'";
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/DatabaseEloquentWithCastsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function setUp(): void
$db = new DB;

$db->addConnection([
'driver' => 'sqlite',
'driver' => 'sqlite',
'database' => ':memory:',
]);

Expand Down
10 changes: 5 additions & 5 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public function testInputMethod()

public function testBooleanMethod()
{
$request = Request::create('/', 'GET', ['with_trashed' => 'false', 'download' => true, 'checked' => 1, 'unchecked' => '0', 'with_on' => 'on', 'with_yes'=> 'yes']);
$request = Request::create('/', 'GET', ['with_trashed' => 'false', 'download' => true, 'checked' => 1, 'unchecked' => '0', 'with_on' => 'on', 'with_yes' => 'yes']);
$this->assertTrue($request->boolean('checked'));
$this->assertTrue($request->boolean('download'));
$this->assertFalse($request->boolean('unchecked'));
Expand All @@ -605,8 +605,8 @@ public function testIntegerMethod()
'zero_padded' => '078',
'space_padded' => ' 901',
'nan' => 'nan',
'mixed'=> '1ab',
'underscore_notation'=> '2_000',
'mixed' => '1ab',
'underscore_notation' => '2_000',
]);
$this->assertSame(123, $request->integer('int'));
$this->assertSame(456, $request->integer('raw_int'));
Expand All @@ -627,8 +627,8 @@ public function testFloatMethod()
'zero_padded' => '0.78',
'space_padded' => ' 90.1',
'nan' => 'nan',
'mixed'=> '1.ab',
'scientific_notation'=> '1e3',
'mixed' => '1.ab',
'scientific_notation' => '1e3',
]);
$this->assertSame(1.23, $request->float('float'));
$this->assertSame(45.6, $request->float('raw_float'));
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Database/EloquentWhereHasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function dataProviderWhereRelationCallback()
};

return [
'Find user with post.public = true' => $callbackArray(true),
'Find user with post.public = true' => $callbackArray(true),
'Find user with post.public = false' => $callbackArray(false),
];
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Notifications/NotificationDatabaseChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public function testCustomizeTypeIsSentToDatabase()
$notifiable = m::mock();

$notifiable->shouldReceive('routeNotificationFor->create')->with([
'id' => 1,
'type' => 'MONTHLY',
'data' => ['invoice_id' => 1],
'read_at' => null,
'id' => 1,
'type' => 'MONTHLY',
'data' => ['invoice_id' => 1],
'read_at' => null,
'something' => 'else',
]);

Expand Down
9 changes: 4 additions & 5 deletions tests/Queue/QueueDatabaseQueueUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ public function testDelayedPushProperlyPushesJobOntoDatabase()
return $uuid;
});

$queue = $this->getMockBuilder(
DatabaseQueue::class)->onlyMethods(
['currentTime'])->setConstructorArgs(
[$database = m::mock(Connection::class), 'table', 'default']
)->getMock();
$queue = $this->getMockBuilder(DatabaseQueue::class)
->onlyMethods(['currentTime'])
->setConstructorArgs([$database = m::mock(Connection::class), 'table', 'default'])
->getMock();
$queue->expects($this->any())->method('currentTime')->willReturn('time');
$queue->setContainer($container = m::spy(Container::class));
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock(stdClass::class));
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,9 @@ public function testForget()
Arr::forget($array, 1);
$this->assertEquals(['name' => 'hAz', 2 => 'bAz'], $array);

$array = [2 => [1 =>'products', 3 => 'users']];
$array = [2 => [1 => 'products', 3 => 'users']];
Arr::forget($array, 2.3);
$this->assertEquals([2 => [1 =>'products']], $array);
$this->assertEquals([2 => [1 => 'products']], $array);
}

public function testWrap()
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function testSlug()
$this->assertSame('500-dollar-bill', Str::slug('500-$-bill', '-', 'en', ['$' => 'dollar']));
$this->assertSame('500-dollar-bill', Str::slug('500$--bill', '-', 'en', ['$' => 'dollar']));
$this->assertSame('500-dollar-bill', Str::slug('500-$--bill', '-', 'en', ['$' => 'dollar']));
$this->assertSame('أحمد-في-المدرسة', Str::slug('أحمد@المدرسة', '-', null, ['@' =>'في']));
$this->assertSame('أحمد-في-المدرسة', Str::slug('أحمد@المدرسة', '-', null, ['@' => 'في']));
}

public function testStrStart()
Expand Down
20 changes: 10 additions & 10 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4736,71 +4736,71 @@ public function testItemAwareSometimesAddingRules()
{
// ['users'] -> if users is not empty it must be validated as array
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]], ['users.*.name'=> 'required|string']);
$v = new Validator($trans, ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]], ['users.*.name' => 'required|string']);
$v->sometimes(['users'], 'array', function ($i, $item) {
return $item !== null;
});
$this->assertEquals(['users' => ['array'], 'users.0.name' => ['required', 'string'], 'users.1.name' => ['required', 'string']], $v->getRules());

// ['users'] -> if users is null no rules will be applied
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['users' => null], ['users.*.name'=> 'required|string']);
$v = new Validator($trans, ['users' => null], ['users.*.name' => 'required|string']);
$v->sometimes(['users'], 'array', function ($i, $item) {
return (bool) $item;
});
$this->assertEquals([], $v->getRules());

// ['company.users'] -> if users is not empty it must be validated as array
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name'=> 'required|string']);
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name' => 'required|string']);
$v->sometimes(['company.users'], 'array', function ($i, $item) {
return $item->users !== null;
});
$this->assertEquals(['company.users' => ['array'], 'company.users.0.name' => ['required', 'string'], 'company.users.1.name' => ['required', 'string']], $v->getRules());

// ['company.users'] -> if users is null no rules will be applied
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['company' => ['users' => null]], ['company'=> 'required', 'company.users.*.name'=> 'required|string']);
$v = new Validator($trans, ['company' => ['users' => null]], ['company' => 'required', 'company.users.*.name' => 'required|string']);
$v->sometimes(['company.users'], 'array', function ($i, $item) {
return (bool) $item->users;
});
$this->assertEquals(['company' => ['required']], $v->getRules());

// ['company.*'] -> if users is not empty it must be validated as array
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name'=> 'required|string']);
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name' => 'required|string']);
$v->sometimes(['company.*'], 'array', function ($i, $item) {
return $item !== null;
});
$this->assertEquals(['company.users' => ['array'], 'company.users.0.name' => ['required', 'string'], 'company.users.1.name' => ['required', 'string']], $v->getRules());

// ['company.*'] -> if users is null no rules will be applied
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['company' => ['users' => null]], ['company'=> 'required', 'company.users.*.name'=> 'required|string']);
$v = new Validator($trans, ['company' => ['users' => null]], ['company' => 'required', 'company.users.*.name' => 'required|string']);
$v->sometimes(['company.*'], 'array', function ($i, $item) {
return (bool) $item;
});
$this->assertEquals(['company' => ['required']], $v->getRules());

// ['users.*'] -> all nested array items in users must be validated as array
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]], ['users.*.name'=> 'required|string']);
$v = new Validator($trans, ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]], ['users.*.name' => 'required|string']);
$v->sometimes(['users.*'], 'array', function ($i, $item) {
return (bool) $item;
});
$this->assertEquals(['users.0' => ['array'], 'users.1' => ['array'], 'users.0.name' => ['required', 'string'], 'users.1.name' => ['required', 'string']], $v->getRules());

// ['company.users.*'] -> all nested array items in users must be validated as array
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name'=> 'required|string']);
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name' => 'required|string']);
$v->sometimes(['company.users.*'], 'array', function () {
return true;
});
$this->assertEquals(['company.users.0' => ['array'], 'company.users.1' => ['array'], 'company.users.0.name' => ['required', 'string'], 'company.users.1.name' => ['required', 'string']], $v->getRules());

// ['company.*.*'] -> all nested array items in users must be validated as array
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name'=> 'required|string']);
$v = new Validator($trans, ['company' => ['users' => [['name' => 'Taylor'], ['name' => 'Abigail']]]], ['company.users.*.name' => 'required|string']);
$v->sometimes(['company.*.*'], 'array', function ($i, $item) {
return true;
});
Expand Down Expand Up @@ -4905,7 +4905,7 @@ public function testItemAwareSometimesAddingRules()

// ['attendee.*'] -> if attendee name is set, all other fields will be required as well
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['attendee' => ['name' => 'Taylor', 'title' => 'Creator of Laravel', 'type' => 'Developer']], ['attendee.*'=> 'string']);
$v = new Validator($trans, ['attendee' => ['name' => 'Taylor', 'title' => 'Creator of Laravel', 'type' => 'Developer']], ['attendee.*' => 'string']);
$v->sometimes(['attendee.*'], 'required', function ($i, $item) {
return (bool) $item;
});
Expand Down
12 changes: 6 additions & 6 deletions types/Database/Eloquent/ModelNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
/** @var ModelNotFoundException<User> $exception */
$exception = new ModelNotFoundException();

assertType('array<int, int|string>', $exception->getIds());
assertType('class-string<User>', $exception->getModel());
assertType('array<int, int|string>', $exception->getIds());
assertType('class-string<User>', $exception->getModel());

$exception->setModel(User::class, 1);
$exception->setModel(User::class, [1]);
$exception->setModel(User::class, '1');
$exception->setModel(User::class, ['1']);
$exception->setModel(User::class, 1);
$exception->setModel(User::class, [1]);
$exception->setModel(User::class, '1');
$exception->setModel(User::class, ['1']);
2 changes: 1 addition & 1 deletion types/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function ($collection, $name) {
}
)
);
assertType('Illuminate\Support\Collection<int, User>|void', $collection->when(fn () =>'Taylor', function ($collection, $name) {
assertType('Illuminate\Support\Collection<int, User>|void', $collection->when(fn () => 'Taylor', function ($collection, $name) {
assertType('Illuminate\Support\Collection<int, User>', $collection);
assertType('string', $name);
}));
Expand Down

0 comments on commit 11edbfe

Please sign in to comment.