Skip to content

Commit

Permalink
Upgrade to Laravel 5.5.33
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Jan 31, 2018
1 parent d885dfa commit 3181055
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Support/Collection.php
Expand Up @@ -34,7 +34,7 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
*/
protected static $proxies = [
'average', 'avg', 'contains', 'each', 'every', 'filter', 'first', 'flatMap',
'keyBy', 'map', 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum',
'keyBy', 'map', 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum', 'unique',
];

/**
Expand Down
20 changes: 2 additions & 18 deletions src/Support/helpers.php
Expand Up @@ -6,19 +6,6 @@
use IlluminateAgnostic\Collection\Support\Debug\Dumper;
use Illuminate\Support\Collection as IlluminateCollection;

if (! function_exists('array_wrap')) {
/**
* If the given value is not an array, wrap it in one.
*
* @param mixed $value
* @return array
*/
function array_wrap($value)
{
return ! is_array($value) ? [$value] : $value;
}
}

if (! function_exists('collect')) {
/**
* Create a collection from the given value.
Expand All @@ -28,10 +15,6 @@ function array_wrap($value)
*/
function collect($value = null)
{
if (class_exists(IlluminateCollection::class)) {
return new IlluminateCollection($value);
}

return new Collection($value);
}
}
Expand Down Expand Up @@ -66,7 +49,7 @@ function data_get($target, $key, $default = null)

$key = is_array($key) ? $key : explode('.', $key);

while (($segment = array_shift($key)) !== null) {
while (! is_null($segment = array_shift($key))) {
if ($segment === '*') {
if ($target instanceof Collection) {
$target = $target->all();
Expand All @@ -92,6 +75,7 @@ function data_get($target, $key, $default = null)
}
}


if (! function_exists('with')) {
/**
* Return the given object. Useful for chaining.
Expand Down
39 changes: 39 additions & 0 deletions tests/Support/SupportCollectionTest.php
Expand Up @@ -330,6 +330,16 @@ public function testHigherOrderKeyBy()
$this->assertEquals(['id1' => 'first', 'id2' => 'second'], $c->keyBy->id->map->name->all());
}

public function testHigherOrderUnique()
{
$c = new Collection([
['id' => '1', 'name' => 'first'],
['id' => '1', 'name' => 'second'],
]);

$this->assertCount(1, $c->unique->id);
}

public function testHigherOrderFilter()
{
$c = new Collection([
Expand Down Expand Up @@ -978,6 +988,12 @@ public function testExcept()
$this->assertEquals(['first' => 'Taylor', 'email' => 'taylorotwell@gmail.com'], $data->except('last')->all());
}

public function testExceptSelf()
{
$data = new Collection(['first' => 'Taylor', 'last' => 'Otwell']);
$this->assertEquals(['first' => 'Taylor', 'last' => 'Otwell'], $data->except($data)->all());
}

public function testPluckWithArrayAndObjectValues()
{
$data = new Collection([(object) ['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']]);
Expand All @@ -996,6 +1012,15 @@ public function testPluckWithArrayAccessValues()
$this->assertEquals(['foo', 'bar'], $data->pluck('email')->all());
}

public function testHas()
{
$data = new Collection(['id' => 1, 'first' => 'Hello', 'second' => 'World']);
$this->assertTrue($data->has('first'));
$this->assertFalse($data->has('third'));
$this->assertTrue($data->has(['first', 'second']));
$this->assertFalse($data->has(['third', 'first']));
}

public function testImplode()
{
$data = new Collection([['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']]);
Expand All @@ -1014,6 +1039,20 @@ public function testTake()
$this->assertEquals(['taylor', 'dayle'], $data->all());
}

public function testPut()
{
$data = new Collection(['name' => 'taylor', 'email' => 'foo']);
$data = $data->put('name', 'dayle');
$this->assertEquals(['name' => 'dayle', 'email' => 'foo'], $data->all());
}

public function testPutWithNoKey()
{
$data = new Collection(['taylor', 'shawn']);
$data = $data->put(null, 'dayle');
$this->assertEquals(['taylor', 'shawn', 'dayle'], $data->all());
}

public function testRandom()
{
$data = new Collection([1, 2, 3, 4, 5, 6]);
Expand Down

0 comments on commit 3181055

Please sign in to comment.