Skip to content

Commit bb47918

Browse files
committed
fix conflicts
2 parents d9a6dfa + 3f8c21a commit bb47918

File tree

12 files changed

+291
-22
lines changed

12 files changed

+291
-22
lines changed

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ public function getDefaultOutput()
160160
*/
161161
public function run(Container $container)
162162
{
163-
if ($this->withoutOverlapping) {
164-
$this->cache->put($this->mutexName(), true, 1440);
163+
if ($this->withoutOverlapping &&
164+
! $this->cache->add($this->mutexName(), true, 1440)) {
165+
return;
165166
}
166167

167168
$this->runInBackground

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ public function getQualifiedKeyName()
11051105
}
11061106

11071107
/**
1108-
* Get the auto incrementing key type.
1108+
* Get the auto-incrementing key type.
11091109
*
11101110
* @return string
11111111
*/
@@ -1114,6 +1114,19 @@ public function getKeyType()
11141114
return $this->keyType;
11151115
}
11161116

1117+
/**
1118+
* Set the data type for the primary key.
1119+
*
1120+
* @param string $type
1121+
* @return $this
1122+
*/
1123+
public function setKeyType($type)
1124+
{
1125+
$this->keyType = $type;
1126+
1127+
return $this;
1128+
}
1129+
11171130
/**
11181131
* Get the value indicating whether the IDs are incrementing.
11191132
*

src/Illuminate/Events/CallQueuedListener.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ class CallQueuedListener implements ShouldQueue
3232
*/
3333
public $data;
3434

35+
/**
36+
* The number of times the job may be attempted.
37+
*
38+
* @var int
39+
*/
40+
public $tries;
41+
42+
/**
43+
* The number of seconds the job can run before timing out.
44+
*
45+
* @var int
46+
*/
47+
public $timeout;
48+
3549
/**
3650
* Create a new job instance.
3751
*

src/Illuminate/Events/Dispatcher.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,49 @@ protected function createQueuedHandlerCallable($class, $method)
427427
*/
428428
protected function queueHandler($class, $method, $arguments)
429429
{
430-
$listener = (new ReflectionClass($class))->newInstanceWithoutConstructor();
430+
list($listener, $job) = $this->createListenerAndJob($class, $method, $arguments);
431431

432-
$connection = isset($listener->connection) ? $listener->connection : null;
432+
$connection = $this->resolveQueue()->connection(
433+
isset($listener->connection) ? $listener->connection : null
434+
);
433435

434436
$queue = isset($listener->queue) ? $listener->queue : null;
435437

436-
$this->resolveQueue()
437-
->connection($connection)
438-
->pushOn($queue, new CallQueuedListener($class, $method, $arguments));
438+
isset($listener->delay)
439+
? $connection->laterOn($queue, $listener->delay, $job)
440+
: $connection->pushOn($queue, $job);
441+
}
442+
443+
/**
444+
* Create the listener and job for a queued listener.
445+
*
446+
* @param string $class
447+
* @param string $method
448+
* @param array $arguments
449+
* @return array
450+
*/
451+
protected function createListenerAndJob($class, $method, $arguments)
452+
{
453+
$listener = (new ReflectionClass($class))->newInstanceWithoutConstructor();
454+
455+
return [$listener, $this->propogateListenerOptions(
456+
$listener, new CallQueuedListener($class, $method, $arguments)
457+
)];
458+
}
459+
460+
/**
461+
* Propogate listener options to the job.
462+
*
463+
* @param mixed $listener
464+
* @param mixed $job
465+
* @return mixed
466+
*/
467+
protected function propogateListenerOptions($listener, $job)
468+
{
469+
return tap($job, function ($job) use ($listener) {
470+
$job->tries = isset($listener->tries) ? $listener->tries : null;
471+
$job->timeout = isset($listener->timeout) ? $listener->timeout : null;
472+
});
439473
}
440474

441475
/**

src/Illuminate/Foundation/Console/ListenerMakeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function getOptions()
113113
return [
114114
['event', 'e', InputOption::VALUE_REQUIRED, 'The event class being listened for.'],
115115

116-
['queued', null, InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'],
116+
['queued', 'q', InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'],
117117
];
118118
}
119119
}

src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php

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

55
use Illuminate\Foundation\Testing\Constraints\HasInDatabase;
66
use PHPUnit\Framework\Constraint\LogicalNot as ReverseConstraint;
7+
use Illuminate\Foundation\Testing\Constraints\SoftDeletedInDatabase;
78

89
trait InteractsWithDatabase
910
{
@@ -43,6 +44,23 @@ protected function assertDatabaseMissing($table, array $data, $connection = null
4344
return $this;
4445
}
4546

47+
/**
48+
* Assert the given record has been deleted.
49+
*
50+
* @param string $table
51+
* @param array $data
52+
* @param string $connection
53+
* @return $this
54+
*/
55+
protected function assertSoftDeleted($table, array $data, $connection = null)
56+
{
57+
$this->assertThat(
58+
$table, new SoftDeletedInDatabase($this->getConnection($connection), $data)
59+
);
60+
61+
return $this;
62+
}
63+
4664
/**
4765
* Get the database connection.
4866
*
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace Illuminate\Foundation\Testing\Constraints;
4+
5+
use Illuminate\Database\Connection;
6+
use PHPUnit\Framework\Constraint\Constraint;
7+
8+
class SoftDeletedInDatabase extends Constraint
9+
{
10+
/**
11+
* Number of records that will be shown in the console in case of failure.
12+
*
13+
* @var int
14+
*/
15+
protected $show = 3;
16+
17+
/**
18+
* The database connection.
19+
*
20+
* @var \Illuminate\Database\Connection
21+
*/
22+
protected $database;
23+
24+
/**
25+
* The data that will be used to narrow the search in the database table.
26+
*
27+
* @var array
28+
*/
29+
protected $data;
30+
31+
/**
32+
* Create a new constraint instance.
33+
*
34+
* @param \Illuminate\Database\Connection $database
35+
* @param array $data
36+
* @return void
37+
*/
38+
public function __construct(Connection $database, array $data)
39+
{
40+
$this->data = $data;
41+
42+
$this->database = $database;
43+
}
44+
45+
/**
46+
* Check if the data is found in the given table.
47+
*
48+
* @param string $table
49+
* @return bool
50+
*/
51+
public function matches($table)
52+
{
53+
return $this->database->table($table)
54+
->where($this->data)->whereNotNull('deleted_at')->count() > 0;
55+
}
56+
57+
/**
58+
* Get the description of the failure.
59+
*
60+
* @param string $table
61+
* @return string
62+
*/
63+
public function failureDescription($table)
64+
{
65+
return sprintf(
66+
"any soft deleted row in the table [%s] matches the attributes %s.\n\n%s",
67+
$table, $this->toString(), $this->getAdditionalInfo($table)
68+
);
69+
}
70+
71+
/**
72+
* Get additional info about the records found in the database table.
73+
*
74+
* @param string $table
75+
* @return string
76+
*/
77+
protected function getAdditionalInfo($table)
78+
{
79+
$results = $this->database->table($table)->get();
80+
81+
if ($results->isEmpty()) {
82+
return 'The table is empty';
83+
}
84+
85+
$description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT);
86+
87+
if ($results->count() > $this->show) {
88+
$description .= sprintf(' and %s others', $results->count() - $this->show);
89+
}
90+
91+
return $description;
92+
}
93+
94+
/**
95+
* Get a string representation of the object.
96+
*
97+
* @return string
98+
*/
99+
public function toString()
100+
{
101+
return json_encode($this->data);
102+
}
103+
}

src/Illuminate/Routing/ImplicitRouteBinding.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,33 @@ public static function resolveForRoute($container, $route)
1818
$parameters = $route->parameters();
1919

2020
foreach ($route->signatureParameters(Model::class) as $parameter) {
21-
$class = $parameter->getClass();
21+
if ($route->parameter($parameter->name) instanceof Model) {
22+
continue;
23+
}
24+
25+
$model = $container->make($parameter->getClass()->name);
2226

23-
if (array_key_exists($parameter->name, $parameters) &&
24-
! $route->parameter($parameter->name) instanceof Model) {
25-
$model = $container->make($class->name);
27+
$parameterName = static::checkForParameter($parameter->name, $parameters) ?:
28+
static::checkForParameter(snake_case($parameter->name), $parameters);
2629

27-
$route->setParameter(
28-
$parameter->name, $model->where(
29-
$model->getRouteKeyName(), $parameters[$parameter->name]
30-
)->firstOrFail()
31-
);
30+
if ($parameterName) {
31+
$route->setParameter($parameterName, $model->where(
32+
$model->getRouteKeyName(), $parameters[$parameterName]
33+
)->firstOrFail());
3234
}
3335
}
3436
}
37+
38+
/**
39+
* Return the parameter name if it exists in the given parameters.
40+
*
41+
* @param string $name
42+
* @param array $parameters
43+
* @return string|null
44+
*/
45+
protected static function checkForParameter($name, $parameters)
46+
{
47+
return array_key_exists($name, $parameters)
48+
? $name : null;
49+
}
3550
}

src/Illuminate/Validation/Validator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ protected function isValidatable($rule, $attribute, $value)
417417
{
418418
return $this->presentOrRuleIsImplicit($rule, $attribute, $value) &&
419419
$this->passesOptionalCheck($attribute) &&
420-
$this->isNotNullIfMarkedAsNullable($attribute, $value) &&
420+
$this->isNotNullIfMarkedAsNullable($rule, $attribute) &&
421421
$this->hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute);
422422
}
423423

@@ -470,13 +470,13 @@ protected function passesOptionalCheck($attribute)
470470
/**
471471
* Determine if the attribute fails the nullable check.
472472
*
473+
* @param string $rule
473474
* @param string $attribute
474-
* @param mixed $value
475475
* @return bool
476476
*/
477-
protected function isNotNullIfMarkedAsNullable($attribute, $value)
477+
protected function isNotNullIfMarkedAsNullable($rule, $attribute)
478478
{
479-
if (! $this->hasRule($attribute, ['Nullable'])) {
479+
if (in_array($rule, $this->implicitRules) || ! $this->hasRule($attribute, ['Nullable'])) {
480480
return true;
481481
}
482482

tests/Foundation/FoundationInteractsWithDatabaseTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,34 @@ public function testDontSeeInDatabaseFindsResults()
101101
$this->assertDatabaseMissing($this->table, $this->data);
102102
}
103103

104+
public function testSeeSoftDeletedInDatabaseFindsResults()
105+
{
106+
$this->mockCountBuilder(1);
107+
108+
$this->assertSoftDeleted($this->table, $this->data);
109+
}
110+
111+
/**
112+
* @expectedException \PHPUnit\Framework\ExpectationFailedException
113+
* @expectedExceptionMessage The table is empty.
114+
*/
115+
public function testSeeSoftDeletedInDatabaseDoesNotFindResults()
116+
{
117+
$builder = $this->mockCountBuilder(0);
118+
119+
$builder->shouldReceive('get')->andReturn(collect());
120+
121+
$this->assertSoftDeleted($this->table, $this->data);
122+
}
123+
104124
protected function mockCountBuilder($countResult)
105125
{
106126
$builder = m::mock(Builder::class);
107127

108128
$builder->shouldReceive('where')->with($this->data)->andReturnSelf();
109129

130+
$builder->shouldReceive('whereNotNull')->with('deleted_at')->andReturnSelf();
131+
110132
$builder->shouldReceive('count')->andReturn($countResult);
111133

112134
$this->connection->shouldReceive('table')

0 commit comments

Comments
 (0)