Repository: laravel/framework (php)

Issue:
Collection: sortBy() on multiple attributes doesn't keep original keys
<!-- DO NOT THROW THIS AWAY -->
<!-- Fill out the FULL versions with patch versions -->

- Laravel Version: 9.23.0
- PHP Version: 8.1.8
- Database Driver & Version: N/A

### Description:
After using the [sortBy()](https://laravel.com/docs/9.x/collections#method-sortby) method the sorted collection is supposed to 'keep the original array keys'. And this is what is does, unless you pass an array of sort operations. Then the original keys are lost.

### Steps To Reproduce:

Code:
```php
$data = collect(['a' => ['sort' => 2], 'b' => ['sort' => 1]]);
$data = $data->sortBy([['sort', 'asc']]);

dd($data->all());
```

Expected output:
```php
array:2 [▼
  'b' => array:1 [▼
    "sort" => 1
  ]
  'a' => array:1 [▼
    "sort" => 2
  ]
]
```

Actual output:
```php
array:2 [▼
  0 => array:1 [▼
    "sort" => 1
  ]
  1 => array:1 [▼
    "sort" => 2
  ]
]
```


<!-- If possible, please provide a GitHub repository to demonstrate your issue -->
<!-- laravel new bug-report --github="--public" -->


Pull request description:
Keep original keys when using Collection->sortBy() with an array of sort operations
<!--
Please only send a pull request to branches that are currently supported: https://laravel.com/docs/releases#support-policy 

If you are unsure which branch your pull request should be sent to, please read: https://laravel.com/docs/contributions#which-branch

Pull requests without a descriptive title, thorough description, or tests will be closed.

In addition, please describe the benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.
-->
Fixes #43608 by using `uasort()` instead of `usort()`.

Patch:
diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php
index e311fa773b..62aa1d430c 100644
--- a/src/Illuminate/Collections/Collection.php
+++ b/src/Illuminate/Collections/Collection.php
@@ -1366,7 +1366,7 @@ protected function sortByMany(array $comparisons = [])
     {
         $items = $this->items;
 
-        usort($items, function ($a, $b) use ($comparisons) {
+        uasort($items, function ($a, $b) use ($comparisons) {
             foreach ($comparisons as $comparison) {
                 $comparison = Arr::wrap($comparison);
 
diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php
index f11e90e64f..386dc24dec 100644
--- a/src/Illuminate/Queue/Worker.php
+++ b/src/Illuminate/Queue/Worker.php
@@ -680,6 +680,10 @@ protected function listenForSignals()
     {
         pcntl_async_signals(true);
 
+        pcntl_signal(SIGQUIT, function () {
+            $this->shouldQuit = true;
+        });
+
         pcntl_signal(SIGTERM, function () {
             $this->shouldQuit = true;
         });


Test patch:
diff --git a/tests/Container/ContainerTest.php b/tests/Container/ContainerTest.php
index 7b6568fea1..f16cd0e6dc 100755
--- a/tests/Container/ContainerTest.php
+++ b/tests/Container/ContainerTest.php
@@ -116,6 +116,20 @@ public function testScopedClosureResolution()
         $this->assertSame($firstInstantiation, $secondInstantiation);
     }
 
+    public function testScopedIf()
+    {
+        $container = new Container;
+        $container->scopedIf('class', function () {
+            return 'foo';
+        });
+        $this->assertSame('foo', $container->make('class'));
+        $container->scopedIf('class', function () {
+            return 'bar';
+        });
+        $this->assertSame('foo', $container->make('class'));
+        $this->assertNotSame('bar', $container->make('class'));
+    }
+
     public function testScopedClosureResets()
     {
         $container = new Container;
@@ -275,6 +289,21 @@ public function testResolutionOfDefaultParameters()
         $this->assertSame('taylor', $instance->default);
     }
 
+    public function testBound()
+    {
+        $container = new Container;
+        $container->bind(ContainerConcreteStub::class, function () {
+            //
+        });
+        $this->assertTrue($container->bound(ContainerConcreteStub::class));
+        $this->assertFalse($container->bound(IContainerContractStub::class));
+
+        $container = new Container;
+        $container->bind(IContainerContractStub::class, ContainerConcreteStub::class);
+        $this->assertTrue($container->bound(IContainerContractStub::class));
+        $this->assertFalse($container->bound(ContainerConcreteStub::class));
+    }
+
     public function testUnsetRemoveBoundInstances()
     {
         $container = new Container;
diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php
index 51e51c76dc..2d0cab7eef 100755
--- a/tests/Support/SupportCollectionTest.php
+++ b/tests/Support/SupportCollectionTest.php
@@ -1982,6 +1982,16 @@ public function testSortByAlwaysReturnsAssoc($collection)
         });
 
         $this->assertEquals([1 => 'dayle', 0 => 'taylor'], $data->all());
+
+        $data = new $collection(['a' => ['sort' => 2], 'b' => ['sort' => 1]]);
+        $data = $data->sortBy([['sort', 'asc']]);
+
+        $this->assertEquals(['b' => ['sort' => 1], 'a' => ['sort' => 2]], $data->all());
+
+        $data = new $collection([['sort' => 2], ['sort' => 1]]);
+        $data = $data->sortBy([['sort', 'asc']]);
+
+        $this->assertEquals([1 => ['sort' => 1], 0 => ['sort' => 2]], $data->all());
     }
 
     /**