language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | laravel | framework | 8ccc8f4ed5cde0bca666def9acdd8aa31eecdd6e.json | Replace strlen() with is_null() | src/Illuminate/Database/Eloquent/Model.php | @@ -2501,7 +2501,7 @@ public function isDirty($attribute = null)
{
$dirtyAttributes = $this->getDirty();
- if (strlen($attribute) > 0) return array_key_exists($attribute, $dirtyAttributes);
+ if ( ! is_null($attribute)) return array_key_exists($attribute, $dirtyAttributes);
return count($dirtyAttributes) > 0;
} | false |
Other | laravel | framework | 24ec1591c3cc3f5624071f3989521f45e2a6ee08.json | fix param count for unique and exists | src/Illuminate/Validation/Validator.php | @@ -870,7 +870,7 @@ protected function validateNotIn($attribute, $value, $parameters)
*/
protected function validateUnique($attribute, $value, $parameters)
{
- $this->requireParameterCount(2, $parameters, 'unique');
+ $this->requireParameterCount(1, $parameters, 'unique');
$table = $parameters[0];
@@ -943,7 +943,7 @@ protected function getUniqueExtra($parameters)
*/
protected function validateExists($attribute, $value, $parameters)
{
- $this->requireParameterCount(2, $parameters, 'exists');
+ $this->requireParameterCount(1, $parameters, 'exists');
$table = $parameters[0];
| false |
Other | laravel | framework | fd8b6bb6a93772822170c3d86659313f00612106.json | Add check for parameter count | src/Illuminate/Validation/Validator.php | @@ -560,6 +560,8 @@ protected function validateRequiredWithoutAll($attribute, $value, $parameters)
*/
protected function validateRequiredIf($attribute, $value, $parameters)
{
+ $this->requireParameterCount(2, $parameters, 'required_if');
+
if ($parameters[1] == array_get($this->data, $parameters[0]))
{
return $this->validateRequired($attribute, $value);
@@ -611,6 +613,8 @@ protected function validateConfirmed($attribute, $value)
*/
protected function validateSame($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'same');
+
$other = array_get($this->data, $parameters[0]);
return (isset($other) && $value == $other);
@@ -626,6 +630,8 @@ protected function validateSame($attribute, $value, $parameters)
*/
protected function validateDifferent($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'different');
+
$other = $parameters[0];
return isset($this->data[$other]) && $value != $this->data[$other];
@@ -693,6 +699,8 @@ protected function validateInteger($attribute, $value)
*/
protected function validateDigits($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'digits');
+
return $this->validateNumeric($attribute, $value)
&& strlen((string) $value) == $parameters[0];
}
@@ -707,6 +715,8 @@ protected function validateDigits($attribute, $value, $parameters)
*/
protected function validateDigitsBetween($attribute, $value, $parameters)
{
+ $this->requireParameterCount(2, $parameters, 'digits_between');
+
$length = strlen((string) $value);
return $length >= $parameters[0] && $length <= $parameters[1];
@@ -722,6 +732,8 @@ protected function validateDigitsBetween($attribute, $value, $parameters)
*/
protected function validateSize($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'size');
+
return $this->getSize($attribute, $value) == $parameters[0];
}
@@ -735,6 +747,8 @@ protected function validateSize($attribute, $value, $parameters)
*/
protected function validateBetween($attribute, $value, $parameters)
{
+ $this->requireParameterCount(2, $parameters, 'between');
+
$size = $this->getSize($attribute, $value);
return $size >= $parameters[0] && $size <= $parameters[1];
@@ -750,6 +764,8 @@ protected function validateBetween($attribute, $value, $parameters)
*/
protected function validateMin($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'min');
+
return $this->getSize($attribute, $value) >= $parameters[0];
}
@@ -763,6 +779,8 @@ protected function validateMin($attribute, $value, $parameters)
*/
protected function validateMax($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'max');
+
if ($value instanceof UploadedFile && ! $value->isValid()) return false;
return $this->getSize($attribute, $value) <= $parameters[0];
@@ -852,6 +870,8 @@ protected function validateNotIn($attribute, $value, $parameters)
*/
protected function validateUnique($attribute, $value, $parameters)
{
+ $this->requireParameterCount(2, $parameters, 'unique');
+
$table = $parameters[0];
// The second parameter position holds the name of the column that needs to
@@ -923,6 +943,8 @@ protected function getUniqueExtra($parameters)
*/
protected function validateExists($attribute, $value, $parameters)
{
+ $this->requireParameterCount(2, $parameters, 'exists');
+
$table = $parameters[0];
// The second parameter position holds the name of the column that should be
@@ -1120,6 +1142,8 @@ protected function validateAlphaDash($attribute, $value)
*/
protected function validateRegex($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'regex');
+
return preg_match($parameters[0], $value);
}
@@ -1151,6 +1175,8 @@ protected function validateDate($attribute, $value)
*/
protected function validateDateFormat($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'date');
+
$parsed = date_parse_from_format($parameters[0], $value);
return $parsed['error_count'] === 0 && $parsed['warning_count'] === 0;
@@ -1166,6 +1192,8 @@ protected function validateDateFormat($attribute, $value, $parameters)
*/
protected function validateBefore($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'before');
+
if ( ! ($date = strtotime($parameters[0])))
{
return strtotime($value) < strtotime($this->getValue($parameters[0]));
@@ -1186,6 +1214,8 @@ protected function validateBefore($attribute, $value, $parameters)
*/
protected function validateAfter($attribute, $value, $parameters)
{
+ $this->requireParameterCount(1, $parameters, 'after');
+
if ( ! ($date = strtotime($parameters[0])))
{
return strtotime($value) > strtotime($this->getValue($parameters[0]));
@@ -2150,6 +2180,23 @@ protected function callClassBasedReplacer($callback, $message, $attribute, $rule
return call_user_func_array(array($this->container->make($class), $method), array_slice(func_get_args(), 1));
}
+ /**
+ * Require a certain number of parameters to be present.
+ *
+ * @param int $count
+ * @param array $parametrers
+ * @param string $rule
+ * @return void
+ * @throws \InvalidArgumentException
+ */
+ protected function requireParameterCount($count, array $parametrers, $rule)
+ {
+ if (count($parameters) < $count)
+ {
+ throw new \InvalidArgumentException("Validation rule $rule requires at least $count parameters.");
+ }
+ }
+
/**
* Handle dynamic calls to class methods.
* | false |
Other | laravel | framework | 5bcdcbaa6fd30cfc3aee851af17954a37453e915.json | Fix code style | src/Illuminate/Support/MessageBag.php | @@ -60,7 +60,8 @@ public function add($key, $message)
*/
public function merge($messages)
{
- if ($messages instanceof MessageProviderInterface) {
+ if ($messages instanceof MessageProviderInterface)
+ {
$messages = $messages->getMessageBag()->getMessages();
}
| false |
Other | laravel | framework | cb0b6ba6ba26137493fd9c03dfdfecbaeba7ca85.json | fix validator docblocks | src/Illuminate/Validation/Validator.php | @@ -126,6 +126,7 @@ class Validator implements MessageProviderInterface {
* @param array $data
* @param array $rules
* @param array $messages
+ * @param array $customAttributes
* @return void
*/
public function __construct(TranslatorInterface $translator, $data, $rules, $messages = array(), $customAttributes = array())
@@ -388,8 +389,6 @@ protected function addError($attribute, $rule, $parameters)
*
* Always returns true, just lets us put sometimes in rules.
*
- * @param string $attribute
- * @param mixed $value
* @return bool
*/
protected function validateSometimes()
@@ -608,7 +607,7 @@ protected function validateConfirmed($attribute, $value)
* @param string $attribute
* @param mixed $value
* @param array $parameters
- * @return void
+ * @return bool
*/
protected function validateSame($attribute, $value, $parameters)
{
@@ -2003,7 +2002,7 @@ public function setCustomMessages(array $messages)
/**
* Get the fallback messages for the validator.
*
- * @return void
+ * @return array
*/
public function getFallbackMessages()
{ | false |
Other | laravel | framework | a656d2d8ac3906347ad838b95de5c3d9b2e12066.json | Fix Beanstalkd tests | tests/Queue/QueueBeanstalkdQueueTest.php | @@ -12,7 +12,7 @@ public function tearDown()
public function testPushProperlyPushesJobOntoBeanstalkd()
{
- $queue = new Illuminate\Queue\BeanstalkdQueue(m::mock('Pheanstalk_Pheanstalk'), 'default');
+ $queue = new Illuminate\Queue\BeanstalkdQueue(m::mock('Pheanstalk_Pheanstalk'), 'default', 60);
$pheanstalk = $queue->getPheanstalk();
$pheanstalk->shouldReceive('useTube')->once()->with('stack')->andReturn($pheanstalk);
$pheanstalk->shouldReceive('useTube')->once()->with('default')->andReturn($pheanstalk);
@@ -25,7 +25,7 @@ public function testPushProperlyPushesJobOntoBeanstalkd()
public function testDelayedPushProperlyPushesJobOntoBeanstalkd()
{
- $queue = new Illuminate\Queue\BeanstalkdQueue(m::mock('Pheanstalk_Pheanstalk'), 'default');
+ $queue = new Illuminate\Queue\BeanstalkdQueue(m::mock('Pheanstalk_Pheanstalk'), 'default', 60);
$pheanstalk = $queue->getPheanstalk();
$pheanstalk->shouldReceive('useTube')->once()->with('stack')->andReturn($pheanstalk);
$pheanstalk->shouldReceive('useTube')->once()->with('default')->andReturn($pheanstalk);
@@ -38,7 +38,7 @@ public function testDelayedPushProperlyPushesJobOntoBeanstalkd()
public function testPopProperlyPopsJobOffOfBeanstalkd()
{
- $queue = new Illuminate\Queue\BeanstalkdQueue(m::mock('Pheanstalk_Pheanstalk'), 'default');
+ $queue = new Illuminate\Queue\BeanstalkdQueue(m::mock('Pheanstalk_Pheanstalk'), 'default', 60);
$queue->setContainer(m::mock('Illuminate\Container\Container'));
$pheanstalk = $queue->getPheanstalk();
$pheanstalk->shouldReceive('watchOnly')->once()->with('default')->andReturn($pheanstalk);
| false |
Other | laravel | framework | 2038e4e625de390991d2ba5a027d7ca4ed1330b3.json | Add TTR to Beanstalkd... | src/Illuminate/Queue/BeanstalkdQueue.php | @@ -20,17 +20,25 @@ class BeanstalkdQueue extends Queue implements QueueInterface {
*/
protected $default;
+ /**
+ * The timeout for workers
+ *
+ * @var int
+ */
+ protected $ttr;
+
/**
* Create a new Beanstalkd queue instance.
*
* @param Pheanstalk $pheanstalk
* @param string $default
* @return void
*/
- public function __construct(Pheanstalk $pheanstalk, $default)
+ public function __construct(Pheanstalk $pheanstalk, $default, $ttr)
{
- $this->default = $default;
+ $this->default = $default;
$this->pheanstalk = $pheanstalk;
+ $this->ttr = $ttr;
}
/**
@@ -56,7 +64,7 @@ public function push($job, $data = '', $queue = null)
*/
public function pushRaw($payload, $queue = null, array $options = array())
{
- return $this->pheanstalk->useTube($this->getQueue($queue))->put($payload);
+ return $this->pheanstalk->useTube($this->getQueue($queue))->put($payload, Pheanstalk::DEFAULT_PRIORITY, PheanstalkInterface::DEFAULT_DELAY, $this->ttr);
}
/**
| true |
Other | laravel | framework | 2038e4e625de390991d2ba5a027d7ca4ed1330b3.json | Add TTR to Beanstalkd... | src/Illuminate/Queue/Connectors/BeanstalkdConnector.php | @@ -15,7 +15,9 @@ public function connect(array $config)
{
$pheanstalk = new Pheanstalk($config['host']);
- return new BeanstalkdQueue($pheanstalk, $config['queue']);
+ $config['ttr'] = isset($config['ttr']) ? $config['ttr'] : Pheanstalk::DEFAULT_TTR;
+
+ return new BeanstalkdQueue($pheanstalk, $config['queue'], $config['ttr']);
}
}
\ No newline at end of file | true |
Other | laravel | framework | 9bcd9c16aa493bc8825d1ae2885195a063bfa0b1.json | Add blank line at EOF | src/Illuminate/Queue/Console/stubs/failed_jobs.stub | @@ -32,4 +32,4 @@ class CreateFailedJobsTable extends Migration {
Schema::drop('failed_jobs');
}
-}
\ No newline at end of file
+} | false |
Other | laravel | framework | 8b0276809f17d0414f6e3d429cd19c6bfdd617fd.json | Simplify method. Fix bug. | src/Illuminate/Database/Eloquent/Builder.php | @@ -601,8 +601,8 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
}
else
{
- return call_user_func_array(
- array($this->query, 'where'), array_slice(func_get_args(), 0, func_num_args())
+ call_user_func_array(
+ array($this->query, 'where'), func_get_args()
);
}
| false |
Other | laravel | framework | f2d4bef8c0bf301bcad398f1e15ce8d0dfe9e48a.json | Fix variable typo. | src/Illuminate/Database/Eloquent/Model.php | @@ -335,7 +335,7 @@ public static function getGlobalScope($scope)
{
return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope)
{
- return $scope instanceof $registered;
+ return $scope instanceof $value;
});
}
| false |
Other | laravel | framework | c30ae3528e5ea831beff8585bf5e244458fd2755.json | Add missing changes and a test. | src/Illuminate/Pagination/Paginator.php | @@ -93,15 +93,29 @@ class Paginator implements ArrayableInterface, ArrayAccess, Countable, IteratorA
* @param \Illuminate\Pagination\Factory $factory
* @param array $items
* @param int $total
- * @param int $perPage
+ * @param mixed $perPage
* @return void
*/
- public function __construct(Factory $factory, array $items, $total, $perPage)
+ public function __construct(Factory $factory, array $items, $total, $perPage = null)
{
- $this->items = $items;
$this->factory = $factory;
- $this->total = (int) $total;
- $this->perPage = (int) $perPage;
+
+ // Paginator received only 3 parameters which means that it's being used
+ // in cursor mode. In this mode third argument $total is used as $perPage.
+ if (is_null($perPage))
+ {
+ $this->items = array_slice($items, 0, $perPage);
+ $this->perPage = (int) $total;
+
+ $cursor = array_slice($items, $this->perPage, 1);
+ $this->cursor = empty($cursor) ? null : $cursor[0];
+ }
+ else
+ {
+ $this->items = $items;
+ $this->total = (int) $total;
+ $this->perPage = (int) $perPage;
+ }
}
/** | true |
Other | laravel | framework | c30ae3528e5ea831beff8585bf5e244458fd2755.json | Add missing changes and a test. | tests/Pagination/PaginationPaginatorTest.php | @@ -22,6 +22,18 @@ public function testPaginationContextIsSetupCorrectly()
}
+ public function testPaginationContextIsSetupCorrectlyInCursorMode()
+ {
+ $p = new Paginator($factory = m::mock('Illuminate\Pagination\Factory'), array('foo', 'bar', 'baz'), 2);
+ $factory->shouldReceive('getCurrentPage')->once()->andReturn(1);
+ $p->setupPaginationContext();
+
+ $this->assertEquals(2, $p->getLastPage());
+ $this->assertEquals(1, $p->getCurrentPage());
+ $this->assertEquals('baz', $p->getCursor());
+ }
+
+
public function testPaginationContextSetsUpRangeCorrectly()
{
$p = new Paginator($factory = m::mock('Illuminate\Pagination\Factory'), array('foo', 'bar', 'baz'), 3, 2); | true |
Other | laravel | framework | f358e0dcb4e8ac37bf19f4a707f45413068d7693.json | Add cursor mode to DB and paginator (no conflict). | src/Illuminate/Database/Eloquent/Builder.php | @@ -269,6 +269,26 @@ protected function ungroupedPaginate($paginator, $perPage, $columns)
return $paginator->make($this->get($columns)->all(), $total, $perPage);
}
+ /**
+ * Get a paginator in cursor mode for the "select" statement.
+ *
+ * @param int $perPage
+ * @param array $columns
+ * @return \Illuminate\Pagination\Paginator
+ */
+ public function cursor($perPage = null, $columns = array('*'))
+ {
+ $paginator = $this->query->getConnection()->getPaginator();
+
+ $page = $paginator->getCurrentPage();
+ $perPage = $perPage ?: $this->model->getPerPage();
+
+ // Use skip method to set correct offset and take perPage + 1 items.
+ $this->query->skip(($page - 1) * $perPage)->take($perPage + 1);
+
+ return $paginator->make($this->get($columns)->all(), $perPage);
+ }
+
/**
* Update a record in the database.
* | true |
Other | laravel | framework | f358e0dcb4e8ac37bf19f4a707f45413068d7693.json | Add cursor mode to DB and paginator (no conflict). | src/Illuminate/Database/Query/Builder.php | @@ -1506,6 +1506,26 @@ public function getPaginationCount()
return $total;
}
+ /**
+ * Get a paginator in cursor mode for the "select" statement.
+ *
+ * @param int $perPage
+ * @param array $columns
+ * @return \Illuminate\Pagination\Paginator
+ */
+ public function cursor($perPage = null, $columns = array('*'))
+ {
+ $paginator = $this->connection->getPaginator();
+
+ $page = $paginator->getCurrentPage();
+ $perPage = $perPage ?: $this->model->getPerPage();
+
+ // Use skip method to set correct offset and take perPage + 1 items.
+ $this->skip(($page - 1) * $perPage)->take($perPage + 1);
+
+ return $paginator->make($this->get($columns), $perPage);
+ }
+
/**
* Determine if any rows exist for the current query.
* | true |
Other | laravel | framework | f358e0dcb4e8ac37bf19f4a707f45413068d7693.json | Add cursor mode to DB and paginator (no conflict). | src/Illuminate/Pagination/Factory.php | @@ -95,10 +95,10 @@ protected function setupPaginationEnvironment()
*
* @param array $items
* @param int $total
- * @param int $perPage
+ * @param mixed $perPage
* @return \Illuminate\Pagination\Paginator
*/
- public function make(array $items, $total, $perPage)
+ public function make(array $items, $total, $perPage = null)
{
$paginator = new Paginator($this, $items, $total, $perPage);
| true |
Other | laravel | framework | f358e0dcb4e8ac37bf19f4a707f45413068d7693.json | Add cursor mode to DB and paginator (no conflict). | src/Illuminate/Pagination/Paginator.php | @@ -31,6 +31,13 @@ class Paginator implements ArrayableInterface, ArrayAccess, Countable, IteratorA
*/
protected $total;
+ /**
+ * Item, array or object indicating if next page is available.
+ *
+ * @var mixed
+ */
+ protected $cursor;
+
/**
* The amount of items to show per page.
*
@@ -118,9 +125,19 @@ public function setupPaginationContext()
*/
protected function calculateCurrentAndLastPages()
{
- $this->lastPage = (int) ceil($this->total / $this->perPage);
+ if (is_null($this->total))
+ {
+ $page = $this->factory->getCurrentPage();
+ $this->currentPage = $this->isValidPageNumber($page) ? (int) $page : 1;
+
+ $this->lastPage = is_null($this->cursor) ? $this->currentPage : $this->currentPage + 1;
+ }
+ else
+ {
+ $this->lastPage = (int) ceil($this->total / $this->perPage);
- $this->currentPage = $this->calculateCurrentPage($this->lastPage);
+ $this->currentPage = $this->calculateCurrentPage($this->lastPage);
+ }
}
/**
@@ -369,6 +386,16 @@ public function getTotal()
return $this->total;
}
+ /**
+ * Get cursor for this paginator.
+ *
+ * @return mixed
+ */
+ public function getCursor()
+ {
+ return $this->cursor;
+ }
+
/**
* Set the base URL in use by the paginator.
* | true |
Other | laravel | framework | f358e0dcb4e8ac37bf19f4a707f45413068d7693.json | Add cursor mode to DB and paginator (no conflict). | tests/Database/DatabaseEloquentBuilderTest.php | @@ -220,6 +220,31 @@ public function testPaginateMethodWithGroupedQuery()
}
+ public function testCursorMethod()
+ {
+ $query = $this->getMock('Illuminate\Database\Query\Builder', array('from', 'getConnection', 'skip', 'take'), array(
+ m::mock('Illuminate\Database\ConnectionInterface'),
+ m::mock('Illuminate\Database\Query\Grammars\Grammar'),
+ m::mock('Illuminate\Database\Query\Processors\Processor'),
+ ));
+ $query->expects($this->once())->method('from')->will($this->returnValue('foo_table'));
+ $builder = $this->getMock('Illuminate\Database\Eloquent\Builder', array('get'), array($query));
+ $builder->setModel($this->getMockModel());
+ $builder->getModel()->shouldReceive('getPerPage')->once()->andReturn(15);
+ $conn = m::mock('stdClass');
+ $paginator = m::mock('stdClass');
+ $paginator->shouldReceive('getCurrentPage')->once()->andReturn(1);
+ $conn->shouldReceive('getPaginator')->once()->andReturn($paginator);
+ $query->expects($this->once())->method('getConnection')->will($this->returnValue($conn));
+ $query->expects($this->once())->method('skip')->with(0)->will($this->returnValue($query));
+ $query->expects($this->once())->method('take')->with(16)->will($this->returnValue($query));
+ $builder->expects($this->once())->method('get')->with($this->equalTo(array('*')))->will($this->returnValue(new Collection(array('results'))));
+ $paginator->shouldReceive('make')->once()->with(array('results'), 15)->andReturn(array('results'));
+
+ $this->assertEquals(array('results'), $builder->cursor());
+ }
+
+
public function testGetModelsProperlyHydratesModels()
{
$builder = m::mock('Illuminate\Database\Eloquent\Builder[get]', array($this->getMockQueryBuilder())); | true |
Other | laravel | framework | f358e0dcb4e8ac37bf19f4a707f45413068d7693.json | Add cursor mode to DB and paginator (no conflict). | tests/Database/DatabaseQueryBuilderTest.php | @@ -587,6 +587,24 @@ public function testGetPaginationCountGetsResultCount()
}
+ public function testCursorCorrectlyCreatesPaginatorInstance()
+ {
+ $connection = m::mock('Illuminate\Database\ConnectionInterface');
+ $grammar = m::mock('Illuminate\Database\Query\Grammars\Grammar');
+ $processor = m::mock('Illuminate\Database\Query\Processors\Processor');
+ $builder = $this->getMock('Illuminate\Database\Query\Builder', array('skip', 'take', 'get'), array($connection, $grammar, $processor));
+ $paginator = m::mock('Illuminate\Pagination\Environment');
+ $paginator->shouldReceive('getCurrentPage')->once()->andReturn(1);
+ $connection->shouldReceive('getPaginator')->once()->andReturn($paginator);
+ $builder->expects($this->once())->method('skip')->with($this->equalTo(0))->will($this->returnValue($builder));
+ $builder->expects($this->once())->method('take')->with($this->equalTo(16))->will($this->returnValue($builder));
+ $builder->expects($this->once())->method('get')->with($this->equalTo(array('*')))->will($this->returnValue(array('foo')));
+ $paginator->shouldReceive('make')->once()->with(array('foo'), 15)->andReturn(array('results'));
+
+ $this->assertEquals(array('results'), $builder->cursor(15, array('*')));
+ }
+
+
public function testPluckMethodReturnsSingleColumn()
{
$builder = $this->getBuilder(); | true |
Other | laravel | framework | 505957ad634e8d107507755075c8d41805c28098.json | Fix present count. | src/Illuminate/Validation/Validator.php | @@ -581,7 +581,7 @@ protected function getPresentCount($attributes)
foreach ($attributes as $key)
{
- if ( ! is_null(array_get($this->data, $key, null)) || ! is_null(array_get($this->files, $key, null)))
+ if (array_get($this->data, $key) || array_get($this->files, $key))
{
$count++;
} | false |
Other | laravel | framework | 114d33dd940ccea8cbacbc400409a9b9b5bef131.json | Fix multiple methods on routes command. | src/Illuminate/Foundation/Console/RoutesCommand.php | @@ -109,7 +109,7 @@ protected function getRoutes()
*/
protected function getRouteInformation(Route $route)
{
- $uri = head($route->methods()).' '.$route->uri();
+ $uri = implode('|', $route->methods()).' '.$route->uri();
return $this->filterRoute(array(
'host' => $route->domain(), | false |
Other | laravel | framework | 5c6c2bb3de560d6ff119b9107a2036416372891a.json | use php 5.4 closures see #3687 | src/Illuminate/Database/Eloquent/Builder.php | @@ -519,14 +519,12 @@ protected function loadRelation(array $models, $name, Closure $constraints)
*/
public function getRelation($relation)
{
- $me = $this;
-
// We want to run a relationship query without any constrains so that we will
// not have to remove these where clauses manually which gets really hacky
// and is error prone while we remove the developer's own where clauses.
- $query = Relation::noConstraints(function() use ($me, $relation)
+ $query = Relation::noConstraints(function() use ($relation)
{
- return $me->getModel()->$relation();
+ return $this->getModel()->$relation();
});
$nested = $this->nestedRelations($relation);
@@ -728,11 +726,9 @@ protected function mergeWheresToHas(Builder $hasQuery, Relation $relation)
*/
protected function getHasRelationQuery($relation)
{
- $me = $this;
-
- return Relation::noConstraints(function() use ($me, $relation)
+ return Relation::noConstraints(function() use ($relation)
{
- return $me->getModel()->$relation();
+ return $this->getModel()->$relation();
});
}
| true |
Other | laravel | framework | 5c6c2bb3de560d6ff119b9107a2036416372891a.json | use php 5.4 closures see #3687 | src/Illuminate/Database/Query/Builder.php | @@ -1308,9 +1308,7 @@ public function generateCacheKey()
*/
protected function getCacheCallback($columns)
{
- $me = $this;
-
- return function() use ($me, $columns) { return $me->getFresh($columns); };
+ return function() use ($columns) { return $this->getFresh($columns); };
}
/** | true |
Other | laravel | framework | 5c6c2bb3de560d6ff119b9107a2036416372891a.json | use php 5.4 closures see #3687 | src/Illuminate/Exception/ExceptionServiceProvider.php | @@ -151,16 +151,14 @@ protected function requestWantsJson()
*/
protected function registerPrettyWhoopsHandler()
{
- $me = $this;
-
- $this->app['whoops.handler'] = $this->app->share(function() use ($me)
+ $this->app['whoops.handler'] = $this->app->share(function()
{
with($handler = new PrettyPageHandler)->setEditor('sublime');
// If the resource path exists, we will register the resource path with Whoops
// so our custom Laravel branded exception pages will be used when they are
// displayed back to the developer. Otherwise, the default pages are run.
- if ( ! is_null($path = $me->resourcePath()))
+ if ( ! is_null($path = $this->resourcePath()))
{
$handler->setResourcesPath($path);
}
| true |
Other | laravel | framework | 5c6c2bb3de560d6ff119b9107a2036416372891a.json | use php 5.4 closures see #3687 | src/Illuminate/Queue/QueueServiceProvider.php | @@ -45,16 +45,14 @@ public function register()
*/
protected function registerManager()
{
- $me = $this;
-
- $this->app->bindShared('queue', function($app) use ($me)
+ $this->app->bindShared('queue', function($app)
{
// Once we have an instance of the queue manager, we will register the various
// resolvers for the queue connectors. These connectors are responsible for
// creating the classes that accept queue configs and instantiate queues.
$manager = new QueueManager($app);
- $me->registerConnectors($manager);
+ $this->registerConnectors($manager);
return $manager;
});
| true |
Other | laravel | framework | 5c6c2bb3de560d6ff119b9107a2036416372891a.json | use php 5.4 closures see #3687 | src/Illuminate/Routing/Router.php | @@ -911,18 +911,16 @@ protected function getControllerAction($action)
*/
protected function getClassClosure($controller)
{
- $me = $this;
-
// Here we'll get an instance of this controller dispatcher and hand it off to
// the Closure so it will be used to resolve the class instances out of our
// IoC container instance and call the appropriate methods on the class.
$d = $this->getControllerDispatcher();
- return function() use ($me, $d, $controller)
+ return function() use ($d, $controller)
{
- $route = $me->current();
+ $route = $this->current();
- $request = $me->getCurrentRequest();
+ $request = $this->getCurrentRequest();
// Now we can split the controller and method out of the action string so that we
// can call them appropriately on the class. This controller and method are in | true |
Other | laravel | framework | 5c6c2bb3de560d6ff119b9107a2036416372891a.json | use php 5.4 closures see #3687 | src/Illuminate/View/ViewServiceProvider.php | @@ -35,9 +35,7 @@ public function register()
*/
public function registerEngineResolver()
{
- $me = $this;
-
- $this->app->bindShared('view.engine.resolver', function($app) use ($me)
+ $this->app->bindShared('view.engine.resolver', function($app)
{
$resolver = new EngineResolver;
@@ -46,7 +44,7 @@ public function registerEngineResolver()
// on the extension of view files. We call a method for each engines.
foreach (array('php', 'blade') as $engine)
{
- $me->{'register'.ucfirst($engine).'Engine'}($resolver);
+ $this->{'register'.ucfirst($engine).'Engine'}($resolver);
}
return $resolver;
| true |
Other | laravel | framework | 17bfed2d234f19ddfa183ef93039c225873c5e53.json | Fix bug in view extending. | src/Illuminate/View/Environment.php | @@ -673,7 +673,7 @@ public function addExtension($extension, $engine, $resolver = null)
$this->engines->register($engine, $resolver);
}
- unset($this->extensions[$engine]);
+ unset($this->extensions[$extension]);
$this->extensions = array_merge(array($extension => $engine), $this->extensions);
} | false |
Other | laravel | framework | a83a19ddeb4bcd52f5ebcd4a08e951826428a272.json | Change import order. | src/Illuminate/Support/Facades/Response.php | @@ -1,8 +1,8 @@
<?php namespace Illuminate\Support\Facades;
use Illuminate\Http\JsonResponse;
-use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Support\Traits\MacroableTrait;
+use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Support\Contracts\ArrayableInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse; | false |
Other | laravel | framework | 9a4ae9e13f126aedb4e22d9d3e2a7fdb52d6e14a.json | Allow pgsql enum fields /w reserved words as names
An enum with a name like `unique` would cause an SQL syntax error, so just wrapped that sucker up in double-quotes to make it work. | src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php | @@ -393,7 +393,7 @@ protected function typeEnum(Fluent $column)
{
$allowed = array_map(function($a) { return "'".$a."'"; }, $column->allowed);
- return "varchar(255) check ({$column->name} in (".implode(', ', $allowed)."))";
+ return "varchar(255) check (\"{$column->name}\" in (".implode(', ', $allowed)."))";
}
/** | true |
Other | laravel | framework | 9a4ae9e13f126aedb4e22d9d3e2a7fdb52d6e14a.json | Allow pgsql enum fields /w reserved words as names
An enum with a name like `unique` would cause an SQL syntax error, so just wrapped that sucker up in double-quotes to make it work. | tests/Database/DatabasePostgresSchemaGrammarTest.php | @@ -355,7 +355,7 @@ public function testAddingEnum()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertEquals(1, count($statements));
- $this->assertEquals('alter table "users" add column "foo" varchar(255) check (foo in (\'bar\', \'baz\')) not null', $statements[0]);
+ $this->assertEquals('alter table "users" add column "foo" varchar(255) check ("foo" in (\'bar\', \'baz\')) not null', $statements[0]);
}
| true |
Other | laravel | framework | a1c5dd80aa6a13e0f8cf1f0e0e1700ff65c11f2c.json | Use php 5.4 closures $this where safe to | src/Illuminate/Database/Query/Grammars/Grammar.php | @@ -458,13 +458,11 @@ protected function compileBasicHaving($having)
*/
protected function compileOrders(Builder $query, $orders)
{
- $me = $this;
-
- return 'order by '.implode(', ', array_map(function($order) use ($me)
+ return 'order by '.implode(', ', array_map(function($order)
{
if (isset($order['sql'])) return $order['sql'];
- return $me->wrap($order['column']).' '.$order['direction'];
+ return $this->wrap($order['column']).' '.$order['direction'];
}
, $orders));
} | true |
Other | laravel | framework | a1c5dd80aa6a13e0f8cf1f0e0e1700ff65c11f2c.json | Use php 5.4 closures $this where safe to | src/Illuminate/Events/Dispatcher.php | @@ -105,11 +105,9 @@ public function hasListeners($eventName)
*/
public function queue($event, $payload = array())
{
- $me = $this;
-
- $this->listen($event.'_queue', function() use ($me, $event, $payload)
+ $this->listen($event.'_queue', function() use ($event, $payload)
{
- $me->fire($event, $payload);
+ $this->fire($event, $payload);
});
}
| true |
Other | laravel | framework | a1c5dd80aa6a13e0f8cf1f0e0e1700ff65c11f2c.json | Use php 5.4 closures $this where safe to | src/Illuminate/Foundation/MigrationPublisher.php | @@ -61,11 +61,9 @@ public function publish($source, $destination)
*/
protected function getFreshMigrations($source, $destination)
{
- $me = $this;
-
- return array_filter($this->getPackageMigrations($source), function($file) use ($me, $destination)
+ return array_filter($this->getPackageMigrations($source), function($file) use ($destination)
{
- return ! $me->migrationExists($file, $destination);
+ return ! $this->migrationExists($file, $destination);
});
}
@@ -129,4 +127,4 @@ protected function getNewMigrationName($file, $add)
return Carbon::now()->addSeconds($add)->format('Y_m_d_His').substr(basename($file), 17);
}
-}
\ No newline at end of file
+} | true |
Other | laravel | framework | a1c5dd80aa6a13e0f8cf1f0e0e1700ff65c11f2c.json | Use php 5.4 closures $this where safe to | src/Illuminate/Remote/Connection.php | @@ -213,9 +213,7 @@ protected function getCallback($callback)
{
if ( ! is_null($callback)) return $callback;
- $me = $this;
-
- return function($line) use ($me) { $me->display($line); };
+ return function($line) { $this->display($line); };
}
/**
@@ -269,4 +267,4 @@ public function setOutput(OutputInterface $output)
$this->output = $output;
}
-}
\ No newline at end of file
+} | true |
Other | laravel | framework | a1c5dd80aa6a13e0f8cf1f0e0e1700ff65c11f2c.json | Use php 5.4 closures $this where safe to | src/Illuminate/Routing/Router.php | @@ -440,14 +440,12 @@ public function getResourceUri($resource)
*/
protected function getNestedResourceUri(array $segments)
{
- $me = $this;
-
// We will spin through the segments and create a place-holder for each of the
// resource segments, as well as the resource itself. Then we should get an
// entire string for the resource URI that contains all nested resources.
- return implode('/', array_map(function($s) use ($me)
+ return implode('/', array_map(function($s)
{
- return $s.'/{'.$me->getResourceWildcard($s).'}';
+ return $s.'/{'.$this->getResourceWildcard($s).'}';
}, $segments));
} | true |
Other | laravel | framework | a1c5dd80aa6a13e0f8cf1f0e0e1700ff65c11f2c.json | Use php 5.4 closures $this where safe to | src/Illuminate/View/Compilers/BladeCompiler.php | @@ -190,13 +190,11 @@ protected function compileEchos($value)
*/
protected function compileRegularEchos($value)
{
- $me = $this;
-
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s/s', $this->contentTags[0], $this->contentTags[1]);
- $callback = function($matches) use ($me)
+ $callback = function($matches)
{
- return $matches[1] ? substr($matches[0], 1) : '<?php echo '.$me->compileEchoDefaults($matches[2]).'; ?>';
+ return $matches[1] ? substr($matches[0], 1) : '<?php echo '.$this->compileEchoDefaults($matches[2]).'; ?>';
};
return preg_replace_callback($pattern, $callback, $value);
@@ -210,13 +208,11 @@ protected function compileRegularEchos($value)
*/
protected function compileEscapedEchos($value)
{
- $me = $this;
-
$pattern = sprintf('/%s\s*(.+?)\s*%s/s', $this->escapedTags[0], $this->escapedTags[1]);
- $callback = function($matches) use ($me)
+ $callback = function($matches)
{
- return '<?php echo e('.$me->compileEchoDefaults($matches[1]).'); ?>';
+ return '<?php echo e('.$this->compileEchoDefaults($matches[1]).'); ?>';
};
return preg_replace_callback($pattern, $callback, $value); | true |
Other | laravel | framework | 0cd120a75090480af98b32e3b7f3adc24890c842.json | Convert spaces to tabs | src/Illuminate/Routing/Router.php | @@ -988,7 +988,7 @@ public function dispatchToRoute(Request $request)
{
$route = $this->findRoute($request);
- $this->events->fire('router.matched', array($route, $request));
+ $this->events->fire('router.matched', array($route, $request));
// Once we have successfully matched the incoming request to a given route we
// can call the before filters on that route. This works similar to global | false |
Other | laravel | framework | f42cc7fa47cdbb5a9f7e43a41c51cbd82786b367.json | Handle __call on Queue capsule | src/Illuminate/Queue/Capsule/Manager.php | @@ -204,6 +204,18 @@ public function setContainer(Container $container)
$this->container = $container;
}
+ /**
+ * Pass dynamic instance methods to the manager.
+ *
+ * @param string $method
+ * @param array $parameters
+ * @return mixed
+ */
+ public function __call($method, $parameters)
+ {
+ return call_user_func_array(array($this->manager, $method), $parameters);
+ }
+
/**
* Dynamically pass methods to the default connection.
* | false |
Other | laravel | framework | 01d5a77488e54bf425cfc6407b0c474d0d4190fc.json | Add tests for Eloquent Builder
Tested methods : pluck, chunk and lists | tests/Database/DatabaseEloquentBuilderTest.php | @@ -95,6 +95,69 @@ public function testGetMethodDoesntHydrateEagerRelationsWhenNoResultsAreReturned
}
+ public function testPluckMethodWithModelFound()
+ {
+ $builder = m::mock('Illuminate\Database\Eloquent\Builder[first]', array($this->getMockQueryBuilder()));
+ $mockModel = new StdClass;
+ $mockModel->name = 'foo';
+ $builder->shouldReceive('first')->with(array('name'))->andReturn($mockModel);
+
+ $this->assertEquals('foo', $builder->pluck('name'));
+ }
+
+ public function testPluckMethodWithModelNotFound()
+ {
+ $builder = m::mock('Illuminate\Database\Eloquent\Builder[first]', array($this->getMockQueryBuilder()));
+ $builder->shouldReceive('first')->with(array('name'))->andReturn(null);
+
+ $this->assertNull($builder->pluck('name'));
+ }
+
+
+ public function testChunkExecuteCallbackOverPaginatedRequest()
+ {
+ $builder = m::mock('Illuminate\Database\Eloquent\Builder[forPage,get]', array($this->getMockQueryBuilder()));
+ $builder->shouldReceive('forPage')->once()->with(1, 2)->andReturn($builder);
+ $builder->shouldReceive('forPage')->once()->with(2, 2)->andReturn($builder);
+ $builder->shouldReceive('forPage')->once()->with(3, 2)->andReturn($builder);
+ $builder->shouldReceive('get')->times(3)->andReturn(array('foo1', 'foo2'), array('foo3'), array());
+
+ $callbackExecutionAssertor = m::mock('StdClass');
+ $callbackExecutionAssertor->shouldReceive('doSomething')->with('foo1')->once();
+ $callbackExecutionAssertor->shouldReceive('doSomething')->with('foo2')->once();
+ $callbackExecutionAssertor->shouldReceive('doSomething')->with('foo3')->once();
+
+ $builder->chunk(2, function($results) use($callbackExecutionAssertor) {
+ foreach ($results as $result) {
+ $callbackExecutionAssertor->doSomething($result);
+ }
+ });
+ }
+
+
+ public function testListsReturnsTheMutatedAttributesOfAModel()
+ {
+ $builder = $this->getBuilder();
+ $builder->getQuery()->shouldReceive('lists')->with('name', '')->andReturn(array('bar', 'baz'));
+ $builder->setModel($this->getMockModel());
+ $builder->getModel()->shouldReceive('hasGetMutator')->with('name')->andReturn(true);
+ $builder->getModel()->shouldReceive('newFromBuilder')->with(array('name' => 'bar'))->andReturn(new EloquentBuilderTestListsStub(array('name' => 'bar')));
+ $builder->getModel()->shouldReceive('newFromBuilder')->with(array('name' => 'baz'))->andReturn(new EloquentBuilderTestListsStub(array('name' => 'baz')));
+
+ $this->assertEquals(array('foo_bar', 'foo_baz'), $builder->lists('name'));
+ }
+
+ public function testListsWithoutModelGetterJustReturnTheAttributesFoundInDatabase()
+ {
+ $builder = $this->getBuilder();
+ $builder->getQuery()->shouldReceive('lists')->with('name', '')->andReturn(array('bar', 'baz'));
+ $builder->setModel($this->getMockModel());
+ $builder->getModel()->shouldReceive('hasGetMutator')->with('name')->andReturn(false);
+
+ $this->assertEquals(array('bar', 'baz'), $builder->lists('name'));
+ }
+
+
public function testWithDeletedProperlyRemovesDeletedClause()
{
$builder = new Illuminate\Database\Eloquent\Builder(new Illuminate\Database\Query\Builder(
@@ -368,3 +431,14 @@ class EloquentBuilderTestNestedStub extends Illuminate\Database\Eloquent\Model {
protected $table = 'table';
protected $softDelete = true;
}
+class EloquentBuilderTestListsStub {
+ protected $attributes;
+ public function __construct($attributes)
+ {
+ $this->attributes = $attributes;
+ }
+ public function __get($key)
+ {
+ return 'foo_' . $this->attributes[$key];
+ }
+} | false |
Other | laravel | framework | 9902e7d5960c6f3a2ad9a187c142ab6dbb384ed1.json | fix filtering of parameters. | src/Illuminate/Routing/Router.php | @@ -1396,7 +1396,21 @@ public function callRouteFilter($filter, $parameters, $route, $request, $respons
$data = array_merge(array($route, $request, $response), $parameters);
- return $this->events->until('router.filter: '.$filter, array_filter($data));
+ return $this->events->until('router.filter: '.$filter, $this->cleanFilterParameters($data));
+ }
+
+ /**
+ * Clean the parameters being passed to a filter callback.
+ *
+ * @param array $parameters
+ * @return array
+ */
+ protected function cleanFilterParameters(array $parameters)
+ {
+ return array_filter($parameters, function($p)
+ {
+ return ! is_null($p) && $p !== '';
+ });
}
/** | true |
Other | laravel | framework | 9902e7d5960c6f3a2ad9a187c142ab6dbb384ed1.json | fix filtering of parameters. | tests/Routing/RoutingRouteTest.php | @@ -187,6 +187,11 @@ public function testBasicBeforeFilters()
$router->filter('foo', function($route, $request, $age) { return $age; });
$this->assertEquals('25', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent());
+ $router = $this->getRouter();
+ $router->get('foo/bar', array('before' => 'foo:0,taylor', function() { return 'hello'; }));
+ $router->filter('foo', function($route, $request, $age, $name) { return $age.$name; });
+ $this->assertEquals('0taylor', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent());
+
$router = $this->getRouter();
$router->get('foo/bar', array('before' => 'foo:bar,baz', function() { return 'hello'; }));
$router->filter('foo', function($route, $request, $bar, $baz) { return $bar.$baz; });
@@ -524,17 +529,17 @@ public function testRouteGrouping()
$router->filter('bar', function() {});
$router->filter('baz', function() { return 'foo!'; });
$this->assertEquals('foo!', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent());
-
+
/**
* getPrefix() method
*/
$router = $this->getRouter();
$router->group(array('prefix' => 'foo'), function() use ($router)
{
$router->get('bar', function() { return 'hello'; });
- });
+ });
$routes = $router->getRoutes();
- $routes = $routes->getRoutes();
+ $routes = $routes->getRoutes();
$this->assertEquals('foo', $routes[0]->getPrefix());
}
| true |
Other | laravel | framework | 26e8fadf89a14f28ee8b613f423c87eaaba701b5.json | Add getter for loggingQueries | src/Illuminate/Database/Connection.php | @@ -918,6 +918,16 @@ public function disableQueryLog()
$this->loggingQueries = false;
}
+ /**
+ * Determine whether we're logging queries.
+ *
+ * @return bool
+ */
+ public function getQueryLogState()
+ {
+ return $this->loggingQueries;
+ }
+
/**
* Get the name of the connected database.
* | false |
Other | laravel | framework | 18e6a1dfb3f14e9f7a42912fbab871acd5d6c947.json | Return ID from Redis queue push. | src/Illuminate/Queue/RedisQueue.php | @@ -64,7 +64,9 @@ public function push($job, $data = '', $queue = null)
*/
public function pushRaw($payload, $queue = null, array $options = array())
{
- return $this->redis->rpush($this->getQueue($queue), $payload);
+ $this->redis->rpush($this->getQueue($queue), $payload);
+
+ return array_get(json_decode($payload, true), 'id');
}
/**
@@ -81,6 +83,8 @@ public function later($delay, $job, $data = '', $queue = null)
$payload = $this->createPayload($job, $data);
$this->redis->zadd($this->getQueue($queue).':delayed', $this->getTime() + $delay, $payload);
+
+ return array_get(json_decode($payload, true), 'id');
}
/** | true |
Other | laravel | framework | 18e6a1dfb3f14e9f7a42912fbab871acd5d6c947.json | Return ID from Redis queue push. | tests/Queue/QueueRedisQueueTest.php | @@ -16,7 +16,8 @@ public function testPushProperlyPushesJobOntoRedis()
$queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
$redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(array('job' => 'foo', 'data' => array('data'), 'id' => 'foo', 'attempts' => 1)));
- $queue->push('foo', array('data'));
+ $id = $queue->push('foo', array('data'));
+ $this->assertEquals('foo', $id);
}
@@ -32,7 +33,8 @@ public function testDelayedPushProperlyPushesJobOntoRedis()
json_encode(array('job' => 'foo', 'data' => array('data'), 'id' => 'foo', 'attempts' => 1))
);
- $queue->later(1, 'foo', array('data'));
+ $id = $queue->later(1, 'foo', array('data'));
+ $this->assertEquals('foo', $id);
}
| true |
Other | laravel | framework | f1e656ba13802af0309bbded9231d9b8484721a0.json | Use rawurldecode in Route::parameters. | src/Illuminate/Foundation/changes.json | @@ -4,7 +4,8 @@
{"message": "Configurable encryption for Iron.io queue messages.", "backport": null},
{"message": "Make FrameGuard middleware opt-in.", "backport": null},
{"message": "Convert View '$errors' shared variable into ViewErrorBag. Allows multiple bags per view. Should be backwards compatible.", "backport": null},
- {"message": "Calling 'create' on a HasOne or HasMany relation will now use 'fill' method so mutators are executed on related model.", "backport": null}
+ {"message": "Calling 'create' on a HasOne or HasMany relation will now use 'fill' method so mutators are executed on related model.", "backport": null},
+ {"message": "Use rawurldecode when decoding parameters in Route::parameters.", "backport": null}
],
"4.1.*": [
{"message": "Added new SSH task runner tools.", "backport": null}, | true |
Other | laravel | framework | f1e656ba13802af0309bbded9231d9b8484721a0.json | Use rawurldecode in Route::parameters. | src/Illuminate/Routing/Route.php | @@ -319,7 +319,7 @@ public function parameters()
{
return array_map(function($value)
{
- return is_string($value) ? urldecode($value) : $value;
+ return is_string($value) ? rawurldecode($value) : $value;
}, $this->parameters);
}
| true |
Other | laravel | framework | cbe8c41080e605622b68ec9ed6908e46e48a9171.json | Modify tests to also test the new behaviour | tests/Database/DatabaseEloquentBelongsToManyTest.php | @@ -235,7 +235,7 @@ public function testSyncMethodSyncsIntermediateTableWithGivenArray($list)
$relation->getRelated()->shouldReceive('touches')->andReturn(false);
$relation->getParent()->shouldReceive('touches')->andReturn(false);
- $relation->sync($list);
+ $this->assertEquals(array('attached' => array(4), 'detached' => array(1), 'updated' => array()), $relation->sync($list));
}
@@ -250,18 +250,19 @@ public function syncMethodListProvider()
public function testSyncMethodSyncsIntermediateTableWithGivenArrayAndAttributes()
{
- $relation = $this->getMock('Illuminate\Database\Eloquent\Relations\BelongsToMany', array('attach', 'detach', 'touchIfTouching'), $this->getRelationArguments());
+ $relation = $this->getMock('Illuminate\Database\Eloquent\Relations\BelongsToMany', array('attach', 'detach', 'touchIfTouching', 'updateExistingPivot'), $this->getRelationArguments());
$query = m::mock('stdClass');
$query->shouldReceive('from')->once()->with('user_role')->andReturn($query);
$query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query);
$relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass'));
$mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query);
$query->shouldReceive('lists')->once()->with('role_id')->andReturn(array(1, 2, 3));
$relation->expects($this->once())->method('attach')->with($this->equalTo(4), $this->equalTo(array('foo' => 'bar')), $this->equalTo(false));
+ $relation->expects($this->once())->method('updateExistingPivot')->with($this->equalTo(3), $this->equalTo(array('baz' => 'qux')), $this->equalTo(false));
$relation->expects($this->once())->method('detach')->with($this->equalTo(array(1)));
$relation->expects($this->once())->method('touchIfTouching');
- $relation->sync(array(2, 3, 4 => array('foo' => 'bar')));
+ $this->assertEquals(array('attached' => array(4), 'detached' => array(1), 'updated' => array(3)), $relation->sync(array(2, 3 => array('baz' => 'qux'), 4 => array('foo' => 'bar'))));
}
@@ -342,4 +343,4 @@ public function __construct()
class EloquentBelongsToManyPivotStub {
public $user_id;
-}
\ No newline at end of file
+} | false |
Other | laravel | framework | 909ddcb8dd5a412b6f71ab45b8e784ee41188cb0.json | Fix boot on unserialize | src/Illuminate/Database/Eloquent/Model.php | @@ -239,6 +239,20 @@ abstract class Model implements ArrayAccess, ArrayableInterface, JsonableInterfa
* @return void
*/
public function __construct(array $attributes = array())
+ {
+ $this->bootIfNotBooted();
+
+ $this->syncOriginal();
+
+ $this->fill($attributes);
+ }
+
+ /**
+ * Check if the model needs to be booted and if so, do it.
+ *
+ * @return void
+ */
+ protected function bootIfNotBooted()
{
if ( ! isset(static::$booted[get_class($this)]))
{
@@ -250,10 +264,6 @@ public function __construct(array $attributes = array())
$this->fireModelEvent('booted', false);
}
-
- $this->syncOriginal();
-
- $this->fill($attributes);
}
/**
@@ -2856,4 +2866,14 @@ public function __toString()
return $this->toJson();
}
+ /**
+ * When a model is being unserialized, check if it needs to be booted.
+ *
+ * @return void
+ */
+ public function __wakeup()
+ {
+ $this->bootIfNotBooted();
+ }
+
} | true |
Other | laravel | framework | 909ddcb8dd5a412b6f71ab45b8e784ee41188cb0.json | Fix boot on unserialize | tests/Database/DatabaseEloquentModelTest.php | @@ -750,6 +750,20 @@ public function testGetModelAttributeMethodThrowsExceptionIfNotRelation()
}
+ public function testModelIsBootedOnUnserialize()
+ {
+ $model = new EloquentModelBootingTestStub;
+ $this->assertTrue(EloquentModelBootingTestStub::isBooted());
+ $model->foo = 'bar';
+ $string = serialize($model);
+ $model = null;
+ EloquentModelBootingTestStub::unboot();
+ $this->assertFalse(EloquentModelBootingTestStub::isBooted());
+ $model = unserialize($string);
+ $this->assertTrue(EloquentModelBootingTestStub::isBooted());
+ }
+
+
protected function addMockConnection($model)
{
$model->setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface'));
@@ -878,3 +892,14 @@ public function newQuery($excludeDeleted = true)
}
class EloquentModelWithoutTableStub extends Illuminate\Database\Eloquent\Model {}
+
+class EloquentModelBootingTestStub extends Illuminate\Database\Eloquent\Model {
+ public static function unboot()
+ {
+ unset(static::$booted[get_called_class()]);
+ }
+ public static function isBooted()
+ {
+ return array_key_exists(get_called_class(), static::$booted);
+ }
+} | true |
Other | laravel | framework | 8654da2892cf4fbd629d99bbf410925d07379cd9.json | Use array_values to rekey filtered array
If the path had an empty segment, for instancem 'foo//bar', requesting segment
2 would return the default value instead of 'bar' | src/Illuminate/Http/Request.php | @@ -94,7 +94,7 @@ public function segment($index, $default = null)
{
$segments = explode('/', trim($this->getPathInfo(), '/'));
- $segments = array_filter($segments, function($v) { return $v != ''; });
+ $segments = array_values(array_filter($segments));
return array_get($segments, $index - 1, $default);
} | true |
Other | laravel | framework | 8654da2892cf4fbd629d99bbf410925d07379cd9.json | Use array_values to rekey filtered array
If the path had an empty segment, for instancem 'foo//bar', requesting segment
2 would return the default value instead of 'bar' | tests/Http/HttpRequestTest.php | @@ -42,16 +42,24 @@ public function testDecodedPathMethod()
}
- public function testSegmentMethod()
+ /**
+ * @dataProvider segmentProvider
+ */
+ public function testSegmentMethod($path, $segment, $expected)
{
- $request = Request::create('', 'GET');
- $this->assertEquals('default', $request->segment(1, 'default'));
-
- $request = Request::create('foo/bar', 'GET');
- $this->assertEquals('foo', $request->segment(1, 'default'));
- $this->assertEquals('bar', $request->segment(2, 'default'));
+ $request = Request::create($path, 'GET');
+ $this->assertEquals($expected, $request->segment($segment, 'default'));
}
+ public function segmentProvider()
+ {
+ return array(
+ array('', 1, 'default'),
+ array('foo/bar//baz', '1', 'foo'),
+ array('foo/bar//baz', '2', 'bar'),
+ array('foo/bar//baz', '3', 'baz')
+ );
+ }
public function testSegmentsMethod()
{ | true |
Other | laravel | framework | 83943331dba1a7acc4cf8388ba43578c8fa674ed.json | Add comment for clarification. | src/Illuminate/View/Engines/EngineResolver.php | @@ -21,6 +21,8 @@ class EngineResolver {
/**
* Register a new engine resolver.
*
+ * The engine string typically corresponds to a file extension.
+ *
* @param string $engine
* @param Closure $resolver
* @return void | false |
Other | laravel | framework | e24c6e67af844a6ac8b5436dbd96d343446684c4.json | Fix caller bug. | src/Illuminate/Database/Eloquent/Model.php | @@ -848,12 +848,14 @@ protected function getBelongsToManyCaller()
{
$self = __FUNCTION__;
- return array_first(debug_backtrace(false), function($trace) use ($self)
+ $caller = array_first(debug_backtrace(false), function($key, $trace) use ($self)
{
$caller = $trace['function'];
return ( ! in_array($caller, Model::$manyMethods) && $caller != $self);
});
+
+ return ! is_null($caller) ? $caller['function'] : null;
}
/** | false |
Other | laravel | framework | c3fc09e4e56b700e390827153acf9d13d51596b9.json | Update MySqlConnector.php to support Sphinx
Sphinx is one of the 4 main search engines PHP has documented and provides classes for.
http://www.php.net/manual/en/refs.search.php
Sphinx uses the mysql protocol as an interface. The problem is when passing collate the connection to sphinx fails. The patch will not include collate in the connection if in the config file its set to null.
Thank you
(Original Ticket #3519) | src/Illuminate/Database/Connectors/MySqlConnector.php | @@ -26,7 +26,7 @@ public function connect(array $config)
// is set on the server but needs to be set here on this client objects.
$charset = $config['charset'];
- $names = "set names '$charset' collate '$collation'";
+ $names = "set names '$charset'".($collation!==null ? " collate '$collation'" : null);
$connection->prepare($names)->execute();
@@ -72,4 +72,4 @@ protected function getDsn(array $config)
return $dsn;
}
-}
\ No newline at end of file
+} | false |
Other | laravel | framework | e747c4a1098d5c33073588ce91d4025f8e9d629e.json | Make getDictionary public | src/Illuminate/Database/Eloquent/Collection.php | @@ -200,7 +200,7 @@ public function unique()
* @param \Illuminate\Support\Collection $collection
* @return array
*/
- protected function getDictionary($collection)
+ public function getDictionary($collection)
{
$dictionary = array();
| false |
Other | laravel | framework | 8c45fba521d318a22387404442e3daa1b2e3e426.json | Add $path param for docblock | src/Illuminate/Support/helpers.php | @@ -484,6 +484,7 @@ function asset($path, $secure = null)
/**
* Get the path to the base of the install.
*
+ * @param string $path
* @return string
*/
function base_path($path = '')
@@ -738,6 +739,7 @@ function preg_replace_sub($pattern, &$replacements, $subject)
/**
* Get the path to the public folder.
*
+ * @param string $path
* @return string
*/
function public_path($path = '')
@@ -752,7 +754,7 @@ function public_path($path = '')
* Generate a URL to a named route.
*
* @param string $route
- * @param string $parameters
+ * @param array $parameters
* @return string
*/
function route($route, $parameters = array())
@@ -825,6 +827,7 @@ function starts_with($haystack, $needle)
/**
* Get the path to the storage folder.
*
+ * @param string $path
* @return string
*/
function storage_path($path = '') | false |
Other | laravel | framework | 9d14fbb21290b0948a46b449e7aa92361eb1df2c.json | fix code and test | src/Illuminate/Database/Eloquent/Builder.php | @@ -593,7 +593,9 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
{
if ($column instanceof Closure)
{
- $query = $this->model->newQuery();
+ // Get a new query builder instance but avoid including any soft
+ // delete constraints that could mess up the nested query.
+ $query = $this->model->newQuery(false);
call_user_func($column, $query);
| true |
Other | laravel | framework | 9d14fbb21290b0948a46b449e7aa92361eb1df2c.json | fix code and test | tests/Database/DatabaseEloquentBuilderTest.php | @@ -339,7 +339,7 @@ public function testNestedWhere()
$nestedRawQuery = $this->getMockQueryBuilder();
$nestedQuery->shouldReceive('getQuery')->once()->andReturn($nestedRawQuery);
$model = $this->getMockModel()->makePartial();
- $model->shouldReceive('newQuery')->once()->andReturn($nestedQuery);
+ $model->shouldReceive('newQuery')->with(false)->once()->andReturn($nestedQuery);
$builder = $this->getBuilder();
$builder->getQuery()->shouldReceive('from');
$builder->setModel($model); | true |
Other | laravel | framework | da39766b20b915a6b554cbf6392f6a9c9c8f1a90.json | Remove previous URL stuff from session. Bad idea. | src/Illuminate/Routing/Redirector.php | @@ -50,14 +50,7 @@ public function home($status = 302)
*/
public function back($status = 302, $headers = array())
{
- if ($this->generator->getRequest()->headers->has('referer'))
- {
- $back = $this->generator->getRequest()->headers->get('referer');
- }
- elseif ($this->session->hasPreviousUrl())
- {
- $back = $this->session->getPreviousUrl();
- }
+ $back = $this->generator->getRequest()->headers->get('referer');
return $this->createRedirect($back, $status, $headers);
} | true |
Other | laravel | framework | da39766b20b915a6b554cbf6392f6a9c9c8f1a90.json | Remove previous URL stuff from session. Bad idea. | src/Illuminate/Session/Middleware.php | @@ -76,7 +76,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
// add the session identifier cookie to the application response headers now.
if ($this->sessionConfigured())
{
- $this->closeSession($session, $request);
+ $this->closeSession($session);
$this->addCookieToResponse($response, $session);
}
@@ -121,10 +121,8 @@ protected function startSession(Request $request)
* @param \Illuminate\Session\SessionInterface $session
* @return void
*/
- protected function closeSession(SessionInterface $session, Request $request)
+ protected function closeSession(SessionInterface $session)
{
- $session->setPreviousUrl($this->getUrl($request));
-
$session->save();
$this->collectGarbage($session); | true |
Other | laravel | framework | da39766b20b915a6b554cbf6392f6a9c9c8f1a90.json | Remove previous URL stuff from session. Bad idea. | src/Illuminate/Session/Store.php | @@ -472,37 +472,6 @@ public function flush()
$this->clear();
}
- /**
- * Determine if the session contains the previous URL.
- *
- * @return bool
- */
- public function hasPreviousUrl()
- {
- return $this->has('_previous_url');
- }
-
- /**
- * Get the previous URL from the session.
- *
- * @return string|null
- */
- public function getPreviousUrl()
- {
- return $this->get('_previous_url');
- }
-
- /**
- * Set the previous URL in the session.
- *
- * @param string $url
- * @return void
- */
- public function setPreviousUrl($url)
- {
- $this->set('_previous_url', $url);
- }
-
/**
* {@inheritdoc}
*/ | true |
Other | laravel | framework | da39766b20b915a6b554cbf6392f6a9c9c8f1a90.json | Remove previous URL stuff from session. Bad idea. | tests/Routing/RoutingRedirectorTest.php | @@ -105,25 +105,13 @@ public function testRefreshRedirectToCurrentUrl()
public function testBackRedirectToHttpReferer()
{
- $this->session->shouldReceive('hasPreviousUrl')->never();
$this->headers->shouldReceive('has')->with('referer')->andReturn(true);
$this->headers->shouldReceive('get')->with('referer')->andReturn('http://foo.com/bar');
$response = $this->redirect->back();
$this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
}
- public function testBackRedirectToSessionsPreviousUrlIfAvailable()
- {
- $this->headers->shouldReceive('has')->with('referer')->andReturn(false);
- $this->session->shouldReceive('hasPreviousUrl')->once()->andReturn(true);
- $this->session->shouldReceive('getPreviousUrl')->once()->andReturn('http://foo.com/bar');
- $this->headers->shouldReceive('get')->never();
- $response = $this->redirect->back();
- $this->assertEquals('http://foo.com/bar', $response->getTargetUrl());
- }
-
-
public function testAwayDoesntValidateTheUrl()
{
$response = $this->redirect->away('bar'); | true |
Other | laravel | framework | b8778d24106ac6fc71d32284424ac0e5c2cb5bd3.json | Use referer header if it exists. | src/Illuminate/Routing/Redirector.php | @@ -50,13 +50,13 @@ public function home($status = 302)
*/
public function back($status = 302, $headers = array())
{
- if ($this->session->hasPreviousUrl())
+ if ($this->generator->getRequest()->headers->has('referer'))
{
- $back = $this->session->getPreviousUrl();
+ $back = $this->generator->getRequest()->headers->get('referer');
}
- else
+ elseif ($this->session->hasPreviousUrl())
{
- $back = $this->generator->getRequest()->headers->get('referer');
+ $back = $this->session->getPreviousUrl();
}
return $this->createRedirect($back, $status, $headers); | false |
Other | laravel | framework | 080a07c3ae6401f911c679732bc7532c8ac9f9b2.json | Add flush test for Http\Request | tests/Http/HttpRequestTest.php | @@ -312,6 +312,16 @@ public function testOldMethodCallsSession()
}
+ public function testFlushMethodCallsSession()
+ {
+ $request = Request::create('/', 'GET');
+ $session = m::mock('Illuminate\Session\Store');
+ $session->shouldReceive('flashInput')->once();
+ $request->setSession($session);
+ $request->flush();
+ }
+
+
public function testFormatReturnsAcceptableFormat()
{
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_ACCEPT' => 'application/json')); | false |
Other | laravel | framework | 663a586c79048051dcd394ceda9965dce60d3d99.json | Improve HTTP\RedirectResponse test coverage | tests/Http/HttpResponseTest.php | @@ -67,6 +67,41 @@ public function testGetOriginalContent()
$response->setContent($arr);
$this->assertTrue($arr === $response->getOriginalContent());
}
+
+
+ public function testHeaderOnRedirect()
+ {
+ $response = new RedirectResponse('foo.bar');
+ $this->assertNull($response->headers->get('foo'));
+ $response->header('foo', 'bar');
+ $this->assertEquals('bar', $response->headers->get('foo'));
+ $response->header('foo', 'baz', false);
+ $this->assertEquals('bar', $response->headers->get('foo'));
+ $response->header('foo', 'baz');
+ $this->assertEquals('baz', $response->headers->get('foo'));
+ }
+
+
+ public function testWithOnRedirect()
+{
+ $response = new RedirectResponse('foo.bar');
+ $response->setRequest(Request::create('/', 'GET', array('name' => 'Taylor', 'age' => 26)));
+ $response->setSession($session = m::mock('Illuminate\Session\Store'));
+ $session->shouldReceive('flash')->twice();
+ $response->with(array('name', 'age'));
+ }
+
+
+ public function testWithCookieOnRedirect()
+ {
+ $response = new RedirectResponse('foo.bar');
+ $this->assertEquals(0, count($response->headers->getCookies()));
+ $this->assertEquals($response, $response->withCookie(new \Symfony\Component\HttpFoundation\Cookie('foo', 'bar')));
+ $cookies = $response->headers->getCookies();
+ $this->assertEquals(1, count($cookies));
+ $this->assertEquals('foo', $cookies[0]->getName());
+ $this->assertEquals('bar', $cookies[0]->getValue());
+ }
public function testInputOnRedirect()
@@ -109,7 +144,23 @@ public function testFlashingErrorsOnRedirect()
$provider->shouldReceive('getMessageBag')->once()->andReturn(array('foo' => 'bar'));
$response->withErrors($provider);
}
+
+
+ public function testSettersGettersOnRequest()
+ {
+ $response = new RedirectResponse('foo.bar');
+ $this->assertNull($response->getRequest());
+ $this->assertNull($response->getSession());
+
+ $request = Request::create('/', 'GET');
+ $session = m::mock('Illuminate\Session\Store');
+ $response->setRequest($request);
+ $response->setSession($session);
+ $this->assertTrue($request === $response->getRequest());
+ $this->assertTrue($session === $response->getSession());
+ }
+
public function testRedirectWithErrorsArrayConvertsToMessageBag()
{
$response = new RedirectResponse('foo.bar');
@@ -119,6 +170,24 @@ public function testRedirectWithErrorsArrayConvertsToMessageBag()
$provider = array('foo' => 'bar');
$response->withErrors($provider);
}
+
+
+ public function testMagicCall()
+ {
+ $response = new RedirectResponse('foo.bar');
+ $response->setRequest(Request::create('/', 'GET', array('name' => 'Taylor', 'age' => 26)));
+ $response->setSession($session = m::mock('Illuminate\Session\Store'));
+ $session->shouldReceive('flash')->once()->with('foo', 'bar');
+ $response->withFoo('bar');
+ }
+
+
+ public function testMagicCallException()
+ {
+ $this->setExpectedException('BadMethodCallException');
+ $response = new RedirectResponse('foo.bar');
+ $response->doesNotExist('bar');
+ }
}
| false |
Other | laravel | framework | 4dfd0b7a3a82d21abd7d2cd1d7a2eb7ec2ac6d65.json | Improve HTTP\Request test coverage | tests/Http/HttpRequestTest.php | @@ -9,6 +9,20 @@ public function tearDown()
{
m::close();
}
+
+
+ public function testInstanceMethod()
+ {
+ $request = Request::create('', 'GET');
+ $this->assertTrue($request === $request->instance());
+ }
+
+
+ public function testRootMethod()
+ {
+ $request = Request::create('http://example.com/foo/bar/script.php?test');
+ $this->assertEquals('http://example.com', $request->root());
+ }
public function testPathMethod()
@@ -19,6 +33,13 @@ public function testPathMethod()
$request = Request::create('/foo/bar', 'GET');
$this->assertEquals('foo/bar', $request->path());
}
+
+
+ public function testDecodedPathMethod()
+ {
+ $request = Request::create('/foo%20bar');
+ $this->assertEquals('foo bar', $request->decodedPath());
+ }
public function testSegmentMethod()
@@ -69,11 +90,30 @@ public function testIsMethod()
$this->assertTrue($request->is('foo*'));
$this->assertFalse($request->is('bar*'));
$this->assertTrue($request->is('*bar*'));
+ $this->assertTrue($request->is('bar*', 'foo*', 'baz'));
$request = Request::create('/', 'GET');
$this->assertTrue($request->is('/'));
}
+
+
+ public function testAjaxMethod()
+ {
+ $request = Request::create('/', 'GET');
+ $this->assertFalse($request->ajax());
+ $request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'), '{}');
+ $this->assertTrue($request->ajax());
+ }
+
+
+ public function testSecureMethod()
+ {
+ $request = Request::create('http://example.com', 'GET');
+ $this->assertFalse($request->secure());
+ $request = Request::create('https://example.com', 'GET');
+ $this->assertTrue($request->secure());
+ }
public function testHasMethod()
@@ -122,6 +162,8 @@ public function testQueryMethod()
$request = Request::create('/', 'GET', array('name' => 'Taylor'));
$this->assertEquals('Taylor', $request->query('name'));
$this->assertEquals('Bob', $request->query('foo', 'Bob'));
+ $all = $request->query(null);
+ $this->assertEquals('Taylor', $all['name']);
}
@@ -130,6 +172,16 @@ public function testCookieMethod()
$request = Request::create('/', 'GET', array(), array('name' => 'Taylor'));
$this->assertEquals('Taylor', $request->cookie('name'));
$this->assertEquals('Bob', $request->cookie('foo', 'Bob'));
+ $all = $request->cookie(null);
+ $this->assertEquals('Taylor', $all['name']);
+ }
+
+
+ public function testHasCookieMethod()
+ {
+ $request = Request::create('/', 'GET', array(), array('foo' => 'bar'));
+ $this->assertTrue($request->hasCookie('foo'));
+ $this->assertFalse($request->hasCookie('qu'));
}
@@ -173,6 +225,8 @@ public function testServerMethod()
$request = Request::create('/', 'GET', array(), array(), array(), array('foo' => 'bar'));
$this->assertEquals('bar', $request->server('foo'));
$this->assertEquals('bar', $request->server('foo.doesnt.exist', 'bar'));
+ $all = $request->server(null);
+ $this->assertEquals('bar', $all['foo']);
}
@@ -200,6 +254,8 @@ public function testHeaderMethod()
{
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_DO_THIS' => 'foo'));
$this->assertEquals('foo', $request->header('do-this'));
+ $all = $request->header(null);
+ $this->assertEquals('foo', $all['do-this'][0]);
}
@@ -260,9 +316,23 @@ public function testFormatReturnsAcceptableFormat()
{
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_ACCEPT' => 'application/json'));
$this->assertEquals('json', $request->format());
+ $this->assertTrue($request->wantsJson());
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_ACCEPT' => 'application/atom+xml'));
$this->assertEquals('atom', $request->format());
+ $this->assertFalse($request->wantsJson());
+
+ $request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_ACCEPT' => 'is/not/known'));
+ $this->assertEquals('html', $request->format());
+ $this->assertEquals('foo', $request->format('foo'));
+ }
+
+
+ public function testSessionMethod()
+ {
+ $this->setExpectedException('RuntimeException');
+ $request = Request::create('/', 'GET');
+ $request->session();
}
} | false |
Other | laravel | framework | ab24f99c5e843cf7ce24c9ff0b12d1b7bbc96ca2.json | Improve HTTP\Response test coverage | tests/Http/HttpResponseTest.php | @@ -18,6 +18,11 @@ public function testJsonResponsesAreConvertedAndHeadersAreSet()
$response = new Illuminate\Http\Response(new JsonableStub);
$this->assertEquals('foo', $response->getContent());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
+
+ $response = new Illuminate\Http\Response();
+ $response->setContent(array('foo'=>'bar'));
+ $this->assertEquals('{"foo":"bar"}', $response->getContent());
+ $this->assertEquals('application/json', $response->headers->get('Content-Type'));
}
@@ -28,6 +33,40 @@ public function testRenderablesAreRendered()
$response = new Illuminate\Http\Response($mock);
$this->assertEquals('foo', $response->getContent());
}
+
+
+ public function testHeader()
+ {
+ $response = new Illuminate\Http\Response();
+ $this->assertNull($response->headers->get('foo'));
+ $response->header('foo', 'bar');
+ $this->assertEquals('bar', $response->headers->get('foo'));
+ $response->header('foo', 'baz', false);
+ $this->assertEquals('bar', $response->headers->get('foo'));
+ $response->header('foo', 'baz');
+ $this->assertEquals('baz', $response->headers->get('foo'));
+ }
+
+
+ public function testWithCookie()
+ {
+ $response = new Illuminate\Http\Response();
+ $this->assertEquals(0, count($response->headers->getCookies()));
+ $this->assertEquals($response, $response->withCookie(new \Symfony\Component\HttpFoundation\Cookie('foo', 'bar')));
+ $cookies = $response->headers->getCookies();
+ $this->assertEquals(1, count($cookies));
+ $this->assertEquals('foo', $cookies[0]->getName());
+ $this->assertEquals('bar', $cookies[0]->getValue());
+ }
+
+
+ public function testGetOriginalContent()
+ {
+ $arr = array('foo'=>'bar');
+ $response = new Illuminate\Http\Response();
+ $response->setContent($arr);
+ $this->assertTrue($arr === $response->getOriginalContent());
+ }
public function testInputOnRedirect() | false |
Other | laravel | framework | 9f654456b101e1d57be8e4f307cff1f96d12a2c4.json | Improve Illuminate\View\View test coverage | tests/View/ViewTest.php | @@ -75,6 +75,7 @@ public function testSectionsAreNotFlushedWhenNotDoneRendering()
$view->getEnvironment()->shouldReceive('flushSectionsIfDoneRendering')->once();
$this->assertEquals('contents', $view->render());
+ $this->assertEquals('contents', (string)$view);
}
@@ -104,6 +105,97 @@ public function testViewAcceptsArrayableImplementations()
$this->assertEquals('bar', $view->foo);
$this->assertEquals(array('qux', 'corge'), $view->baz);
}
+
+
+ public function testViewGettersSetters()
+ {
+ $view = $this->getView();
+ $this->assertEquals($view->getName(), 'view');
+ $this->assertEquals($view->getPath(), 'path');
+ $this->assertEquals($view->getData()['foo'], 'bar');
+ $view->setPath('newPath');
+ $this->assertEquals($view->getPath(), 'newPath');
+ }
+
+
+ public function testViewArrayAccess()
+ {
+ $view = $this->getView();
+ $this->assertTrue($view instanceof ArrayAccess);
+ $this->assertTrue($view->offsetExists('foo'));
+ $this->assertEquals($view->offsetGet('foo'), 'bar');
+ $view->offsetSet('foo','baz');
+ $this->assertEquals($view->offsetGet('foo'), 'baz');
+ $view->offsetUnset('foo');
+ $this->assertFalse($view->offsetExists('foo'));
+ }
+
+
+ public function testViewMagicMethods()
+ {
+ $view = $this->getView();
+ $this->assertTrue(isset($view->foo));
+ $this->assertEquals($view->foo, 'bar');
+ $view->foo = 'baz';
+ $this->assertEquals($view->foo, 'baz');
+ $this->assertEquals($view['foo'], $view->foo);
+ unset($view->foo);
+ $this->assertFalse(isset($view->foo));
+ $this->assertFalse($view->offsetExists('foo'));
+ }
+
+
+ public function testViewBadMethod()
+ {
+ $this->setExpectedException('BadMethodCallException');
+ $view = $this->getView();
+ $view->badMethodCall();
+ }
+
+
+ public function testViewGatherDataWithRenderable()
+ {
+ $view = $this->getView();
+ $view->getEnvironment()->shouldReceive('incrementRender')->once()->ordered();
+ $view->getEnvironment()->shouldReceive('callComposer')->once()->ordered()->with($view);
+ $view->getEnvironment()->shouldReceive('getShared')->once()->andReturn(array('shared' => 'foo'));
+ $view->getEngine()->shouldReceive('get')->once()->andReturn('contents');
+ $view->getEnvironment()->shouldReceive('decrementRender')->once()->ordered();
+ $view->getEnvironment()->shouldReceive('flushSectionsIfDoneRendering')->once();
+
+ $view->renderable = m::mock('Illuminate\Support\Contracts\RenderableInterface');
+ $view->renderable->shouldReceive('render')->once()->andReturn('text');
+ $view->render();
+ }
+
+
+ public function testViewRenderSections()
+ {
+ $view = $this->getView();
+ $view->getEnvironment()->shouldReceive('incrementRender')->once()->ordered();
+ $view->getEnvironment()->shouldReceive('callComposer')->once()->ordered()->with($view);
+ $view->getEnvironment()->shouldReceive('getShared')->once()->andReturn(array('shared' => 'foo'));
+ $view->getEngine()->shouldReceive('get')->once()->andReturn('contents');
+ $view->getEnvironment()->shouldReceive('decrementRender')->once()->ordered();
+ $view->getEnvironment()->shouldReceive('flushSectionsIfDoneRendering')->once();
+
+ $view->getEnvironment()->shouldReceive('getSections')->once()->andReturn(array('foo','bar'));
+ $sections = $view->renderSections();
+ $this->assertEquals($sections[0], 'foo');
+ $this->assertEquals($sections[1], 'bar');
+ }
+
+
+ public function testWithErrors()
+ {
+ $view = $this->getView();
+ $this->assertTrue($view->withErrors(array('foo'=>'bar','qu'=>'ux')) === $view);
+ $this->assertTrue($view->errors instanceof \Illuminate\Support\MessageBag);
+ $this->assertEquals(reset($view->errors->get('foo')), 'bar');
+ $this->assertEquals(reset($view->errors->get('qu')), 'ux');
+ $this->assertTrue($view->withErrors(new \Illuminate\Support\MessageBag(array('foo'=>'baz'))) === $view);
+ $this->assertEquals(reset($view->errors->get('foo')), 'baz');
+ }
protected function getView() | false |
Other | laravel | framework | 545cd1b06c65ce1a11ebe17088ace02d9261d731.json | Reverse if statement conditions. | src/Illuminate/Database/Eloquent/Builder.php | @@ -427,7 +427,7 @@ public function onlyTrashed()
*/
protected function isSoftDeleteConstraint(array $where, $column)
{
- return $where['column'] == $column && $where['type'] == 'Null';
+ return $where['type'] == 'Null' && $where['column'] == $column;
}
/** | false |
Other | laravel | framework | c0c2415bd109721de4fb9d7328f3f264241a1bd5.json | Remove expectedExceptionMessage comment. | tests/Database/DatabaseEloquentModelTest.php | @@ -69,7 +69,6 @@ public function testFindMethodCallsQueryBuilderCorrectly()
/**
* @expectedException Illuminate\Database\Eloquent\ModelNotFoundException
- * @expectedExceptionMessage EloquentModelFindNotFoundStub model not found
*/
public function testFindOrFailMethodThrowsModelNotFoundException()
{ | false |
Other | laravel | framework | ef2220995f73155fd5ebedd754c89656bcb49c25.json | Use JSON_PRETTY_PRINT available in php 5.4. | src/Illuminate/Foundation/ProviderRepository.php | @@ -200,7 +200,7 @@ public function writeManifest($manifest)
{
$path = $this->manifestPath.'/services.json';
- $this->files->put($path, json_encode($manifest));
+ $this->files->put($path, json_encode($manifest, JSON_PRETTY_PRINT));
return $manifest;
} | false |
Other | laravel | framework | 5eb304614019530d360421ba7ec930fac7aa65b1.json | Move getDirty out of timestamp check. | src/Illuminate/Database/Eloquent/Model.php | @@ -1334,13 +1334,13 @@ protected function performUpdate(Builder $query)
if ($this->timestamps)
{
$this->updateTimestamps();
-
- $dirty = $this->getDirty();
}
// Once we have run the update operation, we will fire the "updated" event for
// this model instance. This will allow developers to hook into these after
// models are updated, giving them a chance to do any special processing.
+ $dirty = $this->getDirty();
+
$this->setKeysForSaveQuery($query)->update($dirty);
$this->fireModelEvent('updated', false); | false |
Other | laravel | framework | 8a9b8c6b864cc7e72200e89fab367796c72e4269.json | Improve Illuminate\Cookie\CookieJar test coverage | tests/Cookie/CookieTest.php | @@ -29,6 +29,10 @@ public function testCookiesAreCreatedWithProperOptions()
$this->assertTrue($c2->isSecure());
$this->assertEquals('/domain', $c2->getDomain());
$this->assertEquals('/path', $c2->getPath());
+
+ $c3 = $cookie->forget('color');
+ $this->assertTrue($c3->getValue() === null);
+ $this->assertTrue($c3->getExpiresTime() < time());
}
@@ -49,9 +53,15 @@ public function testQueuedCookies()
{
$cookie = $this->getCreator();
$this->assertEmpty($cookie->getQueuedCookies());
+ $this->assertFalse($cookie->hasQueued('foo'));
$cookie->queue($cookie->make('foo','bar'));
$this->assertArrayHasKey('foo', $cookie->getQueuedCookies());
+ $this->assertTrue($cookie->hasQueued('foo'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Cookie', $cookie->queued('foo'));
+ $cookie->queue('qu','ux');
+ $this->assertArrayHasKey('qu', $cookie->getQueuedCookies());
+ $this->assertTrue($cookie->hasQueued('qu'));
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\Cookie', $cookie->queued('qu'));
}
public function testUnqueue() | false |
Other | laravel | framework | ac9aa8d06c4d81fa746b6e114c2146a7a468a7db.json | Improve Illuminate\Session\Store test coverage | tests/Session/SessionStoreTest.php | @@ -30,6 +30,14 @@ public function testSessionIsLoadedFromHandler()
}
+ public function testSessionGetBagException()
+ {
+ $this->setExpectedException('InvalidArgumentException');
+ $session = $this->getSession();
+ $session->getBag('doesNotExist');
+ }
+
+
public function testSessionMigration()
{
$session = $this->getSession();
@@ -47,6 +55,29 @@ public function testSessionMigration()
}
+ public function testSessionRegeneration()
+ {
+ $session = $this->getSession();
+ $oldId = $session->getId();
+ $session->getHandler()->shouldReceive('destroy')->never();
+ $this->assertTrue($session->regenerate());
+ $this->assertFalse($oldId == $session->getId());
+ }
+
+
+ public function testSessionInvalidate()
+ {
+ $session = $this->getSession();
+ $oldId = $session->getId();
+ $session->set('foo','bar');
+ $this->assertTrue(count($session->all()) > 0);
+ $session->getHandler()->shouldReceive('destroy')->never();
+ $this->assertTrue($session->invalidate());
+ $this->assertFalse($oldId == $session->getId());
+ $this->assertTrue(count($session->all()) == 0);
+ }
+
+
public function testSessionIsProperlySaved()
{
$session = $this->getSession();
@@ -113,7 +144,77 @@ public function testDataFlashing()
}
- public function testHasOldInputWithoutKey ()
+ public function testDataMergeNewFlashes()
+ {
+ $session = $this->getSession();
+ $session->flash('foo', 'bar');
+ $session->set('fu', 'baz');
+ $session->set('flash.old', array('qu'));
+ $this->assertTrue(array_search('foo', $session->get('flash.new')) !== false);
+ $this->assertTrue(array_search('fu', $session->get('flash.new')) === false);
+ $session->keep(array('fu','qu'));
+ $this->assertTrue(array_search('foo', $session->get('flash.new')) !== false);
+ $this->assertTrue(array_search('fu', $session->get('flash.new')) !== false);
+ $this->assertTrue(array_search('qu', $session->get('flash.new')) !== false);
+ $this->assertTrue(array_search('qu', $session->get('flash.old')) === false);
+ }
+
+
+ public function testReflash()
+ {
+ $session = $this->getSession();
+ $session->flash('foo', 'bar');
+ $session->set('flash.old', array('foo'));
+ $session->reflash();
+ $this->assertTrue(array_search('foo', $session->get('flash.new')) !== false);
+ $this->assertTrue(array_search('foo', $session->get('flash.old')) === false);
+ }
+
+
+ public function testReplace()
+ {
+ $session = $this->getSession();
+ $session->set('foo', 'bar');
+ $session->set('qu', 'ux');
+ $session->replace(array('foo'=>'baz'));
+ $this->assertTrue($session->get('foo') == 'baz');
+ $this->assertTrue($session->get('qu') == 'ux');
+ }
+
+
+ public function testRemove()
+ {
+ $session = $this->getSession();
+ $session->set('foo', 'bar');
+ $pulled = $session->remove('foo');
+ $this->assertFalse($session->has('foo'));
+ $this->assertTrue($pulled == 'bar');
+ }
+
+
+ public function testClear()
+ {
+ $session = $this->getSession();
+ $session->set('foo', 'bar');
+
+ $bag = new Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag('bagged');
+ $bag->set('qu', 'ux');
+ $session->registerBag($bag);
+
+ $session->clear();
+ $this->assertFalse($session->has('foo'));
+ $this->assertFalse($session->getBag('bagged')->has('qu'));
+
+ $session->set('foo', 'bar');
+ $session->getBag('bagged')->set('qu', 'ux');
+
+ $session->flush();
+ $this->assertFalse($session->has('foo'));
+ $this->assertFalse($session->getBag('bagged')->has('qu'));
+ }
+
+
+ public function testHasOldInputWithoutKey()
{
$session = $this->getSession();
$session->flash('boom', 'baz');
@@ -122,6 +223,36 @@ public function testHasOldInputWithoutKey ()
$session->flashInput(array('foo' => 'bar'));
$this->assertTrue($session->hasOldInput());
}
+
+
+ public function testHandlerNeedsRequest()
+ {
+ $session = $this->getSession();
+ $this->assertFalse($session->handlerNeedsRequest());
+ $session->getHandler()->shouldReceive('setRequest')->never();
+
+ $session = new \Illuminate\Session\Store('test', m::mock(new \Illuminate\Session\CookieSessionHandler(new \Illuminate\Cookie\CookieJar(), 60)));
+ $this->assertTrue($session->handlerNeedsRequest());
+ $session->getHandler()->shouldReceive('setRequest')->once();
+ $request = new \Symfony\Component\HttpFoundation\Request();
+ $session->setRequestOnHandler($request);
+ }
+
+
+ public function testToken()
+ {
+ $session = $this->getSession();
+ $this->assertTrue($session->token() == $session->getToken());
+ }
+
+
+ public function testName()
+ {
+ $session = $this->getSession();
+ $this->assertEquals($session->getName(), $this->getSessionName());
+ $session->setName('foo');
+ $this->assertEquals($session->getName(), 'foo');
+ }
public function getSession()
@@ -134,10 +265,15 @@ public function getSession()
public function getMocks()
{
return array(
- 'name',
+ $this->getSessionName(),
m::mock('SessionHandlerInterface'),
'1'
);
}
+
+ public function getSessionName()
+ {
+ return 'name';
+ }
}
\ No newline at end of file | false |
Other | laravel | framework | e1e764ee8800203720ff6a5c6601cc821e3073a8.json | Update doc block. | src/Illuminate/Http/RedirectResponse.php | @@ -112,6 +112,7 @@ public function exceptInput()
* Flash a container of errors to the session.
*
* @param \Illuminate\Support\Contracts\MessageProviderInterface|array $provider
+ * @param string $key
* @return \Illuminate\Http\RedirectResponse
*/
public function withErrors($provider, $key = 'default') | false |
Other | laravel | framework | bf062fee1e0b67b2d646f37a7ef734ea5391c34c.json | Allow fallback_locale in translator. | src/Illuminate/Translation/TranslationServiceProvider.php | @@ -31,6 +31,8 @@ public function register()
$trans = new Translator($loader, $locale);
+ $trans->setFallback($app['config']['app.fallback_locale']);
+
return $trans;
});
}
| true |
Other | laravel | framework | bf062fee1e0b67b2d646f37a7ef734ea5391c34c.json | Allow fallback_locale in translator. | src/Illuminate/Translation/Translator.php | @@ -21,6 +21,13 @@ class Translator extends NamespacedItemResolver implements TranslatorInterface {
*/
protected $locale;
+ /**
+ * The fallback locale used by the translator.
+ *
+ * @var string
+ */
+ protected $fallback;
+
/**
* The array of loaded translation groups.
*
@@ -68,13 +75,16 @@ public function get($key, array $replace = array(), $locale = null)
// Here we will get the locale that should be used for the language line. If one
// was not passed, we will use the default locales which was given to us when
// the translator was instantiated. Then, we can load the lines and return.
- $locale = $locale ?: $this->getLocale();
+ foreach ($this->parseLocale($locale) as $locale)
+ {
+ $this->load($namespace, $group, $locale);
- $this->load($namespace, $group, $locale);
+ $line = $this->getLine(
+ $namespace, $group, $locale, $item, $replace
+ );
- $line = $this->getLine(
- $namespace, $group, $locale, $item, $replace
- );
+ if ( ! is_null($line)) break;
+ }
// If the line doesn't exist, we will return back the key which was requested as
// that will be quick to spot in the UI if language keys are wrong or missing
@@ -248,6 +258,23 @@ public function parseKey($key)
return $segments;
}
+ /**
+ * Get the array of locales to be checked.
+ *
+ * @return array
+ */
+ protected function parseLocale($locale)
+ {
+ if ( ! is_null($locale))
+ {
+ return array_filter(array($locale, $this->fallback));
+ }
+ else
+ {
+ return array_filter(array($this->locale, $this->fallback));
+ }
+ }
+
/**
* Get the message selector instance.
*
@@ -315,4 +342,25 @@ public function setLocale($locale)
$this->locale = $locale;
}
+ /**
+ * Set the fallback locale being used.
+ *
+ * @return string
+ */
+ public function getFallback()
+ {
+ return $this->fallback;
+ }
+
+ /**
+ * Set the fallback locale being used.
+ *
+ * @param string $fallback
+ * @return void
+ */
+ public function setFallback($fallback)
+ {
+ $this->fallback = $fallback;
+ }
+
} | true |
Other | laravel | framework | 1a9006b868b3dc7cbfa33d4c63239e76d5e4bc1e.json | Return empty collection if array is empty. | src/Illuminate/Database/Eloquent/Model.php | @@ -502,6 +502,8 @@ public static function all($columns = array('*'))
*/
public static function find($id, $columns = array('*'))
{
+ if (is_array($id) && empty($id)) return new Collection;
+
$instance = new static;
return $instance->newQuery()->find($id, $columns); | true |
Other | laravel | framework | 1a9006b868b3dc7cbfa33d4c63239e76d5e4bc1e.json | Return empty collection if array is empty. | src/Illuminate/Foundation/changes.json | @@ -85,7 +85,8 @@
{"message": "Added 'append_config' helper to assign high keys to configuration items.", "backport": null},
{"message": "Nested where queries using Closures with Eloquent will now use Eloquent query builder.", "backport": null},
{"message": "Allow passing a string into the 'sortBy' and 'sortByDesc' Collection methods.", "backport": null},
- {"message": "Added 'sum' method to the base Support collection.", "backport": null}
+ {"message": "Added 'sum' method to the base Support collection.", "backport": null},
+ {"message": "Return an empty Collection if the array given to Eloquent::find is empty.", "backport": null}
],
"4.0.*": [
{"message": "Added implode method to query builder and Collection class.", "backport": null}, | true |
Other | laravel | framework | 222e5c62c7a013bd4cb0c749bfea69f0988943bd.json | Move Config::append to helper instead. | src/Illuminate/Support/Facades/Config.php | @@ -5,29 +5,6 @@
*/
class Config extends Facade {
- /**
- * Assign high numeric IDs to a config item to force appending.
- *
- * @param array $array
- * @return array
- */
- public static function append(array $array)
- {
- $start = 9999;
-
- foreach ($array as $key => $value)
- {
- if (is_numeric($key))
- {
- $start++;
-
- $array[$start] = array_pull($array, $key);
- }
- }
-
- return $array;
- }
-
/**
* Get the registered name of the component.
*
| true |
Other | laravel | framework | 222e5c62c7a013bd4cb0c749bfea69f0988943bd.json | Move Config::append to helper instead. | src/Illuminate/Support/helpers.php | @@ -48,6 +48,32 @@ function app_path($path = '')
}
}
+if ( ! function_exists('append_config'))
+{
+ /**
+ * Assign high numeric IDs to a config item to force appending.
+ *
+ * @param array $array
+ * @return array
+ */
+ function append_config(array $array)
+ {
+ $start = 9999;
+
+ foreach ($array as $key => $value)
+ {
+ if (is_numeric($key))
+ {
+ $start++;
+
+ $array[$start] = array_pull($array, $key);
+ }
+ }
+
+ return $array;
+
+}
+
if ( ! function_exists('array_add'))
{
/** | true |
Other | laravel | framework | cbec444542fa9da5fec1a39bd8b602d16016eccd.json | Fix unit tests | tests/Cache/CacheFileStoreTest.php | @@ -74,18 +74,28 @@ public function testForeversAreStoredWithHighTimestamp()
$store->forever('foo', 'Hello World', 10);
}
+ public function testRemoveDeletesFileDoesntExist()
+ {
+ $files = $this->mockFilesystem();
+ $md5 = md5('foobull');
+ $cache_dir = substr($md5, 0, 2).'/'.substr($md5, 2, 2);
+ $files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5))->will($this->returnValue(false));
+ $store = new FileStore($files, __DIR__);
+ $store->forget('foobull');
+ }
public function testRemoveDeletesFile()
{
$files = $this->mockFilesystem();
- $md5 = md5('foo');
+ $md5 = md5('foobar');
$cache_dir = substr($md5, 0, 2).'/'.substr($md5, 2, 2);
- $files->expects($this->once())->method('delete')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5));
$store = new FileStore($files, __DIR__);
- $store->forget('foo');
+ $store->put('foobar', 'Hello Baby', 10);
+ $files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5))->will($this->returnValue(true));
+ $files->expects($this->once())->method('delete')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$md5));
+ $store->forget('foobar');
}
-
public function testFlushCleansDirectory()
{
$files = $this->mockFilesystem(); | false |
Other | laravel | framework | 6c2a68891a7069b9e6ffa9c23d0f125720b6307a.json | Fix boolean operators. | src/Illuminate/Foundation/Console/TinkerCommand.php | @@ -118,7 +118,7 @@ protected function prompt()
*/
protected function supportsBoris()
{
- return (extension_loaded('readline') and extension_loaded('posix') and extension_loaded('pcntl'));
+ return extension_loaded('readline') && extension_loaded('posix') && extension_loaded('pcntl');
}
} | false |
Other | laravel | framework | da9970de40d99e58843b27e9f01f56bfcf1789ff.json | Remove some unused variables in functions. | src/Illuminate/Foundation/ViewPublisher.php | @@ -63,9 +63,7 @@ public function publish($package, $source)
*/
public function publishPackage($package, $packagePath = null)
{
- list($vendor, $name) = explode('/', $package);
-
- $source = $this->getSource($package, $name, $packagePath ?: $this->packagePath);
+ $source = $this->getSource($package, $packagePath ?: $this->packagePath);
return $this->publish($package, $source);
}
@@ -74,13 +72,12 @@ public function publishPackage($package, $packagePath = null)
* Get the source views directory to publish.
*
* @param string $package
- * @param string $name
* @param string $packagePath
* @return string
*
* @throws \InvalidArgumentException
*/
- protected function getSource($package, $name, $packagePath)
+ protected function getSource($package, $packagePath)
{
$source = $packagePath."/{$package}/src/views";
| false |
Other | laravel | framework | 0555702816ad551e3a5a98ec9e322e323f06bb8a.json | Return results from function. | src/Illuminate/Remote/Connection.php | @@ -150,7 +150,7 @@ public function get($remote, $local)
*/
public function getString($remote)
{
- $this->getGateway()->getString($remote);
+ return $this->getGateway()->getString($remote);
}
/** | true |
Other | laravel | framework | 0555702816ad551e3a5a98ec9e322e323f06bb8a.json | Return results from function. | src/Illuminate/Remote/SecLibGateway.php | @@ -126,7 +126,7 @@ public function get($remote, $local)
*/
public function getString($remote)
{
- $this->getConnection()->get($remote);
+ return $this->getConnection()->get($remote);
}
/** | true |
Other | laravel | framework | 726ac155f7e27814058607a2c357fe9e71555b13.json | Make encryption optional on Iron.io. | src/Illuminate/Queue/Connectors/IronConnector.php | @@ -46,7 +46,7 @@ public function connect(array $config)
if (isset($config['host'])) $ironConfig['host'] = $config['host'];
- return new IronQueue(new IronMQ($ironConfig), $this->crypt, $this->request, $config['queue']);
+ return new IronQueue(new IronMQ($ironConfig), $this->crypt, $this->request, $config['queue'], $config['encrypt']);
}
}
\ No newline at end of file | true |
Other | laravel | framework | 726ac155f7e27814058607a2c357fe9e71555b13.json | Make encryption optional on Iron.io. | src/Illuminate/Queue/IronQueue.php | @@ -36,21 +36,30 @@ class IronQueue extends Queue implements QueueInterface {
*/
protected $default;
+ /**
+ * Indicates if the messages should be encrypted.
+ *
+ * @var bool
+ */
+ protected $shouldEncrypt;
+
/**
* Create a new IronMQ queue instance.
*
* @param \IronMQ $iron
* @param \Illuminate\Encryption\Encrypter $crypt
* @param \Illuminate\Http\Request $request
* @param string $default
+ * @param bool $shouldEncrypt
* @return void
*/
- public function __construct(IronMQ $iron, Encrypter $crypt, Request $request, $default)
+ public function __construct(IronMQ $iron, Encrypter $crypt, Request $request, $default, $shouldEncrypt = false)
{
$this->iron = $iron;
$this->crypt = $crypt;
$this->request = $request;
$this->default = $default;
+ $this->shouldEncrypt = $shouldEncrypt;
}
/**
@@ -76,7 +85,7 @@ public function push($job, $data = '', $queue = null)
*/
public function pushRaw($payload, $queue = null, array $options = array())
{
- $payload = $this->crypt->encrypt($payload);
+ if ($this->shouldEncrypt) $payload = $this->crypt->encrypt($payload);
return $this->iron->postMessage($this->getQueue($queue), $payload, $options)->id;
}
@@ -131,7 +140,7 @@ public function pop($queue = null)
// queues will be a security hazard to unsuspecting developers using it.
if ( ! is_null($job))
{
- $job->body = $this->crypt->decrypt($job->body);
+ $job->body = $this->parseJobBody($job->body);
return new IronJob($this->container, $this, $job);
}
@@ -170,7 +179,7 @@ protected function marshalPushedJob()
{
$r = $this->request;
- $body = $this->crypt->decrypt($r->getContent());
+ $body = $this->parseJobBody($r->getContent());
return (object) array(
'id' => $r->header('iron-message-id'), 'body' => $body, 'pushed' => true,
@@ -203,6 +212,17 @@ protected function createPayload($job, $data = '', $queue = null)
return $this->setMeta($payload, 'queue', $this->getQueue($queue));
}
+ /**
+ * Parse the job body for firing.
+ *
+ * @param string $body
+ * @return string
+ */
+ protected function parseJobBody($body)
+ {
+ return $this->shouldEncrypt ? $this->crypt->decrypt($body) : $body;
+ }
+
/**
* Get the queue or return the default.
* | true |
Other | laravel | framework | 726ac155f7e27814058607a2c357fe9e71555b13.json | Make encryption optional on Iron.io. | tests/Queue/QueueIronQueueTest.php | @@ -12,16 +12,25 @@ public function tearDown()
public function testPushProperlyPushesJobOntoIron()
{
- $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
+ $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true);
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array('job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default')))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array())->andReturn((object) array('id' => 1));
$queue->push('foo', array(1, 2, 3));
}
- public function testPushProperlyPushesJobOntoIronWithClosures()
+ public function testPushProperlyPushesJobOntoIronWithoutEncryption()
{
$queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
+ $crypt->shouldReceive('encrypt')->never();
+ $iron->shouldReceive('postMessage')->once()->with('default', json_encode(['job' => 'foo', 'data' => [1, 2, 3], 'attempts' => 1, 'queue' => 'default']), array())->andReturn((object) array('id' => 1));
+ $queue->push('foo', array(1, 2, 3));
+ }
+
+
+ public function testPushProperlyPushesJobOntoIronWithClosures()
+ {
+ $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true);
$name = 'Foo';
$closure = new Illuminate\Support\SerializableClosure($innerClosure = function() use ($name) { return $name; });
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array(
@@ -34,7 +43,7 @@ public function testPushProperlyPushesJobOntoIronWithClosures()
public function testDelayedPushProperlyPushesJobOntoIron()
{
- $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
+ $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true);
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array(
'job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default',
)))->andReturn('encrypted');
@@ -46,7 +55,7 @@ public function testDelayedPushProperlyPushesJobOntoIron()
public function testDelayedPushProperlyPushesJobOntoIronWithTimestamp()
{
$now = Carbon\Carbon::now();
- $queue = $this->getMock('Illuminate\Queue\IronQueue', array('getTime'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default'));
+ $queue = $this->getMock('Illuminate\Queue\IronQueue', array('getTime'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true));
$queue->expects($this->once())->method('getTime')->will($this->returnValue($now->getTimestamp()));
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array('job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default')))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array('delay' => 5))->andReturn((object) array('id' => 1));
@@ -56,7 +65,7 @@ public function testDelayedPushProperlyPushesJobOntoIronWithTimestamp()
public function testPopProperlyPopsJobOffOfIron()
{
- $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
+ $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true);
$queue->setContainer(m::mock('Illuminate\Container\Container'));
$iron->shouldReceive('getMessage')->once()->with('default')->andReturn($job = m::mock('IronMQ_Message'));
$job->body = 'foo';
@@ -67,9 +76,22 @@ public function testPopProperlyPopsJobOffOfIron()
}
+ public function testPopProperlyPopsJobOffOfIronWithoutEncryption()
+ {
+ $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
+ $queue->setContainer(m::mock('Illuminate\Container\Container'));
+ $iron->shouldReceive('getMessage')->once()->with('default')->andReturn($job = m::mock('IronMQ_Message'));
+ $job->body = 'foo';
+ $crypt->shouldReceive('decrypt')->never();
+ $result = $queue->pop();
+
+ $this->assertInstanceOf('Illuminate\Queue\Jobs\IronJob', $result);
+ }
+
+
public function testPushedJobsCanBeMarshaled()
{
- $queue = $this->getMock('Illuminate\Queue\IronQueue', array('createPushedIronJob'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), $request = m::mock('Illuminate\Http\Request'), 'default'));
+ $queue = $this->getMock('Illuminate\Queue\IronQueue', array('createPushedIronJob'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), $request = m::mock('Illuminate\Http\Request'), 'default', true));
$request->shouldReceive('header')->once()->with('iron-message-id')->andReturn('message-id');
$request->shouldReceive('getContent')->once()->andReturn($content = json_encode(array('foo' => 'bar')));
$crypt->shouldReceive('decrypt')->once()->with($content)->andReturn($content); | true |
Other | laravel | framework | 13f00c8e26a792da3817f47c07e1e5f48cd84b0f.json | Fix incorrect comment | src/Illuminate/Http/FrameGuard.php | @@ -13,7 +13,7 @@ class FrameGuard implements HttpKernelInterface {
protected $app;
/**
- * Create a new CookieQueue instance.
+ * Create a new FrameGuard instance.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $app
* @return void | false |
Other | laravel | framework | 7b1b90e5ee8420758c5c880d5d6ec92092315b13.json | Implement array sessions on certain callbacks. | src/Illuminate/Foundation/Application.php | @@ -514,6 +514,20 @@ public function shutdown($callback = null)
}
}
+ /**
+ * Register a function for determining when to use array sessions.
+ *
+ * @param \Closure $callback
+ * @return void
+ */
+ public function useArraySessions(Closure $callback)
+ {
+ $this->bind('session.reject', function() use ($callback)
+ {
+ return $callback;
+ });
+ }
+
/**
* Determine if the application has booted.
*
@@ -603,10 +617,12 @@ public function run(SymfonyRequest $request = null)
*/
protected function getStackedClient()
{
+ $sessionReject = $this->bound('session.reject') ? $this['session.reject'] : null;
+
$client = with(new \Stack\Builder)
->push('Illuminate\Cookie\Guard', $this['encrypter'])
->push('Illuminate\Cookie\Queue', $this['cookie'])
- ->push('Illuminate\Session\Middleware', $this['session']);
+ ->push('Illuminate\Session\Middleware', $this['session'], $sessionReject);
$this->mergeCustomMiddlewares($client);
| true |
Other | laravel | framework | 7b1b90e5ee8420758c5c880d5d6ec92092315b13.json | Implement array sessions on certain callbacks. | src/Illuminate/Session/Middleware.php | @@ -1,5 +1,6 @@
<?php namespace Illuminate\Session;
+use Closure;
use Carbon\Carbon;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
@@ -22,16 +23,25 @@ class Middleware implements HttpKernelInterface {
*/
protected $manager;
+ /**
+ * The callback to determine to use session arrays.
+ *
+ * @var \Closure|null
+ */
+ protected $reject;
+
/**
* Create a new session middleware.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $app
* @param \Illuminate\Session\SessionManager $manager
+ * @param \Closure|null $reject
* @return void
*/
- public function __construct(HttpKernelInterface $app, SessionManager $manager)
+ public function __construct(HttpKernelInterface $app, SessionManager $manager, Closure $reject = null)
{
$this->app = $app;
+ $this->reject = $reject;
$this->manager = $manager;
}
@@ -47,6 +57,8 @@ public function __construct(HttpKernelInterface $app, SessionManager $manager)
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
+ $this->checkRequestForArraySessions($request);
+
// If a session driver has been configured, we will need to start the session here
// so that the data is ready for an application. Note that the Laravel sessions
// do not make use of PHP "native" sessions in any way since they are crappy.
@@ -72,6 +84,22 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
return $response;
}
+ /**
+ * Check the request and reject callback for array sessions.
+ *
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ * @return void
+ */
+ public function checkRequestForArraySessions(Request $request)
+ {
+ if (is_null($this->reject)) return;
+
+ if (call_user_func($this->reject, $request))
+ {
+ $this->manager->setDefaultDriver('array');
+ }
+ }
+
/**
* Start the session for the given request.
* | true |
Other | laravel | framework | 7b1b90e5ee8420758c5c880d5d6ec92092315b13.json | Implement array sessions on certain callbacks. | tests/Session/SessionMiddlewareTest.php | @@ -63,4 +63,18 @@ public function testSessionIsNotUsedWhenNoDriver()
$this->assertTrue($response === $middleResponse);
}
+
+ public function testCheckingForRequestUsingArraySessions()
+ {
+ $middleware = new Illuminate\Session\Middleware(
+ m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'),
+ $manager = m::mock('Illuminate\Session\SessionManager'),
+ function() { return true; }
+ );
+
+ $manager->shouldReceive('setDefaultDriver')->once()->with('array');
+
+ $middleware->checkRequestForArraySessions(new Symfony\Component\HttpFoundation\Request);
+ }
+
}
\ No newline at end of file | true |
Other | laravel | framework | 13063142ac0539362d07f4aca83084b43cbf77b1.json | Move locale method. | src/Illuminate/Foundation/Application.php | @@ -937,31 +937,6 @@ public function getProviderRepository()
return new ProviderRepository(new Filesystem, $manifest);
}
- /**
- * Get the current application locale.
- *
- * @return string
- */
- public function getLocale()
- {
- return $this['config']->get('app.locale');
- }
-
- /**
- * Set the current application locale.
- *
- * @param string $locale
- * @return void
- */
- public function setLocale($locale)
- {
- $this['config']->set('app.locale', $locale);
-
- $this['translator']->setLocale($locale);
-
- $this['events']->fire('locale.changed', array($locale));
- }
-
/**
* Get the service providers that have been loaded.
*
@@ -1022,6 +997,31 @@ public static function onRequest($method, $parameters = array())
return forward_static_call_array(array(static::requestClass(), $method), $parameters);
}
+ /**
+ * Get the current application locale.
+ *
+ * @return string
+ */
+ public function getLocale()
+ {
+ return $this['config']->get('app.locale');
+ }
+
+ /**
+ * Set the current application locale.
+ *
+ * @param string $locale
+ * @return void
+ */
+ public function setLocale($locale)
+ {
+ $this['config']->set('app.locale', $locale);
+
+ $this['translator']->setLocale($locale);
+
+ $this['events']->fire('locale.changed', array($locale));
+ }
+
/**
* Register the core class aliases in the container.
* | false |
Other | laravel | framework | 5e125b1290749373358ff8c1efe260f88b2e0a59.json | Resolve customer connectors out of the container. | tests/Database/DatabaseConnectionFactoryTest.php | @@ -103,7 +103,18 @@ public function testIfDriverIsntSetExceptionIsThrown()
public function testExceptionIsThrownOnUnsupportedDriver()
{
$factory = new Illuminate\Database\Connectors\ConnectionFactory($container = m::mock('Illuminate\Container\Container'));
+ $container->shouldReceive('bound')->once()->andReturn(false);
$factory->createConnector(array('driver' => 'foo'));
}
+
+ public function testCustomConnectorsCanBeResolvedViaContainer()
+ {
+ $factory = new Illuminate\Database\Connectors\ConnectionFactory($container = m::mock('Illuminate\Container\Container'));
+ $container->shouldReceive('bound')->once()->with('db.connector.foo')->andReturn(true);
+ $container->shouldReceive('make')->once()->with('db.connector.foo')->andReturn('connector');
+
+ $this->assertEquals('connector', $factory->createConnector(array('driver' => 'foo')));
+ }
+
}
\ No newline at end of file | false |
Other | laravel | framework | d78fb051caa5c3c8cf8b59ef82d8562bd3de1e92.json | Pass container instance to resolving callbacks. | src/Illuminate/Container/Container.php | @@ -639,7 +639,7 @@ protected function fireCallbackArray($object, array $callbacks)
{
foreach ($callbacks as $callback)
{
- call_user_func($callback, $object);
+ call_user_func($callback, $object, $this);
}
}
| false |
Other | laravel | framework | a4124979faa0e57bda92f0e3f8f8214fe545a2ba.json | str_limit helper added | src/Illuminate/Support/helpers.php | @@ -932,6 +932,22 @@ function studly_case($value)
}
}
+if ( ! function_exists('str_limit'))
+{
+ /**
+ * Limit the number of characters in a string.
+ *
+ * @param string $value
+ * @param int $limit
+ * @param string $end
+ * @return string
+ */
+ function str_limit($value, $limit = 100, $end = '...')
+ {
+ return Illuminate\Support\Str::limit($value, $limit, $end);
+ }
+}
+
if ( ! function_exists('trans'))
{
/** | false |
Other | laravel | framework | f0efda482ebf0d76bc3478257655a2e079c11cd7.json | Pass getBindings through to querybuilder | src/Illuminate/Database/Eloquent/Builder.php | @@ -34,8 +34,8 @@ class Builder {
* @var array
*/
protected $passthru = array(
- 'toSql', 'lists', 'insert', 'insertGetId', 'pluck',
- 'count', 'min', 'max', 'avg', 'sum', 'exists',
+ 'toSql', 'lists', 'insert', 'insertGetId', 'pluck', 'count',
+ 'min', 'max', 'avg', 'sum', 'exists', 'getBindings',
);
/** | false |
Other | laravel | framework | 93baad51c57176d8363b3720b57415c3c4a669fe.json | Fix cache minutes. | src/Illuminate/Cache/Repository.php | @@ -233,15 +233,12 @@ protected function getMinutes($duration)
if ($duration instanceof DateTime)
{
$duration = Carbon::instance($duration);
- }
- if ($duration instanceof Carbon)
- {
return max(0, Carbon::now()->diffInMinutes($duration, false));
}
else
{
- return intval($duration);
+ return is_string($duration) ? intval($duration) : $duration;
}
}
| false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.