Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 16, 2017
2 parents d9a6dfa + 3f8c21a commit bb47918
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ public function getDefaultOutput()
*/
public function run(Container $container)
{
if ($this->withoutOverlapping) {
$this->cache->put($this->mutexName(), true, 1440);
if ($this->withoutOverlapping &&
! $this->cache->add($this->mutexName(), true, 1440)) {
return;
}

$this->runInBackground
Expand Down
15 changes: 14 additions & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ public function getQualifiedKeyName()
}

/**
* Get the auto incrementing key type.
* Get the auto-incrementing key type.
*
* @return string
*/
Expand All @@ -1114,6 +1114,19 @@ public function getKeyType()
return $this->keyType;
}

/**
* Set the data type for the primary key.
*
* @param string $type
* @return $this
*/
public function setKeyType($type)
{
$this->keyType = $type;

return $this;
}

/**
* Get the value indicating whether the IDs are incrementing.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Illuminate/Events/CallQueuedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ class CallQueuedListener implements ShouldQueue
*/
public $data;

/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries;

/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout;

/**
* Create a new job instance.
*
Expand Down
44 changes: 39 additions & 5 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,49 @@ protected function createQueuedHandlerCallable($class, $method)
*/
protected function queueHandler($class, $method, $arguments)
{
$listener = (new ReflectionClass($class))->newInstanceWithoutConstructor();
list($listener, $job) = $this->createListenerAndJob($class, $method, $arguments);

$connection = isset($listener->connection) ? $listener->connection : null;
$connection = $this->resolveQueue()->connection(
isset($listener->connection) ? $listener->connection : null
);

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

$this->resolveQueue()
->connection($connection)
->pushOn($queue, new CallQueuedListener($class, $method, $arguments));
isset($listener->delay)
? $connection->laterOn($queue, $listener->delay, $job)
: $connection->pushOn($queue, $job);
}

/**
* Create the listener and job for a queued listener.
*
* @param string $class
* @param string $method
* @param array $arguments
* @return array
*/
protected function createListenerAndJob($class, $method, $arguments)
{
$listener = (new ReflectionClass($class))->newInstanceWithoutConstructor();

return [$listener, $this->propogateListenerOptions(
$listener, new CallQueuedListener($class, $method, $arguments)
)];
}

/**
* Propogate listener options to the job.
*
* @param mixed $listener
* @param mixed $job
* @return mixed
*/
protected function propogateListenerOptions($listener, $job)
{
return tap($job, function ($job) use ($listener) {
$job->tries = isset($listener->tries) ? $listener->tries : null;
$job->timeout = isset($listener->timeout) ? $listener->timeout : null;
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/ListenerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function getOptions()
return [
['event', 'e', InputOption::VALUE_REQUIRED, 'The event class being listened for.'],

['queued', null, InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'],
['queued', 'q', InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Testing\Constraints\HasInDatabase;
use PHPUnit\Framework\Constraint\LogicalNot as ReverseConstraint;
use Illuminate\Foundation\Testing\Constraints\SoftDeletedInDatabase;

trait InteractsWithDatabase
{
Expand Down Expand Up @@ -43,6 +44,23 @@ protected function assertDatabaseMissing($table, array $data, $connection = null
return $this;
}

/**
* Assert the given record has been deleted.
*
* @param string $table
* @param array $data
* @param string $connection
* @return $this
*/
protected function assertSoftDeleted($table, array $data, $connection = null)
{
$this->assertThat(
$table, new SoftDeletedInDatabase($this->getConnection($connection), $data)
);

return $this;
}

/**
* Get the database connection.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace Illuminate\Foundation\Testing\Constraints;

use Illuminate\Database\Connection;
use PHPUnit\Framework\Constraint\Constraint;

class SoftDeletedInDatabase extends Constraint
{
/**
* Number of records that will be shown in the console in case of failure.
*
* @var int
*/
protected $show = 3;

/**
* The database connection.
*
* @var \Illuminate\Database\Connection
*/
protected $database;

/**
* The data that will be used to narrow the search in the database table.
*
* @var array
*/
protected $data;

/**
* Create a new constraint instance.
*
* @param \Illuminate\Database\Connection $database
* @param array $data
* @return void
*/
public function __construct(Connection $database, array $data)
{
$this->data = $data;

$this->database = $database;
}

/**
* Check if the data is found in the given table.
*
* @param string $table
* @return bool
*/
public function matches($table)
{
return $this->database->table($table)
->where($this->data)->whereNotNull('deleted_at')->count() > 0;
}

/**
* Get the description of the failure.
*
* @param string $table
* @return string
*/
public function failureDescription($table)
{
return sprintf(
"any soft deleted row in the table [%s] matches the attributes %s.\n\n%s",
$table, $this->toString(), $this->getAdditionalInfo($table)
);
}

/**
* Get additional info about the records found in the database table.
*
* @param string $table
* @return string
*/
protected function getAdditionalInfo($table)
{
$results = $this->database->table($table)->get();

if ($results->isEmpty()) {
return 'The table is empty';
}

$description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT);

if ($results->count() > $this->show) {
$description .= sprintf(' and %s others', $results->count() - $this->show);
}

return $description;
}

/**
* Get a string representation of the object.
*
* @return string
*/
public function toString()
{
return json_encode($this->data);
}
}
33 changes: 24 additions & 9 deletions src/Illuminate/Routing/ImplicitRouteBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,33 @@ public static function resolveForRoute($container, $route)
$parameters = $route->parameters();

foreach ($route->signatureParameters(Model::class) as $parameter) {
$class = $parameter->getClass();
if ($route->parameter($parameter->name) instanceof Model) {
continue;
}

$model = $container->make($parameter->getClass()->name);

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

$route->setParameter(
$parameter->name, $model->where(
$model->getRouteKeyName(), $parameters[$parameter->name]
)->firstOrFail()
);
if ($parameterName) {
$route->setParameter($parameterName, $model->where(
$model->getRouteKeyName(), $parameters[$parameterName]
)->firstOrFail());
}
}
}

/**
* Return the parameter name if it exists in the given parameters.
*
* @param string $name
* @param array $parameters
* @return string|null
*/
protected static function checkForParameter($name, $parameters)
{
return array_key_exists($name, $parameters)
? $name : null;
}
}
8 changes: 4 additions & 4 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ protected function isValidatable($rule, $attribute, $value)
{
return $this->presentOrRuleIsImplicit($rule, $attribute, $value) &&
$this->passesOptionalCheck($attribute) &&
$this->isNotNullIfMarkedAsNullable($attribute, $value) &&
$this->isNotNullIfMarkedAsNullable($rule, $attribute) &&
$this->hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute);
}

Expand Down Expand Up @@ -470,13 +470,13 @@ protected function passesOptionalCheck($attribute)
/**
* Determine if the attribute fails the nullable check.
*
* @param string $rule
* @param string $attribute
* @param mixed $value
* @return bool
*/
protected function isNotNullIfMarkedAsNullable($attribute, $value)
protected function isNotNullIfMarkedAsNullable($rule, $attribute)
{
if (! $this->hasRule($attribute, ['Nullable'])) {
if (in_array($rule, $this->implicitRules) || ! $this->hasRule($attribute, ['Nullable'])) {
return true;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Foundation/FoundationInteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,34 @@ public function testDontSeeInDatabaseFindsResults()
$this->assertDatabaseMissing($this->table, $this->data);
}

public function testSeeSoftDeletedInDatabaseFindsResults()
{
$this->mockCountBuilder(1);

$this->assertSoftDeleted($this->table, $this->data);
}

/**
* @expectedException \PHPUnit\Framework\ExpectationFailedException
* @expectedExceptionMessage The table is empty.
*/
public function testSeeSoftDeletedInDatabaseDoesNotFindResults()
{
$builder = $this->mockCountBuilder(0);

$builder->shouldReceive('get')->andReturn(collect());

$this->assertSoftDeleted($this->table, $this->data);
}

protected function mockCountBuilder($countResult)
{
$builder = m::mock(Builder::class);

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

$builder->shouldReceive('whereNotNull')->with('deleted_at')->andReturnSelf();

$builder->shouldReceive('count')->andReturn($countResult);

$this->connection->shouldReceive('table')
Expand Down
18 changes: 18 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ public function testModelBindingWithBindingClosure()
$this->assertEquals('tayloralt', $router->dispatch(Request::create('foo/TAYLOR', 'GET'))->getContent());
}

/**
* @group shit
*/
public function testModelBindingWithCompoundParameterName()
{
$router = $this->getRouter();
$router->resource('foo-bar', 'Illuminate\Tests\Routing\RouteTestResourceControllerWithModelParameter', ['middleware' => SubstituteBindings::class]);
$this->assertEquals('12345', $router->dispatch(Request::create('foo-bar/12345', 'GET'))->getContent());
}

public function testModelBindingThroughIOC()
{
$container = new Container;
Expand Down Expand Up @@ -1321,6 +1331,14 @@ public function returnParameter($bar = '')
}
}

class RouteTestResourceControllerWithModelParameter extends Controller
{
public function show(RoutingTestUserModel $fooBar)
{
return $fooBar->value;
}
}

class RouteTestClosureMiddlewareController extends Controller
{
public function __construct()
Expand Down
Loading

0 comments on commit bb47918

Please sign in to comment.