Skip to content

Commit 81d8ba9

Browse files
committed
Merge branch '10.x'
2 parents 23b6adc + 784bf76 commit 81d8ba9

File tree

9 files changed

+153
-27
lines changed

9 files changed

+153
-27
lines changed

src/Illuminate/Database/Console/PruneCommand.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class PruneCommand extends Command
2424
protected $signature = 'model:prune
2525
{--model=* : Class names of the models to be pruned}
2626
{--except=* : Class names of the models to be excluded from pruning}
27+
{--path=* : Absolute path(s) to directories where models are located}
2728
{--chunk=1000 : The number of models to retrieve per chunk of models to be deleted}
2829
{--pretend : Display the number of prunable records found instead of deleting them}';
2930

@@ -125,7 +126,7 @@ protected function models()
125126
throw new InvalidArgumentException('The --models and --except options cannot be combined.');
126127
}
127128

128-
return collect((new Finder)->in($this->getDefaultPath())->files()->name('*.php'))
129+
return collect((new Finder)->in($this->getPath())->files()->name('*.php'))
129130
->map(function ($model) {
130131
$namespace = $this->laravel->getNamespace();
131132

@@ -146,12 +147,18 @@ protected function models()
146147
}
147148

148149
/**
149-
* Get the default path where models are located.
150+
* Get the path where models are located.
150151
*
151-
* @return string|string[]
152+
* @return string[]|string
152153
*/
153-
protected function getDefaultPath()
154+
protected function getPath()
154155
{
156+
if (! empty($path = $this->option('path'))) {
157+
return collect($path)->map(function ($path) {
158+
return base_path($path);
159+
})->all();
160+
}
161+
155162
return app_path('Models');
156163
}
157164

src/Illuminate/Foundation/Bus/PendingChain.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function catchCallbacks()
132132
}
133133

134134
/**
135-
* Dispatch the job with the given arguments.
135+
* Dispatch the job chain.
136136
*
137137
* @return \Illuminate\Foundation\Bus\PendingDispatch
138138
*/
@@ -165,4 +165,26 @@ public function dispatch()
165165

166166
return app(Dispatcher::class)->dispatch($firstJob);
167167
}
168+
169+
/**
170+
* Dispatch the job chain if the given truth test passes.
171+
*
172+
* @param bool|\Closure $boolean
173+
* @return \Illuminate\Foundation\Bus\PendingDispatch|null
174+
*/
175+
public function dispatchIf($boolean)
176+
{
177+
return value($boolean) ? $this->dispatch() : null;
178+
}
179+
180+
/**
181+
* Dispatch the job chain unless the given truth test passes.
182+
*
183+
* @param bool|\Closure $boolean
184+
* @return \Illuminate\Foundation\Bus\PendingDispatch|null
185+
*/
186+
public function dispatchUnless($boolean)
187+
{
188+
return ! value($boolean) ? $this->dispatch() : null;
189+
}
168190
}

src/Illuminate/Mail/Mailable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ public function assertTo($address, $name = null)
12311231

12321232
PHPUnit::assertTrue(
12331233
$this->hasTo($address, $name),
1234-
"Did not see expected recipient [{$recipient}] in email recipients."
1234+
"Did not see expected recipient [{$recipient}] in email 'to' recipients."
12351235
);
12361236

12371237
return $this;
@@ -1264,7 +1264,7 @@ public function assertHasCc($address, $name = null)
12641264

12651265
PHPUnit::assertTrue(
12661266
$this->hasCc($address, $name),
1267-
"Did not see expected recipient [{$recipient}] in email recipients."
1267+
"Did not see expected recipient [{$recipient}] in email 'cc' recipients."
12681268
);
12691269

12701270
return $this;
@@ -1285,7 +1285,7 @@ public function assertHasBcc($address, $name = null)
12851285

12861286
PHPUnit::assertTrue(
12871287
$this->hasBcc($address, $name),
1288-
"Did not see expected recipient [{$recipient}] in email recipients."
1288+
"Did not see expected recipient [{$recipient}] in email 'bcc' recipients."
12891289
);
12901290

12911291
return $this;

src/Illuminate/Support/Number.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,22 @@ public static function format(int|float $number, ?int $precision = null, ?int $m
4646
*
4747
* @param int|float $number
4848
* @param string|null $locale
49+
* @param int|null $after
50+
* @param int|null $until
4951
* @return string
5052
*/
51-
public static function spell(int|float $number, ?string $locale = null)
53+
public static function spell(int|float $number, ?string $locale = null, ?int $after = null, ?int $until = null)
5254
{
5355
static::ensureIntlExtensionIsInstalled();
5456

57+
if (! is_null($after) && $number <= $after) {
58+
return static::format($number, locale: $locale);
59+
}
60+
61+
if (! is_null($until) && $number >= $until) {
62+
return static::format($number, locale: $locale);
63+
}
64+
5565
$formatter = new NumberFormatter($locale ?? static::$locale, NumberFormatter::SPELLOUT);
5666

5767
return $formatter->format($number);

src/Illuminate/Testing/TestView.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ public function assertViewMissing($key)
109109

110110
/**
111111
* Assert that the view's rendered content is empty.
112+
*
113+
* @return $this
112114
*/
113115
public function assertViewEmpty()
114116
{
115117
PHPUnit::assertEmpty($this->rendered);
116118

117-
return true;
119+
return $this;
118120
}
119121

120122
/**

src/Illuminate/View/ComponentAttributeBag.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use ArrayAccess;
66
use ArrayIterator;
7-
use Illuminate\Contracts\Support\Arrayable;
87
use Illuminate\Contracts\Support\Htmlable;
98
use Illuminate\Support\Arr;
109
use Illuminate\Support\HtmlString;
@@ -488,16 +487,6 @@ public function jsonSerialize(): mixed
488487
return $this->attributes;
489488
}
490489

491-
/**
492-
* Convert the object into an array.
493-
*
494-
* @return array
495-
*/
496-
public function toArray()
497-
{
498-
return $this->attributes;
499-
}
500-
501490
/**
502491
* Implode the attributes into a single HTML ready string.
503492
*

tests/Integration/Queue/JobChainingTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,54 @@ public function testBatchConditionable()
496496

497497
$this->assertEquals('sync1', $batch->connection());
498498
}
499+
500+
public function testJobsAreChainedWhenDispatchIfIsTrue()
501+
{
502+
JobChainingTestFirstJob::withChain([
503+
new JobChainingTestSecondJob,
504+
])->dispatchIf(true);
505+
506+
$this->runQueueWorkerCommand(['--stop-when-empty' => true]);
507+
508+
$this->assertTrue(JobChainingTestFirstJob::$ran);
509+
$this->assertTrue(JobChainingTestSecondJob::$ran);
510+
}
511+
512+
public function testJobsAreNotChainedWhenDispatchIfIsFalse()
513+
{
514+
JobChainingTestFirstJob::withChain([
515+
new JobChainingTestSecondJob,
516+
])->dispatchIf(false);
517+
518+
$this->runQueueWorkerCommand(['--stop-when-empty' => true]);
519+
520+
$this->assertFalse(JobChainingTestFirstJob::$ran);
521+
$this->assertFalse(JobChainingTestSecondJob::$ran);
522+
}
523+
524+
public function testJobsAreChainedWhenDispatchUnlessIsFalse()
525+
{
526+
JobChainingTestFirstJob::withChain([
527+
new JobChainingTestSecondJob,
528+
])->dispatchUnless(false);
529+
530+
$this->runQueueWorkerCommand(['--stop-when-empty' => true]);
531+
532+
$this->assertTrue(JobChainingTestFirstJob::$ran);
533+
$this->assertTrue(JobChainingTestSecondJob::$ran);
534+
}
535+
536+
public function testJobsAreNotChainedWhenDispatchUnlessIsTrue()
537+
{
538+
JobChainingTestFirstJob::withChain([
539+
new JobChainingTestSecondJob,
540+
])->dispatchUnless(true);
541+
542+
$this->runQueueWorkerCommand(['--stop-when-empty' => true]);
543+
544+
$this->assertFalse(JobChainingTestFirstJob::$ran);
545+
$this->assertFalse(JobChainingTestSecondJob::$ran);
546+
}
499547
}
500548

501549
class JobChainingTestFirstJob implements ShouldQueue

tests/Mail/MailMailableTest.php

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function render()
6161
$mailable->assertHasTo('[email protected]', 'Taylor Otwell');
6262
$this->fail();
6363
} catch (AssertionFailedError $e) {
64-
$this->assertSame("Did not see expected recipient [[email protected] (Taylor Otwell)] in email recipients.\nFailed asserting that false is true.", $e->getMessage());
64+
$this->assertSame("Did not see expected recipient [[email protected] (Taylor Otwell)] in email 'to' recipients.\nFailed asserting that false is true.", $e->getMessage());
6565
}
6666

6767
$mailable = new WelcomeMailableStub;
@@ -107,7 +107,7 @@ public function render()
107107
if (! is_string($address)) {
108108
$address = json_encode($address);
109109
}
110-
$this->assertSame("Did not see expected recipient [{$address}] in email recipients.\nFailed asserting that false is true.", $e->getMessage());
110+
$this->assertSame("Did not see expected recipient [{$address}] in email 'to' recipients.\nFailed asserting that false is true.", $e->getMessage());
111111
}
112112
}
113113
}
@@ -146,7 +146,7 @@ public function render()
146146
$mailable->assertHasCc('[email protected]', 'Taylor Otwell');
147147
$this->fail();
148148
} catch (AssertionFailedError $e) {
149-
$this->assertSame("Did not see expected recipient [[email protected] (Taylor Otwell)] in email recipients.\nFailed asserting that false is true.", $e->getMessage());
149+
$this->assertSame("Did not see expected recipient [[email protected] (Taylor Otwell)] in email 'cc' recipients.\nFailed asserting that false is true.", $e->getMessage());
150150
}
151151

152152
$mailable = new WelcomeMailableStub;
@@ -204,7 +204,7 @@ public function render()
204204
if (! is_string($address)) {
205205
$address = json_encode($address);
206206
}
207-
$this->assertSame("Did not see expected recipient [{$address}] in email recipients.\nFailed asserting that false is true.", $e->getMessage());
207+
$this->assertSame("Did not see expected recipient [{$address}] in email 'cc' recipients.\nFailed asserting that false is true.", $e->getMessage());
208208
}
209209
}
210210
}
@@ -243,7 +243,7 @@ public function render()
243243
$mailable->assertHasBcc('[email protected]', 'Taylor Otwell');
244244
$this->fail();
245245
} catch (AssertionFailedError $e) {
246-
$this->assertSame("Did not see expected recipient [[email protected] (Taylor Otwell)] in email recipients.\nFailed asserting that false is true.", $e->getMessage());
246+
$this->assertSame("Did not see expected recipient [[email protected] (Taylor Otwell)] in email 'bcc' recipients.\nFailed asserting that false is true.", $e->getMessage());
247247
}
248248

249249
$mailable = new WelcomeMailableStub;
@@ -301,7 +301,7 @@ public function render()
301301
if (! is_string($address)) {
302302
$address = json_encode($address);
303303
}
304-
$this->assertSame("Did not see expected recipient [{$address}] in email recipients.\nFailed asserting that false is true.", $e->getMessage());
304+
$this->assertSame("Did not see expected recipient [{$address}] in email 'bcc' recipients.\nFailed asserting that false is true.", $e->getMessage());
305305
}
306306
}
307307
}
@@ -1133,6 +1133,38 @@ public function build()
11331133

11341134
public function testAssertHasSubject()
11351135
{
1136+
Container::getInstance()->instance('mailer', new class
1137+
{
1138+
public function render()
1139+
{
1140+
//
1141+
}
1142+
});
1143+
1144+
$mailable = new class() extends Mailable
1145+
{
1146+
public function build()
1147+
{
1148+
//
1149+
}
1150+
};
1151+
1152+
try {
1153+
$mailable->assertHasSubject('Foo Subject');
1154+
$this->fail();
1155+
} catch (AssertionFailedError $e) {
1156+
$this->assertSame("Did not see expected text [Foo Subject] in email subject.\nFailed asserting that false is true.", $e->getMessage());
1157+
}
1158+
1159+
$mailable = new class() extends Mailable
1160+
{
1161+
public function build()
1162+
{
1163+
$this->subject('Foo Subject');
1164+
}
1165+
};
1166+
1167+
$mailable->assertHasSubject('Foo Subject');
11361168
}
11371169

11381170
public function testMailableHeadersGetSent()

tests/Support/SupportNumberTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ public function testSpelloutWithLocale()
7777
$this->assertSame('trois', Number::spell(3, 'fr'));
7878
}
7979

80+
public function testSpelloutWithThreshold()
81+
{
82+
$this->needsIntlExtension();
83+
84+
$this->assertSame('9', Number::spell(9, after: 10));
85+
$this->assertSame('10', Number::spell(10, after: 10));
86+
$this->assertSame('eleven', Number::spell(11, after: 10));
87+
88+
$this->assertSame('nine', Number::spell(9, until: 10));
89+
$this->assertSame('10', Number::spell(10, until: 10));
90+
$this->assertSame('11', Number::spell(11, until: 10));
91+
92+
$this->assertSame('ten thousand', Number::spell(10000, until: 50000));
93+
$this->assertSame('100,000', Number::spell(100000, until: 50000));
94+
}
95+
8096
public function testOrdinal()
8197
{
8298
$this->assertSame('1st', Number::ordinal(1));

0 commit comments

Comments
 (0)