Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/merge' into merge
Browse files Browse the repository at this point in the history
  • Loading branch information
chu121su12 committed Apr 6, 2022
2 parents 976926c + 147f19b commit 53e25d7
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 1 deletion.
50 changes: 50 additions & 0 deletions src/Illuminate/Bus/PendingBatch.php
Expand Up @@ -282,4 +282,54 @@ public function dispatch()

return $batch;
}

/**
* Dispatch the batch after the response is sent to the browser.
*
* @return \Illuminate\Bus\Batch
*/
public function dispatchAfterResponse()
{
$repository = $this->container->make(BatchRepository::class);

$batch = $repository->store($this);

if ($batch) {
$this->container->terminating(function () use ($batch) {
$this->dispatchExistingBatch($batch);
});
}

return $batch;
}

/**
* Dispatch an existing batch.
*
* @param \Illuminate\Bus\Batch $batch
* @return void
*
* @throws \Throwable
*/
protected function dispatchExistingBatch($batch)
{
try {
$batch = $batch->add($this->jobs);
} catch (\Exception $e) {
} catch (\Error $e) {
} catch (Throwable $e) {
}

if (isset($e)) {
if (isset($batch)) {
$batch->delete();
}

throw $e;
}

$this->container->make(EventDispatcher::class)->dispatch(
new BatchDispatched($batch)
);
}
}
2 changes: 2 additions & 0 deletions src/Illuminate/Support/Facades/Queue.php
Expand Up @@ -17,8 +17,10 @@
* @method static mixed pushRaw(string $payload, string $queue = null, array $options = [])
* @method static string getConnectionName()
* @method static void assertNotPushed(string|\Closure $job, callable $callback = null)
* @method static void assertClosureNotPushed(callable $callback = null)
* @method static void assertNothingPushed()
* @method static void assertPushed(string|\Closure $job, callable|int $callback = null)
* @method static void assertClosurePushed(callable|int $callback = null)
* @method static void assertPushedOn(string $queue, string|\Closure $job, callable $callback = null)
* @method static void assertPushedWithChain(string $job, array $expectedChain = [], callable $callback = null)
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Support/Str.php
Expand Up @@ -897,6 +897,17 @@ public static function snake($value, $delimiter = '_')
return static::$snakeCache[$key][$delimiter] = $value;
}

/**
* Remove all "extra" blank space from the given string.
*
* @param string $value
* @return string
*/
public static function squish($value)
{
return preg_replace('/\s+/', ' ', trim($value));
}

/**
* Determine if a given string starts with a given substring.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Support/Stringable.php
Expand Up @@ -626,6 +626,16 @@ public function scan($format)
return collect(sscanf($this->value, $format));
}

/**
* Remove all "extra" blank space from the given string.
*
* @return static
*/
public function squish()
{
return new static(Str::squish($this->value));
}

/**
* Begin a string with a single instance of a given value.
*
Expand Down
27 changes: 27 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/QueueFake.php
Expand Up @@ -5,6 +5,7 @@
use BadMethodCallException;
use Closure;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\ReflectsClosures;
Expand Down Expand Up @@ -201,6 +202,28 @@ protected function assertPushedWithChainOfClasses($job, $expectedChain, $callbac
);
}

/**
* Assert if a closure was pushed based on a truth-test callback.
*
* @param callable|int|null $callback
* @return void
*/
public function assertClosurePushed($callback = null)
{
$this->assertPushed(CallQueuedClosure::class, $callback);
}

/**
* Assert that a closure was not pushed based on a truth-test callback.
*
* @param callable|null $callback
* @return void
*/
public function assertClosureNotPushed($callback = null)
{
$this->assertNotPushed(CallQueuedClosure::class, $callback);
}

/**
* Determine if the given chain is entirely composed of objects.
*
Expand Down Expand Up @@ -311,6 +334,10 @@ public function size($queue = null)
public function push($job, $data = '', $queue = null)
{
if ($this->shouldFakeJob($job)) {
if ($job instanceof Closure) {
$job = CallQueuedClosure::create($job);
}

$this->jobs[is_object($job) ? get_class($job) : $job][] = [
'job' => $job,
'queue' => $queue,
Expand Down
19 changes: 19 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Expand Up @@ -1687,6 +1687,25 @@ public function validateRequiredUnless($attribute, $value, $parameters)
return true;
}

/**
* Indicate that an attribute should be excluded when another attribute presents.
*
* @param string $attribute
* @param mixed $value
* @param mixed $parameters
* @return bool
*/
public function validateExcludeWith($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'exclude_with');

if (! Arr::has($this->data, $parameters[0])) {
return true;
}

return false;
}

/**
* Indicate that an attribute should be excluded when another attribute is missing.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Validation/Validator.php
Expand Up @@ -231,6 +231,7 @@ class Validator implements ValidatorContract
'Different',
'ExcludeIf',
'ExcludeUnless',
'ExcludeWith',
'ExcludeWithout',
'Gt',
'Gte',
Expand All @@ -257,7 +258,7 @@ class Validator implements ValidatorContract
*
* @var string[]
*/
protected $excludeRules = ['Exclude', 'ExcludeIf', 'ExcludeUnless', 'ExcludeWithout'];
protected $excludeRules = ['Exclude', 'ExcludeIf', 'ExcludeUnless', 'ExcludeWith', 'ExcludeWithout'];

/**
* The size related validation rules.
Expand Down
11 changes: 11 additions & 0 deletions tests/Support/SupportStrTest.php
Expand Up @@ -540,6 +540,17 @@ public function testSnake()
$this->assertSame('żółtałódka', Str::snake('ŻółtaŁódka'));
}

public function testSquish()
{
$this->assertSame('laravel php framework', Str::squish(' laravel php framework '));
$this->assertSame('laravel php framework', Str::squish("laravel\t\tphp\n\nframework"));
$this->assertSame('laravel php framework', Str::squish('
laravel
php
framework
'));
}

public function testStudly()
{
$this->assertSame('LaravelPHPFramework', Str::studly('laravel_p_h_p_framework'));
Expand Down
11 changes: 11 additions & 0 deletions tests/Support/SupportStringableTest.php
Expand Up @@ -611,6 +611,17 @@ public function testSlug()
$this->assertSame('', (string) $this->stringable('')->slug());
}

public function testSquish()
{
$this->assertSame('words with spaces', (string) $this->stringable(' words with spaces ')->squish());
$this->assertSame('words with spaces', (string) $this->stringable("words\t\twith\n\nspaces")->squish());
$this->assertSame('words with spaces', (string) $this->stringable('
words
with
spaces
')->squish());
}

public function testStart()
{
$this->assertSame('/test/string', (string) $this->stringable('test/string')->start('/'));
Expand Down
29 changes: 29 additions & 0 deletions tests/Support/SupportTestingQueueFakeTest.php
Expand Up @@ -332,6 +332,35 @@ public function testCallUndefinedMethodErrorHandling()
)));
}
}

public function testAssertClosurePushed()
{
$this->fake->push(function () {
// Do nothing
});

$this->fake->assertClosurePushed();
}

public function testAssertClosurePushedWithTimes()
{
$this->fake->push(function () {
// Do nothing
});

$this->fake->push(function () {
// Do nothing
});

$this->fake->assertClosurePushed(2);
}

public function testAssertClosureNotPushed()
{
$this->fake->push($this->job);

$this->fake->assertClosureNotPushed();
}
}

class JobStub
Expand Down
20 changes: 20 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Expand Up @@ -7013,6 +7013,26 @@ public function testExcludeValuesAreReallyRemoved()
$this->assertSame(['mouse' => null], $validator->invalid());
}

public function testExcludeWithValuesAreReallyRemoved()
{
$validator = new Validator(
$this->getIlluminateArrayTranslator(),
[
'cat' => 'Tom',
'mouse' => 'Jerry',
],
[
'cat' => 'string',
'mouse' => 'string|exclude_with:cat',
]
);

$this->assertTrue($validator->passes());
$this->assertSame(['cat' => 'Tom'], $validator->validated());
$this->assertSame(['cat' => 'Tom'], $validator->valid());
$this->assertSame([], $validator->invalid());
}

public function testValidateFailsWithAsterisksAsDataKeys()
{
$post = ['data' => [0 => ['date' => '2019-01-24'], 1 => ['date' => 'blah'], '*' => ['date' => 'blah']]];
Expand Down

0 comments on commit 53e25d7

Please sign in to comment.