Skip to content

Commit dcc4b0d

Browse files
committed
Merge branch '8.x' of github.com:laravel/framework into 8.x
2 parents cec579e + 08dbb8b commit dcc4b0d

File tree

10 files changed

+116
-42
lines changed

10 files changed

+116
-42
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,24 @@ public function reduce(callable $callback, $initial = null)
884884
return array_reduce($this->items, $callback, $initial);
885885
}
886886

887+
/**
888+
* Reduce an associative collection to a single value.
889+
*
890+
* @param callable $callback
891+
* @param mixed $initial
892+
* @return mixed
893+
*/
894+
public function reduceWithKeys(callable $callback, $initial = null)
895+
{
896+
$result = $initial;
897+
898+
foreach ($this->items as $key => $value) {
899+
$result = $callback($result, $value, $key);
900+
}
901+
902+
return $result;
903+
}
904+
887905
/**
888906
* Replace the collection items with the given items.
889907
*

src/Illuminate/Collections/LazyCollection.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,24 @@ public function reduce(callable $callback, $initial = null)
845845
return $result;
846846
}
847847

848+
/**
849+
* Reduce an associative collection to a single value.
850+
*
851+
* @param callable $callback
852+
* @param mixed $initial
853+
* @return mixed
854+
*/
855+
public function reduceWithKeys(callable $callback, $initial = null)
856+
{
857+
$result = $initial;
858+
859+
foreach ($this as $key => $value) {
860+
$result = $callback($result, $value, $key);
861+
}
862+
863+
return $result;
864+
}
865+
848866
/**
849867
* Replace the collection items with the given items.
850868
*

src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
256256
// If the type value is null it is probably safe to assume we're eager loading
257257
// the relationship. In this case we'll just pass in a dummy query where we
258258
// need to remove any eager loads that may already be defined on a model.
259-
return is_null($class = $this->getAttributeFromArray($type))
259+
return is_null($class = $this->getAttributeFromArray($type)) || $class === ''
260260
? $this->morphEagerTo($name, $type, $id, $ownerKey)
261261
: $this->morphInstanceTo($class, $name, $type, $id, $ownerKey);
262262
}

src/Illuminate/Queue/Console/RetryCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Queue\Console;
44

5+
use DateTimeInterface;
56
use Illuminate\Console\Command;
67
use Illuminate\Support\Arr;
78

@@ -133,7 +134,11 @@ protected function refreshRetryUntil($payload)
133134
$instance = unserialize($payload['data']['command']);
134135

135136
if (is_object($instance) && method_exists($instance, 'retryUntil')) {
136-
$payload['retryUntil'] = $instance->retryUntil()->timestamp;
137+
$retryUntil = $instance->retryUntil();
138+
139+
$payload['retryUntil'] = $retryUntil instanceof DateTimeInterface
140+
? $retryUntil->getTimestamp()
141+
: $retryUntil;
137142
}
138143

139144
return json_encode($payload);

src/Illuminate/Support/Facades/Session.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @method static bool save()
1414
* @method static bool start()
1515
* @method static mixed get(string $key, $default = null)
16+
* @method static mixed flash(string $class, string $message)
1617
* @method static mixed pull(string $key, $default = null)
1718
* @method static mixed remove(string $key)
1819
* @method static string getId()

src/Illuminate/Support/Testing/Fakes/EventFake.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ public function assertNotDispatched($event, $callback = null)
106106
);
107107
}
108108

109+
/**
110+
* Assert that no events were dispatched.
111+
*
112+
* @return void
113+
*/
114+
public function assertNothingDispatched()
115+
{
116+
$count = count(Arr::flatten($this->events));
117+
118+
PHPUnit::assertSame(
119+
0, $count,
120+
"{$count} unexpected events were dispatched."
121+
);
122+
}
123+
109124
/**
110125
* Get all of the events matching a truth-test callback.
111126
*

src/Illuminate/Testing/PendingCommand.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,24 @@ public function doesntExpectOutput($output)
157157
*/
158158
public function expectsTable($headers, $rows, $tableStyle = 'default', array $columnStyles = [])
159159
{
160-
$this->test->expectedTables[] = [
161-
'headers' => (array) $headers,
162-
'rows' => $rows instanceof Arrayable ? $rows->toArray() : $rows,
163-
'tableStyle' => $tableStyle,
164-
'columnStyles' => $columnStyles,
165-
];
160+
$table = (new Table($output = new BufferedOutput))
161+
->setHeaders((array) $headers)
162+
->setRows($rows instanceof Arrayable ? $rows->toArray() : $rows)
163+
->setStyle($tableStyle);
164+
165+
foreach ($columnStyles as $columnIndex => $columnStyle) {
166+
$table->setColumnStyle($columnIndex, $columnStyle);
167+
}
168+
169+
$table->render();
170+
171+
$lines = array_filter(
172+
explode(PHP_EOL, $output->fetch())
173+
);
174+
175+
foreach ($lines as $line) {
176+
$this->expectsOutput($line);
177+
}
166178

167179
return $this;
168180
}
@@ -305,8 +317,6 @@ private function createABufferedOutputMock()
305317
->shouldAllowMockingProtectedMethods()
306318
->shouldIgnoreMissing();
307319

308-
$this->applyTableOutputExpectations($mock);
309-
310320
foreach ($this->test->expectedOutput as $i => $output) {
311321
$mock->shouldReceive('doWrite')
312322
->once()
@@ -330,38 +340,6 @@ private function createABufferedOutputMock()
330340
return $mock;
331341
}
332342

333-
/**
334-
* Apply the output table expectations to the mock.
335-
*
336-
* @param \Mockery\MockInterface $mock
337-
* @return void
338-
*/
339-
private function applyTableOutputExpectations($mock)
340-
{
341-
foreach ($this->test->expectedTables as $i => $consoleTable) {
342-
$table = (new Table($output = new BufferedOutput))
343-
->setHeaders($consoleTable['headers'])
344-
->setRows($consoleTable['rows'])
345-
->setStyle($consoleTable['tableStyle']);
346-
347-
foreach ($consoleTable['columnStyles'] as $columnIndex => $columnStyle) {
348-
$table->setColumnStyle($columnIndex, $columnStyle);
349-
}
350-
351-
$table->render();
352-
353-
$lines = array_filter(
354-
explode(PHP_EOL, $output->fetch())
355-
);
356-
357-
foreach ($lines as $line) {
358-
$this->expectsOutput($line);
359-
}
360-
361-
unset($this->test->expectedTables[$i]);
362-
}
363-
}
364-
365343
/**
366344
* Flush the expectations from the test case.
367345
*

tests/Database/DatabaseEloquentMorphToTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ public function testMorphToWithZeroMorphType()
100100
$parent->relation();
101101
}
102102

103+
public function testMorphToWithEmptyStringMorphType()
104+
{
105+
$parent = $this->getMockBuilder(EloquentMorphToModelStub::class)->onlyMethods(['getAttributeFromArray', 'morphEagerTo', 'morphInstanceTo'])->getMock();
106+
$parent->method('getAttributeFromArray')->with('relation_type')->willReturn('');
107+
$parent->expects($this->once())->method('morphEagerTo');
108+
$parent->expects($this->never())->method('morphInstanceTo');
109+
110+
$parent->relation();
111+
}
112+
103113
public function testMorphToWithSpecifiedClassDefault()
104114
{
105115
$parent = new EloquentMorphToModelStub;

tests/Support/SupportCollectionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,20 @@ public function testReduce($collection)
35923592
}));
35933593
}
35943594

3595+
/**
3596+
* @dataProvider collectionClassProvider
3597+
*/
3598+
public function testReduceWithKeys($collection)
3599+
{
3600+
$data = new $collection([
3601+
'foo' => 'bar',
3602+
'baz' => 'qux',
3603+
]);
3604+
$this->assertEquals('foobarbazqux', $data->reduceWithKeys(function ($carry, $element, $key) {
3605+
return $carry .= $key.$element;
3606+
}));
3607+
}
3608+
35953609
/**
35963610
* @dataProvider collectionClassProvider
35973611
*/

tests/Support/SupportTestingEventFakeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ function ($event, $payload) {
118118
$fake->assertDispatched('Bar');
119119
$fake->assertNotDispatched('Baz');
120120
}
121+
122+
public function testAssertNothingDispatched()
123+
{
124+
$this->fake->assertNothingDispatched();
125+
126+
$this->fake->dispatch(EventStub::class);
127+
$this->fake->dispatch(EventStub::class);
128+
129+
try {
130+
$this->fake->assertNothingDispatched();
131+
$this->fail();
132+
} catch (ExpectationFailedException $e) {
133+
$this->assertThat($e, new ExceptionMessage('2 unexpected events were dispatched.'));
134+
}
135+
}
121136
}
122137

123138
class EventStub

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy