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 | 9f84d8de45106d97feb672e199840ea186035ef4.json | Update versions for 7.0 | src/Illuminate/View/composer.json | @@ -16,11 +16,11 @@
"require": {
"php": "^7.2",
"ext-json": "*",
- "illuminate/container": "^6.0",
- "illuminate/contracts": "^6.0",
- "illuminate/events": "^6.0",
- "illuminate/filesystem": "^6.0",
- "illuminate/support": "^6.0",
+ "illuminate/container": "^7.0",
+ "illuminate/contracts": "^7.0",
+ "illuminate/events": "^7.0",
+ "illuminate/filesystem": "^7.0",
+ "illuminate/support": "^7.0",
"symfony/debug": "^4.3"
},
"autoload": { | true |
Other | laravel | framework | 7c1f079ce047b83cdee0787bea86468262a0f22d.json | Fix incorrect return type | src/Illuminate/Cache/RedisStore.php | @@ -235,7 +235,7 @@ public function tags($names)
/**
* Get the Redis connection instance.
*
- * @return \Predis\ClientInterface
+ * @return \Illuminate\Redis\Connections\Connection
*/
public function connection()
{ | false |
Other | laravel | framework | e54e1cc6841efca50c1d5a548f1ce15d7d59c51e.json | Remove Nexmo routing
After seeing https://github.com/laravel/framework/pull/29679 I noticed this was left over from when we removed the Nexmo notification channel from the core. After this change people will need to implement the routeNotificationForNexmo method themselves as they do for the Slack driver.
This is a breaking change for anyone using the Nexmo channel so this should be in the upgrade guide. | src/Illuminate/Notifications/RoutesNotifications.php | @@ -48,8 +48,6 @@ public function routeNotificationFor($driver, $notification = null)
return $this->notifications();
case 'mail':
return $this->email;
- case 'nexmo':
- return $this->phone_number;
}
}
} | true |
Other | laravel | framework | e54e1cc6841efca50c1d5a548f1ce15d7d59c51e.json | Remove Nexmo routing
After seeing https://github.com/laravel/framework/pull/29679 I noticed this was left over from when we removed the Nexmo notification channel from the core. After this change people will need to implement the routeNotificationForNexmo method themselves as they do for the Slack driver.
This is a breaking change for anyone using the Nexmo channel so this should be in the upgrade guide. | tests/Notifications/NotificationRoutesNotificationsTest.php | @@ -49,7 +49,6 @@ public function testNotificationOptionRouting()
$instance = new RoutesNotificationsTestInstance;
$this->assertEquals('bar', $instance->routeNotificationFor('foo'));
$this->assertEquals('taylor@laravel.com', $instance->routeNotificationFor('mail'));
- $this->assertEquals('5555555555', $instance->routeNotificationFor('nexmo'));
}
}
@@ -58,7 +57,6 @@ class RoutesNotificationsTestInstance
use RoutesNotifications;
protected $email = 'taylor@laravel.com';
- protected $phone_number = '5555555555';
public function routeNotificationForFoo()
{ | true |
Other | laravel | framework | 1239e66293c025210d69bab8a4556fdda9cfab85.json | Remove symfony dependencies from require-dev | composer.json | @@ -88,8 +88,6 @@
"phpunit/phpunit": "^8.0",
"predis/predis": "^1.1.1",
"symfony/cache": "^4.3",
- "symfony/css-selector": "^4.3",
- "symfony/dom-crawler": "^4.3",
"true/punycode": "^2.1"
},
"autoload": { | false |
Other | laravel | framework | 68359835771a43ee2432735b0d25de8d8c41b02c.json | Simplify lazy collection | src/Illuminate/Support/LazyCollection.php | @@ -149,10 +149,8 @@ public function mode($key = null)
*/
public function collapse()
{
- $original = clone $this;
-
- return new static(function () use ($original) {
- foreach ($original as $values) {
+ return new static(function () {
+ foreach ($this as $values) {
if (is_array($values) || $values instanceof Enumerable) {
foreach ($values as $value) {
yield $value;
@@ -321,10 +319,8 @@ public function filter(callable $callback = null)
};
}
- $original = clone $this;
-
- return new static(function () use ($original, $callback) {
- foreach ($original as $key => $value) {
+ return new static(function () use ($callback) {
+ foreach ($this as $key => $value) {
if ($callback($value, $key)) {
yield $key => $value;
}
@@ -368,10 +364,8 @@ public function first(callable $callback = null, $default = null)
*/
public function flatten($depth = INF)
{
- $original = clone $this;
-
- $instance = new static(function () use ($original, $depth) {
- foreach ($original as $item) {
+ $instance = new static(function () use ($depth) {
+ foreach ($this as $item) {
if (! is_array($item) && ! $item instanceof Enumerable) {
yield $item;
} elseif ($depth === 1) {
@@ -392,10 +386,8 @@ public function flatten($depth = INF)
*/
public function flip()
{
- $original = clone $this;
-
- return new static(function () use ($original) {
- foreach ($original as $key => $value) {
+ return new static(function () {
+ foreach ($this as $key => $value) {
yield $value => $key;
}
});
@@ -443,12 +435,10 @@ public function groupBy($groupBy, $preserveKeys = false)
*/
public function keyBy($keyBy)
{
- $original = clone $this;
-
- return new static(function () use ($original, $keyBy) {
+ return new static(function () use ($keyBy) {
$keyBy = $this->valueRetriever($keyBy);
- foreach ($original as $key => $item) {
+ foreach ($this as $key => $item) {
$resolvedKey = $keyBy($item, $key);
if (is_object($resolvedKey)) {
@@ -543,10 +533,8 @@ public function join($glue, $finalGlue = '')
*/
public function keys()
{
- $original = clone $this;
-
- return new static(function () use ($original) {
- foreach ($original as $key => $value) {
+ return new static(function () {
+ foreach ($this as $key => $value) {
yield $key;
}
});
@@ -581,12 +569,10 @@ public function last(callable $callback = null, $default = null)
*/
public function pluck($value, $key = null)
{
- $original = clone $this;
-
- return new static(function () use ($original, $value, $key) {
+ return new static(function () use ($value, $key) {
[$value, $key] = $this->explodePluckParameters($value, $key);
- foreach ($original as $item) {
+ foreach ($this as $item) {
$itemValue = data_get($item, $value);
if (is_null($key)) {
@@ -612,10 +598,8 @@ public function pluck($value, $key = null)
*/
public function map(callable $callback)
{
- $original = clone $this;
-
- return new static(function () use ($original, $callback) {
- foreach ($original as $key => $value) {
+ return new static(function () use ($callback) {
+ foreach ($this as $key => $value) {
yield $key => $callback($value, $key);
}
});
@@ -644,10 +628,8 @@ public function mapToDictionary(callable $callback)
*/
public function mapWithKeys(callable $callback)
{
- $original = clone $this;
-
- return new static(function () use ($original, $callback) {
- foreach ($original as $key => $value) {
+ return new static(function () use ($callback) {
+ foreach ($this as $key => $value) {
yield from $callback($value, $key);
}
});
@@ -683,14 +665,12 @@ public function mergeRecursive($items)
*/
public function combine($values)
{
- $original = clone $this;
-
- return new static(function () use ($original, $values) {
+ return new static(function () use ($values) {
$values = $this->makeIterator($values);
$errorMessage = 'Both parameters should have an equal number of elements';
- foreach ($original as $key) {
+ foreach ($this as $key) {
if (! $values->valid()) {
trigger_error($errorMessage, E_USER_WARNING);
@@ -728,12 +708,10 @@ public function union($items)
*/
public function nth($step, $offset = 0)
{
- $original = clone $this;
-
- return new static(function () use ($original, $step, $offset) {
+ return new static(function () use ($step, $offset) {
$position = 0;
- foreach ($original as $item) {
+ foreach ($this as $item) {
if ($position % $step === $offset) {
yield $item;
}
@@ -757,15 +735,13 @@ public function only($keys)
$keys = is_array($keys) ? $keys : func_get_args();
}
- $original = clone $this;
-
- return new static(function () use ($original, $keys) {
+ return new static(function () use ($keys) {
if (is_null($keys)) {
- yield from $original;
+ yield from $this;
} else {
$keys = array_flip($keys);
- foreach ($original as $key => $value) {
+ foreach ($this as $key => $value) {
if (array_key_exists($key, $keys)) {
yield $key => $value;
@@ -788,10 +764,8 @@ public function only($keys)
*/
public function concat($source)
{
- $original = clone $this;
-
- return (new static(function () use ($original, $source) {
- yield from $original;
+ return (new static(function () use ($source) {
+ yield from $this;
yield from $source;
}))->values();
}
@@ -837,12 +811,10 @@ public function reduce(callable $callback, $initial = null)
*/
public function replace($items)
{
- $original = clone $this;
-
- return new static(function () use ($original, $items) {
+ return new static(function () use ($items) {
$items = $this->getArrayableItems($items);
- foreach ($original as $key => $value) {
+ foreach ($this as $key => $value) {
if (array_key_exists($key, $items)) {
yield $key => $items[$key];
@@ -922,10 +894,8 @@ public function shuffle($seed = null)
*/
public function skip($count)
{
- $original = clone $this;
-
- return new static(function () use ($original, $count) {
- $iterator = $original->getIterator();
+ return new static(function () use ($count) {
+ $iterator = $this->getIterator();
while ($iterator->valid() && $count--) {
$iterator->next();
@@ -980,10 +950,8 @@ public function chunk($size)
return static::empty();
}
- $original = clone $this;
-
- return new static(function () use ($original, $size) {
- $iterator = $original->getIterator();
+ return new static(function () use ($size) {
+ $iterator = $this->getIterator();
while ($iterator->valid()) {
$chunk = [];
@@ -1080,10 +1048,8 @@ public function take($limit)
return $this->passthru('take', func_get_args());
}
- $original = clone $this;
-
- return new static(function () use ($original, $limit) {
- $iterator = $original->getIterator();
+ return new static(function () use ($limit) {
+ $iterator = $this->getIterator();
while ($limit--) {
if (! $iterator->valid()) {
@@ -1107,10 +1073,8 @@ public function take($limit)
*/
public function tapEach(callable $callback)
{
- $original = clone $this;
-
- return new static(function () use ($original, $callback) {
- foreach ($original as $key => $value) {
+ return new static(function () use ($callback) {
+ foreach ($this as $key => $value) {
$callback($value, $key);
yield $key => $value;
@@ -1125,10 +1089,8 @@ public function tapEach(callable $callback)
*/
public function values()
{
- $original = clone $this;
-
- return new static(function () use ($original) {
- foreach ($original as $item) {
+ return new static(function () {
+ foreach ($this as $item) {
yield $item;
}
});
@@ -1147,12 +1109,10 @@ public function zip($items)
{
$iterables = func_get_args();
- $original = clone $this;
-
- return new static(function () use ($original, $iterables) {
+ return new static(function () use ($iterables) {
$iterators = Collection::make($iterables)->map(function ($iterable) {
return $this->makeIterator($iterable);
- })->prepend($original->getIterator());
+ })->prepend($this->getIterator());
while ($iterators->contains->valid()) {
yield new static($iterators->map->current());
@@ -1175,12 +1135,10 @@ public function pad($size, $value)
return $this->passthru('pad', func_get_args());
}
- $original = clone $this;
-
- return new static(function () use ($original, $size, $value) {
+ return new static(function () use ($size, $value) {
$yielded = 0;
- foreach ($original as $index => $item) {
+ foreach ($this as $index => $item) {
yield $index => $item;
$yielded++;
@@ -1260,22 +1218,8 @@ protected function explodePluckParameters($value, $key)
*/
protected function passthru($method, array $params)
{
- $original = clone $this;
-
- return new static(function () use ($original, $method, $params) {
- yield from $original->collect()->$method(...$params);
+ return new static(function () use ($method, $params) {
+ yield from $this->collect()->$method(...$params);
});
}
-
- /**
- * Finish cloning the collection instance.
- *
- * @return void
- */
- public function __clone()
- {
- if (! is_array($this->source)) {
- $this->source = clone $this->source;
- }
- }
} | false |
Other | laravel | framework | 4365561e5e5ad3b088d1752c6c6bb5bab652a5db.json | Remove mutating methods from lazy collection | src/Illuminate/Support/Collection.php | @@ -805,6 +805,19 @@ public function prepend($value, $key = null)
return $this;
}
+ /**
+ * Push an item onto the end of the collection.
+ *
+ * @param mixed $value
+ * @return $this
+ */
+ public function push($value)
+ {
+ $this->items[] = $value;
+
+ return $this;
+ }
+
/**
* Push all of the given items onto the collection.
* | true |
Other | laravel | framework | 4365561e5e5ad3b088d1752c6c6bb5bab652a5db.json | Remove mutating methods from lazy collection | src/Illuminate/Support/Enumerable.php | @@ -408,14 +408,6 @@ public function firstWhere($key, $operator = null, $value = null);
*/
public function flip();
- /**
- * Remove an item by key.
- *
- * @param string|array $keys
- * @return $this
- */
- public function forget($keys);
-
/**
* Get an item from the collection by key.
*
@@ -660,30 +652,6 @@ public function forPage($page, $perPage);
*/
public function partition($key, $operator = null, $value = null);
- /**
- * Get and remove the last item from the collection.
- *
- * @return mixed
- */
- public function pop();
-
- /**
- * Push an item onto the beginning of the collection.
- *
- * @param mixed $value
- * @param mixed $key
- * @return $this
- */
- public function prepend($value, $key = null);
-
- /**
- * Push an item onto the end of the collection.
- *
- * @param mixed $value
- * @return $this
- */
- public function push($value);
-
/**
* Push all of the given items onto the collection.
*
@@ -692,15 +660,6 @@ public function push($value);
*/
public function concat($source);
- /**
- * Put an item in the collection by key.
- *
- * @param mixed $key
- * @param mixed $value
- * @return $this
- */
- public function put($key, $value);
-
/**
* Get one or a specified number of items randomly from the collection.
*
@@ -752,13 +711,6 @@ public function reverse();
*/
public function search($value, $strict = false);
- /**
- * Get and remove the first item from the collection.
- *
- * @return mixed
- */
- public function shift();
-
/**
* Shuffle the items in the collection.
*
@@ -844,16 +796,6 @@ public function sortKeys($options = SORT_REGULAR, $descending = false);
*/
public function sortKeysDesc($options = SORT_REGULAR);
- /**
- * Splice a portion of the underlying collection array.
- *
- * @param int $offset
- * @param int|null $length
- * @param mixed $replacement
- * @return static
- */
- public function splice($offset, $length = null, $replacement = []);
-
/**
* Get the sum of the given values.
*
@@ -878,14 +820,6 @@ public function take($limit);
*/
public function tap(callable $callback);
- /**
- * Transform each item in the collection using a callback.
- *
- * @param callable $callback
- * @return $this
- */
- public function transform(callable $callback);
-
/**
* Pass the enumerable to the given callback and return the result.
*
@@ -952,14 +886,6 @@ public function pad($size, $value);
*/
public function countBy($callback = null);
- /**
- * Add an item to the collection.
- *
- * @param mixed $item
- * @return $this
- */
- public function add($item);
-
/**
* Convert the collection to its string representation.
* | true |
Other | laravel | framework | 4365561e5e5ad3b088d1752c6c6bb5bab652a5db.json | Remove mutating methods from lazy collection | src/Illuminate/Support/LazyCollection.php | @@ -401,29 +401,6 @@ public function flip()
});
}
- /**
- * Remove an item by key.
- *
- * @param string|array $keys
- * @return $this
- */
- public function forget($keys)
- {
- $original = clone $this;
-
- $this->source = function () use ($original, $keys) {
- $keys = array_flip((array) $keys);
-
- foreach ($original as $key => $value) {
- if (! array_key_exists($key, $keys)) {
- yield $key => $value;
- }
- }
- };
-
- return $this;
- }
-
/**
* Get an item by key.
*
@@ -803,50 +780,6 @@ public function only($keys)
});
}
- /**
- * Get and remove the last item from the collection.
- *
- * @return mixed
- */
- public function pop()
- {
- $items = $this->collect();
-
- $result = $items->pop();
-
- $this->source = $items;
-
- return $result;
- }
-
- /**
- * Push an item onto the beginning of the collection.
- *
- * @param mixed $value
- * @param mixed $key
- * @return $this
- */
- public function prepend($value, $key = null)
- {
- $original = clone $this;
-
- $this->source = function () use ($original, $value, $key) {
- $instance = new static(function () use ($original, $value, $key) {
- yield $key => $value;
-
- yield from $original;
- });
-
- if (is_null($key)) {
- $instance = $instance->values();
- }
-
- yield from $instance;
- };
-
- return $this;
- }
-
/**
* Push all of the given items onto the collection.
*
@@ -863,48 +796,6 @@ public function concat($source)
}))->values();
}
- /**
- * Put an item in the collection by key.
- *
- * @param mixed $key
- * @param mixed $value
- * @return $this
- */
- public function put($key, $value)
- {
- $original = clone $this;
-
- if (is_null($key)) {
- $this->source = function () use ($original, $value) {
- foreach ($original as $innerKey => $innerValue) {
- yield $innerKey => $innerValue;
- }
-
- yield $value;
- };
- } else {
- $this->source = function () use ($original, $key, $value) {
- $found = false;
-
- foreach ($original as $innerKey => $innerValue) {
- if ($innerKey == $key) {
- yield $key => $value;
-
- $found = true;
- } else {
- yield $innerKey => $innerValue;
- }
- }
-
- if (! $found) {
- yield $key => $value;
- }
- };
- }
-
- return $this;
- }
-
/**
* Get one or a specified number of items randomly from the collection.
*
@@ -1012,18 +903,6 @@ public function search($value, $strict = false)
return false;
}
- /**
- * Get and remove the first item from the collection.
- *
- * @return mixed
- */
- public function shift()
- {
- return tap($this->first(), function () {
- $this->source = $this->skip(1);
- });
- }
-
/**
* Shuffle the items in the collection.
*
@@ -1189,27 +1068,6 @@ public function sortKeysDesc($options = SORT_REGULAR)
return $this->passthru('sortKeysDesc', func_get_args());
}
- /**
- * Splice a portion of the underlying collection array.
- *
- * @param int $offset
- * @param int|null $length
- * @param mixed $replacement
- * @return static
- */
- public function splice($offset, $length = null, $replacement = [])
- {
- $items = $this->collect();
-
- $extracted = $items->splice(...func_get_args());
-
- $this->source = function () use ($items) {
- yield from $items;
- };
-
- return new static($extracted);
- }
-
/**
* Take the first or last {$limit} items.
*
@@ -1260,23 +1118,6 @@ public function tapEach(callable $callback)
});
}
- /**
- * Transform each item in the collection using a callback.
- *
- * @param callable $callback
- * @return $this
- */
- public function transform(callable $callback)
- {
- $original = clone $this;
-
- $this->source = function () use ($original, $callback) {
- yield from $original->map($callback);
- };
-
- return $this;
- }
-
/**
* Reset the keys on the underlying array.
*
@@ -1375,27 +1216,6 @@ public function count()
return iterator_count($this->getIterator());
}
- /**
- * Add an item to the collection.
- *
- * @param mixed $item
- * @return $this
- */
- public function add($item)
- {
- $original = clone $this;
-
- $this->source = function () use ($original, $item) {
- foreach ($original as $value) {
- yield $value;
- }
-
- yield $item;
- };
-
- return $this;
- }
-
/**
* Make an iterator from the given source.
* | true |
Other | laravel | framework | 4365561e5e5ad3b088d1752c6c6bb5bab652a5db.json | Remove mutating methods from lazy collection | src/Illuminate/Support/Traits/EnumeratesValues.php | @@ -377,17 +377,6 @@ public function partition($key, $operator = null, $value = null)
return new static([new static($passed), new static($failed)]);
}
- /**
- * Push an item onto the end.
- *
- * @param mixed $value
- * @return $this
- */
- public function push($value)
- {
- return $this->add($value);
- }
-
/**
* Get the sum of the given values.
* | true |
Other | laravel | framework | 4365561e5e5ad3b088d1752c6c6bb5bab652a5db.json | Remove mutating methods from lazy collection | tests/Support/SupportCollectionTest.php | @@ -127,23 +127,17 @@ public function testLastWithDefaultAndWithoutCallback($collection)
$this->assertEquals('default', $result);
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testPopReturnsAndRemovesLastItemInCollection($collection)
+ public function testPopReturnsAndRemovesLastItemInCollection()
{
- $c = new $collection(['foo', 'bar']);
+ $c = new Collection(['foo', 'bar']);
$this->assertEquals('bar', $c->pop());
$this->assertEquals('foo', $c->first());
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testShiftReturnsAndRemovesFirstItemInCollection($collection)
+ public function testShiftReturnsAndRemovesFirstItemInCollection()
{
- $data = new $collection(['Taylor', 'Otwell']);
+ $data = new Collection(['Taylor', 'Otwell']);
$this->assertEquals('Taylor', $data->shift());
$this->assertEquals('Otwell', $data->first());
@@ -365,32 +359,26 @@ public function testArrayAccessOffsetUnset()
$this->assertFalse(isset($c[1]));
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testForgetSingleKey($collection)
+ public function testForgetSingleKey()
{
- $c = new $collection(['foo', 'bar']);
+ $c = new Collection(['foo', 'bar']);
$c = $c->forget(0)->all();
$this->assertFalse(isset($c['foo']));
- $c = new $collection(['foo' => 'bar', 'baz' => 'qux']);
+ $c = new Collection(['foo' => 'bar', 'baz' => 'qux']);
$c = $c->forget('foo')->all();
$this->assertFalse(isset($c['foo']));
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testForgetArrayOfKeys($collection)
+ public function testForgetArrayOfKeys()
{
- $c = new $collection(['foo', 'bar', 'baz']);
+ $c = new Collection(['foo', 'bar', 'baz']);
$c = $c->forget([0, 2])->all();
$this->assertFalse(isset($c[0]));
$this->assertFalse(isset($c[2]));
$this->assertTrue(isset($c[1]));
- $c = new $collection(['name' => 'taylor', 'foo' => 'bar', 'baz' => 'qux']);
+ $c = new Collection(['name' => 'taylor', 'foo' => 'bar', 'baz' => 'qux']);
$c = $c->forget(['foo', 'baz'])->all();
$this->assertFalse(isset($c['foo']));
$this->assertFalse(isset($c['baz']));
@@ -1543,7 +1531,7 @@ public function testEvery($collection)
$c = new $collection([['active' => true], ['active' => true]]);
$this->assertTrue($c->every('active'));
$this->assertTrue($c->every->active);
- $this->assertFalse($c->push(['active' => false])->every->active);
+ $this->assertFalse($c->concat([['active' => false]])->every->active);
}
/**
@@ -1630,22 +1618,16 @@ public function testTake($collection)
$this->assertEquals(['taylor', 'dayle'], $data->all());
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testPut($collection)
+ public function testPut()
{
- $data = new $collection(['name' => 'taylor', 'email' => 'foo']);
+ $data = new Collection(['name' => 'taylor', 'email' => 'foo']);
$data = $data->put('name', 'dayle');
$this->assertEquals(['name' => 'dayle', 'email' => 'foo'], $data->all());
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testPutWithNoKey($collection)
+ public function testPutWithNoKey()
{
- $data = new $collection(['taylor', 'shawn']);
+ $data = new Collection(['taylor', 'shawn']);
$data = $data->put(null, 'dayle');
$this->assertEquals(['taylor', 'shawn', 'dayle'], $data->all());
}
@@ -1965,24 +1947,21 @@ public function testConstructMethodFromObject($collection)
$this->assertEquals(['foo' => 'bar'], $data->all());
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testSplice($collection)
+ public function testSplice()
{
- $data = new $collection(['foo', 'baz']);
+ $data = new Collection(['foo', 'baz']);
$data->splice(1);
$this->assertEquals(['foo'], $data->all());
- $data = new $collection(['foo', 'baz']);
+ $data = new Collection(['foo', 'baz']);
$data->splice(1, 0, 'bar');
$this->assertEquals(['foo', 'bar', 'baz'], $data->all());
- $data = new $collection(['foo', 'baz']);
+ $data = new Collection(['foo', 'baz']);
$data->splice(1, 1);
$this->assertEquals(['foo'], $data->all());
- $data = new $collection(['foo', 'baz']);
+ $data = new Collection(['foo', 'baz']);
$cut = $data->splice(1, 1, 'bar');
$this->assertEquals(['foo', 'bar'], $data->all());
$this->assertEquals(['baz'], $cut->all());
@@ -2261,12 +2240,9 @@ public function testMapWithKeysOverwritingKeys($collection)
);
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testTransform($collection)
+ public function testTransform()
{
- $data = new $collection(['first' => 'taylor', 'last' => 'otwell']);
+ $data = new Collection(['first' => 'taylor', 'last' => 'otwell']);
$data->transform(function ($item, $key) {
return $key.'-'.strrev($item);
});
@@ -2851,15 +2827,12 @@ public function testPaginate($collection)
$this->assertEquals([], $c->forPage(3, 2)->all());
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testPrepend($collection)
+ public function testPrepend()
{
- $c = new $collection(['one', 'two', 'three', 'four']);
+ $c = new Collection(['one', 'two', 'three', 'four']);
$this->assertEquals(['zero', 'one', 'two', 'three', 'four'], $c->prepend('zero')->all());
- $c = new $collection(['one' => 1, 'two' => 2]);
+ $c = new Collection(['one' => 1, 'two' => 2]);
$this->assertEquals(['zero' => 0, 'one' => 1, 'two' => 2], $c->prepend(0, 'zero')->all());
}
@@ -3670,16 +3643,16 @@ public function testWhen($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->when('adam', function ($data, $newName) {
- return $data->push($newName);
+ $data = $data->when('adam', function ($data, $newName) {
+ return $data->concat([$newName]);
});
$this->assertSame(['michael', 'tom', 'adam'], $data->toArray());
$data = new $collection(['michael', 'tom']);
- $data->when(false, function ($collection) {
- return $data->push('adam');
+ $data = $data->when(false, function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame(['michael', 'tom'], $data->toArray());
@@ -3692,10 +3665,10 @@ public function testWhenDefault($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->when(false, function ($data) {
- return $data->push('adam');
+ $data = $data->when(false, function ($data) {
+ return $data->concat(['adam']);
}, function ($data) {
- return $data->push('taylor');
+ return $data->concat(['taylor']);
});
$this->assertSame(['michael', 'tom', 'taylor'], $data->toArray());
@@ -3708,16 +3681,16 @@ public function testWhenEmpty($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->whenEmpty(function ($collection) {
- return $data->push('adam');
+ $data = $data->whenEmpty(function ($collection) {
+ return $data->concat(['adam']);
});
$this->assertSame(['michael', 'tom'], $data->toArray());
$data = new $collection;
- $data->whenEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->whenEmpty(function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame(['adam'], $data->toArray());
@@ -3730,10 +3703,10 @@ public function testWhenEmptyDefault($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->whenEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->whenEmpty(function ($data) {
+ return $data->concat(['adam']);
}, function ($data) {
- return $data->push('taylor');
+ return $data->concat(['taylor']);
});
$this->assertSame(['michael', 'tom', 'taylor'], $data->toArray());
@@ -3746,16 +3719,16 @@ public function testWhenNotEmpty($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->whenNotEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->whenNotEmpty(function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame(['michael', 'tom', 'adam'], $data->toArray());
$data = new $collection;
- $data->whenNotEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->whenNotEmpty(function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame([], $data->toArray());
@@ -3768,10 +3741,10 @@ public function testWhenNotEmptyDefault($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->whenNotEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->whenNotEmpty(function ($data) {
+ return $data->concat(['adam']);
}, function ($data) {
- return $data->push('taylor');
+ return $data->concat(['taylor']);
});
$this->assertSame(['michael', 'tom', 'adam'], $data->toArray());
@@ -3784,16 +3757,16 @@ public function testUnless($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->unless(false, function ($data) {
- return $data->push('caleb');
+ $data = $data->unless(false, function ($data) {
+ return $data->concat(['caleb']);
});
$this->assertSame(['michael', 'tom', 'caleb'], $data->toArray());
$data = new $collection(['michael', 'tom']);
- $data->unless(true, function ($data) {
- return $data->push('caleb');
+ $data = $data->unless(true, function ($data) {
+ return $data->concat(['caleb']);
});
$this->assertSame(['michael', 'tom'], $data->toArray());
@@ -3806,10 +3779,10 @@ public function testUnlessDefault($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->unless(true, function ($data) {
- return $data->push('caleb');
+ $data = $data->unless(true, function ($data) {
+ return $data->concat(['caleb']);
}, function ($data) {
- return $data->push('taylor');
+ return $data->concat(['taylor']);
});
$this->assertSame(['michael', 'tom', 'taylor'], $data->toArray());
@@ -3822,16 +3795,16 @@ public function testUnlessEmpty($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->unlessEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->unlessEmpty(function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame(['michael', 'tom', 'adam'], $data->toArray());
$data = new $collection;
- $data->unlessEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->unlessEmpty(function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame([], $data->toArray());
@@ -3844,10 +3817,10 @@ public function testUnlessEmptyDefault($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->unlessEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->unlessEmpty(function ($data) {
+ return $data->concat(['adam']);
}, function ($data) {
- return $data->push('taylor');
+ return $data->concat(['taylor']);
});
$this->assertSame(['michael', 'tom', 'adam'], $data->toArray());
@@ -3860,16 +3833,16 @@ public function testUnlessNotEmpty($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->unlessNotEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->unlessNotEmpty(function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame(['michael', 'tom'], $data->toArray());
$data = new $collection;
- $data->unlessNotEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->unlessNotEmpty(function ($data) {
+ return $data->concat(['adam']);
});
$this->assertSame(['adam'], $data->toArray());
@@ -3882,10 +3855,10 @@ public function testUnlessNotEmptyDefault($collection)
{
$data = new $collection(['michael', 'tom']);
- $data->unlessNotEmpty(function ($data) {
- return $data->push('adam');
+ $data = $data->unlessNotEmpty(function ($data) {
+ return $data->concat(['adam']);
}, function ($data) {
- return $data->push('taylor');
+ return $data->concat(['taylor']);
});
$this->assertSame(['michael', 'tom', 'taylor'], $data->toArray());
@@ -3903,12 +3876,9 @@ public function testHasReturnsValidResults($collection)
$this->assertFalse($data->has('baz'));
}
- /**
- * @dataProvider collectionClassProvider
- */
- public function testPutAddsItemToCollection($collection)
+ public function testPutAddsItemToCollection()
{
- $data = new $collection;
+ $data = new Collection;
$this->assertSame([], $data->toArray());
$data->put('foo', 1);
$this->assertSame(['foo' => 1], $data->toArray()); | true |
Other | laravel | framework | 4365561e5e5ad3b088d1752c6c6bb5bab652a5db.json | Remove mutating methods from lazy collection | tests/Support/SupportLazyCollectionIsLazyTest.php | @@ -8,17 +8,6 @@
class SupportLazyCollectionIsLazyTest extends TestCase
{
- public function testAddIsLazy()
- {
- $this->assertDoesNotEnumerate(function ($collection) {
- $collection->add(11);
- });
-
- $this->assertEnumerates(2, function ($collection) {
- $collection->add(11)->take(2)->all();
- });
- }
-
public function testChunkIsLazy()
{
$this->assertDoesNotEnumerate(function ($collection) {
@@ -379,17 +368,6 @@ public function testFlipIsLazy()
});
}
- public function testForgetIsLazy()
- {
- $this->assertDoesNotEnumerate(function ($collection) {
- $collection->forget(5);
- });
-
- $this->assertEnumeratesOnce(function ($collection) {
- $collection->forget(5)->all();
- });
- }
-
public function testForPageIsLazy()
{
$this->assertDoesNotEnumerate(function ($collection) {
@@ -727,47 +705,6 @@ public function testPluckIsLazy()
});
}
- public function testPopEnumeratesOnce()
- {
- $this->assertEnumeratesOnce(function ($collection) {
- $collection->pop();
- $collection->all();
- });
- }
-
- public function testPrependIsLazy()
- {
- $this->assertDoesNotEnumerate(function ($collection) {
- $collection->prepend(0);
- });
-
- $this->assertEnumeratesOnce(function ($collection) {
- $collection->prepend(0)->all();
- });
- }
-
- public function testPushIsLazy()
- {
- $this->assertDoesNotEnumerate(function ($collection) {
- $collection->push(11);
- });
-
- $this->assertEnumerates(2, function ($collection) {
- $collection->push(11)->take(2)->all();
- });
- }
-
- public function testPutIsLazy()
- {
- $this->assertDoesNotEnumerate(function ($collection) {
- $collection->put(20, 'a');
- });
-
- $this->assertEnumeratesOnce(function ($collection) {
- $collection->put(20, 'a')->all();
- });
- }
-
public function testRandomEnumeratesOnce()
{
$this->assertEnumeratesOnce(function ($collection) {
@@ -860,20 +797,6 @@ public function testSearchIsLazy()
});
}
- public function testShiftIsLazy()
- {
- $this->assertEnumerates(1, function ($collection) {
- $collection->shift();
- });
-
- $data = $this->make([1, 2, 3, 4, 5]);
-
- $this->assertEnumeratesCollection($data, 6, function ($collection) {
- $collection->shift();
- $collection->all();
- });
- }
-
public function testShuffleIsLazy()
{
$this->assertDoesNotEnumerate(function ($collection) {
@@ -995,13 +918,6 @@ public function testSortKeysDescIsLazy()
});
}
- public function testSpliceEnumeratesOnce()
- {
- $this->assertEnumeratesOnce(function ($collection) {
- $collection->splice(2);
- });
- }
-
public function testSplitIsLazy()
{
$this->assertDoesNotEnumerate(function ($collection) {
@@ -1078,21 +994,6 @@ public function testToJsonEnumeratesOnce()
});
}
- public function testTransformIsLazy()
- {
- $this->assertDoesNotEnumerate(function ($collection) {
- $collection->transform(function ($value) {
- return $value * 2;
- });
- });
-
- $this->assertEnumeratesOnce(function ($collection) {
- $collection->transform(function ($value) {
- return $value * 2;
- })->all();
- });
- }
-
public function testUnionIsLazy()
{
$this->assertDoesNotEnumerate(function ($collection) {
@@ -1247,9 +1148,10 @@ public function testWhereInIsLazy()
public function testWhereInstanceOfIsLazy()
{
- $data = $this->make([['a' => 1], ['a' => 2], ['a' => 3], ['a' => 4]])
- ->mapInto(stdClass::class)
- ->prepend(['a' => 0]);
+ $data = $this->make(['a' => 0])->concat(
+ $this->make([['a' => 1], ['a' => 2], ['a' => 3], ['a' => 4]])
+ ->mapInto(stdClass::class)
+ );
$this->assertDoesNotEnumerateCollection($data, function ($collection) {
$collection->whereInstanceOf(stdClass::class); | true |
Other | laravel | framework | 5c7ece78e17b581990838f9b7b81d7c311d2f0d8.json | Replace Application contract with Container
This is a follow-up for https://github.com/laravel/framework/pull/29619
Mior correctly noted that Managers only need to have a container instance to function properly. The fact that the default container we inject here is an instance of the Laravel application is an implementation detail.
This PR contains no breaking changes other than renaming the $app property to $container. The new type-hint still allows for the current Application instance to be passed through but makes it clear that this could be any implementation of a container.
I've also made $config a dedicated property on the Manager class as it's widely used on our own adapters. This makes it easy to reference it. The container array calls were replaced by `make` methods because `ArrayAccess` isn't part of the Container contract (and it shouldn't be). | src/Illuminate/Hashing/HashManager.php | @@ -14,7 +14,7 @@ class HashManager extends Manager implements Hasher
*/
public function createBcryptDriver()
{
- return new BcryptHasher($this->app['config']['hashing.bcrypt'] ?? []);
+ return new BcryptHasher($this->config->get('hashing.bcrypt') ?? []);
}
/**
@@ -24,7 +24,7 @@ public function createBcryptDriver()
*/
public function createArgonDriver()
{
- return new ArgonHasher($this->app['config']['hashing.argon'] ?? []);
+ return new ArgonHasher($this->config->get('hashing.argon') ?? []);
}
/**
@@ -34,7 +34,7 @@ public function createArgonDriver()
*/
public function createArgon2idDriver()
{
- return new Argon2IdHasher($this->app['config']['hashing.argon'] ?? []);
+ return new Argon2IdHasher($this->config->get('hashing.argon') ?? []);
}
/**
@@ -92,6 +92,6 @@ public function needsRehash($hashedValue, array $options = [])
*/
public function getDefaultDriver()
{
- return $this->app['config']['hashing.driver'] ?? 'bcrypt';
+ return $this->config->get('hashing.driver', 'bcrypt');
}
} | true |
Other | laravel | framework | 5c7ece78e17b581990838f9b7b81d7c311d2f0d8.json | Replace Application contract with Container
This is a follow-up for https://github.com/laravel/framework/pull/29619
Mior correctly noted that Managers only need to have a container instance to function properly. The fact that the default container we inject here is an instance of the Laravel application is an implementation detail.
This PR contains no breaking changes other than renaming the $app property to $container. The new type-hint still allows for the current Application instance to be passed through but makes it clear that this could be any implementation of a container.
I've also made $config a dedicated property on the Manager class as it's widely used on our own adapters. This makes it easy to reference it. The container array calls were replaced by `make` methods because `ArrayAccess` isn't part of the Container contract (and it shouldn't be). | src/Illuminate/Mail/TransportManager.php | @@ -25,7 +25,7 @@ class TransportManager extends Manager
*/
protected function createSmtpDriver()
{
- $config = $this->app->make('config')->get('mail');
+ $config = $this->config->get('mail');
// The Swift SMTP transport instance will allow us to use any SMTP backend
// for delivering mail such as Sendgrid, Amazon SES, or a custom server
@@ -79,7 +79,7 @@ protected function configureSmtpDriver($transport, $config)
*/
protected function createSendmailDriver()
{
- return new SendmailTransport($this->app['config']['mail']['sendmail']);
+ return new SendmailTransport($this->config->get('mail.sendmail'));
}
/**
@@ -89,7 +89,7 @@ protected function createSendmailDriver()
*/
protected function createSesDriver()
{
- $config = array_merge($this->app['config']->get('services.ses', []), [
+ $config = array_merge($this->config->get('services.ses', []), [
'version' => 'latest', 'service' => 'email',
]);
@@ -131,7 +131,7 @@ protected function createMailDriver()
*/
protected function createMailgunDriver()
{
- $config = $this->app['config']->get('services.mailgun', []);
+ $config = $this->config->get('services.mailgun', []);
return new MailgunTransport(
$this->guzzle($config),
@@ -149,7 +149,7 @@ protected function createMailgunDriver()
protected function createPostmarkDriver()
{
return new PostmarkTransport(
- $this->app['config']->get('services.postmark.token')
+ $this->config->get('services.postmark.token')
);
}
@@ -160,10 +160,10 @@ protected function createPostmarkDriver()
*/
protected function createLogDriver()
{
- $logger = $this->app->make(LoggerInterface::class);
+ $logger = $this->container->make(LoggerInterface::class);
if ($logger instanceof LogManager) {
- $logger = $logger->channel($this->app['config']['mail.log_channel']);
+ $logger = $logger->channel($this->config->get('mail.log_channel'));
}
return new LogTransport($logger);
@@ -199,7 +199,7 @@ protected function guzzle($config)
*/
public function getDefaultDriver()
{
- return $this->app['config']['mail.driver'];
+ return $this->config->get('mail.driver');
}
/**
@@ -210,6 +210,6 @@ public function getDefaultDriver()
*/
public function setDefaultDriver($name)
{
- $this->app['config']['mail.driver'] = $name;
+ $this->config->set('mail.driver', $name);
}
} | true |
Other | laravel | framework | 5c7ece78e17b581990838f9b7b81d7c311d2f0d8.json | Replace Application contract with Container
This is a follow-up for https://github.com/laravel/framework/pull/29619
Mior correctly noted that Managers only need to have a container instance to function properly. The fact that the default container we inject here is an instance of the Laravel application is an implementation detail.
This PR contains no breaking changes other than renaming the $app property to $container. The new type-hint still allows for the current Application instance to be passed through but makes it clear that this could be any implementation of a container.
I've also made $config a dedicated property on the Manager class as it's widely used on our own adapters. This makes it easy to reference it. The container array calls were replaced by `make` methods because `ArrayAccess` isn't part of the Container contract (and it shouldn't be). | src/Illuminate/Notifications/ChannelManager.php | @@ -35,7 +35,7 @@ class ChannelManager extends Manager implements DispatcherContract, FactoryContr
public function send($notifiables, $notification)
{
return (new NotificationSender(
- $this, $this->app->make(Bus::class), $this->app->make(Dispatcher::class), $this->locale)
+ $this, $this->container->make(Bus::class), $this->container->make(Dispatcher::class), $this->locale)
)->send($notifiables, $notification);
}
@@ -50,7 +50,7 @@ public function send($notifiables, $notification)
public function sendNow($notifiables, $notification, array $channels = null)
{
return (new NotificationSender(
- $this, $this->app->make(Bus::class), $this->app->make(Dispatcher::class), $this->locale)
+ $this, $this->container->make(Bus::class), $this->container->make(Dispatcher::class), $this->locale)
)->sendNow($notifiables, $notification, $channels);
}
@@ -72,7 +72,7 @@ public function channel($name = null)
*/
protected function createDatabaseDriver()
{
- return $this->app->make(Channels\DatabaseChannel::class);
+ return $this->container->make(Channels\DatabaseChannel::class);
}
/**
@@ -82,7 +82,7 @@ protected function createDatabaseDriver()
*/
protected function createBroadcastDriver()
{
- return $this->app->make(Channels\BroadcastChannel::class);
+ return $this->container->make(Channels\BroadcastChannel::class);
}
/**
@@ -92,7 +92,7 @@ protected function createBroadcastDriver()
*/
protected function createMailDriver()
{
- return $this->app->make(Channels\MailChannel::class);
+ return $this->container->make(Channels\MailChannel::class);
}
/**
@@ -109,7 +109,7 @@ protected function createDriver($driver)
return parent::createDriver($driver);
} catch (InvalidArgumentException $e) {
if (class_exists($driver)) {
- return $this->app->make($driver);
+ return $this->container->make($driver);
}
throw $e; | true |
Other | laravel | framework | 5c7ece78e17b581990838f9b7b81d7c311d2f0d8.json | Replace Application contract with Container
This is a follow-up for https://github.com/laravel/framework/pull/29619
Mior correctly noted that Managers only need to have a container instance to function properly. The fact that the default container we inject here is an instance of the Laravel application is an implementation detail.
This PR contains no breaking changes other than renaming the $app property to $container. The new type-hint still allows for the current Application instance to be passed through but makes it clear that this could be any implementation of a container.
I've also made $config a dedicated property on the Manager class as it's widely used on our own adapters. This makes it easy to reference it. The container array calls were replaced by `make` methods because `ArrayAccess` isn't part of the Container contract (and it shouldn't be). | src/Illuminate/Session/SessionManager.php | @@ -35,7 +35,7 @@ protected function createArrayDriver()
protected function createCookieDriver()
{
return $this->buildSession(new CookieSessionHandler(
- $this->app['cookie'], $this->app['config']['session.lifetime']
+ $this->container->make('cookie'), $this->config->get('session.lifetime')
));
}
@@ -56,10 +56,10 @@ protected function createFileDriver()
*/
protected function createNativeDriver()
{
- $lifetime = $this->app['config']['session.lifetime'];
+ $lifetime = $this->config->get('session.lifetime');
return $this->buildSession(new FileSessionHandler(
- $this->app['files'], $this->app['config']['session.files'], $lifetime
+ $this->container->make('files'), $this->config->get('session.files'), $lifetime
));
}
@@ -70,12 +70,12 @@ protected function createNativeDriver()
*/
protected function createDatabaseDriver()
{
- $table = $this->app['config']['session.table'];
+ $table = $this->config->get('session.table');
- $lifetime = $this->app['config']['session.lifetime'];
+ $lifetime = $this->config->get('session.lifetime');
return $this->buildSession(new DatabaseSessionHandler(
- $this->getDatabaseConnection(), $table, $lifetime, $this->app
+ $this->getDatabaseConnection(), $table, $lifetime, $this->container
));
}
@@ -86,9 +86,9 @@ protected function createDatabaseDriver()
*/
protected function getDatabaseConnection()
{
- $connection = $this->app['config']['session.connection'];
+ $connection = $this->config->get('session.connection');
- return $this->app['db']->connection($connection);
+ return $this->container->make('db')->connection($connection);
}
/**
@@ -121,7 +121,7 @@ protected function createRedisDriver()
$handler = $this->createCacheHandler('redis');
$handler->getCache()->getStore()->setConnection(
- $this->app['config']['session.connection']
+ $this->config->get('session.connection')
);
return $this->buildSession($handler);
@@ -156,11 +156,11 @@ protected function createCacheBased($driver)
*/
protected function createCacheHandler($driver)
{
- $store = $this->app['config']->get('session.store') ?: $driver;
+ $store = $this->config->get('session.store') ?: $driver;
return new CacheBasedSessionHandler(
- clone $this->app['cache']->store($store),
- $this->app['config']['session.lifetime']
+ clone $this->container->make('cache')->store($store),
+ $this->config->get('session.lifetime')
);
}
@@ -172,9 +172,9 @@ protected function createCacheHandler($driver)
*/
protected function buildSession($handler)
{
- return $this->app['config']['session.encrypt']
+ return $this->config->get('session.encrypt')
? $this->buildEncryptedSession($handler)
- : new Store($this->app['config']['session.cookie'], $handler);
+ : new Store($this->config->get('session.cookie'), $handler);
}
/**
@@ -186,7 +186,7 @@ protected function buildSession($handler)
protected function buildEncryptedSession($handler)
{
return new EncryptedStore(
- $this->app['config']['session.cookie'], $handler, $this->app['encrypter']
+ $this->config->get('session.cookie'), $handler, $this->container['encrypter']
);
}
@@ -197,7 +197,7 @@ protected function buildEncryptedSession($handler)
*/
public function getSessionConfig()
{
- return $this->app['config']['session'];
+ return $this->config->get('session');
}
/**
@@ -207,7 +207,7 @@ public function getSessionConfig()
*/
public function getDefaultDriver()
{
- return $this->app['config']['session.driver'];
+ return $this->config->get('session.driver');
}
/**
@@ -218,6 +218,6 @@ public function getDefaultDriver()
*/
public function setDefaultDriver($name)
{
- $this->app['config']['session.driver'] = $name;
+ $this->config->set('session.driver', $name);
}
} | true |
Other | laravel | framework | 5c7ece78e17b581990838f9b7b81d7c311d2f0d8.json | Replace Application contract with Container
This is a follow-up for https://github.com/laravel/framework/pull/29619
Mior correctly noted that Managers only need to have a container instance to function properly. The fact that the default container we inject here is an instance of the Laravel application is an implementation detail.
This PR contains no breaking changes other than renaming the $app property to $container. The new type-hint still allows for the current Application instance to be passed through but makes it clear that this could be any implementation of a container.
I've also made $config a dedicated property on the Manager class as it's widely used on our own adapters. This makes it easy to reference it. The container array calls were replaced by `make` methods because `ArrayAccess` isn't part of the Container contract (and it shouldn't be). | src/Illuminate/Support/Manager.php | @@ -4,15 +4,23 @@
use Closure;
use InvalidArgumentException;
+use Illuminate\Contracts\Container\Container;
abstract class Manager
{
/**
- * The application instance.
+ * The container instance.
*
- * @var \Illuminate\Contracts\Container\Container|\Illuminate\Contracts\Foundation\Application
+ * @var \Illuminate\Contracts\Container\Container
*/
- protected $app;
+ protected $container;
+
+ /**
+ * The config repository instance.
+ *
+ * @var \Illuminate\Contracts\Config\Repository
+ */
+ protected $config;
/**
* The registered custom driver creators.
@@ -31,12 +39,13 @@ abstract class Manager
/**
* Create a new manager instance.
*
- * @param \Illuminate\Contracts\Container\Container|\Illuminate\Contracts\Foundation\Application $app
+ * @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
- public function __construct($app)
+ public function __construct(Container $container)
{
- $this->app = $app;
+ $this->config = $container->make('config');
+ $this->container = $container;
}
/**
@@ -107,7 +116,7 @@ protected function createDriver($driver)
*/
protected function callCustomCreator($driver)
{
- return $this->customCreators[$driver]($this->app);
+ return $this->customCreators[$driver]($this->container);
}
/** | true |
Other | laravel | framework | 9c31b1e0e1eb80086952952003b33ce1a29e7da9.json | Add LazyCollection tests | tests/Support/SupportLazyCollectionTest.php | @@ -3,10 +3,87 @@
namespace Illuminate\Tests\Support;
use PHPUnit\Framework\TestCase;
+use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
class SupportLazyCollectionTest extends TestCase
{
+ public function testCanCreateEmptyCollection()
+ {
+ $this->assertSame([], LazyCollection::make()->all());
+ $this->assertSame([], LazyCollection::empty()->all());
+ }
+
+ public function testCanCreateCollectionFromArray()
+ {
+ $array = [1, 2, 3];
+
+ $data = LazyCollection::make($array);
+
+ $this->assertSame($array, $data->all());
+
+ $array = ['a' => 1, 'b' => 2, 'c' => 3];
+
+ $data = LazyCollection::make($array);
+
+ $this->assertSame($array, $data->all());
+ }
+
+ public function testCanCreateCollectionFromArrayable()
+ {
+ $array = [1, 2, 3];
+
+ $data = LazyCollection::make(Collection::make($array));
+
+ $this->assertSame($array, $data->all());
+
+ $array = ['a' => 1, 'b' => 2, 'c' => 3];
+
+ $data = LazyCollection::make(Collection::make($array));
+
+ $this->assertSame($array, $data->all());
+ }
+
+ public function testCanCreateCollectionFromClosure()
+ {
+ $data = LazyCollection::make(function () {
+ yield 1;
+ yield 2;
+ yield 3;
+ });
+
+ $this->assertSame([1, 2, 3], $data->all());
+
+ $data = LazyCollection::make(function () {
+ yield 'a' => 1;
+ yield 'b' => 2;
+ yield 'c' => 3;
+ });
+
+ $this->assertSame([
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ ], $data->all());
+ }
+
+ public function testCollect()
+ {
+ $data = LazyCollection::make(function () {
+ yield 'a' => 1;
+ yield 'b' => 2;
+ yield 'c' => 3;
+ })->collect();
+
+ $this->assertInstanceOf(Collection::class, $data);
+
+ $this->assertSame([
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ ], $data->all());
+ }
+
public function testTapEach()
{
$data = LazyCollection::times(10); | false |
Other | laravel | framework | c02cd1e04f73b76b5e059a7b5b18fa5b8ba679b7.json | Add tapEach() method to LazyCollection | src/Illuminate/Support/LazyCollection.php | @@ -1212,8 +1212,35 @@ public function take($limit)
return new static(function () use ($original, $limit) {
$iterator = $original->getIterator();
- for (; $iterator->valid() && $limit--; $iterator->next()) {
+ while ($limit--) {
+ if (! $iterator->valid()) {
+ break;
+ }
+
yield $iterator->key() => $iterator->current();
+
+ if ($limit) {
+ $iterator->next();
+ }
+ }
+ });
+ }
+
+ /**
+ * Pass each item in the collection to the given callback, lazily.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function tapEach(callable $callback)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $callback) {
+ foreach ($original as $key => $value) {
+ $callback($value, $key);
+
+ yield $key => $value;
}
});
} | true |
Other | laravel | framework | c02cd1e04f73b76b5e059a7b5b18fa5b8ba679b7.json | Add tapEach() method to LazyCollection | tests/Support/SupportLazyCollectionTest.php | @@ -0,0 +1,27 @@
+<?php
+
+namespace Illuminate\Tests\Support;
+
+use PHPUnit\Framework\TestCase;
+use Illuminate\Support\LazyCollection;
+
+class SupportLazyCollectionTest extends TestCase
+{
+ public function testTapEach()
+ {
+ $data = LazyCollection::times(10);
+
+ $tapped = [];
+
+ $data = $data->tapEach(function ($value, $key) use (&$tapped) {
+ $tapped[$key] = $value;
+ });
+
+ $this->assertEmpty($tapped);
+
+ $data = $data->take(5)->all();
+
+ $this->assertSame([1, 2, 3, 4, 5], $data);
+ $this->assertSame([1, 2, 3, 4, 5], $tapped);
+ }
+} | true |
Other | laravel | framework | be140fcc63fb2c7373e8c19269125b8f711a127b.json | Avoid call to method alias | src/Illuminate/Cache/Repository.php | @@ -205,7 +205,7 @@ public function put($key, $value, $ttl = null)
$seconds = $this->getSeconds($ttl);
if ($seconds <= 0) {
- return $this->delete($key);
+ return $this->forget($key);
}
$result = $this->store->put($this->itemKey($key), $value, $seconds); | false |
Other | laravel | framework | 2fea43d024fa0f0faf10059113781942cc03a5ff.json | Return a lazy collection from Query@cursor() | src/Illuminate/Database/Eloquent/Builder.php | @@ -636,15 +636,15 @@ protected function isNestedUnder($relation, $name)
}
/**
- * Get a generator for the given query.
+ * Get a lazy collection for the given query.
*
- * @return \Generator
+ * @return \Illuminate\Support\LazyCollection
*/
public function cursor()
{
- foreach ($this->applyScopes()->query->cursor() as $record) {
- yield $this->newModelInstance()->newFromBuilder($record);
- }
+ return $this->applyScopes()->query->cursor()->map(function ($record) {
+ return $this->newModelInstance()->newFromBuilder($record);
+ });
}
/** | true |
Other | laravel | framework | 2fea43d024fa0f0faf10059113781942cc03a5ff.json | Return a lazy collection from Query@cursor() | src/Illuminate/Database/Query/Builder.php | @@ -10,6 +10,7 @@
use InvalidArgumentException;
use Illuminate\Support\Collection;
use Illuminate\Pagination\Paginator;
+use Illuminate\Support\LazyCollection;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\ConnectionInterface;
@@ -2234,19 +2235,21 @@ protected function withoutSelectAliases(array $columns)
}
/**
- * Get a generator for the given query.
+ * Get a lazy collection for the given query.
*
- * @return \Generator
+ * @return \Illuminate\Support\LazyCollection
*/
public function cursor()
{
if (is_null($this->columns)) {
$this->columns = ['*'];
}
- return $this->connection->cursor(
- $this->toSql(), $this->getBindings(), ! $this->useWritePdo
- );
+ return new LazyCollection(function () {
+ yield from $this->connection->cursor(
+ $this->toSql(), $this->getBindings(), ! $this->useWritePdo
+ );
+ });
}
/** | true |
Other | laravel | framework | 2fea43d024fa0f0faf10059113781942cc03a5ff.json | Return a lazy collection from Query@cursor() | tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php | @@ -3,6 +3,7 @@
namespace Illuminate\Tests\Database;
use PHPUnit\Framework\TestCase;
+use Illuminate\Support\LazyCollection;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model as Eloquent;
@@ -224,6 +225,8 @@ public function testCursorReturnsCorrectModels()
$posts = $country->posts()->cursor();
+ $this->assertInstanceOf(LazyCollection::class, $posts);
+
foreach ($posts as $post) {
$this->assertEquals([
'id', | true |
Other | laravel | framework | 0c25708a288dd1dc00ac2321851d0dcafaa2c6c2.json | Fix broken tests | src/Illuminate/Console/Command.php | @@ -641,8 +641,10 @@ public function setLaravel($laravel)
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int
*/
- private function runCommand($command, array $arguments, OutputInterface $output): int
+ private function runCommand($command, array $arguments, OutputInterface $output)
{
+ $arguments['command'] = $command;
+
return $this->resolveCommand($command)->run(
$this->createInputFromArguments($arguments), $output
); | false |
Other | laravel | framework | 7d2c2c4d8b0fcf533ca6df68ad5ecc921e424e94.json | Fix UNION queries with ORDER BY bindings | src/Illuminate/Database/Query/Builder.php | @@ -59,6 +59,7 @@ class Builder
'having' => [],
'order' => [],
'union' => [],
+ 'unionOrder' => [],
];
/**
@@ -1804,7 +1805,7 @@ public function orderBy($column, $direction = 'asc')
$column = new Expression('('.$query.')');
- $this->addBinding($bindings, 'order');
+ $this->addBinding($bindings, $this->unions ? 'unionOrder' : 'order');
}
$direction = strtolower($direction);
@@ -1878,7 +1879,7 @@ public function orderByRaw($sql, $bindings = [])
$this->{$this->unions ? 'unionOrders' : 'orders'}[] = compact('type', 'sql');
- $this->addBinding($bindings, 'order');
+ $this->addBinding($bindings, $this->unions ? 'unionOrder' : 'order');
return $this;
} | true |
Other | laravel | framework | 7d2c2c4d8b0fcf533ca6df68ad5ecc921e424e94.json | Fix UNION queries with ORDER BY bindings | tests/Database/DatabaseQueryBuilderTest.php | @@ -1067,6 +1067,13 @@ public function testOrderBys()
$builder = $this->getBuilder();
$builder->select('*')->from('users')->orderByDesc('name');
$this->assertEquals('select * from "users" order by "name" desc', $builder->toSql());
+
+ $builder = $this->getBuilder();
+ $builder->select('*')->from('posts')->where('public', 1)
+ ->unionAll($this->getBuilder()->select('*')->from('videos')->where('public', 1))
+ ->orderByRaw('field(category, ?, ?) asc', ['news', 'opinion']);
+ $this->assertEquals('(select * from "posts" where "public" = ?) union all (select * from "videos" where "public" = ?) order by field(category, ?, ?) asc', $builder->toSql());
+ $this->assertEquals([1, 1, 'news', 'opinion'], $builder->getBindings());
}
public function testOrderBySubQueries()
@@ -1084,6 +1091,13 @@ public function testOrderBySubQueries()
$builder = $this->getBuilder()->select('*')->from('users')->orderByDesc($subQuery);
$this->assertEquals("$expected desc", $builder->toSql());
+
+ $builder = $this->getBuilder();
+ $builder->select('*')->from('posts')->where('public', 1)
+ ->unionAll($this->getBuilder()->select('*')->from('videos')->where('public', 1))
+ ->orderBy($this->getBuilder()->selectRaw('field(category, ?, ?)', ['news', 'opinion']));
+ $this->assertEquals('(select * from "posts" where "public" = ?) union all (select * from "videos" where "public" = ?) order by (select field(category, ?, ?)) asc', $builder->toSql());
+ $this->assertEquals([1, 1, 'news', 'opinion'], $builder->getBindings());
}
public function testOrderByInvalidDirectionParam() | true |
Other | laravel | framework | 6c1e014943a508afb2c10869c3175f7783a004e1.json | Add subquery support for "from" and "table" | src/Illuminate/Database/Capsule/Manager.php | @@ -77,13 +77,14 @@ public static function connection($connection = null)
/**
* Get a fluent query builder instance.
*
- * @param string $table
+ * @param \Closure|\Illuminate\Database\Query\Builder|string $table
+ * @param string|null $as
* @param string|null $connection
* @return \Illuminate\Database\Query\Builder
*/
- public static function table($table, $connection = null)
+ public static function table($table, $as = null, $connection = null)
{
- return static::$instance->connection($connection)->table($table);
+ return static::$instance->connection($connection)->table($table, $as);
}
/** | true |
Other | laravel | framework | 6c1e014943a508afb2c10869c3175f7783a004e1.json | Add subquery support for "from" and "table" | src/Illuminate/Database/Connection.php | @@ -257,12 +257,13 @@ public function getSchemaBuilder()
/**
* Begin a fluent query against a database table.
*
- * @param string $table
+ * @param \Closure|\Illuminate\Database\Query\Builder|string $table
+ * @param string|null $as
* @return \Illuminate\Database\Query\Builder
*/
- public function table($table)
+ public function table($table, $as = null)
{
- return $this->query()->from($table);
+ return $this->query()->from($table, $as);
}
/** | true |
Other | laravel | framework | 6c1e014943a508afb2c10869c3175f7783a004e1.json | Add subquery support for "from" and "table" | src/Illuminate/Database/ConnectionInterface.php | @@ -9,10 +9,11 @@ interface ConnectionInterface
/**
* Begin a fluent query against a database table.
*
- * @param string $table
+ * @param \Closure|\Illuminate\Database\Query\Builder|string $table
+ * @param string|null $as
* @return \Illuminate\Database\Query\Builder
*/
- public function table($table);
+ public function table($table, $as = null);
/**
* Get a new raw query expression. | true |
Other | laravel | framework | 6c1e014943a508afb2c10869c3175f7783a004e1.json | Add subquery support for "from" and "table" | src/Illuminate/Database/Query/Builder.php | @@ -367,12 +367,19 @@ public function distinct()
/**
* Set the table which the query is targeting.
*
- * @param string $table
+ * @param \Closure|\Illuminate\Database\Query\Builder|string $table
+ * @param string|null $as
* @return $this
*/
- public function from($table)
+ public function from($table, $as = null)
{
- $this->from = $table;
+ if ($table instanceof self ||
+ $table instanceof EloquentBuilder ||
+ $table instanceof Closure) {
+ return $this->fromSub($table, $as);
+ }
+
+ $this->from = $as ? "{$table} as {$as}" : $table;
return $this;
} | true |
Other | laravel | framework | 6c1e014943a508afb2c10869c3175f7783a004e1.json | Add subquery support for "from" and "table" | tests/Integration/Database/QueryBuilderTest.php | @@ -31,6 +31,21 @@ protected function setUp(): void
]);
}
+ public function testFromWithAlias()
+ {
+ $this->assertSame('select * from "posts" as "alias"', DB::table('posts', 'alias')->toSql());
+ }
+
+ public function testFromWithSubQuery()
+ {
+ $this->assertSame(
+ 'Fake Post',
+ DB::table(function ($query) {
+ $query->selectRaw("'Fake Post' as title");
+ }, 'posts')->first()->title
+ );
+ }
+
public function testWhereDate()
{
$this->assertSame(1, DB::table('posts')->whereDate('created_at', '2018-01-02')->count()); | true |
Other | laravel | framework | ee7398572518e7fe768cbea10d4bfddd87314c18.json | Apply fixes from StyleCI (#29613) | src/Illuminate/Cache/CacheServiceProvider.php | @@ -3,8 +3,8 @@
namespace Illuminate\Cache;
use Illuminate\Support\ServiceProvider;
-use Illuminate\Contracts\Support\DeferrableProvider;
use Symfony\Component\Cache\Adapter\Psr16Adapter;
+use Illuminate\Contracts\Support\DeferrableProvider;
class CacheServiceProvider extends ServiceProvider implements DeferrableProvider
{ | false |
Other | laravel | framework | bbc559073aed1706be8c0ee134c56fdcc347614a.json | Apply fixes from StyleCI (#29612) | tests/Integration/Foundation/DiscoverEventsTest.php | @@ -7,7 +7,6 @@
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventOne;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventTwo;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener;
-use Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener as ListenerAlias;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\AbstractListener;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\ListenerInterface;
| false |
Other | laravel | framework | 0b8b18bfc1d8ecb1b2d7027629c1ea38f6508af6.json | Apply fixes from StyleCI (#29611) | tests/Integration/Foundation/DiscoverEventsTest.php | @@ -7,7 +7,6 @@
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventOne;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventTwo;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener;
-use Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener as ListenerAlias;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\AbstractListener;
use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\ListenerInterface;
| false |
Other | laravel | framework | 31983f6d2fa14b24892bd2debcf8c22abed081f2.json | Add dependencies to commands | src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | @@ -635,8 +635,8 @@ protected function registerQueueListenCommand()
*/
protected function registerQueueRestartCommand()
{
- $this->app->singleton('command.queue.restart', function () {
- return new QueueRestartCommand;
+ $this->app->singleton('command.queue.restart', function ($app) {
+ return new QueueRestartCommand($app['cache.store']);
});
}
@@ -660,7 +660,7 @@ protected function registerQueueRetryCommand()
protected function registerQueueWorkCommand()
{
$this->app->singleton('command.queue.work', function ($app) {
- return new QueueWorkCommand($app['queue.worker']);
+ return new QueueWorkCommand($app['queue.worker'], $app['cache.store']);
});
}
| false |
Other | laravel | framework | 4e44ae56d1a4a22b78d1d6fb7f82f06bb3678bbe.json | Use repository interfaces instead of alias | src/Illuminate/Queue/Console/RestartCommand.php | @@ -4,6 +4,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\InteractsWithTime;
+use Illuminate\Contracts\Cache\Repository as Cache;
class RestartCommand extends Command
{
@@ -23,14 +24,34 @@ class RestartCommand extends Command
*/
protected $description = 'Restart queue worker daemons after their current job';
+ /**
+ * The cache store implementation.
+ *
+ * @var \Illuminate\Contracts\Cache\Repository
+ */
+ protected $cache;
+
+ /**
+ * Create a new queue restart command.
+ *
+ * @param \Illuminate\Contracts\Cache\Repository $cache
+ * @return void
+ */
+ public function __construct(Cache $cache)
+ {
+ parent::__construct();
+
+ $this->cache = $cache;
+ }
+
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
- $this->laravel['cache.store']->forever('illuminate:queue:restart', $this->currentTime());
+ $this->cache->forever('illuminate:queue:restart', $this->currentTime());
$this->info('Broadcasting queue restart signal.');
} | true |
Other | laravel | framework | 4e44ae56d1a4a22b78d1d6fb7f82f06bb3678bbe.json | Use repository interfaces instead of alias | src/Illuminate/Queue/Console/WorkCommand.php | @@ -10,6 +10,7 @@
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
+use Illuminate\Contracts\Cache\Repository as Cache;
class WorkCommand extends Command
{
@@ -45,16 +46,25 @@ class WorkCommand extends Command
*/
protected $worker;
+ /**
+ * The cache store implementation.
+ *
+ * @var \Illuminate\Contracts\Cache\Repository
+ */
+ protected $cache;
+
/**
* Create a new queue work command.
*
* @param \Illuminate\Queue\Worker $worker
+ * @param \Illuminate\Contracts\Cache\Repository $cache
* @return void
*/
- public function __construct(Worker $worker)
+ public function __construct(Worker $worker, Cache $cache)
{
parent::__construct();
+ $this->cache = $cache;
$this->worker = $worker;
}
@@ -96,7 +106,7 @@ public function handle()
*/
protected function runWorker($connection, $queue)
{
- $this->worker->setCache($this->laravel['cache.store']);
+ $this->worker->setCache($this->cache);
return $this->worker->{$this->option('once') ? 'runNextJob' : 'daemon'}(
$connection, $queue, $this->gatherWorkerOptions() | true |
Other | laravel | framework | da88b26a56bcd35e1e62f362c5920e023be6a9aa.json | Use real classname for seeders
This way, if a programmer decides to override (example below) a seeder in a container, an actual class name is printed instead of the parent class name.
Example:
I'm working on a multi-tenant app, where each tenant has its own "configuration" folder (contains a service provider and some additional classes such as seeders for example). I can choose which configuration is enabled by tweaking an environment variable.
```php
class PostsSeeder {}
class TenantAPostsSeeder extends PostsSeeder {}
```
With this change, I'll be able to tell which seeder is actually being executed when I run `php artisan db:seed` | src/Illuminate/Database/Seeder.php | @@ -35,11 +35,13 @@ public function call($class, $silent = false)
$classes = Arr::wrap($class);
foreach ($classes as $class) {
+ $seeder = $this->resolve($class);
+
if ($silent === false && isset($this->command)) {
- $this->command->getOutput()->writeln("<info>Seeding:</info> $class");
+ $this->command->getOutput()->writeln('<info>Seeding:</info> '.get_class($seeder));
}
- $this->resolve($class)->__invoke();
+ $seeder->__invoke();
}
return $this; | false |
Other | laravel | framework | 55785d3514a8149d4858acef40c56a31b6b2ccd1.json | Remove Input Facade | src/Illuminate/Support/Facades/Input.php | @@ -1,114 +0,0 @@
-<?php
-
-namespace Illuminate\Support\Facades;
-
-/**
- * @method static bool matchesType(string $actual, string $type)
- * @method static bool isJson()
- * @method static bool expectsJson()
- * @method static bool wantsJson()
- * @method static bool accepts(string|array $contentTypes)
- * @method static bool prefers(string|array $contentTypes)
- * @method static bool acceptsAnyContentType()
- * @method static bool acceptsJson()
- * @method static bool acceptsHtml()
- * @method static string format($default = 'html')
- * @method static string|array old(string|null $key = null, string|array|null $default = null)
- * @method static void flash()
- * @method static void flashOnly(array|mixed $keys)
- * @method static void flashExcept(array|mixed $keys)
- * @method static void flush()
- * @method static string|array|null server(string|null $key = null, string|array|null $default = null)
- * @method static bool hasHeader(string $key)
- * @method static string|array|null header(string|null $key = null, string|array|null $default = null)
- * @method static string|null bearerToken()
- * @method static bool exists(string|array $key)
- * @method static bool has(string|array $key)
- * @method static bool hasAny(string|array $key)
- * @method static bool filled(string|array $key)
- * @method static bool anyFilled(string|array $key)
- * @method static array keys()
- * @method static array all(array|mixed|null $keys = null)
- * @method static string|array|null input(string|null $key = null, string|array|null $default = null)
- * @method static array only(array|mixed $keys)
- * @method static array except(array|mixed $keys)
- * @method static string|array|null query(string|null $key = null, string|array|null $default = null)
- * @method static string|array|null post(string|null $key = null, string|array|null $default = null)
- * @method static bool hasCookie(string $key)
- * @method static string|array|null cookie(string|null $key = null, string|array|null $default = null)
- * @method static array allFiles()
- * @method static bool hasFile(string $key)
- * @method static \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]|array|null file(string|null $key = null, mixed $default = null)
- * @method static \Illuminate\Http\Request capture()
- * @method static \Illuminate\Http\Request instance()
- * @method static string method()
- * @method static string root()
- * @method static string url()
- * @method static string fullUrl()
- * @method static string fullUrlWithQuery(array $query)
- * @method static string path()
- * @method static string decodedPath()
- * @method static string|null segment(int $index, string|null $default = null)
- * @method static array segments()
- * @method static bool is(mixed ...$patterns)
- * @method static bool routeIs(mixed ...$patterns)
- * @method static bool fullUrlIs(mixed ...$patterns)
- * @method static bool ajax()
- * @method static bool pjax()
- * @method static bool prefetch()
- * @method static bool secure()
- * @method static string|null ip()
- * @method static array ips()
- * @method static string userAgent()
- * @method static \Illuminate\Http\Request merge(array $input)
- * @method static \Illuminate\Http\Request replace(array $input)
- * @method static \Symfony\Component\HttpFoundation\ParameterBag|mixed json(string|null $key = null, mixed $default = null)
- * @method static \Illuminate\Http\Request createFrom(\Illuminate\Http\Request $from, \Illuminate\Http\Request|null $to = null)
- * @method static \Illuminate\Http\Request createFromBase(\Symfony\Component\HttpFoundation\Request $request)
- * @method static \Illuminate\Http\Request duplicate(array|null $query = null, array|null $request = null, array|null $attributes = null, array|null $cookies = null, array|null $files = null, array|null $server = null)
- * @method static mixed filterFiles(mixed $files)
- * @method static \Illuminate\Session\Store session()
- * @method static \Illuminate\Session\Store|null getSession()
- * @method static void setLaravelSession(\Illuminate\Contracts\Session\Session $session)
- * @method static mixed user(string|null $guard = null)
- * @method static \Illuminate\Routing\Route|object|string route(string|null $param = null, string|null $default = null)
- * @method static string fingerprint()
- * @method static \Illuminate\Http\Request setJson(\Symfony\Component\HttpFoundation\ParameterBag $json)
- * @method static \Closure getUserResolver()
- * @method static \Illuminate\Http\Request setUserResolver(\Closure $callback)
- * @method static \Closure getRouteResolver()
- * @method static \Illuminate\Http\Request setRouteResolver(\Closure $callback)
- * @method static array toArray()
- * @method static bool offsetExists(string $offset)
- * @method static mixed offsetGet(string $offset)
- * @method static void offsetSet(string $offset, mixed $value)
- * @method static void offsetUnset(string $offset)
- *
- * @see \Illuminate\Http\Request
- */
-class Input extends Facade
-{
- /**
- * Get an item from the input data.
- *
- * This method is used for all request verbs (GET, POST, PUT, and DELETE)
- *
- * @param string|null $key
- * @param mixed $default
- * @return mixed
- */
- public static function get($key = null, $default = null)
- {
- return static::$app['request']->input($key, $default);
- }
-
- /**
- * Get the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor()
- {
- return 'request';
- }
-} | true |
Other | laravel | framework | 55785d3514a8149d4858acef40c56a31b6b2ccd1.json | Remove Input Facade | src/Illuminate/Support/Facades/Request.php | @@ -3,6 +3,43 @@
namespace Illuminate\Support\Facades;
/**
+ * @method static bool matchesType(string $actual, string $type)
+ * @method static bool isJson()
+ * @method static bool expectsJson()
+ * @method static bool wantsJson()
+ * @method static bool accepts(string|array $contentTypes)
+ * @method static bool prefers(string|array $contentTypes)
+ * @method static bool acceptsAnyContentType()
+ * @method static bool acceptsJson()
+ * @method static bool acceptsHtml()
+ * @method static string format($default = 'html')
+ * @method static string|array old(string|null $key = null, string|array|null $default = null)
+ * @method static void flash()
+ * @method static void flashOnly(array|mixed $keys)
+ * @method static void flashExcept(array|mixed $keys)
+ * @method static void flush()
+ * @method static string|array|null server(string|null $key = null, string|array|null $default = null)
+ * @method static bool hasHeader(string $key)
+ * @method static string|array|null header(string|null $key = null, string|array|null $default = null)
+ * @method static string|null bearerToken()
+ * @method static bool exists(string|array $key)
+ * @method static bool has(string|array $key)
+ * @method static bool hasAny(string|array $key)
+ * @method static bool filled(string|array $key)
+ * @method static bool anyFilled(string|array $key)
+ * @method static array keys()
+ * @method static array all(array|mixed|null $keys = null)
+ * @method static string|array|null input(string|null $key = null, string|array|null $default = null)
+ * @method static array only(array|mixed $keys)
+ * @method static array except(array|mixed $keys)
+ * @method static string|array|null query(string|null $key = null, string|array|null $default = null)
+ * @method static string|array|null post(string|null $key = null, string|array|null $default = null)
+ * @method static bool hasCookie(string $key)
+ * @method static string|array|null cookie(string|null $key = null, string|array|null $default = null)
+ * @method static array allFiles()
+ * @method static bool hasFile(string $key)
+ * @method static \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]|array|null file(string|null $key = null, mixed $default = null)
+ * @method static \Illuminate\Http\Request capture()
* @method static \Illuminate\Http\Request instance()
* @method static string method()
* @method static string root()
@@ -13,23 +50,28 @@
* @method static string decodedPath()
* @method static string|null segment(int $index, string|null $default = null)
* @method static array segments()
- * @method static bool is(...$patterns)
- * @method static bool routeIs(...$patterns)
- * @method static bool fullUrlIs(...$patterns)
+ * @method static bool is(mixed ...$patterns)
+ * @method static bool routeIs(mixed ...$patterns)
+ * @method static bool fullUrlIs(mixed ...$patterns)
* @method static bool ajax()
* @method static bool pjax()
+ * @method static bool prefetch()
* @method static bool secure()
- * @method static string ip()
+ * @method static string|null ip()
* @method static array ips()
* @method static string userAgent()
* @method static \Illuminate\Http\Request merge(array $input)
* @method static \Illuminate\Http\Request replace(array $input)
- * @method static \Symfony\Component\HttpFoundation\ParameterBag|mixed json(string $key = null, $default = null)
+ * @method static \Symfony\Component\HttpFoundation\ParameterBag|mixed json(string|null $key = null, mixed $default = null)
+ * @method static \Illuminate\Http\Request createFrom(\Illuminate\Http\Request $from, \Illuminate\Http\Request|null $to = null)
+ * @method static \Illuminate\Http\Request createFromBase(\Symfony\Component\HttpFoundation\Request $request)
+ * @method static \Illuminate\Http\Request duplicate(array|null $query = null, array|null $request = null, array|null $attributes = null, array|null $cookies = null, array|null $files = null, array|null $server = null)
+ * @method static mixed filterFiles(mixed $files)
* @method static \Illuminate\Session\Store session()
* @method static \Illuminate\Session\Store|null getSession()
* @method static void setLaravelSession(\Illuminate\Contracts\Session\Session $session)
* @method static mixed user(string|null $guard = null)
- * @method static \Illuminate\Routing\Route|object|string route(string|null $param = null)
+ * @method static \Illuminate\Routing\Route|object|string route(string|null $param = null, string|null $default = null)
* @method static string fingerprint()
* @method static \Illuminate\Http\Request setJson(\Symfony\Component\HttpFoundation\ParameterBag $json)
* @method static \Closure getUserResolver()
@@ -39,7 +81,7 @@
* @method static array toArray()
* @method static bool offsetExists(string $offset)
* @method static mixed offsetGet(string $offset)
- * @method static void offsetSet(string $offset, $value)
+ * @method static void offsetSet(string $offset, mixed $value)
* @method static void offsetUnset(string $offset)
*
* @see \Illuminate\Http\Request | true |
Other | laravel | framework | bbc0a1980a51a8894c5bcc9a42e605f43b18f897.json | Use proper assertions. | tests/Database/DatabaseEloquentModelTest.php | @@ -149,7 +149,7 @@ public function testArrayAccessToAttributes()
$this->assertTrue(isset($model['connection']));
$this->assertEquals($model['connection'], 2);
$this->assertFalse(isset($model['table']));
- $this->assertEquals($model['table'], null);
+ $this->assertNull($model['table']);
$this->assertFalse(isset($model['with']));
}
| true |
Other | laravel | framework | bbc0a1980a51a8894c5bcc9a42e605f43b18f897.json | Use proper assertions. | tests/Http/HttpRequestTest.php | @@ -16,6 +16,8 @@ class HttpRequestTest extends TestCase
{
protected function tearDown(): void
{
+ parent::tearDown();
+
m::close();
}
@@ -915,18 +917,18 @@ public function testMagicMethods()
// Parameter 'foo' is 'bar', then it ISSET and is NOT EMPTY.
$this->assertEquals($request->foo, 'bar');
- $this->assertEquals(isset($request->foo), true);
- $this->assertEquals(empty($request->foo), false);
+ $this->assertTrue(isset($request->foo));
+ $this->assertFalse(empty($request->foo));
// Parameter 'empty' is '', then it ISSET and is EMPTY.
$this->assertEquals($request->empty, '');
$this->assertTrue(isset($request->empty));
$this->assertEmpty($request->empty);
// Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
- $this->assertEquals($request->undefined, null);
- $this->assertEquals(isset($request->undefined), false);
- $this->assertEquals(empty($request->undefined), true);
+ $this->assertNull($request->undefined);
+ $this->assertFalse(isset($request->undefined));
+ $this->assertEmpty($request->undefined);
// Simulates Route parameters.
$request = Request::create('/example/bar', 'GET', ['xyz' => 'overwritten']);
@@ -940,19 +942,19 @@ public function testMagicMethods()
// Router parameter 'foo' is 'bar', then it ISSET and is NOT EMPTY.
$this->assertEquals('bar', $request->foo);
$this->assertEquals('bar', $request['foo']);
- $this->assertEquals(isset($request->foo), true);
- $this->assertEquals(empty($request->foo), false);
+ $this->assertTrue(isset($request->foo));
+ $this->assertFalse(empty($request->foo));
// Router parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
- $this->assertEquals($request->undefined, null);
- $this->assertEquals(isset($request->undefined), false);
- $this->assertEquals(empty($request->undefined), true);
+ $this->assertNull($request->undefined);
+ $this->assertFalse(isset($request->undefined));
+ $this->assertTrue($request->undefined);
// Special case: router parameter 'xyz' is 'overwritten' by QueryString, then it ISSET and is NOT EMPTY.
// Basically, QueryStrings have priority over router parameters.
$this->assertEquals($request->xyz, 'overwritten');
- $this->assertEquals(isset($request->foo), true);
- $this->assertEquals(empty($request->foo), false);
+ $this->assertTrue(isset($request->foo));
+ $this->assertFalse(empty($request->foo));
// Simulates empty QueryString and Routes.
$request = Request::create('/', 'GET');
@@ -964,18 +966,18 @@ public function testMagicMethods()
});
// Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
- $this->assertEquals($request->undefined, null);
- $this->assertEquals(isset($request->undefined), false);
- $this->assertEquals(empty($request->undefined), true);
+ $this->assertNull($request->undefined);
+ $this->assertFalse(isset($request->undefined));
+ $this->assertEmpty($request->undefined);
// Special case: simulates empty QueryString and Routes, without the Route Resolver.
// It'll happen when you try to get a parameter outside a route.
$request = Request::create('/', 'GET');
// Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY.
- $this->assertEquals($request->undefined, null);
- $this->assertEquals(isset($request->undefined), false);
- $this->assertEquals(empty($request->undefined), true);
+ $this->assertNull($request->undefined);
+ $this->assertFalse(isset($request->undefined));
+ $this->assertTrue($request->undefined);
}
public function testHttpRequestFlashCallsSessionFlashInputWithInputData() | true |
Other | laravel | framework | bbc0a1980a51a8894c5bcc9a42e605f43b18f897.json | Use proper assertions. | tests/Mail/MailMarkdownTest.php | @@ -11,6 +11,8 @@ class MailMarkdownTest extends TestCase
{
protected function tearDown(): void
{
+ parent::tearDown();
+
m::close();
}
@@ -24,9 +26,9 @@ public function testRenderFunctionReturnsHtml()
$viewFactory->shouldReceive('make')->with('mail::themes.default')->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');
- $result = $markdown->render('view', []);
+ $result = $markdown->render('view', [])->toHtml();
- $this->assertTrue(strpos($result, '<html></html>') !== false);
+ $this->assertNotFalse(strpos($result, '<html></html>'));
}
public function testRenderFunctionReturnsHtmlWithCustomTheme()
@@ -40,9 +42,9 @@ public function testRenderFunctionReturnsHtmlWithCustomTheme()
$viewFactory->shouldReceive('make')->with('mail::themes.yaz')->andReturnSelf();
$viewFactory->shouldReceive('render')->twice()->andReturn('<html></html>', 'body {}');
- $result = $markdown->render('view', []);
+ $result = $markdown->render('view', [])->toHtml();
- $this->assertTrue(strpos($result, '<html></html>') !== false);
+ $this->assertNotFalse(strpos($result, '<html></html>'));
}
public function testRenderTextReturnsText() | true |
Other | laravel | framework | 2bc42882d85787d1cbace7215c27dda138e67a10.json | Add lazy() method to standard collection | src/Illuminate/Support/Collection.php | @@ -60,6 +60,16 @@ public function all()
return $this->items;
}
+ /**
+ * Get a lazy collection for the items in this collection.
+ *
+ * @return \Illuminate\Support\LazyCollection
+ */
+ public function lazy()
+ {
+ return new LazyCollection($this->items);
+ }
+
/**
* Get the average value of a given key.
* | true |
Other | laravel | framework | 2bc42882d85787d1cbace7215c27dda138e67a10.json | Add lazy() method to standard collection | tests/Support/SupportCollectionTest.php | @@ -269,6 +269,18 @@ public function testToArrayCallsToArrayOnEachItemInCollection($collection)
$this->assertEquals(['foo.array', 'bar.array'], $results);
}
+ public function testLazyReturnsLazyCollection()
+ {
+ $data = new Collection([1, 2, 3, 4, 5]);
+
+ $lazy = $data->lazy();
+
+ $data->add(6);
+
+ $this->assertInstanceOf(LazyCollection::class, $lazy);
+ $this->assertSame([1, 2, 3, 4, 5], $lazy->all());
+ }
+
/**
* @dataProvider collectionClassProvider
*/ | true |
Other | laravel | framework | ecf7f30e9778c6df91677fbc8f3d407318a8d298.json | Create LazyCollection class | src/Illuminate/Support/LazyCollection.php | @@ -0,0 +1,1419 @@
+<?php
+
+namespace Illuminate\Support;
+
+use Closure;
+use stdClass;
+use ArrayIterator;
+use IteratorAggregate;
+use Illuminate\Support\Traits\Macroable;
+use Illuminate\Support\Traits\EnumeratesValues;
+
+class LazyCollection implements Enumerable
+{
+ use EnumeratesValues, Macroable;
+
+ /**
+ * The source from which to generate items.
+ *
+ * @var callable|static
+ */
+ public $source;
+
+ /**
+ * Create a new lazy collection instance.
+ *
+ * @param mixed $source
+ * @return void
+ */
+ public function __construct($source = null)
+ {
+ if ($source instanceof Closure || $source instanceof self) {
+ $this->source = $source;
+ } elseif (is_null($source)) {
+ $this->source = static::empty();
+ } else {
+ $this->source = $this->getArrayableItems($source);
+ }
+ }
+
+ /**
+ * Create a new instance with no items.
+ *
+ * @return static
+ */
+ public static function empty()
+ {
+ return new static([]);
+ }
+
+ /**
+ * Create a new instance by invoking the callback a given amount of times.
+ *
+ * @param int $number
+ * @param callable $callback
+ * @return static
+ */
+ public static function times($number, callable $callback = null)
+ {
+ if ($number < 1) {
+ return new static;
+ }
+
+ $instance = new static(function () use ($number) {
+ for ($current = 1; $current <= $number; $current++) {
+ yield $current;
+ }
+ });
+
+ return is_null($callback) ? $instance : $instance->map($callback);
+ }
+
+ /**
+ * Create an enumerable with the given range.
+ *
+ * @param int $from
+ * @param int $to
+ * @return static
+ */
+ public static function range($from, $to)
+ {
+ return new static(function () use ($from, $to) {
+ for (; $from <= $to; $from++) {
+ yield $from;
+ }
+ });
+ }
+
+ /**
+ * Get all items in the enumerable.
+ *
+ * @return array
+ */
+ public function all()
+ {
+ if (is_array($this->source)) {
+ return $this->source;
+ }
+
+ return iterator_to_array($this->getIterator());
+ }
+
+ /**
+ * Collect the values into a collection.
+ *
+ * @return \Illuminate\Support\Collection
+ */
+ public function collect()
+ {
+ return new Collection($this->all());
+ }
+
+ /**
+ * Get the average value of a given key.
+ *
+ * @param callable|string|null $callback
+ * @return mixed
+ */
+ public function avg($callback = null)
+ {
+ return $this->collect()->avg($callback);
+ }
+
+ /**
+ * Get the median of a given key.
+ *
+ * @param string|array|null $key
+ * @return mixed
+ */
+ public function median($key = null)
+ {
+ return $this->collect()->median($key);
+ }
+
+ /**
+ * Get the mode of a given key.
+ *
+ * @param string|array|null $key
+ * @return array|null
+ */
+ public function mode($key = null)
+ {
+ return $this->collect()->mode($key);
+ }
+
+ /**
+ * Collapse the collection of items into a single array.
+ *
+ * @return static
+ */
+ public function collapse()
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original) {
+ foreach ($original as $values) {
+ if (is_array($values) || $values instanceof Enumerable) {
+ foreach ($values as $value) {
+ yield $value;
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Determine if an item exists in the enumerable.
+ *
+ * @param mixed $key
+ * @param mixed $operator
+ * @param mixed $value
+ * @return bool
+ */
+ public function contains($key, $operator = null, $value = null)
+ {
+ if (func_num_args() === 1 && $this->useAsCallable($key)) {
+ $placeholder = new stdClass;
+
+ return $this->first($key, $placeholder) !== $placeholder;
+ }
+
+ if (func_num_args() === 1) {
+ $needle = $key;
+
+ foreach ($this as $value) {
+ if ($value == $needle) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ return $this->contains($this->operatorForWhere(...func_get_args()));
+ }
+
+ /**
+ * Cross join the given iterables, returning all possible permutations.
+ *
+ * @param array ...$arrays
+ * @return static
+ */
+ public function crossJoin(...$arrays)
+ {
+ return $this->passthru('crossJoin', func_get_args());
+ }
+
+ /**
+ * Get the items that are not present in the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function diff($items)
+ {
+ return $this->passthru('diff', func_get_args());
+ }
+
+ /**
+ * Get the items that are not present in the given items, using the callback.
+ *
+ * @param mixed $items
+ * @param callable $callback
+ * @return static
+ */
+ public function diffUsing($items, callable $callback)
+ {
+ return $this->passthru('diffUsing', func_get_args());
+ }
+
+ /**
+ * Get the items whose keys and values are not present in the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function diffAssoc($items)
+ {
+ return $this->passthru('diffAssoc', func_get_args());
+ }
+
+ /**
+ * Get the items whose keys and values are not present in the given items.
+ *
+ * @param mixed $items
+ * @param callable $callback
+ * @return static
+ */
+ public function diffAssocUsing($items, callable $callback)
+ {
+ return $this->passthru('diffAssocUsing', func_get_args());
+ }
+
+ /**
+ * Get the items whose keys are not present in the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function diffKeys($items)
+ {
+ return $this->passthru('diffKeys', func_get_args());
+ }
+
+ /**
+ * Get the items whose keys are not present in the given items.
+ *
+ * @param mixed $items
+ * @param callable $callback
+ * @return static
+ */
+ public function diffKeysUsing($items, callable $callback)
+ {
+ return $this->passthru('diffKeysUsing', func_get_args());
+ }
+
+ /**
+ * Retrieve duplicate items.
+ *
+ * @param callable|null $callback
+ * @param bool $strict
+ * @return static
+ */
+ public function duplicates($callback = null, $strict = false)
+ {
+ return $this->passthru('duplicates', func_get_args());
+ }
+
+ /**
+ * Retrieve duplicate items using strict comparison.
+ *
+ * @param callable|null $callback
+ * @return static
+ */
+ public function duplicatesStrict($callback = null)
+ {
+ return $this->passthru('duplicatesStrict', func_get_args());
+ }
+
+ /**
+ * Get all items except for those with the specified keys.
+ *
+ * @param mixed $keys
+ * @return static
+ */
+ public function except($keys)
+ {
+ return $this->passthru('except', func_get_args());
+ }
+
+ /**
+ * Run a filter over each of the items.
+ *
+ * @param callable|null $callback
+ * @return static
+ */
+ public function filter(callable $callback = null)
+ {
+ if (is_null($callback)) {
+ $callback = function ($value) {
+ return (bool) $value;
+ };
+ }
+
+ $original = clone $this;
+
+ return new static(function () use ($original, $callback) {
+ foreach ($original as $key => $value) {
+ if ($callback($value, $key)) {
+ yield $key => $value;
+ }
+ }
+ });
+ }
+
+ /**
+ * Get the first item from the enumerable passing the given truth test.
+ *
+ * @param callable|null $callback
+ * @param mixed $default
+ * @return mixed
+ */
+ public function first(callable $callback = null, $default = null)
+ {
+ $iterator = $this->getIterator();
+
+ if (is_null($callback)) {
+ if (! $iterator->valid()) {
+ return value($default);
+ }
+
+ return $iterator->current();
+ }
+
+ foreach ($iterator as $key => $value) {
+ if ($callback($value, $key)) {
+ return $value;
+ }
+ }
+
+ return value($default);
+ }
+
+ /**
+ * Get a flattened list of the items in the collection.
+ *
+ * @param int $depth
+ * @return static
+ */
+ public function flatten($depth = INF)
+ {
+ $original = clone $this;
+
+ $instance = new static(function () use ($original, $depth) {
+ foreach ($original as $item) {
+ if (! is_array($item) && ! $item instanceof Enumerable) {
+ yield $item;
+ } elseif ($depth === 1) {
+ yield from $item;
+ } else {
+ yield from (new static($item))->flatten($depth - 1);
+ }
+ }
+ });
+
+ return $instance->values();
+ }
+
+ /**
+ * Flip the items in the collection.
+ *
+ * @return static
+ */
+ public function flip()
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original) {
+ foreach ($original as $key => $value) {
+ yield $value => $key;
+ }
+ });
+ }
+
+ /**
+ * Remove an item by key.
+ *
+ * @param string|array $keys
+ * @return $this
+ */
+ public function forget($keys)
+ {
+ $original = clone $this;
+
+ $this->source = function () use ($original, $keys) {
+ $keys = array_flip((array) $keys);
+
+ foreach ($original as $key => $value) {
+ if (! array_key_exists($key, $keys)) {
+ yield $key => $value;
+ }
+ }
+ };
+
+ return $this;
+ }
+
+ /**
+ * Get an item by key.
+ *
+ * @param mixed $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function get($key, $default = null)
+ {
+ if (is_null($key)) {
+ return;
+ }
+
+ foreach ($this as $outerKey => $outerValue) {
+ if ($outerKey == $key) {
+ return $outerValue;
+ }
+ }
+
+ return value($default);
+ }
+
+ /**
+ * Group an associative array by a field or using a callback.
+ *
+ * @param array|callable|string $groupBy
+ * @param bool $preserveKeys
+ * @return static
+ */
+ public function groupBy($groupBy, $preserveKeys = false)
+ {
+ return $this->passthru('groupBy', func_get_args());
+ }
+
+ /**
+ * Key an associative array by a field or using a callback.
+ *
+ * @param callable|string $keyBy
+ * @return static
+ */
+ public function keyBy($keyBy)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $keyBy) {
+ $keyBy = $this->valueRetriever($keyBy);
+
+ foreach ($original as $key => $item) {
+ $resolvedKey = $keyBy($item, $key);
+
+ if (is_object($resolvedKey)) {
+ $resolvedKey = (string) $resolvedKey;
+ }
+
+ yield $resolvedKey => $item;
+ }
+ });
+ }
+
+ /**
+ * Determine if an item exists in the collection by key.
+ *
+ * @param mixed $key
+ * @return bool
+ */
+ public function has($key)
+ {
+ $keys = array_flip(is_array($key) ? $key : func_get_args());
+ $count = count($keys);
+
+ foreach ($this as $key => $value) {
+ if (array_key_exists($key, $keys) && --$count == 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Concatenate values of a given key as a string.
+ *
+ * @param string $value
+ * @param string $glue
+ * @return string
+ */
+ public function implode($value, $glue = null)
+ {
+ return $this->collect()->implode(...func_get_args());
+ }
+
+ /**
+ * Intersect the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function intersect($items)
+ {
+ return $this->passthru('intersect', func_get_args());
+ }
+
+ /**
+ * Intersect the collection with the given items by key.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function intersectByKeys($items)
+ {
+ return $this->passthru('intersectByKeys', func_get_args());
+ }
+
+ /**
+ * Determine if the items is empty or not.
+ *
+ * @return bool
+ */
+ public function isEmpty()
+ {
+ return ! $this->getIterator()->valid();
+ }
+
+ /**
+ * Join all items from the collection using a string. The final items can use a separate glue string.
+ *
+ * @param string $glue
+ * @param string $finalGlue
+ * @return string
+ */
+ public function join($glue, $finalGlue = '')
+ {
+ return $this->collect()->join(...func_get_args());
+ }
+
+ /**
+ * Get the keys of the collection items.
+ *
+ * @return static
+ */
+ public function keys()
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original) {
+ foreach ($original as $key => $value) {
+ yield $key;
+ }
+ });
+ }
+
+ /**
+ * Get the last item from the collection.
+ *
+ * @param callable|null $callback
+ * @param mixed $default
+ * @return mixed
+ */
+ public function last(callable $callback = null, $default = null)
+ {
+ $needle = $placeholder = new stdClass;
+
+ foreach ($this as $key => $value) {
+ if (is_null($callback) || $callback($value, $key)) {
+ $needle = $value;
+ }
+ }
+
+ return $needle === $placeholder ? value($default) : $needle;
+ }
+
+ /**
+ * Get the values of a given key.
+ *
+ * @param string|array $value
+ * @param string|null $key
+ * @return static
+ */
+ public function pluck($value, $key = null)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $value, $key) {
+ [$value, $key] = $this->explodePluckParameters($value, $key);
+
+ foreach ($original as $item) {
+ $itemValue = data_get($item, $value);
+
+ if (is_null($key)) {
+ yield $itemValue;
+ } else {
+ $itemKey = data_get($item, $key);
+
+ if (is_object($itemKey) && method_exists($itemKey, '__toString')) {
+ $itemKey = (string) $itemKey;
+ }
+
+ yield $itemKey => $itemValue;
+ }
+ }
+ });
+ }
+
+ /**
+ * Run a map over each of the items.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function map(callable $callback)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $callback) {
+ foreach ($original as $key => $value) {
+ yield $key => $callback($value, $key);
+ }
+ });
+ }
+
+ /**
+ * Run a dictionary map over the items.
+ *
+ * The callback should return an associative array with a single key/value pair.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function mapToDictionary(callable $callback)
+ {
+ return $this->passthru('mapToDictionary', func_get_args());
+ }
+
+ /**
+ * Run an associative map over each of the items.
+ *
+ * The callback should return an associative array with a single key/value pair.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function mapWithKeys(callable $callback)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $callback) {
+ foreach ($original as $key => $value) {
+ yield from $callback($value, $key);
+ }
+ });
+ }
+
+ /**
+ * Merge the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function merge($items)
+ {
+ return $this->passthru('merge', func_get_args());
+ }
+
+ /**
+ * Recursively merge the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function mergeRecursive($items)
+ {
+ return $this->passthru('mergeRecursive', func_get_args());
+ }
+
+ /**
+ * Create a collection by using this collection for keys and another for its values.
+ *
+ * @param mixed $values
+ * @return static
+ */
+ public function combine($values)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $values) {
+ $values = $this->makeIterator($values);
+
+ $errorMessage = 'Both parameters should have an equal number of elements';
+
+ foreach ($original as $key) {
+ if (! $values->valid()) {
+ trigger_error($errorMessage, E_USER_WARNING);
+
+ break;
+ }
+
+ yield $key => $values->current();
+
+ $values->next();
+ }
+
+ if ($values->valid()) {
+ trigger_error($errorMessage, E_USER_WARNING);
+ }
+ });
+ }
+
+ /**
+ * Union the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function union($items)
+ {
+ return $this->passthru('union', func_get_args());
+ }
+
+ /**
+ * Create a new collection consisting of every n-th element.
+ *
+ * @param int $step
+ * @param int $offset
+ * @return static
+ */
+ public function nth($step, $offset = 0)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $step, $offset) {
+ $position = 0;
+
+ foreach ($original as $item) {
+ if ($position % $step === $offset) {
+ yield $item;
+ }
+
+ $position++;
+ }
+ });
+ }
+
+ /**
+ * Get the items with the specified keys.
+ *
+ * @param mixed $keys
+ * @return static
+ */
+ public function only($keys)
+ {
+ if ($keys instanceof Enumerable) {
+ $keys = $keys->all();
+ } elseif (! is_null($keys)) {
+ $keys = is_array($keys) ? $keys : func_get_args();
+ }
+
+ $original = clone $this;
+
+ return new static(function () use ($original, $keys) {
+ if (is_null($keys)) {
+ yield from $original;
+ } else {
+ $keys = array_flip($keys);
+
+ foreach ($original as $key => $value) {
+ if (array_key_exists($key, $keys)) {
+ yield $key => $value;
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Get and remove the last item from the collection.
+ *
+ * @return mixed
+ */
+ public function pop()
+ {
+ $items = $this->collect();
+
+ $result = $items->pop();
+
+ $this->source = $items;
+
+ return $result;
+ }
+
+ /**
+ * Push an item onto the beginning of the collection.
+ *
+ * @param mixed $value
+ * @param mixed $key
+ * @return $this
+ */
+ public function prepend($value, $key = null)
+ {
+ $original = clone $this;
+
+ $this->source = function () use ($original, $value, $key) {
+ $instance = new static(function () use ($original, $value, $key) {
+ yield $key => $value;
+
+ yield from $original;
+ });
+
+ if (is_null($key)) {
+ $instance = $instance->values();
+ }
+
+ yield from $instance;
+ };
+
+ return $this;
+ }
+
+ /**
+ * Push all of the given items onto the collection.
+ *
+ * @param iterable $source
+ * @return static
+ */
+ public function concat($source)
+ {
+ $original = clone $this;
+
+ return (new static(function () use ($original, $source) {
+ yield from $original;
+ yield from $source;
+ }))->values();
+ }
+
+ /**
+ * Put an item in the collection by key.
+ *
+ * @param mixed $key
+ * @param mixed $value
+ * @return $this
+ */
+ public function put($key, $value)
+ {
+ $original = clone $this;
+
+ if (is_null($key)) {
+ $this->source = function () use ($original, $value) {
+ foreach ($original as $innerKey => $innerValue) {
+ yield $innerKey => $innerValue;
+ }
+
+ yield $value;
+ };
+ } else {
+ $this->source = function () use ($original, $key, $value) {
+ $found = false;
+
+ foreach ($original as $innerKey => $innerValue) {
+ if ($innerKey == $key) {
+ yield $key => $value;
+
+ $found = true;
+ } else {
+ yield $innerKey => $innerValue;
+ }
+ }
+
+ if (! $found) {
+ yield $key => $value;
+ }
+ };
+ }
+
+ return $this;
+ }
+
+ /**
+ * Get one or a specified number of items randomly from the collection.
+ *
+ * @param int|null $number
+ * @return static|mixed
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function random($number = null)
+ {
+ $result = $this->collect()->random(...func_get_args());
+
+ return is_null($number) ? $result : new static($result);
+ }
+
+ /**
+ * Reduce the collection to a single value.
+ *
+ * @param callable $callback
+ * @param mixed $initial
+ * @return mixed
+ */
+ public function reduce(callable $callback, $initial = null)
+ {
+ $result = $initial;
+
+ foreach ($this as $value) {
+ $result = $callback($result, $value);
+ }
+
+ return $result;
+ }
+
+ /**
+ * Replace the collection items with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function replace($items)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $items) {
+ $items = $this->getArrayableItems($items);
+ $usedItems = [];
+
+ foreach ($original as $key => $value) {
+ if (array_key_exists($key, $items)) {
+ yield $key => $items[$key];
+
+ $usedItems[$key] = true;
+ } else {
+ yield $key => $value;
+ }
+ }
+
+ foreach ($items as $key => $value) {
+ if (! array_key_exists($key, $usedItems)) {
+ yield $key => $value;
+ }
+ }
+ });
+ }
+
+ /**
+ * Recursively replace the collection items with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function replaceRecursive($items)
+ {
+ return $this->passthru('replaceRecursive', func_get_args());
+ }
+
+ /**
+ * Reverse items order.
+ *
+ * @return static
+ */
+ public function reverse()
+ {
+ return $this->passthru('reverse', func_get_args());
+ }
+
+ /**
+ * Search the collection for a given value and return the corresponding key if successful.
+ *
+ * @param mixed $value
+ * @param bool $strict
+ * @return mixed
+ */
+ public function search($value, $strict = false)
+ {
+ $predicate = $this->useAsCallable($value)
+ ? $value
+ : function ($item) use ($value, $strict) {
+ return $strict ? $item === $value : $item == $value;
+ };
+
+ foreach ($this as $key => $item) {
+ if ($predicate($item, $key)) {
+ return $key;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Get and remove the first item from the collection.
+ *
+ * @return mixed
+ */
+ public function shift()
+ {
+ return tap($this->first(), function () {
+ $this->source = $this->skip(1);
+ });
+ }
+
+ /**
+ * Shuffle the items in the collection.
+ *
+ * @param int $seed
+ * @return static
+ */
+ public function shuffle($seed = null)
+ {
+ return $this->passthru('shuffle', func_get_args());
+ }
+
+ /**
+ * Skip the first {$count} items.
+ *
+ * @param int $count
+ * @return static
+ */
+ public function skip($count)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $count) {
+ $iterator = $original->getIterator();
+
+ while ($iterator->valid() && $count--) {
+ $iterator->next();
+ }
+
+ while ($iterator->valid()) {
+ yield $iterator->key() => $iterator->current();
+
+ $iterator->next();
+ }
+ });
+ }
+
+ /**
+ * Get a slice of items from the enumerable.
+ *
+ * @param int $offset
+ * @param int $length
+ * @return static
+ */
+ public function slice($offset, $length = null)
+ {
+ if ($offset < 0 || $length < 0) {
+ return $this->passthru('slice', func_get_args());
+ }
+
+ $instance = $this->skip($offset);
+
+ return is_null($length) ? $instance : $instance->take($length);
+ }
+
+ /**
+ * Split a collection into a certain number of groups.
+ *
+ * @param int $numberOfGroups
+ * @return static
+ */
+ public function split($numberOfGroups)
+ {
+ return $this->passthru('split', func_get_args());
+ }
+
+ /**
+ * Chunk the collection into chunks of the given size.
+ *
+ * @param int $size
+ * @return static
+ */
+ public function chunk($size)
+ {
+ if ($size <= 0) {
+ return static::empty();
+ }
+
+ $original = clone $this;
+
+ return new static(function () use ($original, $size) {
+ $iterator = $original->getIterator();
+
+ while ($iterator->valid()) {
+ $values = [];
+
+ for ($i = 0; $iterator->valid() && $i < $size; $i++, $iterator->next()) {
+ $values[$iterator->key()] = $iterator->current();
+ }
+
+ yield new static($values);
+ }
+ });
+ }
+
+ /**
+ * Sort through each item with a callback.
+ *
+ * @param callable|null $callback
+ * @return static
+ */
+ public function sort(callable $callback = null)
+ {
+ return $this->passthru('sort', func_get_args());
+ }
+
+ /**
+ * Sort the collection using the given callback.
+ *
+ * @param callable|string $callback
+ * @param int $options
+ * @param bool $descending
+ * @return static
+ */
+ public function sortBy($callback, $options = SORT_REGULAR, $descending = false)
+ {
+ return $this->passthru('sortBy', func_get_args());
+ }
+
+ /**
+ * Sort the collection in descending order using the given callback.
+ *
+ * @param callable|string $callback
+ * @param int $options
+ * @return static
+ */
+ public function sortByDesc($callback, $options = SORT_REGULAR)
+ {
+ return $this->passthru('sortByDesc', func_get_args());
+ }
+
+ /**
+ * Sort the collection keys.
+ *
+ * @param int $options
+ * @param bool $descending
+ * @return static
+ */
+ public function sortKeys($options = SORT_REGULAR, $descending = false)
+ {
+ return $this->passthru('sortKeys', func_get_args());
+ }
+
+ /**
+ * Sort the collection keys in descending order.
+ *
+ * @param int $options
+ * @return static
+ */
+ public function sortKeysDesc($options = SORT_REGULAR)
+ {
+ return $this->passthru('sortKeysDesc', func_get_args());
+ }
+
+ /**
+ * Splice a portion of the underlying collection array.
+ *
+ * @param int $offset
+ * @param int|null $length
+ * @param mixed $replacement
+ * @return static
+ */
+ public function splice($offset, $length = null, $replacement = [])
+ {
+ $items = $this->collect();
+
+ $extracted = $items->splice(...func_get_args());
+
+ $this->source = function () use ($items) {
+ yield from $items;
+ };
+
+ return new static($extracted);
+ }
+
+ /**
+ * Take the first or last {$limit} items.
+ *
+ * @param int $limit
+ * @return static
+ */
+ public function take($limit)
+ {
+ if ($limit < 0) {
+ return $this->passthru('take', func_get_args());
+ }
+
+ $original = clone $this;
+
+ return new static(function () use ($original, $limit) {
+ $iterator = $original->getIterator();
+
+ for (; $iterator->valid() && $limit--; $iterator->next()) {
+ yield $iterator->key() => $iterator->current();
+ }
+ });
+ }
+
+ /**
+ * Transform each item in the collection using a callback.
+ *
+ * @param callable $callback
+ * @return $this
+ */
+ public function transform(callable $callback)
+ {
+ $original = clone $this;
+
+ $this->source = function () use ($original, $callback) {
+ yield from $original->map($callback);
+ };
+
+ return $this;
+ }
+
+ /**
+ * Reset the keys on the underlying array.
+ *
+ * @return static
+ */
+ public function values()
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original) {
+ foreach ($original as $item) {
+ yield $item;
+ }
+ });
+ }
+
+ /**
+ * Zip the collection together with one or more arrays.
+ *
+ * e.g. new LazyCollection([1, 2, 3])->zip([4, 5, 6]);
+ * => [[1, 4], [2, 5], [3, 6]]
+ *
+ * @param mixed ...$items
+ * @return static
+ */
+ public function zip($items)
+ {
+ $iterables = func_get_args();
+
+ $original = clone $this;
+
+ return new static(function () use ($original, $iterables) {
+ $iterators = Collection::make($iterables)->map(function ($iterable) {
+ return $this->makeIterator($iterable);
+ })->prepend($original->getIterator());
+
+ while ($iterators->contains->valid()) {
+ yield new static($iterators->map->current());
+
+ $iterators->each->next();
+ }
+ });
+ }
+
+ /**
+ * Pad collection to the specified length with a value.
+ *
+ * @param int $size
+ * @param mixed $value
+ * @return static
+ */
+ public function pad($size, $value)
+ {
+ if ($size < 0) {
+ return $this->passthru('pad', func_get_args());
+ }
+
+ $original = clone $this;
+
+ return new static(function () use ($original, $size, $value) {
+ $yielded = 0;
+
+ foreach ($original as $index => $item) {
+ yield $index => $item;
+
+ $yielded++;
+ }
+
+ while ($yielded++ < $size) {
+ yield $value;
+ }
+ });
+ }
+
+ /**
+ * Get the values iterator.
+ *
+ * @return \Traversable
+ */
+ public function getIterator()
+ {
+ return $this->makeIterator($this->source);
+ }
+
+ /**
+ * Count the number of items in the collection.
+ *
+ * @return int
+ */
+ public function count()
+ {
+ if (is_array($this->source)) {
+ return count($this->source);
+ }
+
+ return iterator_count($this->getIterator());
+ }
+
+ /**
+ * Add an item to the collection.
+ *
+ * @param mixed $item
+ * @return $this
+ */
+ public function add($item)
+ {
+ $original = clone $this;
+
+ $this->source = function () use ($original, $item) {
+ foreach ($original as $value) {
+ yield $value;
+ }
+
+ yield $item;
+ };
+
+ return $this;
+ }
+
+ /**
+ * Make an iterator from the given source.
+ *
+ * @param mixed $source
+ * @return \Traversable
+ */
+ protected function makeIterator($source)
+ {
+ if ($source instanceof IteratorAggregate) {
+ return $source->getIterator();
+ }
+
+ if (is_array($source)) {
+ return new ArrayIterator($source);
+ }
+
+ return $source();
+ }
+
+ /**
+ * Explode the "value" and "key" arguments passed to "pluck".
+ *
+ * @param string|array $value
+ * @param string|array|null $key
+ * @return array
+ */
+ protected function explodePluckParameters($value, $key)
+ {
+ $value = is_string($value) ? explode('.', $value) : $value;
+
+ $key = is_null($key) || is_array($key) ? $key : explode('.', $key);
+
+ return [$value, $key];
+ }
+
+ /**
+ * Pass this lazy collection through a method on the collection class.
+ *
+ * @param string $method
+ * @param array $params
+ * @return static
+ */
+ protected function passthru($method, array $params)
+ {
+ $original = clone $this;
+
+ return new static(function () use ($original, $method, $params) {
+ yield from $original->collect()->$method(...$params);
+ });
+ }
+
+ /**
+ * Finish cloning the collection instance.
+ *
+ * @return void
+ */
+ public function __clone()
+ {
+ if (! is_array($this->source)) {
+ $this->source = clone $this->source;
+ }
+ }
+} | true |
Other | laravel | framework | ecf7f30e9778c6df91677fbc8f3d407318a8d298.json | Create LazyCollection class | tests/Support/SupportCollectionTest.php | @@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
+use Illuminate\Support\LazyCollection;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
@@ -3934,6 +3935,7 @@ public function collectionClassProvider()
{
return [
[Collection::class],
+ [LazyCollection::class],
];
}
} | true |
Other | laravel | framework | 67d6b72b68b4f02665ddba079fb9edd3ddb90d8f.json | Add Enumerable skip() method | src/Illuminate/Support/Collection.php | @@ -942,6 +942,17 @@ public function shuffle($seed = null)
return new static(Arr::shuffle($this->items, $seed));
}
+ /**
+ * Skip the first {$count} items.
+ *
+ * @param int $count
+ * @return static
+ */
+ public function skip($count)
+ {
+ return $this->slice($count);
+ }
+
/**
* Slice the underlying collection array.
* | true |
Other | laravel | framework | 67d6b72b68b4f02665ddba079fb9edd3ddb90d8f.json | Add Enumerable skip() method | src/Illuminate/Support/Enumerable.php | @@ -767,6 +767,14 @@ public function shift();
*/
public function shuffle($seed = null);
+ /**
+ * Skip the first {$count} items.
+ *
+ * @param int $count
+ * @return static
+ */
+ public function skip($count);
+
/**
* Get a slice of items from the enumerable.
* | true |
Other | laravel | framework | 67d6b72b68b4f02665ddba079fb9edd3ddb90d8f.json | Add Enumerable skip() method | tests/Support/SupportCollectionTest.php | @@ -205,6 +205,18 @@ public function testCollectionShuffleWithSeed($collection)
$this->assertEquals($firstRandom, $secondRandom);
}
+ /**
+ * @dataProvider collectionClassProvider
+ */
+ public function testSkipMethod($collection)
+ {
+ $data = new $collection([1, 2, 3, 4, 5, 6]);
+
+ $data = $data->skip(4)->values();
+
+ $this->assertSame([5, 6], $data->all());
+ }
+
/**
* @dataProvider collectionClassProvider
*/ | true |
Other | laravel | framework | 0c86fd2d155e431b5055046eced247a9037b9099.json | Support all Enumerables in proxy | src/Illuminate/Support/HigherOrderCollectionProxy.php | @@ -3,14 +3,14 @@
namespace Illuminate\Support;
/**
- * @mixin \Illuminate\Support\Collection
+ * @mixin \Illuminate\Support\Enumerable
*/
class HigherOrderCollectionProxy
{
/**
* The collection being operated on.
*
- * @var \Illuminate\Support\Collection
+ * @var \Illuminate\Support\Enumerable
*/
protected $collection;
@@ -24,11 +24,11 @@ class HigherOrderCollectionProxy
/**
* Create a new proxy instance.
*
- * @param \Illuminate\Support\Collection $collection
+ * @param \Illuminate\Support\Enumerable $collection
* @param string $method
* @return void
*/
- public function __construct(Collection $collection, $method)
+ public function __construct(Enumerable $collection, $method)
{
$this->method = $method;
$this->collection = $collection; | false |
Other | laravel | framework | 7657da10f2a3b9e49270d371685fb836947ca724.json | Create Enumerable contract | src/Illuminate/Support/Collection.php | @@ -37,7 +37,8 @@
* @property-read HigherOrderCollectionProxy $sum
* @property-read HigherOrderCollectionProxy $unique
*/
-class Collection implements Arrayable, ArrayAccess, Countable, IteratorAggregate, Jsonable, JsonSerializable
+
+class Collection implements ArrayAccess, Enumerable
{
use Macroable;
| true |
Other | laravel | framework | 7657da10f2a3b9e49270d371685fb836947ca724.json | Create Enumerable contract | src/Illuminate/Support/Enumerable.php | @@ -0,0 +1,979 @@
+<?php
+
+namespace Illuminate\Support;
+
+use Countable;
+use JsonSerializable;
+use IteratorAggregate;
+use Illuminate\Contracts\Support\Jsonable;
+use Illuminate\Contracts\Support\Arrayable;
+
+interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable
+{
+ /**
+ * Create a new collection instance if the value isn't one already.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public static function make($items = []);
+
+ /**
+ * Create a new instance by invoking the callback a given amount of times.
+ *
+ * @param int $number
+ * @param callable $callback
+ * @return static
+ */
+ public static function times($number, callable $callback = null);
+
+ /**
+ * Wrap the given value in a collection if applicable.
+ *
+ * @param mixed $value
+ * @return static
+ */
+ public static function wrap($value);
+
+ /**
+ * Get the underlying items from the given collection if applicable.
+ *
+ * @param array|static $value
+ * @return array
+ */
+ public static function unwrap($value);
+
+ /**
+ * Get all items in the enumerable.
+ *
+ * @return array
+ */
+ public function all();
+
+ /**
+ * Alias for the "avg" method.
+ *
+ * @param callable|string|null $callback
+ * @return mixed
+ */
+ public function average($callback = null);
+
+ /**
+ * Get the median of a given key.
+ *
+ * @param string|array|null $key
+ * @return mixed
+ */
+ public function median($key = null);
+
+ /**
+ * Get the mode of a given key.
+ *
+ * @param string|array|null $key
+ * @return array|null
+ */
+ public function mode($key = null);
+
+ /**
+ * Collapse the items into a single enumerable.
+ *
+ * @return static
+ */
+ public function collapse();
+
+ /**
+ * Alias for the "contains" method.
+ *
+ * @param mixed $key
+ * @param mixed $operator
+ * @param mixed $value
+ * @return bool
+ */
+ public function some($key, $operator = null, $value = null);
+
+ /**
+ * Determine if an item exists, using strict comparison.
+ *
+ * @param mixed $key
+ * @param mixed $value
+ * @return bool
+ */
+ public function containsStrict($key, $value = null);
+
+ /**
+ * Get the average value of a given key.
+ *
+ * @param callable|string|null $callback
+ * @return mixed
+ */
+ public function avg($callback = null);
+
+ /**
+ * Determine if an item exists in the enumerable.
+ *
+ * @param mixed $key
+ * @param mixed $operator
+ * @param mixed $value
+ * @return bool
+ */
+ public function contains($key, $operator = null, $value = null);
+
+ /**
+ * Dump the collection and end the script.
+ *
+ * @param mixed ...$args
+ * @return void
+ */
+ public function dd(...$args);
+
+ /**
+ * Dump the collection.
+ *
+ * @return $this
+ */
+ public function dump();
+
+ /**
+ * Get the items that are not present in the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function diff($items);
+
+ /**
+ * Get the items that are not present in the given items, using the callback.
+ *
+ * @param mixed $items
+ * @param callable $callback
+ * @return static
+ */
+ public function diffUsing($items, callable $callback);
+
+ /**
+ * Get the items whose keys and values are not present in the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function diffAssoc($items);
+
+ /**
+ * Get the items whose keys and values are not present in the given items.
+ *
+ * @param mixed $items
+ * @param callable $callback
+ * @return static
+ */
+ public function diffAssocUsing($items, callable $callback);
+
+ /**
+ * Get the items whose keys are not present in the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function diffKeys($items);
+
+ /**
+ * Get the items whose keys are not present in the given items.
+ *
+ * @param mixed $items
+ * @param callable $callback
+ * @return static
+ */
+ public function diffKeysUsing($items, callable $callback);
+
+ /**
+ * Retrieve duplicate items.
+ *
+ * @param callable|null $callback
+ * @param bool $strict
+ * @return static
+ */
+ public function duplicates($callback = null, $strict = false);
+
+ /**
+ * Retrieve duplicate items using strict comparison.
+ *
+ * @param callable|null $callback
+ * @return static
+ */
+ public function duplicatesStrict($callback = null);
+
+ /**
+ * Execute a callback over each item.
+ *
+ * @param callable $callback
+ * @return $this
+ */
+ public function each(callable $callback);
+
+ /**
+ * Execute a callback over each nested chunk of items.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function eachSpread(callable $callback);
+
+ /**
+ * Determine if all items pass the given test.
+ *
+ * @param string|callable $key
+ * @param mixed $operator
+ * @param mixed $value
+ * @return bool
+ */
+ public function every($key, $operator = null, $value = null);
+
+ /**
+ * Get all items except for those with the specified keys.
+ *
+ * @param mixed $keys
+ * @return static
+ */
+ public function except($keys);
+
+ /**
+ * Run a filter over each of the items.
+ *
+ * @param callable|null $callback
+ * @return static
+ */
+ public function filter(callable $callback = null);
+
+ /**
+ * Apply the callback if the value is truthy.
+ *
+ * @param bool $value
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function when($value, callable $callback, callable $default = null);
+
+ /**
+ * Apply the callback if the collection is empty.
+ *
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function whenEmpty(callable $callback, callable $default = null);
+
+ /**
+ * Apply the callback if the collection is not empty.
+ *
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function whenNotEmpty(callable $callback, callable $default = null);
+
+ /**
+ * Apply the callback if the value is falsy.
+ *
+ * @param bool $value
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function unless($value, callable $callback, callable $default = null);
+
+ /**
+ * Apply the callback unless the collection is empty.
+ *
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function unlessEmpty(callable $callback, callable $default = null);
+
+ /**
+ * Apply the callback unless the collection is not empty.
+ *
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function unlessNotEmpty(callable $callback, callable $default = null);
+
+ /**
+ * Filter items by the given key value pair.
+ *
+ * @param string $key
+ * @param mixed $operator
+ * @param mixed $value
+ * @return static
+ */
+ public function where($key, $operator = null, $value = null);
+
+ /**
+ * Filter items by the given key value pair using strict comparison.
+ *
+ * @param string $key
+ * @param mixed $value
+ * @return static
+ */
+ public function whereStrict($key, $value);
+
+ /**
+ * Filter items by the given key value pair.
+ *
+ * @param string $key
+ * @param mixed $values
+ * @param bool $strict
+ * @return static
+ */
+ public function whereIn($key, $values, $strict = false);
+
+ /**
+ * Filter items by the given key value pair using strict comparison.
+ *
+ * @param string $key
+ * @param mixed $values
+ * @return static
+ */
+ public function whereInStrict($key, $values);
+
+ /**
+ * Filter items such that the value of the given key is between the given values.
+ *
+ * @param string $key
+ * @param array $values
+ * @return static
+ */
+ public function whereBetween($key, $values);
+
+ /**
+ * Filter items such that the value of the given key is not between the given values.
+ *
+ * @param string $key
+ * @param array $values
+ * @return static
+ */
+ public function whereNotBetween($key, $values);
+
+ /**
+ * Filter items by the given key value pair.
+ *
+ * @param string $key
+ * @param mixed $values
+ * @param bool $strict
+ * @return static
+ */
+ public function whereNotIn($key, $values, $strict = false);
+
+ /**
+ * Filter items by the given key value pair using strict comparison.
+ *
+ * @param string $key
+ * @param mixed $values
+ * @return static
+ */
+ public function whereNotInStrict($key, $values);
+
+ /**
+ * Filter the items, removing any items that don't match the given type.
+ *
+ * @param string $type
+ * @return static
+ */
+ public function whereInstanceOf($type);
+
+ /**
+ * Get the first item from the enumerable passing the given truth test.
+ *
+ * @param callable|null $callback
+ * @param mixed $default
+ * @return mixed
+ */
+ public function first(callable $callback = null, $default = null);
+
+ /**
+ * Get the first item by the given key value pair.
+ *
+ * @param string $key
+ * @param mixed $operator
+ * @param mixed $value
+ * @return mixed
+ */
+ public function firstWhere($key, $operator = null, $value = null);
+
+ /**
+ * Flip the values with their keys.
+ *
+ * @return static
+ */
+ public function flip();
+
+ /**
+ * Remove an item by key.
+ *
+ * @param string|array $keys
+ * @return $this
+ */
+ public function forget($keys);
+
+ /**
+ * Get an item from the collection by key.
+ *
+ * @param mixed $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function get($key, $default = null);
+
+ /**
+ * Group an associative array by a field or using a callback.
+ *
+ * @param array|callable|string $groupBy
+ * @param bool $preserveKeys
+ * @return static
+ */
+ public function groupBy($groupBy, $preserveKeys = false);
+
+ /**
+ * Key an associative array by a field or using a callback.
+ *
+ * @param callable|string $keyBy
+ * @return static
+ */
+ public function keyBy($keyBy);
+
+ /**
+ * Determine if an item exists in the collection by key.
+ *
+ * @param mixed $key
+ * @return bool
+ */
+ public function has($key);
+
+ /**
+ * Concatenate values of a given key as a string.
+ *
+ * @param string $value
+ * @param string $glue
+ * @return string
+ */
+ public function implode($value, $glue = null);
+
+ /**
+ * Intersect the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function intersect($items);
+
+ /**
+ * Intersect the collection with the given items by key.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function intersectByKeys($items);
+
+ /**
+ * Determine if the collection is empty or not.
+ *
+ * @return bool
+ */
+ public function isEmpty();
+
+ /**
+ * Determine if the collection is not empty.
+ *
+ * @return bool
+ */
+ public function isNotEmpty();
+
+ /**
+ * Join all items from the collection using a string. The final items can use a separate glue string.
+ *
+ * @param string $glue
+ * @param string $finalGlue
+ * @return string
+ */
+ public function join($glue, $finalGlue = '');
+
+ /**
+ * Get the keys of the collection items.
+ *
+ * @return static
+ */
+ public function keys();
+
+ /**
+ * Get the last item from the collection.
+ *
+ * @param callable|null $callback
+ * @param mixed $default
+ * @return mixed
+ */
+ public function last(callable $callback = null, $default = null);
+
+ /**
+ * Run a map over each of the items.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function map(callable $callback);
+
+ /**
+ * Run a map over each nested chunk of items.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function mapSpread(callable $callback);
+
+ /**
+ * Run a dictionary map over the items.
+ *
+ * The callback should return an associative array with a single key/value pair.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function mapToDictionary(callable $callback);
+
+ /**
+ * Run a grouping map over the items.
+ *
+ * The callback should return an associative array with a single key/value pair.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function mapToGroups(callable $callback);
+
+ /**
+ * Run an associative map over each of the items.
+ *
+ * The callback should return an associative array with a single key/value pair.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function mapWithKeys(callable $callback);
+
+ /**
+ * Map a collection and flatten the result by a single level.
+ *
+ * @param callable $callback
+ * @return static
+ */
+ public function flatMap(callable $callback);
+
+ /**
+ * Map the values into a new class.
+ *
+ * @param string $class
+ * @return static
+ */
+ public function mapInto($class);
+
+ /**
+ * Merge the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function merge($items);
+
+ /**
+ * Recursively merge the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function mergeRecursive($items);
+
+ /**
+ * Create a collection by using this collection for keys and another for its values.
+ *
+ * @param mixed $values
+ * @return static
+ */
+ public function combine($values);
+
+ /**
+ * Union the collection with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function union($items);
+
+ /**
+ * Get the min value of a given key.
+ *
+ * @param callable|string|null $callback
+ * @return mixed
+ */
+ public function min($callback = null);
+
+ /**
+ * Get the max value of a given key.
+ *
+ * @param callable|string|null $callback
+ * @return mixed
+ */
+ public function max($callback = null);
+
+ /**
+ * Create a new collection consisting of every n-th element.
+ *
+ * @param int $step
+ * @param int $offset
+ * @return static
+ */
+ public function nth($step, $offset = 0);
+
+ /**
+ * Get the items with the specified keys.
+ *
+ * @param mixed $keys
+ * @return static
+ */
+ public function only($keys);
+
+ /**
+ * "Paginate" the collection by slicing it into a smaller collection.
+ *
+ * @param int $page
+ * @param int $perPage
+ * @return static
+ */
+ public function forPage($page, $perPage);
+
+ /**
+ * Partition the collection into two arrays using the given callback or key.
+ *
+ * @param callable|string $key
+ * @param mixed $operator
+ * @param mixed $value
+ * @return static
+ */
+ public function partition($key, $operator = null, $value = null);
+
+ /**
+ * Get and remove the last item from the collection.
+ *
+ * @return mixed
+ */
+ public function pop();
+
+ /**
+ * Push an item onto the beginning of the collection.
+ *
+ * @param mixed $value
+ * @param mixed $key
+ * @return $this
+ */
+ public function prepend($value, $key = null);
+
+ /**
+ * Push an item onto the end of the collection.
+ *
+ * @param mixed $value
+ * @return $this
+ */
+ public function push($value);
+
+ /**
+ * Push all of the given items onto the collection.
+ *
+ * @param iterable $source
+ * @return static
+ */
+ public function concat($source);
+
+ /**
+ * Put an item in the collection by key.
+ *
+ * @param mixed $key
+ * @param mixed $value
+ * @return $this
+ */
+ public function put($key, $value);
+
+ /**
+ * Get one or a specified number of items randomly from the collection.
+ *
+ * @param int|null $number
+ * @return static|mixed
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function random($number = null);
+
+ /**
+ * Reduce the collection to a single value.
+ *
+ * @param callable $callback
+ * @param mixed $initial
+ * @return mixed
+ */
+ public function reduce(callable $callback, $initial = null);
+
+ /**
+ * Replace the collection items with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function replace($items);
+
+ /**
+ * Recursively replace the collection items with the given items.
+ *
+ * @param mixed $items
+ * @return static
+ */
+ public function replaceRecursive($items);
+
+ /**
+ * Reverse items order.
+ *
+ * @return static
+ */
+ public function reverse();
+
+ /**
+ * Search the collection for a given value and return the corresponding key if successful.
+ *
+ * @param mixed $value
+ * @param bool $strict
+ * @return mixed
+ */
+ public function search($value, $strict = false);
+
+ /**
+ * Get and remove the first item from the collection.
+ *
+ * @return mixed
+ */
+ public function shift();
+
+ /**
+ * Shuffle the items in the collection.
+ *
+ * @param int $seed
+ * @return static
+ */
+ public function shuffle($seed = null);
+
+ /**
+ * Get a slice of items from the enumerable.
+ *
+ * @param int $offset
+ * @param int $length
+ * @return static
+ */
+ public function slice($offset, $length = null);
+
+ /**
+ * Split a collection into a certain number of groups.
+ *
+ * @param int $numberOfGroups
+ * @return static
+ */
+ public function split($numberOfGroups);
+
+ /**
+ * Chunk the collection into chunks of the given size.
+ *
+ * @param int $size
+ * @return static
+ */
+ public function chunk($size);
+
+ /**
+ * Sort through each item with a callback.
+ *
+ * @param callable|null $callback
+ * @return static
+ */
+ public function sort(callable $callback = null);
+
+ /**
+ * Sort the collection using the given callback.
+ *
+ * @param callable|string $callback
+ * @param int $options
+ * @param bool $descending
+ * @return static
+ */
+ public function sortBy($callback, $options = SORT_REGULAR, $descending = false);
+
+ /**
+ * Sort the collection in descending order using the given callback.
+ *
+ * @param callable|string $callback
+ * @param int $options
+ * @return static
+ */
+ public function sortByDesc($callback, $options = SORT_REGULAR);
+
+ /**
+ * Sort the collection keys.
+ *
+ * @param int $options
+ * @param bool $descending
+ * @return static
+ */
+ public function sortKeys($options = SORT_REGULAR, $descending = false);
+
+ /**
+ * Sort the collection keys in descending order.
+ *
+ * @param int $options
+ * @return static
+ */
+ public function sortKeysDesc($options = SORT_REGULAR);
+
+ /**
+ * Splice a portion of the underlying collection array.
+ *
+ * @param int $offset
+ * @param int|null $length
+ * @param mixed $replacement
+ * @return static
+ */
+ public function splice($offset, $length = null, $replacement = []);
+
+ /**
+ * Get the sum of the given values.
+ *
+ * @param callable|string|null $callback
+ * @return mixed
+ */
+ public function sum($callback = null);
+
+ /**
+ * Take the first or last {$limit} items.
+ *
+ * @param int $limit
+ * @return static
+ */
+ public function take($limit);
+
+ /**
+ * Pass the collection to the given callback and then return it.
+ *
+ * @param callable $callback
+ * @return $this
+ */
+ public function tap(callable $callback);
+
+ /**
+ * Transform each item in the collection using a callback.
+ *
+ * @param callable $callback
+ * @return $this
+ */
+ public function transform(callable $callback);
+
+ /**
+ * Pass the enumerable to the given callback and return the result.
+ *
+ * @param callable $callback
+ * @return mixed
+ */
+ public function pipe(callable $callback);
+
+ /**
+ * Get the values of a given key.
+ *
+ * @param string|array $value
+ * @param string|null $key
+ * @return static
+ */
+ public function pluck($value, $key = null);
+
+ /**
+ * Create a collection of all elements that do not pass a given truth test.
+ *
+ * @param callable|mixed $callback
+ * @return static
+ */
+ public function reject($callback = true);
+
+ /**
+ * Return only unique items from the collection array.
+ *
+ * @param string|callable|null $key
+ * @param bool $strict
+ * @return static
+ */
+ public function unique($key = null, $strict = false);
+
+ /**
+ * Return only unique items from the collection array using strict comparison.
+ *
+ * @param string|callable|null $key
+ * @return static
+ */
+ public function uniqueStrict($key = null);
+
+ /**
+ * Reset the keys on the underlying array.
+ *
+ * @return static
+ */
+ public function values();
+
+ /**
+ * Pad collection to the specified length with a value.
+ *
+ * @param int $size
+ * @param mixed $value
+ * @return static
+ */
+ public function pad($size, $value);
+
+ /**
+ * Count the number of items in the collection using a given truth test.
+ *
+ * @param callable|null $callback
+ * @return static
+ */
+ public function countBy($callback = null);
+
+ /**
+ * Add an item to the collection.
+ *
+ * @param mixed $item
+ * @return $this
+ */
+ public function add($item);
+
+ /**
+ * Convert the collection to its string representation.
+ *
+ * @return string
+ */
+ public function __toString();
+
+ /**
+ * Add a method to the list of proxied methods.
+ *
+ * @param string $method
+ * @return void
+ */
+ public static function proxy($method);
+
+ /**
+ * Dynamically access collection proxies.
+ *
+ * @param string $key
+ * @return mixed
+ *
+ * @throws \Exception
+ */
+ public function __get($key);
+} | true |
Other | laravel | framework | 7414de1dbe645e371f9ddff758e11aa287ae92c8.json | Fix StyleCI warning | src/Illuminate/Foundation/Testing/TestCase.php | @@ -4,8 +4,8 @@
use Mockery;
use Carbon\Carbon;
-use Illuminate\Support\Str;
use Carbon\CarbonImmutable;
+use Illuminate\Support\Str;
use Illuminate\Support\Facades\Facade;
use Illuminate\Database\Eloquent\Model;
use Mockery\Exception\InvalidCountException; | false |
Other | laravel | framework | c06ea522ca7e553584e7fb0f3726d2c979c25ec5.json | Remove unused variables | tests/Log/LogLoggerTest.php | @@ -54,15 +54,15 @@ public function testListenShortcutFailsWithNoDispatcher()
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Events dispatcher has not been set.');
- $writer = new Logger($monolog = m::mock(Monolog::class));
+ $writer = new Logger(m::mock(Monolog::class));
$writer->listen(function () {
//
});
}
public function testListenShortcut()
{
- $writer = new Logger($monolog = m::mock(Monolog::class), $events = m::mock(DispatcherContract::class));
+ $writer = new Logger(m::mock(Monolog::class), $events = m::mock(DispatcherContract::class));
$callback = function () {
return 'success'; | false |
Other | laravel | framework | 7b0b2e847ae32e6973f9226a9f4b650920e74480.json | Fix exception message | src/Illuminate/Foundation/ProviderRepository.php | @@ -186,8 +186,8 @@ protected function freshManifest(array $providers)
*/
public function writeManifest($manifest)
{
- if (! is_writable(dirname($this->manifestPath))) {
- throw new Exception('The bootstrap/cache directory must be present and writable.');
+ if (! is_writable($dirname = dirname($this->manifestPath))) {
+ throw new Exception("The {$dirname} directory must be present and writable.");
}
$this->files->replace( | true |
Other | laravel | framework | 7b0b2e847ae32e6973f9226a9f4b650920e74480.json | Fix exception message | tests/Foundation/FoundationProviderRepositoryTest.php | @@ -2,6 +2,7 @@
namespace Illuminate\Tests\Foundation;
+use Exception;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Filesystem\Filesystem;
@@ -87,4 +88,15 @@ public function testWriteManifestStoresToProperLocation()
$this->assertEquals(['foo', 'when' => []], $result);
}
+
+ public function testWriteManifestThrowsExceptionIfManifestDirDoesntExist()
+ {
+ $this->expectException(Exception::class);
+ $this->expectExceptionMessageRegExp('/^The (.*) directory must be present and writable.$/');
+
+ $repo = new ProviderRepository(m::mock(ApplicationContract::class), $files = m::mock(Filesystem::class), __DIR__.'/cache/services.php');
+ $files->shouldReceive('replace')->never();
+
+ $repo->writeManifest(['foo']);
+ }
} | true |
Other | laravel | framework | d4f1b423350607582d33bbd9710747ea7558fd38.json | Remove unused property | src/Illuminate/Cache/NullStore.php | @@ -6,13 +6,6 @@ class NullStore extends TaggableStore
{
use RetrievesMultipleKeys;
- /**
- * The array of stored values.
- *
- * @var array
- */
- protected $storage = [];
-
/**
* Retrieve an item from the cache by key.
* | false |
Other | laravel | framework | 9cb116d9f7d810b71f3e878db8ec9d27af148ada.json | Add the ability add a sub query select | src/Illuminate/Database/Query/Builder.php | @@ -335,10 +335,23 @@ protected function parseSub($query)
* Add a new select column to the query.
*
* @param array|mixed $column
+ * @param \Closure|\Illuminate\Database\Query\Builder|string|null $query
* @return $this
*/
- public function addSelect($column)
+ public function addSelect($column, $query = null)
{
+ if (is_string($column) && (
+ $query instanceof self ||
+ $query instanceof EloquentBuilder ||
+ $query instanceof Closure
+ )) {
+ if (is_null($this->columns)) {
+ $this->select($this->from.'.*');
+ }
+
+ return $this->selectSub($query, $column);
+ }
+
$column = is_array($column) ? $column : func_get_args();
$this->columns = array_merge((array) $this->columns, $column); | true |
Other | laravel | framework | 9cb116d9f7d810b71f3e878db8ec9d27af148ada.json | Add the ability add a sub query select | tests/Database/DatabaseQueryBuilderTest.php | @@ -103,6 +103,24 @@ public function testAddingSelects()
$builder = $this->getBuilder();
$builder->select('foo')->addSelect('bar')->addSelect(['baz', 'boom'])->from('users');
$this->assertEquals('select "foo", "bar", "baz", "boom" from "users"', $builder->toSql());
+
+ $builder = $this->getBuilder();
+ $builder->select('foo')->addSelect('bar')->addSelect('baz', 'boom')->from('users');
+ $this->assertEquals('select "foo", "bar", "baz", "boom" from "users"', $builder->toSql());
+
+ $builder = $this->getBuilder();
+ $builder->from('sub')->select(['foo', 'bar'])->addSelect('sub', function ($query) {
+ $query->from('two')->select('baz')->where('subkey', '=', 'subval');
+ });
+ $this->assertEquals('select "foo", "bar", (select "baz" from "two" where "subkey" = ?) as "sub" from "sub"', $builder->toSql());
+ $this->assertEquals(['subval'], $builder->getBindings());
+
+ $builder = $this->getBuilder();
+ $builder->from('sub')->addSelect('sub', function ($query) {
+ $query->from('two')->select('baz')->where('subkey', '=', 'subval');
+ });
+ $this->assertEquals('select "sub".*, (select "baz" from "two" where "subkey" = ?) as "sub" from "sub"', $builder->toSql());
+ $this->assertEquals(['subval'], $builder->getBindings());
}
public function testBasicSelectWithPrefix() | true |
Other | laravel | framework | 8c994c3394c5f1ddc77717e2d3150ba3c9c70d16.json | Add the ability to order by subqueries | src/Illuminate/Database/Query/Builder.php | @@ -1761,14 +1761,24 @@ public function orHavingRaw($sql, array $bindings = [])
/**
* Add an "order by" clause to the query.
*
- * @param string $column
+ * @param \Closure|\Illuminate\Database\Query\Builder|string $column
* @param string $direction
* @return $this
*
* @throws \InvalidArgumentException
*/
public function orderBy($column, $direction = 'asc')
{
+ if ($column instanceof self ||
+ $column instanceof EloquentBuilder ||
+ $column instanceof Closure) {
+ [$query, $bindings] = $this->createSub($column);
+
+ $column = new Expression('('.$query.')');
+
+ $this->addBinding($bindings, 'order');
+ }
+
$direction = strtolower($direction);
if (! in_array($direction, ['asc', 'desc'], true)) { | true |
Other | laravel | framework | 8c994c3394c5f1ddc77717e2d3150ba3c9c70d16.json | Add the ability to order by subqueries | tests/Database/DatabaseQueryBuilderTest.php | @@ -1069,6 +1069,23 @@ public function testOrderBys()
$this->assertEquals('select * from "users" order by "name" desc', $builder->toSql());
}
+ public function testOrderBySubQueries()
+ {
+ $expected = 'select * from "users" order by (select "created_at" from "logins" where "user_id" = "users"."id" limit 1)';
+ $subQuery = function ($query) {
+ return $query->select('created_at')->from('logins')->whereColumn('user_id', 'users.id')->limit(1);
+ };
+
+ $builder = $this->getBuilder()->select('*')->from('users')->orderBy($subQuery);
+ $this->assertEquals("$expected asc", $builder->toSql());
+
+ $builder = $this->getBuilder()->select('*')->from('users')->orderBy($subQuery, 'desc');
+ $this->assertEquals("$expected desc", $builder->toSql());
+
+ $builder = $this->getBuilder()->select('*')->from('users')->orderByDesc($subQuery);
+ $this->assertEquals("$expected desc", $builder->toSql());
+ }
+
public function testOrderByInvalidDirectionParam()
{
$this->expectException(InvalidArgumentException::class); | true |
Other | laravel | framework | a5ccc1302223042a2b5656da009e8e19aaf4e9df.json | Use DI and Contract instead of static method
This allows for a custom container and is a cleaner way than using a static resolver. | src/Illuminate/Queue/CallQueuedHandler.php | @@ -5,9 +5,9 @@
use Exception;
use ReflectionClass;
use Illuminate\Pipeline\Pipeline;
-use Illuminate\Container\Container;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Bus\Dispatcher;
+use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class CallQueuedHandler
@@ -19,14 +19,23 @@ class CallQueuedHandler
*/
protected $dispatcher;
+ /**
+ * The container instance.
+ *
+ * @var \Illuminate\Contracts\Container\Container
+ */
+ protected $container;
+
/**
* Create a new handler instance.
*
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
+ * @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
- public function __construct(Dispatcher $dispatcher)
+ public function __construct(Dispatcher $dispatcher, Container $container)
{
+ $this->container = $container;
$this->dispatcher = $dispatcher;
}
@@ -67,7 +76,7 @@ public function call(Job $job, array $data)
*/
protected function dispatchThroughMiddleware(Job $job, $command)
{
- return (new Pipeline(Container::getInstance()))->send($command)
+ return (new Pipeline($this->container))->send($command)
->through(array_merge(method_exists($command, 'middleware') ? $command->middleware() : [], $command->middleware ?? []))
->then(function ($command) use ($job) {
return $this->dispatcher->dispatchNow( | true |
Other | laravel | framework | a5ccc1302223042a2b5656da009e8e19aaf4e9df.json | Use DI and Contract instead of static method
This allows for a custom container and is a cleaner way than using a static resolver. | tests/Integration/Queue/CallQueuedHandlerTest.php | @@ -29,7 +29,7 @@ public function testJobCanBeDispatched()
{
CallQueuedHandlerTestJob::$handled = false;
- $instance = new CallQueuedHandler(new Dispatcher(app()));
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
$job = m::mock(Job::class);
$job->shouldReceive('hasFailed')->andReturn(false);
@@ -50,7 +50,7 @@ public function testJobCanBeDispatchedThroughMiddleware()
CallQueuedHandlerTestJobWithMiddleware::$handled = false;
CallQueuedHandlerTestJobWithMiddleware::$middlewareCommand = null;
- $instance = new CallQueuedHandler(new Dispatcher(app()));
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
$job = m::mock(Job::class);
$job->shouldReceive('hasFailed')->andReturn(false);
@@ -73,7 +73,7 @@ public function testJobCanBeDispatchedThroughMiddlewareOnDispatch()
CallQueuedHandlerTestJobWithMiddleware::$handled = false;
CallQueuedHandlerTestJobWithMiddleware::$middlewareCommand = null;
- $instance = new CallQueuedHandler(new Dispatcher(app()));
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
$job = m::mock(Job::class);
$job->shouldReceive('hasFailed')->andReturn(false);
@@ -96,7 +96,7 @@ public function testJobCanBeDispatchedThroughMiddlewareOnDispatch()
public function testJobIsMarkedAsFailedIfModelNotFoundExceptionIsThrown()
{
- $instance = new CallQueuedHandler(new Dispatcher(app()));
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
$job = m::mock(Job::class);
$job->shouldReceive('resolveName')->andReturn(__CLASS__);
@@ -111,7 +111,7 @@ public function testJobIsDeletedIfHasDeleteProperty()
{
Event::fake();
- $instance = new CallQueuedHandler(new Dispatcher(app()));
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
$job = m::mock(Job::class);
$job->shouldReceive('getConnectionName')->andReturn('connection'); | true |
Other | laravel | framework | 2e2fd1ff8deef57f5e03bb0263567ac9efd3367e.json | Remove JsonExpression class | src/Illuminate/Database/Query/Grammars/MySqlGrammar.php | @@ -3,7 +3,6 @@
namespace Illuminate\Database\Query\Grammars;
use Illuminate\Database\Query\Builder;
-use Illuminate\Database\Query\JsonExpression;
class MySqlGrammar extends Grammar
{
@@ -145,25 +144,33 @@ protected function compileUpdateColumns($values)
{
return collect($values)->map(function ($value, $key) {
if ($this->isJsonSelector($key)) {
- return $this->compileJsonUpdateColumn($key, new JsonExpression($value));
+ return $this->compileJsonUpdateColumn($key, $value);
}
return $this->wrap($key).' = '.$this->parameter($value);
})->implode(', ');
}
/**
- * Prepares a JSON column being updated using the JSON_SET function.
+ * Prepare a JSON column being updated using the JSON_SET function.
*
* @param string $key
- * @param \Illuminate\Database\Query\JsonExpression $value
+ * @param mixed $value
* @return string
*/
- protected function compileJsonUpdateColumn($key, JsonExpression $value)
+ protected function compileJsonUpdateColumn($key, $value)
{
+ if (is_bool($value)) {
+ $value = $value ? 'true' : 'false';
+ } elseif (is_array($value)) {
+ $value = 'cast(? as json)';
+ } else {
+ $value = $this->parameter($value);
+ }
+
[$field, $path] = $this->wrapJsonFieldAndPath($key);
- return "{$field} = json_set({$field}{$path}, {$value->getValue()})";
+ return "{$field} = json_set({$field}{$path}, {$value})";
}
/** | true |
Other | laravel | framework | 2e2fd1ff8deef57f5e03bb0263567ac9efd3367e.json | Remove JsonExpression class | src/Illuminate/Database/Query/JsonExpression.php | @@ -1,51 +0,0 @@
-<?php
-
-namespace Illuminate\Database\Query;
-
-use InvalidArgumentException;
-
-class JsonExpression extends Expression
-{
- /**
- * Create a new raw query expression.
- *
- * @param mixed $value
- * @return void
- */
- public function __construct($value)
- {
- parent::__construct(
- $this->getJsonBindingParameter($value)
- );
- }
-
- /**
- * Translate the given value into the appropriate JSON binding parameter.
- *
- * @param mixed $value
- * @return string
- *
- * @throws \InvalidArgumentException
- */
- protected function getJsonBindingParameter($value)
- {
- if ($value instanceof Expression) {
- return $value->getValue();
- }
-
- switch ($type = gettype($value)) {
- case 'boolean':
- return $value ? 'true' : 'false';
- case 'NULL':
- case 'integer':
- case 'double':
- case 'string':
- case 'object':
- return '?';
- case 'array':
- return 'cast(? as json)';
- }
-
- throw new InvalidArgumentException("JSON value is of illegal type: {$type}");
- }
-} | true |
Other | laravel | framework | 74b62bbbb32674dfa167e2812231bf302454e67f.json | remove unneeded code | src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php | @@ -85,9 +85,7 @@ protected function restoreCollection($value)
return new $collectionClass(
collect($value->id)->map(function ($id) use ($collection) {
return $collection[$id] ?? null;
- })->when($collection->count() !== count($value->id), function ($collection) {
- return $collection->filter();
- })
+ })->filter()
);
}
| false |
Other | laravel | framework | 8557dc56b11c5e4dc746cb5558d6e694131f0dd8.json | Remove duplicate trans methods on Translator
This removes the duplicate trans and transChoice methods on the Translator class since these are already implemented as "get" and "choice".
Replaces https://github.com/laravel/framework/pull/29516 | src/Illuminate/Contracts/Translation/Translator.php | @@ -12,7 +12,7 @@ interface Translator
* @param string|null $locale
* @return mixed
*/
- public function trans($key, array $replace = [], $locale = null);
+ public function get($key, array $replace = [], $locale = null);
/**
* Get a translation according to an integer value.
@@ -23,7 +23,7 @@ public function trans($key, array $replace = [], $locale = null);
* @param string|null $locale
* @return string
*/
- public function transChoice($key, $number, array $replace = [], $locale = null);
+ public function choice($key, $number, array $replace = [], $locale = null);
/**
* Get the default locale being used. | true |
Other | laravel | framework | 8557dc56b11c5e4dc746cb5558d6e694131f0dd8.json | Remove duplicate trans methods on Translator
This removes the duplicate trans and transChoice methods on the Translator class since these are already implemented as "get" and "choice".
Replaces https://github.com/laravel/framework/pull/29516 | src/Illuminate/Foundation/helpers.php | @@ -875,7 +875,7 @@ function trans($key = null, $replace = [], $locale = null)
return app('translator');
}
- return app('translator')->trans($key, $replace, $locale);
+ return app('translator')->get($key, $replace, $locale);
}
}
@@ -891,7 +891,7 @@ function trans($key = null, $replace = [], $locale = null)
*/
function trans_choice($key, $number, array $replace = [], $locale = null)
{
- return app('translator')->transChoice($key, $number, $replace, $locale);
+ return app('translator')->choice($key, $number, $replace, $locale);
}
}
| true |
Other | laravel | framework | 8557dc56b11c5e4dc746cb5558d6e694131f0dd8.json | Remove duplicate trans methods on Translator
This removes the duplicate trans and transChoice methods on the Translator class since these are already implemented as "get" and "choice".
Replaces https://github.com/laravel/framework/pull/29516 | src/Illuminate/Translation/Translator.php | @@ -88,19 +88,6 @@ public function has($key, $locale = null, $fallback = true)
return $this->get($key, [], $locale, $fallback) !== $key;
}
- /**
- * Get the translation for a given key.
- *
- * @param string $key
- * @param array $replace
- * @param string|null $locale
- * @return string|array
- */
- public function trans($key, array $replace = [], $locale = null)
- {
- return $this->get($key, $replace, $locale);
- }
-
/**
* Get the translation for the given key.
*
@@ -147,20 +134,6 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
return $this->makeReplacements($line ?: $key, $replace);
}
- /**
- * Get a translation according to an integer value.
- *
- * @param string $key
- * @param int|array|\Countable $number
- * @param array $replace
- * @param string|null $locale
- * @return string
- */
- public function transChoice($key, $number, array $replace = [], $locale = null)
- {
- return $this->choice($key, $number, $replace, $locale);
- }
-
/**
* Get a translation according to an integer value.
* | true |
Other | laravel | framework | 8557dc56b11c5e4dc746cb5558d6e694131f0dd8.json | Remove duplicate trans methods on Translator
This removes the duplicate trans and transChoice methods on the Translator class since these are already implemented as "get" and "choice".
Replaces https://github.com/laravel/framework/pull/29516 | src/Illuminate/Validation/Concerns/FormatsMessages.php | @@ -54,7 +54,7 @@ protected function getMessage($attribute, $rule)
// messages out of the translator service for this validation rule.
$key = "validation.{$lowerRule}";
- if ($key != ($value = $this->translator->trans($key))) {
+ if ($key != ($value = $this->translator->get($key))) {
return $value;
}
@@ -113,7 +113,7 @@ protected function getFromLocalArray($attribute, $lowerRule, $source = null)
*/
protected function getCustomMessageFromTranslator($key)
{
- if (($message = $this->translator->trans($key)) !== $key) {
+ if (($message = $this->translator->get($key)) !== $key) {
return $message;
}
@@ -125,7 +125,7 @@ protected function getCustomMessageFromTranslator($key)
);
return $this->getWildcardCustomMessages(Arr::dot(
- (array) $this->translator->trans('validation.custom')
+ (array) $this->translator->get('validation.custom')
), $shortKey, $key);
}
@@ -166,7 +166,7 @@ protected function getSizeMessage($attribute, $rule)
$key = "validation.{$lowerRule}.{$type}";
- return $this->translator->trans($key);
+ return $this->translator->get($key);
}
/**
@@ -264,7 +264,7 @@ public function getDisplayableAttribute($attribute)
*/
protected function getAttributeFromTranslations($name)
{
- return Arr::get($this->translator->trans('validation.attributes'), $name);
+ return Arr::get($this->translator->get('validation.attributes'), $name);
}
/**
@@ -316,7 +316,7 @@ public function getDisplayableValue($attribute, $value)
$key = "validation.values.{$attribute}.{$value}";
- if (($line = $this->translator->trans($key)) !== $key) {
+ if (($line = $this->translator->get($key)) !== $key) {
return $line;
}
| true |
Other | laravel | framework | 8557dc56b11c5e4dc746cb5558d6e694131f0dd8.json | Remove duplicate trans methods on Translator
This removes the duplicate trans and transChoice methods on the Translator class since these are already implemented as "get" and "choice".
Replaces https://github.com/laravel/framework/pull/29516 | tests/Translation/TranslationTranslatorTest.php | @@ -71,7 +71,7 @@ public function testTransMethodProperlyLoadsAndRetrievesItemWithHTMLInTheMessage
$t = new Translator($this->getLoader(), 'en');
$t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
$t->getLoader()->shouldReceive('load')->once()->with('en', 'foo', '*')->andReturn(['bar' => 'breeze <p>test</p>']);
- $this->assertSame('breeze <p>test</p>', $t->trans('foo.bar', [], 'en'));
+ $this->assertSame('breeze <p>test</p>', $t->get('foo.bar', [], 'en'));
}
public function testGetMethodProperlyLoadsAndRetrievesItemWithCapitalization() | true |
Other | laravel | framework | 42b16bfc934ca7b5c1f33c8438d0ab45a7484950.json | Remove unused variables | tests/Routing/RoutingUrlGeneratorTest.php | @@ -17,8 +17,8 @@ class RoutingUrlGeneratorTest extends TestCase
public function testBasicGeneration()
{
$url = new UrlGenerator(
- $routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ new RouteCollection,
+ Request::create('http://www.foo.com/')
);
$this->assertEquals('http://www.foo.com/foo/bar', $url->to('foo/bar'));
@@ -30,8 +30,8 @@ public function testBasicGeneration()
* Test HTTPS request URL generation...
*/
$url = new UrlGenerator(
- $routes = new RouteCollection,
- $request = Request::create('https://www.foo.com/')
+ new RouteCollection,
+ Request::create('https://www.foo.com/')
);
$this->assertEquals('https://www.foo.com/foo/bar', $url->to('foo/bar'));
@@ -40,8 +40,8 @@ public function testBasicGeneration()
* Test asset URL generation...
*/
$url = new UrlGenerator(
- $routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/index.php/')
+ new RouteCollection,
+ Request::create('http://www.foo.com/index.php/')
);
$this->assertEquals('http://www.foo.com/foo/bar', $url->asset('foo/bar'));
@@ -52,7 +52,7 @@ public function testBasicGenerationWithHostFormatting()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$route = new Route(['GET'], '/named-route', ['as' => 'plain']);
@@ -129,7 +129,7 @@ public function testBasicGenerationWithPathFormatting()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$route = new Route(['GET'], '/named-route', ['as' => 'plain']);
@@ -147,7 +147,7 @@ public function testUrlFormattersShouldReceiveTargetRoute()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://abc.com/')
+ Request::create('http://abc.com/')
);
$namedRoute = new Route(['GET'], '/bar', ['as' => 'plain', 'root' => 'bar.com', 'path' => 'foo']);
@@ -169,7 +169,7 @@ public function testBasicRouteGeneration()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
/*
@@ -262,7 +262,7 @@ public function testFluentRouteNameDefinitions()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
/*
@@ -280,7 +280,7 @@ public function testControllerRoutesWithADefaultNamespace()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$url->setRootControllerNamespace('namespace');
@@ -306,7 +306,7 @@ public function testControllerRoutesOutsideOfDefaultNamespace()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$url->setRootControllerNamespace('namespace');
@@ -325,7 +325,7 @@ public function testRoutableInterfaceRouting()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$route = new Route(['GET'], 'foo/{bar}', ['as' => 'routable']);
@@ -341,7 +341,7 @@ public function testRoutableInterfaceRoutingWithSingleParameter()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$route = new Route(['GET'], 'foo/{bar}', ['as' => 'routable']);
@@ -357,7 +357,7 @@ public function testRoutesMaintainRequestScheme()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('https://www.foo.com/')
+ Request::create('https://www.foo.com/')
);
/*
@@ -373,7 +373,7 @@ public function testHttpOnlyRoutes()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('https://www.foo.com/')
+ Request::create('https://www.foo.com/')
);
/*
@@ -389,7 +389,7 @@ public function testRoutesWithDomains()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$route = new Route(['GET'], 'foo/bar', ['as' => 'foo', 'domain' => 'sub.foo.com']);
@@ -410,7 +410,7 @@ public function testRoutesWithDomainsAndPorts()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com:8080/')
+ Request::create('http://www.foo.com:8080/')
);
$route = new Route(['GET'], 'foo/bar', ['as' => 'foo', 'domain' => 'sub.foo.com']);
@@ -433,7 +433,7 @@ public function testRoutesWithDomainsStripsProtocols()
*/
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$route = new Route(['GET'], 'foo/bar', ['as' => 'foo', 'domain' => 'http://sub.foo.com']);
@@ -446,7 +446,7 @@ public function testRoutesWithDomainsStripsProtocols()
*/
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('https://www.foo.com/')
+ Request::create('https://www.foo.com/')
);
$route = new Route(['GET'], 'foo/bar', ['as' => 'foo', 'domain' => 'https://sub.foo.com']);
@@ -459,7 +459,7 @@ public function testHttpsRoutesWithDomains()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('https://foo.com/')
+ Request::create('https://foo.com/')
);
/*
@@ -477,7 +477,7 @@ public function testRoutesWithDomainsThroughProxy()
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1', 'HTTP_X_FORWARDED_PORT' => '80'])
+ Request::create('http://www.foo.com/', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1', 'HTTP_X_FORWARDED_PORT' => '80'])
);
$route = new Route(['GET'], 'foo/bar', ['as' => 'foo', 'domain' => 'sub.foo.com']);
@@ -492,7 +492,7 @@ public function testUrlGenerationForControllersRequiresPassingOfRequiredParamete
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com:8080/')
+ Request::create('http://www.foo.com:8080/')
);
$route = new Route(['GET'], 'foo/{one}/{two?}/{three?}', ['as' => 'foo', function () {
@@ -507,7 +507,7 @@ public function testForceRootUrl()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$url->forceRootUrl('https://www.bar.com');
@@ -522,7 +522,7 @@ public function testForceRootUrl()
*/
$url = new UrlGenerator(
$routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ Request::create('http://www.foo.com/')
);
$url->forceScheme('https');
@@ -538,8 +538,8 @@ public function testForceRootUrl()
public function testPrevious()
{
$url = new UrlGenerator(
- $routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ new RouteCollection,
+ Request::create('http://www.foo.com/')
);
$url->getRequest()->headers->set('referer', 'http://www.bar.com/');
@@ -557,8 +557,8 @@ public function testRouteNotDefinedException()
$this->expectExceptionMessage('Route [not_exists_route] not defined.');
$url = new UrlGenerator(
- $routes = new RouteCollection,
- $request = Request::create('http://www.foo.com/')
+ new RouteCollection,
+ Request::create('http://www.foo.com/')
);
$url->route('not_exists_route'); | false |
Other | laravel | framework | b28424410e46ebcdc0733f46b5a4c9aca36b1c58.json | Add missing test for getRoutesByMethod. | tests/Routing/RouteCollectionTest.php | @@ -190,6 +190,42 @@ public function testRouteCollectionCanGetRoutesByName()
$this->assertSame($routesByName, $this->routeCollection->getRoutesByName());
}
+ public function testRouteCollectionCanGetRoutesByMethod()
+ {
+ $routes = [
+ 'foo_index' => new Route('GET', 'foo/index', [
+ 'uses' => 'FooController@index',
+ 'as' => 'foo_index',
+ ]),
+ 'foo_show' => new Route('GET', 'foo/show', [
+ 'uses' => 'FooController@show',
+ 'as' => 'foo_show',
+ ]),
+ 'bar_create' => new Route('POST', 'bar', [
+ 'uses' => 'BarController@create',
+ 'as' => 'bar_create',
+ ]),
+ ];
+
+ $this->routeCollection->add($routes['foo_index']);
+ $this->routeCollection->add($routes['foo_show']);
+ $this->routeCollection->add($routes['bar_create']);
+
+ $this->assertSame([
+ 'GET' => [
+ 'foo/index' => $routes['foo_index'],
+ 'foo/show' => $routes['foo_show'],
+ ],
+ 'HEAD' => [
+ 'foo/index' => $routes['foo_index'],
+ 'foo/show' => $routes['foo_show'],
+ ],
+ 'POST' => [
+ 'bar' => $routes['bar_create'],
+ ],
+ ], $this->routeCollection->getRoutesByMethod());
+ }
+
public function testRouteCollectionCleansUpOverwrittenRoutes()
{
// Create two routes with the same path and method. | false |
Other | laravel | framework | ab3a6af87d07632e5d5643bd4987902c6fe239db.json | Fix duplicate implements. | src/Illuminate/Filesystem/FilesystemAdapter.php | @@ -26,7 +26,7 @@
/**
* @mixin \League\Flysystem\FilesystemInterface
*/
-class FilesystemAdapter implements CloudFilesystemContract, FilesystemContract
+class FilesystemAdapter implements CloudFilesystemContract
{
/**
* The Flysystem filesystem implementation. | false |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Auth/AuthEloquentUserProviderTest.php | @@ -24,7 +24,7 @@ public function testRetrieveByIDReturnsUser()
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
$mock->shouldReceive('first')->once()->andReturn('bar');
- $provider->expects($this->once())->method('createModel')->will($this->returnValue($mock));
+ $provider->expects($this->once())->method('createModel')->willReturn($mock);
$user = $provider->retrieveById(1);
$this->assertEquals('bar', $user);
@@ -41,7 +41,7 @@ public function testRetrieveByTokenReturnsUser()
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
$mock->shouldReceive('first')->once()->andReturn($mockUser);
- $provider->expects($this->once())->method('createModel')->will($this->returnValue($mock));
+ $provider->expects($this->once())->method('createModel')->willReturn($mock);
$user = $provider->retrieveByToken(1, 'a');
$this->assertEquals($mockUser, $user);
@@ -55,7 +55,7 @@ public function testRetrieveTokenWithBadIdentifierReturnsNull()
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
$mock->shouldReceive('first')->once()->andReturn(null);
- $provider->expects($this->once())->method('createModel')->will($this->returnValue($mock));
+ $provider->expects($this->once())->method('createModel')->willReturn($mock);
$user = $provider->retrieveByToken(1, 'a');
$this->assertNull($user);
@@ -72,7 +72,7 @@ public function testRetrieveByBadTokenReturnsNull()
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
$mock->shouldReceive('first')->once()->andReturn($mockUser);
- $provider->expects($this->once())->method('createModel')->will($this->returnValue($mock));
+ $provider->expects($this->once())->method('createModel')->willReturn($mock);
$user = $provider->retrieveByToken(1, 'a');
$this->assertNull($user);
@@ -86,7 +86,7 @@ public function testRetrieveByCredentialsReturnsUser()
$mock->shouldReceive('where')->once()->with('username', 'dayle');
$mock->shouldReceive('whereIn')->once()->with('group', ['one', 'two']);
$mock->shouldReceive('first')->once()->andReturn('bar');
- $provider->expects($this->once())->method('createModel')->will($this->returnValue($mock));
+ $provider->expects($this->once())->method('createModel')->willReturn($mock);
$user = $provider->retrieveByCredentials(['username' => 'dayle', 'password' => 'foo', 'group' => ['one', 'two']]);
$this->assertEquals('bar', $user); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Auth/AuthGuardTest.php | @@ -128,7 +128,7 @@ public function testLoginStoresIdentifierInSession()
[$session, $provider, $request, $cookie] = $this->getMocks();
$mock = $this->getMockBuilder(SessionGuard::class)->setMethods(['getName'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$user = m::mock(Authenticatable::class);
- $mock->expects($this->once())->method('getName')->will($this->returnValue('foo'));
+ $mock->expects($this->once())->method('getName')->willReturn('foo');
$user->shouldReceive('getAuthIdentifier')->once()->andReturn('bar');
$mock->getSession()->shouldReceive('put')->with('foo', 'bar')->once();
$session->shouldReceive('migrate')->once();
@@ -156,7 +156,7 @@ public function testLoginFiresLoginAndAuthenticatedEvents()
$user = m::mock(Authenticatable::class);
$events->shouldReceive('dispatch')->once()->with(m::type(Login::class));
$events->shouldReceive('dispatch')->once()->with(m::type(Authenticated::class));
- $mock->expects($this->once())->method('getName')->will($this->returnValue('foo'));
+ $mock->expects($this->once())->method('getName')->willReturn('foo');
$user->shouldReceive('getAuthIdentifier')->once()->andReturn('bar');
$mock->getSession()->shouldReceive('put')->with('foo', 'bar')->once();
$session->shouldReceive('migrate')->once();
@@ -230,7 +230,7 @@ public function testIsAuthedReturnsFalseWhenUserIsNull()
{
[$session, $provider, $request, $cookie] = $this->getMocks();
$mock = $this->getMockBuilder(SessionGuard::class)->setMethods(['user'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
- $mock->expects($this->exactly(2))->method('user')->will($this->returnValue(null));
+ $mock->expects($this->exactly(2))->method('user')->willReturn(null);
$this->assertFalse($mock->check());
$this->assertTrue($mock->guest());
}
@@ -268,9 +268,9 @@ public function testLogoutRemovesSessionTokenAndRememberMeCookie()
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getRememberToken')->once()->andReturn('a');
$user->shouldReceive('setRememberToken')->once();
- $mock->expects($this->once())->method('getName')->will($this->returnValue('foo'));
- $mock->expects($this->once())->method('getRecallerName')->will($this->returnValue('bar'));
- $mock->expects($this->once())->method('recaller')->will($this->returnValue('non-null-cookie'));
+ $mock->expects($this->once())->method('getName')->willReturn('foo');
+ $mock->expects($this->once())->method('getRecallerName')->willReturn('bar');
+ $mock->expects($this->once())->method('recaller')->willReturn('non-null-cookie');
$provider->shouldReceive('updateRememberToken')->once();
$cookie = m::mock(Cookie::class);
@@ -289,8 +289,8 @@ public function testLogoutDoesNotEnqueueRememberMeCookieForDeletionIfCookieDoesn
$mock->setCookieJar($cookies = m::mock(CookieJar::class));
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getRememberToken')->andReturn(null);
- $mock->expects($this->once())->method('getName')->will($this->returnValue('foo'));
- $mock->expects($this->once())->method('recaller')->will($this->returnValue(null));
+ $mock->expects($this->once())->method('getName')->willReturn('foo');
+ $mock->expects($this->once())->method('recaller')->willReturn(null);
$mock->getSession()->shouldReceive('remove')->once()->with('foo');
$mock->setUser($user);
@@ -332,9 +332,9 @@ public function testLogoutCurrentDeviceRemovesRememberMeCookie()
$mock = $this->getMockBuilder(SessionGuard::class)->setMethods(['getName', 'getRecallerName', 'recaller'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$mock->setCookieJar($cookies = m::mock(CookieJar::class));
$user = m::mock(Authenticatable::class);
- $mock->expects($this->once())->method('getName')->will($this->returnValue('foo'));
- $mock->expects($this->once())->method('getRecallerName')->will($this->returnValue('bar'));
- $mock->expects($this->once())->method('recaller')->will($this->returnValue('non-null-cookie'));
+ $mock->expects($this->once())->method('getName')->willReturn('foo');
+ $mock->expects($this->once())->method('getRecallerName')->willReturn('bar');
+ $mock->expects($this->once())->method('recaller')->willReturn('non-null-cookie');
$cookie = m::mock(Cookie::class);
$cookies->shouldReceive('forget')->once()->with('bar')->andReturn($cookie);
@@ -352,8 +352,8 @@ public function testLogoutCurrentDeviceDoesNotEnqueueRememberMeCookieForDeletion
$mock->setCookieJar($cookies = m::mock(CookieJar::class));
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getRememberToken')->andReturn(null);
- $mock->expects($this->once())->method('getName')->will($this->returnValue('foo'));
- $mock->expects($this->once())->method('recaller')->will($this->returnValue(null));
+ $mock->expects($this->once())->method('getName')->willReturn('foo');
+ $mock->expects($this->once())->method('recaller')->willReturn(null);
$mock->getSession()->shouldReceive('remove')->once()->with('foo');
$mock->setUser($user); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Auth/AuthPasswordBrokerTest.php | @@ -24,7 +24,7 @@ public function testIfUserIsNotFoundErrorRedirectIsReturned()
{
$mocks = $this->getMocks();
$broker = $this->getMockBuilder(PasswordBroker::class)->setMethods(['getUser', 'makeErrorRedirect'])->setConstructorArgs(array_values($mocks))->getMock();
- $broker->expects($this->once())->method('getUser')->will($this->returnValue(null));
+ $broker->expects($this->once())->method('getUser')->willReturn(null);
$this->assertEquals(PasswordBrokerContract::INVALID_USER, $broker->sendResetLink(['credentials']));
}
@@ -88,7 +88,7 @@ public function testResetRemovesRecordOnReminderTableAndCallsCallback()
{
unset($_SERVER['__password.reset.test']);
$broker = $this->getMockBuilder(PasswordBroker::class)->setMethods(['validateReset', 'getPassword', 'getToken'])->setConstructorArgs(array_values($mocks = $this->getMocks()))->getMock();
- $broker->expects($this->once())->method('validateReset')->will($this->returnValue($user = m::mock(CanResetPassword::class)));
+ $broker->expects($this->once())->method('validateReset')->willReturn($user = m::mock(CanResetPassword::class));
$mocks['tokens']->shouldReceive('delete')->once()->with($user);
$callback = function ($user, $password) {
$_SERVER['__password.reset.test'] = compact('user', 'password'); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Cache/CacheApcStoreTest.php | @@ -11,15 +11,15 @@ class CacheApcStoreTest extends TestCase
public function testGetReturnsNullWhenNotFound()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->setMethods(['get'])->getMock();
- $apc->expects($this->once())->method('get')->with($this->equalTo('foobar'))->will($this->returnValue(null));
+ $apc->expects($this->once())->method('get')->with($this->equalTo('foobar'))->willReturn(null);
$store = new ApcStore($apc, 'foo');
$this->assertNull($store->get('bar'));
}
public function testAPCValueIsReturned()
{
$apc = $this->getMockBuilder(ApcWrapper::class)->setMethods(['get'])->getMock();
- $apc->expects($this->once())->method('get')->will($this->returnValue('bar'));
+ $apc->expects($this->once())->method('get')->willReturn('bar');
$store = new ApcStore($apc);
$this->assertEquals('bar', $store->get('foo'));
} | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Cache/CacheDatabaseStoreTest.php | @@ -36,7 +36,7 @@ public function testNullIsReturnedAndItemDeletedWhenItemIsExpired()
$store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table);
$table->shouldReceive('where')->once()->with('key', '=', 'prefixfoo')->andReturn($table);
$table->shouldReceive('first')->once()->andReturn((object) ['expiration' => 1]);
- $store->expects($this->once())->method('forget')->with($this->equalTo('foo'))->will($this->returnValue(null));
+ $store->expects($this->once())->method('forget')->with($this->equalTo('foo'))->willReturn(null);
$this->assertNull($store->get('foo'));
}
@@ -68,7 +68,7 @@ public function testValueIsInsertedWhenNoExceptionsAreThrown()
$store = $this->getMockBuilder(DatabaseStore::class)->setMethods(['getTime'])->setConstructorArgs($this->getMocks())->getMock();
$table = m::mock(stdClass::class);
$store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table);
- $store->expects($this->once())->method('getTime')->will($this->returnValue(1));
+ $store->expects($this->once())->method('getTime')->willReturn(1);
$table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnTrue();
$result = $store->put('foo', 'bar', 60);
@@ -80,7 +80,7 @@ public function testValueIsUpdatedWhenInsertThrowsException()
$store = $this->getMockBuilder(DatabaseStore::class)->setMethods(['getTime'])->setConstructorArgs($this->getMocks())->getMock();
$table = m::mock(stdClass::class);
$store->getConnection()->shouldReceive('table')->with('table')->andReturn($table);
- $store->expects($this->once())->method('getTime')->will($this->returnValue(1));
+ $store->expects($this->once())->method('getTime')->willReturn(1);
$table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnUsing(function () {
throw new Exception;
});
@@ -96,7 +96,7 @@ public function testValueIsInsertedOnPostgres()
$store = $this->getMockBuilder(DatabaseStore::class)->setMethods(['getTime'])->setConstructorArgs($this->getPostgresMocks())->getMock();
$table = m::mock(stdClass::class);
$store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table);
- $store->expects($this->once())->method('getTime')->will($this->returnValue(1));
+ $store->expects($this->once())->method('getTime')->willReturn(1);
$table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => base64_encode(serialize("\0")), 'expiration' => 61])->andReturnTrue();
$result = $store->put('foo', "\0", 60); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Cache/CacheFileStoreTest.php | @@ -50,7 +50,7 @@ public function testExpiredItemsReturnNull()
{
$files = $this->mockFilesystem();
$contents = '0000000000';
- $files->expects($this->once())->method('get')->will($this->returnValue($contents));
+ $files->expects($this->once())->method('get')->willReturn($contents);
$store = $this->getMockBuilder(FileStore::class)->setMethods(['forget'])->setConstructorArgs([$files, __DIR__])->getMock();
$store->expects($this->once())->method('forget');
$value = $store->get('foo');
@@ -61,7 +61,7 @@ public function testValidItemReturnsContents()
{
$files = $this->mockFilesystem();
$contents = '9999999999'.serialize('Hello World');
- $files->expects($this->once())->method('get')->will($this->returnValue($contents));
+ $files->expects($this->once())->method('get')->willReturn($contents);
$store = new FileStore($files, __DIR__);
$this->assertEquals('Hello World', $store->get('foo'));
}
@@ -70,7 +70,7 @@ public function testStoreItemProperlyStoresValues()
{
$files = $this->mockFilesystem();
$store = $this->getMockBuilder(FileStore::class)->setMethods(['expiration'])->setConstructorArgs([$files, __DIR__])->getMock();
- $store->expects($this->once())->method('expiration')->with($this->equalTo(10))->will($this->returnValue(1111111111));
+ $store->expects($this->once())->method('expiration')->with($this->equalTo(10))->willReturn(1111111111);
$contents = '1111111111'.serialize('Hello World');
$hash = sha1('foo');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
@@ -98,7 +98,7 @@ public function testForeversAreNotRemovedOnIncrement()
$store = new FileStore($files, __DIR__);
$store->forever('foo', 'Hello World');
$store->increment('foo');
- $files->expects($this->once())->method('get')->will($this->returnValue($contents));
+ $files->expects($this->once())->method('get')->willReturn($contents);
$this->assertEquals('Hello World', $store->get('foo'));
}
@@ -109,7 +109,7 @@ public function testIncrementDoesNotExtendCacheLife()
$initialValue = $expiration.serialize(1);
$valueAfterIncrement = $expiration.serialize(2);
$store = new FileStore($files, __DIR__);
- $files->expects($this->once())->method('get')->will($this->returnValue($initialValue));
+ $files->expects($this->once())->method('get')->willReturn($initialValue);
$hash = sha1('foo');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash), $this->equalTo($valueAfterIncrement));
@@ -121,7 +121,7 @@ public function testRemoveDeletesFileDoesntExist()
$files = $this->mockFilesystem();
$hash = sha1('foobull');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
- $files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash))->will($this->returnValue(false));
+ $files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash))->willReturn(false);
$store = new FileStore($files, __DIR__);
$store->forget('foobull');
}
@@ -133,17 +133,17 @@ public function testRemoveDeletesFile()
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$store = new FileStore($files, __DIR__);
$store->put('foobar', 'Hello Baby', 10);
- $files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash))->will($this->returnValue(true));
+ $files->expects($this->once())->method('exists')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash))->willReturn(true);
$files->expects($this->once())->method('delete')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash));
$store->forget('foobar');
}
public function testFlushCleansDirectory()
{
$files = $this->mockFilesystem();
- $files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->will($this->returnValue(true));
- $files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->will($this->returnValue(['foo']));
- $files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'))->will($this->returnValue(true));
+ $files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->willReturn(true);
+ $files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->willReturn(['foo']);
+ $files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'))->willReturn(true);
$store = new FileStore($files, __DIR__);
$result = $store->flush();
@@ -153,9 +153,9 @@ public function testFlushCleansDirectory()
public function testFlushFailsDirectoryClean()
{
$files = $this->mockFilesystem();
- $files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->will($this->returnValue(true));
- $files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->will($this->returnValue(['foo']));
- $files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'))->will($this->returnValue(false));
+ $files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__))->willReturn(true);
+ $files->expects($this->once())->method('directories')->with($this->equalTo(__DIR__))->willReturn(['foo']);
+ $files->expects($this->once())->method('deleteDirectory')->with($this->equalTo('foo'))->willReturn(false);
$store = new FileStore($files, __DIR__);
$result = $store->flush();
@@ -165,7 +165,7 @@ public function testFlushFailsDirectoryClean()
public function testFlushIgnoreNonExistingDirectory()
{
$files = $this->mockFilesystem();
- $files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'--wrong'))->will($this->returnValue(false));
+ $files->expects($this->once())->method('isDirectory')->with($this->equalTo(__DIR__.'--wrong'))->willReturn(false);
$store = new FileStore($files, __DIR__.'--wrong');
$result = $store->flush(); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Cache/CacheMemcachedConnectorTest.php | @@ -21,7 +21,7 @@ public function testServersAreAddedCorrectly()
$connector = $this->connectorMock();
$connector->expects($this->once())
->method('createMemcachedInstance')
- ->will($this->returnValue($memcached));
+ ->willReturn($memcached);
$result = $this->connect($connector);
@@ -38,7 +38,7 @@ public function testServersAreAddedCorrectlyWithPersistentConnection()
$connector->expects($this->once())
->method('createMemcachedInstance')
->with($persistentConnectionId)
- ->will($this->returnValue($memcached));
+ ->willReturn($memcached);
$result = $this->connect($connector, $persistentConnectionId);
@@ -62,7 +62,7 @@ public function testServersAreAddedCorrectlyWithValidOptions()
$connector = $this->connectorMock();
$connector->expects($this->once())
->method('createMemcachedInstance')
- ->will($this->returnValue($memcached));
+ ->willReturn($memcached);
$result = $this->connect($connector, false, $validOptions);
@@ -84,7 +84,7 @@ public function testServersAreAddedCorrectlyWithSaslCredentials()
->andReturn(true);
$connector = $this->connectorMock();
- $connector->expects($this->once())->method('createMemcachedInstance')->will($this->returnValue($memcached));
+ $connector->expects($this->once())->method('createMemcachedInstance')->willReturn($memcached);
$result = $this->connect($connector, false, [], $saslCredentials);
| true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Cache/CacheMemcachedStoreTest.php | @@ -17,8 +17,8 @@ public function testGetReturnsNullWhenNotFound()
}
$memcache = $this->getMockBuilder(stdClass::class)->setMethods(['get', 'getResultCode'])->getMock();
- $memcache->expects($this->once())->method('get')->with($this->equalTo('foo:bar'))->will($this->returnValue(null));
- $memcache->expects($this->once())->method('getResultCode')->will($this->returnValue(1));
+ $memcache->expects($this->once())->method('get')->with($this->equalTo('foo:bar'))->willReturn(null);
+ $memcache->expects($this->once())->method('getResultCode')->willReturn(1);
$store = new MemcachedStore($memcache, 'foo');
$this->assertNull($store->get('bar'));
}
@@ -30,8 +30,8 @@ public function testMemcacheValueIsReturned()
}
$memcache = $this->getMockBuilder(stdClass::class)->setMethods(['get', 'getResultCode'])->getMock();
- $memcache->expects($this->once())->method('get')->will($this->returnValue('bar'));
- $memcache->expects($this->once())->method('getResultCode')->will($this->returnValue(0));
+ $memcache->expects($this->once())->method('get')->willReturn('bar');
+ $memcache->expects($this->once())->method('getResultCode')->willReturn(0);
$store = new MemcachedStore($memcache);
$this->assertEquals('bar', $store->get('foo'));
}
@@ -45,10 +45,10 @@ public function testMemcacheGetMultiValuesAreReturnedWithCorrectKeys()
$memcache = $this->getMockBuilder(stdClass::class)->setMethods(['getMulti', 'getResultCode'])->getMock();
$memcache->expects($this->once())->method('getMulti')->with(
['foo:foo', 'foo:bar', 'foo:baz']
- )->will($this->returnValue([
+ )->willReturn([
'fizz', 'buzz', 'norf',
- ]));
- $memcache->expects($this->once())->method('getResultCode')->will($this->returnValue(0));
+ ]);
+ $memcache->expects($this->once())->method('getResultCode')->willReturn(0);
$store = new MemcachedStore($memcache, 'foo');
$this->assertEquals([
'foo' => 'fizz', | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Console/ConsoleApplicationTest.php | @@ -22,7 +22,7 @@ public function testAddSetsLaravelInstance()
$app = $this->getMockConsole(['addToParent']);
$command = m::mock(Command::class);
$command->shouldReceive('setLaravel')->once()->with(m::type(ApplicationContract::class));
- $app->expects($this->once())->method('addToParent')->with($this->equalTo($command))->will($this->returnValue($command));
+ $app->expects($this->once())->method('addToParent')->with($this->equalTo($command))->willReturn($command);
$result = $app->add($command);
$this->assertEquals($command, $result);
@@ -33,7 +33,7 @@ public function testLaravelNotSetOnSymfonyCommands()
$app = $this->getMockConsole(['addToParent']);
$command = m::mock(SymfonyCommand::class);
$command->shouldReceive('setLaravel')->never();
- $app->expects($this->once())->method('addToParent')->with($this->equalTo($command))->will($this->returnValue($command));
+ $app->expects($this->once())->method('addToParent')->with($this->equalTo($command))->willReturn($command);
$result = $app->add($command);
$this->assertEquals($command, $result);
@@ -44,7 +44,7 @@ public function testResolveAddsCommandViaApplicationResolution()
$app = $this->getMockConsole(['addToParent']);
$command = m::mock(SymfonyCommand::class);
$app->getLaravel()->shouldReceive('make')->once()->with('foo')->andReturn(m::mock(SymfonyCommand::class));
- $app->expects($this->once())->method('addToParent')->with($this->equalTo($command))->will($this->returnValue($command));
+ $app->expects($this->once())->method('addToParent')->with($this->equalTo($command))->willReturn($command);
$result = $app->resolve('foo');
$this->assertEquals($command, $result); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Container/ContainerTest.php | @@ -413,7 +413,7 @@ public function testMakeWithMethodIsAnAliasForMakeMethod()
$mock->expects($this->once())
->method('make')
->with(ContainerDefaultValueStub::class, ['default' => 'laurence'])
- ->will($this->returnValue(new stdClass));
+ ->willReturn(new stdClass);
$result = $mock->makeWith(ContainerDefaultValueStub::class, ['default' => 'laurence']);
| true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseConnectionTest.php | @@ -34,7 +34,7 @@ public function testSettingDefaultCallsGetDefaultGrammar()
{
$connection = $this->getMockConnection();
$mock = m::mock(stdClass::class);
- $connection->expects($this->once())->method('getDefaultQueryGrammar')->will($this->returnValue($mock));
+ $connection->expects($this->once())->method('getDefaultQueryGrammar')->willReturn($mock);
$connection->useDefaultQueryGrammar();
$this->assertEquals($mock, $connection->getQueryGrammar());
}
@@ -43,15 +43,15 @@ public function testSettingDefaultCallsGetDefaultPostProcessor()
{
$connection = $this->getMockConnection();
$mock = m::mock(stdClass::class);
- $connection->expects($this->once())->method('getDefaultPostProcessor')->will($this->returnValue($mock));
+ $connection->expects($this->once())->method('getDefaultPostProcessor')->willReturn($mock);
$connection->useDefaultPostProcessor();
$this->assertEquals($mock, $connection->getPostProcessor());
}
public function testSelectOneCallsSelectAndReturnsSingleResult()
{
$connection = $this->getMockConnection(['select']);
- $connection->expects($this->once())->method('select')->with('foo', ['bar' => 'baz'])->will($this->returnValue(['foo']));
+ $connection->expects($this->once())->method('select')->with('foo', ['bar' => 'baz'])->willReturn(['foo']);
$this->assertEquals('foo', $connection->selectOne('foo', ['bar' => 'baz']));
}
@@ -63,11 +63,11 @@ public function testSelectProperlyCallsPDO()
$statement = $this->getMockBuilder('PDOStatement')->setMethods(['execute', 'fetchAll', 'bindValue'])->getMock();
$statement->expects($this->once())->method('bindValue')->with('foo', 'bar', 2);
$statement->expects($this->once())->method('execute');
- $statement->expects($this->once())->method('fetchAll')->will($this->returnValue(['boom']));
- $pdo->expects($this->once())->method('prepare')->with('foo')->will($this->returnValue($statement));
+ $statement->expects($this->once())->method('fetchAll')->willReturn(['boom']);
+ $pdo->expects($this->once())->method('prepare')->with('foo')->willReturn($statement);
$mock = $this->getMockConnection(['prepareBindings'], $writePdo);
$mock->setReadPdo($pdo);
- $mock->expects($this->once())->method('prepareBindings')->with($this->equalTo(['foo' => 'bar']))->will($this->returnValue(['foo' => 'bar']));
+ $mock->expects($this->once())->method('prepareBindings')->with($this->equalTo(['foo' => 'bar']))->willReturn(['foo' => 'bar']);
$results = $mock->select('foo', ['foo' => 'bar']);
$this->assertEquals(['boom'], $results);
$log = $mock->getQueryLog();
@@ -79,23 +79,23 @@ public function testSelectProperlyCallsPDO()
public function testInsertCallsTheStatementMethod()
{
$connection = $this->getMockConnection(['statement']);
- $connection->expects($this->once())->method('statement')->with($this->equalTo('foo'), $this->equalTo(['bar']))->will($this->returnValue('baz'));
+ $connection->expects($this->once())->method('statement')->with($this->equalTo('foo'), $this->equalTo(['bar']))->willReturn('baz');
$results = $connection->insert('foo', ['bar']);
$this->assertEquals('baz', $results);
}
public function testUpdateCallsTheAffectingStatementMethod()
{
$connection = $this->getMockConnection(['affectingStatement']);
- $connection->expects($this->once())->method('affectingStatement')->with($this->equalTo('foo'), $this->equalTo(['bar']))->will($this->returnValue('baz'));
+ $connection->expects($this->once())->method('affectingStatement')->with($this->equalTo('foo'), $this->equalTo(['bar']))->willReturn('baz');
$results = $connection->update('foo', ['bar']);
$this->assertEquals('baz', $results);
}
public function testDeleteCallsTheAffectingStatementMethod()
{
$connection = $this->getMockConnection(['affectingStatement']);
- $connection->expects($this->once())->method('affectingStatement')->with($this->equalTo('foo'), $this->equalTo(['bar']))->will($this->returnValue('baz'));
+ $connection->expects($this->once())->method('affectingStatement')->with($this->equalTo('foo'), $this->equalTo(['bar']))->willReturn('baz');
$results = $connection->delete('foo', ['bar']);
$this->assertEquals('baz', $results);
}
@@ -105,10 +105,10 @@ public function testStatementProperlyCallsPDO()
$pdo = $this->getMockBuilder(DatabaseConnectionTestMockPDO::class)->setMethods(['prepare'])->getMock();
$statement = $this->getMockBuilder('PDOStatement')->setMethods(['execute', 'bindValue'])->getMock();
$statement->expects($this->once())->method('bindValue')->with(1, 'bar', 2);
- $statement->expects($this->once())->method('execute')->will($this->returnValue('foo'));
- $pdo->expects($this->once())->method('prepare')->with($this->equalTo('foo'))->will($this->returnValue($statement));
+ $statement->expects($this->once())->method('execute')->willReturn('foo');
+ $pdo->expects($this->once())->method('prepare')->with($this->equalTo('foo'))->willReturn($statement);
$mock = $this->getMockConnection(['prepareBindings'], $pdo);
- $mock->expects($this->once())->method('prepareBindings')->with($this->equalTo(['bar']))->will($this->returnValue(['bar']));
+ $mock->expects($this->once())->method('prepareBindings')->with($this->equalTo(['bar']))->willReturn(['bar']);
$results = $mock->statement('foo', ['bar']);
$this->assertEquals('foo', $results);
$log = $mock->getQueryLog();
@@ -123,10 +123,10 @@ public function testAffectingStatementProperlyCallsPDO()
$statement = $this->getMockBuilder('PDOStatement')->setMethods(['execute', 'rowCount', 'bindValue'])->getMock();
$statement->expects($this->once())->method('bindValue')->with('foo', 'bar', 2);
$statement->expects($this->once())->method('execute');
- $statement->expects($this->once())->method('rowCount')->will($this->returnValue(['boom']));
- $pdo->expects($this->once())->method('prepare')->with('foo')->will($this->returnValue($statement));
+ $statement->expects($this->once())->method('rowCount')->willReturn(['boom']);
+ $pdo->expects($this->once())->method('prepare')->with('foo')->willReturn($statement);
$mock = $this->getMockConnection(['prepareBindings'], $pdo);
- $mock->expects($this->once())->method('prepareBindings')->with($this->equalTo(['foo' => 'bar']))->will($this->returnValue(['foo' => 'bar']));
+ $mock->expects($this->once())->method('prepareBindings')->with($this->equalTo(['foo' => 'bar']))->willReturn(['foo' => 'bar']);
$results = $mock->update('foo', ['foo' => 'bar']);
$this->assertEquals(['boom'], $results);
$log = $mock->getQueryLog();
@@ -165,7 +165,7 @@ public function testBeginTransactionMethodNeverRetriesIfWithinTransaction()
$pdo->expects($this->once())->method('exec')->will($this->throwException(new Exception));
$connection = $this->getMockConnection(['reconnect'], $pdo);
$queryGrammar = $this->createMock(Grammar::class);
- $queryGrammar->expects($this->once())->method('supportsSavepoints')->will($this->returnValue(true));
+ $queryGrammar->expects($this->once())->method('supportsSavepoints')->willReturn(true);
$connection->setQueryGrammar($queryGrammar);
$connection->expects($this->never())->method('reconnect');
$connection->beginTransaction();
@@ -180,7 +180,7 @@ public function testBeginTransactionMethodNeverRetriesIfWithinTransaction()
public function testSwapPDOWithOpenTransactionResetsTransactionLevel()
{
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
- $pdo->expects($this->once())->method('beginTransaction')->will($this->returnValue(true));
+ $pdo->expects($this->once())->method('beginTransaction')->willReturn(true);
$connection = $this->getMockConnection([], $pdo);
$connection->beginTransaction();
$connection->disconnect();
@@ -191,7 +191,7 @@ public function testBeganTransactionFiresEventsIfSet()
{
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
$connection = $this->getMockConnection(['getName'], $pdo);
- $connection->expects($this->any())->method('getName')->will($this->returnValue('name'));
+ $connection->expects($this->any())->method('getName')->willReturn('name');
$connection->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('dispatch')->once()->with(m::type(TransactionBeginning::class));
$connection->beginTransaction();
@@ -201,7 +201,7 @@ public function testCommittedFiresEventsIfSet()
{
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
$connection = $this->getMockConnection(['getName'], $pdo);
- $connection->expects($this->any())->method('getName')->will($this->returnValue('name'));
+ $connection->expects($this->any())->method('getName')->willReturn('name');
$connection->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('dispatch')->once()->with(m::type(TransactionCommitted::class));
$connection->commit();
@@ -211,7 +211,7 @@ public function testRollBackedFiresEventsIfSet()
{
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
$connection = $this->getMockConnection(['getName'], $pdo);
- $connection->expects($this->any())->method('getName')->will($this->returnValue('name'));
+ $connection->expects($this->any())->method('getName')->willReturn('name');
$connection->beginTransaction();
$connection->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('dispatch')->once()->with(m::type(TransactionRolledBack::class));
@@ -222,7 +222,7 @@ public function testRedundantRollBackFiresNoEvent()
{
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
$connection = $this->getMockConnection(['getName'], $pdo);
- $connection->expects($this->any())->method('getName')->will($this->returnValue('name'));
+ $connection->expects($this->any())->method('getName')->willReturn('name');
$connection->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldNotReceive('dispatch');
$connection->rollBack(); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseConnectorTest.php | @@ -32,8 +32,8 @@ public function testMySqlConnectCallsCreateConnectionWithProperArguments($dsn, $
{
$connector = $this->getMockBuilder(MySqlConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(PDO::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\' collate \'utf8_unicode_ci\'')->andReturn($connection);
$connection->shouldReceive('execute')->once();
$connection->shouldReceive('exec')->zeroOrMoreTimes();
@@ -57,8 +57,8 @@ public function testPostgresConnectCallsCreateConnectionWithProperArguments()
$config = ['host' => 'foo', 'database' => 'bar', 'port' => 111, 'charset' => 'utf8'];
$connector = $this->getMockBuilder(PostgresConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
$connection->shouldReceive('execute')->once();
$result = $connector->connect($config);
@@ -72,8 +72,8 @@ public function testPostgresSearchPathIsSet()
$config = ['host' => 'foo', 'database' => 'bar', 'schema' => 'public', 'charset' => 'utf8'];
$connector = $this->getMockBuilder(PostgresConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set search_path to "public"')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
@@ -88,8 +88,8 @@ public function testPostgresSearchPathArraySupported()
$config = ['host' => 'foo', 'database' => 'bar', 'schema' => ['public', 'user'], 'charset' => 'utf8'];
$connector = $this->getMockBuilder(PostgresConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set search_path to "public", "user"')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
@@ -104,8 +104,8 @@ public function testPostgresApplicationNameIsSet()
$config = ['host' => 'foo', 'database' => 'bar', 'charset' => 'utf8', 'application_name' => 'Laravel App'];
$connector = $this->getMockBuilder(PostgresConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set application_name to \'Laravel App\'')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
@@ -120,8 +120,8 @@ public function testSQLiteMemoryDatabasesMayBeConnectedTo()
$config = ['database' => ':memory:'];
$connector = $this->getMockBuilder(SQLiteConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$result = $connector->connect($config);
$this->assertSame($result, $connection);
@@ -133,8 +133,8 @@ public function testSQLiteFileDatabasesMayBeConnectedTo()
$config = ['database' => __DIR__];
$connector = $this->getMockBuilder(SQLiteConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$result = $connector->connect($config);
$this->assertSame($result, $connection);
@@ -146,8 +146,8 @@ public function testSqlServerConnectCallsCreateConnectionWithProperArguments()
$dsn = $this->getDsn($config);
$connector = $this->getMockBuilder(SqlServerConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$result = $connector->connect($config);
$this->assertSame($result, $connection);
@@ -159,8 +159,8 @@ public function testSqlServerConnectCallsCreateConnectionWithOptionalArguments()
$dsn = $this->getDsn($config);
$connector = $this->getMockBuilder(SqlServerConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$result = $connector->connect($config);
$this->assertSame($result, $connection);
@@ -176,8 +176,8 @@ public function testSqlServerConnectCallsCreateConnectionWithPreferredODBC()
$dsn = $this->getDsn($config);
$connector = $this->getMockBuilder(SqlServerConnector::class)->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock(stdClass::class);
- $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
- $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
+ $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
+ $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$result = $connector->connect($config);
$this->assertSame($result, $connection); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseEloquentCollectionTest.php | @@ -159,7 +159,7 @@ public function testLoadMethodEagerLoadsGivenRelationships()
{
$c = $this->getMockBuilder(Collection::class)->setMethods(['first'])->setConstructorArgs([['foo']])->getMock();
$mockItem = m::mock(stdClass::class);
- $c->expects($this->once())->method('first')->will($this->returnValue($mockItem));
+ $c->expects($this->once())->method('first')->willReturn($mockItem);
$mockItem->shouldReceive('newQueryWithoutRelationships')->once()->andReturn($mockItem);
$mockItem->shouldReceive('with')->with(['bar', 'baz'])->andReturn($mockItem);
$mockItem->shouldReceive('eagerLoadRelations')->once()->with(['foo'])->andReturn(['results']); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseEloquentHasOneTest.php | @@ -111,7 +111,7 @@ public function testSaveMethodSetsForeignKeyOnModel()
{
$relation = $this->getRelation();
$mockModel = $this->getMockBuilder(Model::class)->setMethods(['save'])->getMock();
- $mockModel->expects($this->once())->method('save')->will($this->returnValue(true));
+ $mockModel->expects($this->once())->method('save')->willReturn(true);
$result = $relation->save($mockModel);
$attributes = $result->getAttributes();
@@ -122,7 +122,7 @@ public function testCreateMethodProperlyCreatesNewModel()
{
$relation = $this->getRelation();
$created = $this->getMockBuilder(Model::class)->setMethods(['save', 'getKey', 'setAttribute'])->getMock();
- $created->expects($this->once())->method('save')->will($this->returnValue(true));
+ $created->expects($this->once())->method('save')->willReturn(true);
$relation->getRelated()->shouldReceive('newInstance')->once()->with(['name' => 'taylor'])->andReturn($created);
$created->expects($this->once())->method('setAttribute')->with('foreign_key', 1);
| true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseEloquentModelTest.php | @@ -259,7 +259,7 @@ public function testUpdateProcess()
$query = m::mock(Builder::class);
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1);
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
@@ -282,7 +282,7 @@ public function testUpdateProcessDoesntOverrideTimestamps()
$query = m::mock(Builder::class);
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['created_at' => 'foo', 'updated_at' => 'bar'])->andReturn(1);
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('until');
$events->shouldReceive('dispatch');
@@ -299,7 +299,7 @@ public function testSaveIsCancelledIfSavingEventReturnsFalse()
{
$model = $this->getMockBuilder(EloquentModelStub::class)->setMethods(['newModelQuery'])->getMock();
$query = m::mock(Builder::class);
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(false);
$model->exists = true;
@@ -311,7 +311,7 @@ public function testUpdateIsCancelledIfUpdatingEventReturnsFalse()
{
$model = $this->getMockBuilder(EloquentModelStub::class)->setMethods(['newModelQuery'])->getMock();
$query = m::mock(Builder::class);
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(false);
@@ -325,7 +325,7 @@ public function testEventsCanBeFiredWithCustomEventObjects()
{
$model = $this->getMockBuilder(EloquentModelEventObjectStub::class)->setMethods(['newModelQuery'])->getMock();
$query = m::mock(Builder::class);
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('until')->once()->with(m::type(EloquentModelSavingEventStub::class))->andReturn(false);
$model->exists = true;
@@ -340,9 +340,9 @@ public function testUpdateProcessWithoutTimestamps()
$query = m::mock(Builder::class);
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1);
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->never())->method('updateTimestamps');
- $model->expects($this->any())->method('fireModelEvent')->will($this->returnValue(true));
+ $model->expects($this->any())->method('fireModelEvent')->willReturn(true);
$model->id = 1;
$model->syncOriginal();
@@ -357,7 +357,7 @@ public function testUpdateUsesOldPrimaryKey()
$query = m::mock(Builder::class);
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['id' => 2, 'foo' => 'bar'])->andReturn(1);
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
@@ -377,7 +377,7 @@ public function testUpdateUsesOldPrimaryKey()
public function testTimestampsAreReturnedAsObjects()
{
$model = $this->getMockBuilder(EloquentDateModelStub::class)->setMethods(['getDateFormat'])->getMock();
- $model->expects($this->any())->method('getDateFormat')->will($this->returnValue('Y-m-d'));
+ $model->expects($this->any())->method('getDateFormat')->willReturn('Y-m-d');
$model->setRawAttributes([
'created_at' => '2012-12-04',
'updated_at' => '2012-12-05',
@@ -390,7 +390,7 @@ public function testTimestampsAreReturnedAsObjects()
public function testTimestampsAreReturnedAsObjectsFromPlainDatesAndTimestamps()
{
$model = $this->getMockBuilder(EloquentDateModelStub::class)->setMethods(['getDateFormat'])->getMock();
- $model->expects($this->any())->method('getDateFormat')->will($this->returnValue('Y-m-d H:i:s'));
+ $model->expects($this->any())->method('getDateFormat')->willReturn('Y-m-d H:i:s');
$model->setRawAttributes([
'created_at' => '2012-12-04',
'updated_at' => $this->currentTime(),
@@ -491,7 +491,7 @@ public function testFromDateTimeMilliseconds()
}
$model = $this->getMockBuilder('Illuminate\Tests\Database\EloquentDateModelStub')->setMethods(['getDateFormat'])->getMock();
- $model->expects($this->any())->method('getDateFormat')->will($this->returnValue('Y-m-d H:s.vi'));
+ $model->expects($this->any())->method('getDateFormat')->willReturn('Y-m-d H:s.vi');
$model->setRawAttributes([
'created_at' => '2012-12-04 22:59.32130',
]);
@@ -506,7 +506,7 @@ public function testInsertProcess()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
@@ -525,7 +525,7 @@ public function testInsertProcess()
$query = m::mock(Builder::class);
$query->shouldReceive('insert')->once()->with(['name' => 'taylor']);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->setIncrementing(false);
@@ -547,7 +547,7 @@ public function testInsertIsCancelledIfCreatingEventReturnsFalse()
$model = $this->getMockBuilder(EloquentModelStub::class)->setMethods(['newModelQuery'])->getMock();
$query = m::mock(Builder::class);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(false);
@@ -562,7 +562,7 @@ public function testDeleteProperlyDeletesModel()
$query = m::mock(Builder::class);
$query->shouldReceive('where')->once()->with('id', '=', 1)->andReturn($query);
$query->shouldReceive('delete')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('touchOwners');
$model->exists = true;
$model->id = 1;
@@ -575,7 +575,7 @@ public function testPushNoRelations()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -592,7 +592,7 @@ public function testPushEmptyOneRelation()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -611,7 +611,7 @@ public function testPushOneRelation()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2);
$query->shouldReceive('getConnection')->once();
- $related1->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $related1->expects($this->once())->method('newModelQuery')->willReturn($query);
$related1->expects($this->once())->method('updateTimestamps');
$related1->name = 'related1';
$related1->exists = false;
@@ -620,7 +620,7 @@ public function testPushOneRelation()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -642,7 +642,7 @@ public function testPushEmptyManyRelation()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -661,7 +661,7 @@ public function testPushManyRelation()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'related1'], 'id')->andReturn(2);
$query->shouldReceive('getConnection')->once();
- $related1->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $related1->expects($this->once())->method('newModelQuery')->willReturn($query);
$related1->expects($this->once())->method('updateTimestamps');
$related1->name = 'related1';
$related1->exists = false;
@@ -670,7 +670,7 @@ public function testPushManyRelation()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'related2'], 'id')->andReturn(3);
$query->shouldReceive('getConnection')->once();
- $related2->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $related2->expects($this->once())->method('newModelQuery')->willReturn($query);
$related2->expects($this->once())->method('updateTimestamps');
$related2->name = 'related2';
$related2->exists = false;
@@ -679,7 +679,7 @@ public function testPushManyRelation()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with(['name' => 'taylor'], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$model->expects($this->once())->method('updateTimestamps');
$model->name = 'taylor';
@@ -1791,7 +1791,7 @@ public function testIntKeyTypePreserved()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn(1);
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$this->assertTrue($model->save());
$this->assertEquals(1, $model->id);
@@ -1803,7 +1803,7 @@ public function testStringKeyTypePreserved()
$query = m::mock(Builder::class);
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn('string id');
$query->shouldReceive('getConnection')->once();
- $model->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
+ $model->expects($this->once())->method('newModelQuery')->willReturn($query);
$this->assertTrue($model->save());
$this->assertEquals('string id', $model->id); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseEloquentPivotTest.php | @@ -117,7 +117,7 @@ public function testDeleteMethodDeletesModelByKeys()
$query = m::mock(stdClass::class);
$query->shouldReceive('where')->once()->with(['foreign' => 'foreign.value', 'other' => 'other.value'])->andReturn($query);
$query->shouldReceive('delete')->once()->andReturn(true);
- $pivot->expects($this->once())->method('newQueryWithoutRelationships')->will($this->returnValue($query));
+ $pivot->expects($this->once())->method('newQueryWithoutRelationships')->willReturn($query);
$rowsAffected = $pivot->delete();
$this->assertEquals(1, $rowsAffected); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseMigrationCreatorTest.php | @@ -19,7 +19,7 @@ public function testBasicCreateMethodStoresMigrationFile()
{
$creator = $this->getCreator();
- $creator->expects($this->any())->method('getDatePrefix')->will($this->returnValue('foo'));
+ $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo');
$creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/blank.stub')->andReturn('DummyClass');
$creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar');
@@ -36,7 +36,7 @@ public function testBasicCreateMethodCallsPostCreateHooks()
$_SERVER['__migration.creator'] = $table;
});
- $creator->expects($this->any())->method('getDatePrefix')->will($this->returnValue('foo'));
+ $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo');
$creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/update.stub')->andReturn('DummyClass DummyTable');
$creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar baz');
@@ -50,7 +50,7 @@ public function testBasicCreateMethodCallsPostCreateHooks()
public function testTableUpdateMigrationStoresMigrationFile()
{
$creator = $this->getCreator();
- $creator->expects($this->any())->method('getDatePrefix')->will($this->returnValue('foo'));
+ $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo');
$creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/update.stub')->andReturn('DummyClass DummyTable');
$creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar baz');
@@ -60,7 +60,7 @@ public function testTableUpdateMigrationStoresMigrationFile()
public function testTableCreationMigrationStoresMigrationFile()
{
$creator = $this->getCreator();
- $creator->expects($this->any())->method('getDatePrefix')->will($this->returnValue('foo'));
+ $creator->expects($this->any())->method('getDatePrefix')->willReturn('foo');
$creator->getFilesystem()->shouldReceive('get')->once()->with($creator->stubPath().'/create.stub')->andReturn('DummyClass DummyTable');
$creator->getFilesystem()->shouldReceive('put')->once()->with('foo/foo_create_bar.php', 'CreateBar baz');
| true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseMigrationRepositoryTest.php | @@ -38,7 +38,7 @@ public function testGetLastMigrationsGetsAllMigrationsWithTheLatestBatchNumber()
$repo = $this->getMockBuilder(DatabaseMigrationRepository::class)->setMethods(['getLastBatchNumber'])->setConstructorArgs([
$resolver = m::mock(ConnectionResolverInterface::class), 'migrations',
])->getMock();
- $repo->expects($this->once())->method('getLastBatchNumber')->will($this->returnValue(1));
+ $repo->expects($this->once())->method('getLastBatchNumber')->willReturn(1);
$query = m::mock(stdClass::class);
$connectionMock = m::mock(Connection::class);
$repo->getConnectionResolver()->shouldReceive('connection')->with(null)->andReturn($connectionMock);
@@ -84,7 +84,7 @@ public function testGetNextBatchNumberReturnsLastBatchNumberPlusOne()
$repo = $this->getMockBuilder(DatabaseMigrationRepository::class)->setMethods(['getLastBatchNumber'])->setConstructorArgs([
m::mock(ConnectionResolverInterface::class), 'migrations',
])->getMock();
- $repo->expects($this->once())->method('getLastBatchNumber')->will($this->returnValue(1));
+ $repo->expects($this->once())->method('getLastBatchNumber')->willReturn(1);
$this->assertEquals(2, $repo->getNextBatchNumber());
} | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseProcessorTest.php | @@ -19,7 +19,7 @@ protected function tearDown(): void
public function testInsertGetIdProcessing()
{
$pdo = $this->createMock(ProcessorTestPDOStub::class);
- $pdo->expects($this->once())->method('lastInsertId')->with($this->equalTo('id'))->will($this->returnValue('1'));
+ $pdo->expects($this->once())->method('lastInsertId')->with($this->equalTo('id'))->willReturn('1');
$connection = m::mock(Connection::class);
$connection->shouldReceive('insert')->once()->with('sql', ['foo']);
$connection->shouldReceive('getPdo')->once()->andReturn($pdo); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Database/DatabaseSchemaBlueprintTest.php | @@ -25,7 +25,7 @@ public function testToSqlRunsCommandsFromBlueprint()
$conn->shouldReceive('statement')->once()->with('bar');
$grammar = m::mock(MySqlGrammar::class);
$blueprint = $this->getMockBuilder(Blueprint::class)->setMethods(['toSql'])->setConstructorArgs(['users'])->getMock();
- $blueprint->expects($this->once())->method('toSql')->with($this->equalTo($conn), $this->equalTo($grammar))->will($this->returnValue(['foo', 'bar']));
+ $blueprint->expects($this->once())->method('toSql')->with($this->equalTo($conn), $this->equalTo($grammar))->willReturn(['foo', 'bar']);
$blueprint->build($conn, $grammar);
} | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Mail/MailMailerTest.php | @@ -28,7 +28,7 @@ public function testMailerSendSendsMessageWithProperViewContent()
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder(Mailer::class)->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock(Swift_Mime_SimpleMessage::class);
- $mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
+ $mailer->expects($this->once())->method('createMessage')->willReturn($message);
$view = m::mock(stdClass::class);
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', ['data', 'message' => $message])->andReturn($view);
$view->shouldReceive('render')->once()->andReturn('rendered.view');
@@ -48,7 +48,7 @@ public function testMailerSendSendsMessageWithProperViewContentUsingHtmlStrings(
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder(Mailer::class)->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock(Swift_Mime_SimpleMessage::class);
- $mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
+ $mailer->expects($this->once())->method('createMessage')->willReturn($message);
$view = m::mock(stdClass::class);
$mailer->getViewFactory()->shouldReceive('make')->never();
$view->shouldReceive('render')->never();
@@ -69,7 +69,7 @@ public function testMailerSendSendsMessageWithProperViewContentUsingHtmlMethod()
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder(Mailer::class)->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock(Swift_Mime_SimpleMessage::class);
- $mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
+ $mailer->expects($this->once())->method('createMessage')->willReturn($message);
$view = m::mock(stdClass::class);
$mailer->getViewFactory()->shouldReceive('make')->never();
$view->shouldReceive('render')->never();
@@ -89,7 +89,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContent()
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder(Mailer::class)->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock(Swift_Mime_SimpleMessage::class);
- $mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
+ $mailer->expects($this->once())->method('createMessage')->willReturn($message);
$view = m::mock(stdClass::class);
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', ['data', 'message' => $message])->andReturn($view);
$mailer->getViewFactory()->shouldReceive('make')->once()->with('bar', ['data', 'message' => $message])->andReturn($view);
@@ -111,7 +111,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContentWhenExplicit
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder(Mailer::class)->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock(Swift_Mime_SimpleMessage::class);
- $mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
+ $mailer->expects($this->once())->method('createMessage')->willReturn($message);
$view = m::mock(stdClass::class);
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', ['data', 'message' => $message])->andReturn($view);
$mailer->getViewFactory()->shouldReceive('make')->once()->with('bar', ['data', 'message' => $message])->andReturn($view); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Mail/MailMessageTest.php | @@ -103,7 +103,7 @@ public function testBasicAttachment()
$swift = m::mock(stdClass::class);
$message = $this->getMockBuilder(Message::class)->setMethods(['createAttachmentFromPath'])->setConstructorArgs([$swift])->getMock();
$attachment = m::mock(stdClass::class);
- $message->expects($this->once())->method('createAttachmentFromPath')->with($this->equalTo('foo.jpg'))->will($this->returnValue($attachment));
+ $message->expects($this->once())->method('createAttachmentFromPath')->with($this->equalTo('foo.jpg'))->willReturn($attachment);
$swift->shouldReceive('attach')->once()->with($attachment);
$attachment->shouldReceive('setContentType')->once()->with('image/jpeg');
$attachment->shouldReceive('setFilename')->once()->with('bar.jpg');
@@ -115,7 +115,7 @@ public function testDataAttachment()
$swift = m::mock(stdClass::class);
$message = $this->getMockBuilder(Message::class)->setMethods(['createAttachmentFromData'])->setConstructorArgs([$swift])->getMock();
$attachment = m::mock(stdClass::class);
- $message->expects($this->once())->method('createAttachmentFromData')->with($this->equalTo('foo'), $this->equalTo('name'))->will($this->returnValue($attachment));
+ $message->expects($this->once())->method('createAttachmentFromData')->with($this->equalTo('foo'), $this->equalTo('name'))->willReturn($attachment);
$swift->shouldReceive('attach')->once()->with($attachment);
$attachment->shouldReceive('setContentType')->once()->with('image/jpeg');
$message->attachData('foo', 'name', ['mime' => 'image/jpeg']); | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Queue/QueueDatabaseQueueUnitTest.php | @@ -20,7 +20,7 @@ protected function tearDown(): void
public function testPushProperlyPushesJobOntoDatabase()
{
$queue = $this->getMockBuilder(DatabaseQueue::class)->setMethods(['currentTime'])->setConstructorArgs([$database = m::mock(Connection::class), 'table', 'default'])->getMock();
- $queue->expects($this->any())->method('currentTime')->will($this->returnValue('time'));
+ $queue->expects($this->any())->method('currentTime')->willReturn('time');
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock(stdClass::class));
$query->shouldReceive('insertGetId')->once()->andReturnUsing(function ($array) {
$this->assertEquals('default', $array['queue']);
@@ -40,7 +40,7 @@ public function testDelayedPushProperlyPushesJobOntoDatabase()
['currentTime'])->setConstructorArgs(
[$database = m::mock(Connection::class), 'table', 'default']
)->getMock();
- $queue->expects($this->any())->method('currentTime')->will($this->returnValue('time'));
+ $queue->expects($this->any())->method('currentTime')->willReturn('time');
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock(stdClass::class));
$query->shouldReceive('insertGetId')->once()->andReturnUsing(function ($array) {
$this->assertEquals('default', $array['queue']);
@@ -90,8 +90,8 @@ public function testBulkBatchPushesOntoDatabase()
{
$database = m::mock(Connection::class);
$queue = $this->getMockBuilder(DatabaseQueue::class)->setMethods(['currentTime', 'availableAt'])->setConstructorArgs([$database, 'table', 'default'])->getMock();
- $queue->expects($this->any())->method('currentTime')->will($this->returnValue('created'));
- $queue->expects($this->any())->method('availableAt')->will($this->returnValue('available'));
+ $queue->expects($this->any())->method('currentTime')->willReturn('created');
+ $queue->expects($this->any())->method('availableAt')->willReturn('available');
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock(stdClass::class));
$query->shouldReceive('insert')->once()->andReturnUsing(function ($records) {
$this->assertEquals([[ | true |
Other | laravel | framework | e2518c79d793094533bc97a522c32922ada17d8f.json | Simplify mock returns. | tests/Queue/QueueRedisQueueTest.php | @@ -20,7 +20,7 @@ protected function tearDown(): void
public function testPushProperlyPushesJobOntoRedis()
{
$queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock();
- $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
+ $queue->expects($this->once())->method('getRandomId')->willReturn('foo');
$redis->shouldReceive('connection')->once()->andReturn($redis);
$redis->shouldReceive('eval')->once()->with(LuaScripts::push(), 2, 'queues:default', 'queues:default:notify', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'delay' => null, 'timeout' => null, 'data' => ['data'], 'id' => 'foo', 'attempts' => 0]));
@@ -31,7 +31,7 @@ public function testPushProperlyPushesJobOntoRedis()
public function testPushProperlyPushesJobOntoRedisWithCustomPayloadHook()
{
$queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock();
- $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
+ $queue->expects($this->once())->method('getRandomId')->willReturn('foo');
$redis->shouldReceive('connection')->once()->andReturn($redis);
$redis->shouldReceive('eval')->once()->with(LuaScripts::push(), 2, 'queues:default', 'queues:default:notify', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'delay' => null, 'timeout' => null, 'data' => ['data'], 'custom' => 'taylor', 'id' => 'foo', 'attempts' => 0]));
@@ -48,7 +48,7 @@ public function testPushProperlyPushesJobOntoRedisWithCustomPayloadHook()
public function testPushProperlyPushesJobOntoRedisWithTwoCustomPayloadHook()
{
$queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock();
- $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
+ $queue->expects($this->once())->method('getRandomId')->willReturn('foo');
$redis->shouldReceive('connection')->once()->andReturn($redis);
$redis->shouldReceive('eval')->once()->with(LuaScripts::push(), 2, 'queues:default', 'queues:default:notify', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'delay' => null, 'timeout' => null, 'data' => ['data'], 'custom' => 'taylor', 'bar' => 'foo', 'id' => 'foo', 'attempts' => 0]));
@@ -69,8 +69,8 @@ public function testPushProperlyPushesJobOntoRedisWithTwoCustomPayloadHook()
public function testDelayedPushProperlyPushesJobOntoRedis()
{
$queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['availableAt', 'getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock();
- $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
- $queue->expects($this->once())->method('availableAt')->with(1)->will($this->returnValue(2));
+ $queue->expects($this->once())->method('getRandomId')->willReturn('foo');
+ $queue->expects($this->once())->method('availableAt')->with(1)->willReturn(2);
$redis->shouldReceive('connection')->once()->andReturn($redis);
$redis->shouldReceive('zadd')->once()->with(
@@ -87,8 +87,8 @@ public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis()
{
$date = Carbon::now();
$queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['availableAt', 'getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock();
- $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
- $queue->expects($this->once())->method('availableAt')->with($date)->will($this->returnValue(2));
+ $queue->expects($this->once())->method('getRandomId')->willReturn('foo');
+ $queue->expects($this->once())->method('availableAt')->with($date)->willReturn(2);
$redis->shouldReceive('connection')->once()->andReturn($redis);
$redis->shouldReceive('zadd')->once()->with( | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.