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
16afbf8465dc54e4998e54e364fe4b0cda4a477f.json
Add tests for Str::replaceArray
tests/Support/SupportStrTest.php
@@ -141,6 +141,8 @@ public function testRandom() public function testReplaceArray() { $this->assertEquals('foo/bar/baz', Str::replaceArray('?', ['foo', 'bar', 'baz'], '?/?/?')); + $this->assertEquals('foo/bar/baz/?', Str::replaceArray('?', ['foo', 'bar', 'baz'], '?/?/?/?')); + $this->assertEquals('foo/bar', Str::replaceArray('?', ['foo', 'bar', 'baz'], '?/?')); $this->assertEquals('?/?/?', Str::replaceArray('x', ['foo', 'bar', 'baz'], '?/?/?')); }
false
Other
laravel
framework
6199d9f9ab862849cfd80b708b115d0eff38b2fc.json
Add url method to Cloud filesystem interface The url method was added to FilesystemAdapter in commit ef81c53. It should be added to the interface for sanity. Since url is more relevant for cloud filesystems, it is added to the Cloud filesystem interface instead of Filesystem.
src/Illuminate/Contracts/Filesystem/Cloud.php
@@ -4,5 +4,11 @@ interface Cloud extends Filesystem { - // + /** + * Get the URL for the file at the given path. + * + * @param string $path + * @return string + */ + public function url($path); }
false
Other
laravel
framework
116c1ebbdd8d3f2ca7d27ce3afd1402337cd5390.json
Add tests for self relationships.
tests/Database/DatabaseEloquentBuilderTest.php
@@ -493,6 +493,40 @@ public function testOrHasNested() $this->assertEquals($builder->toSql(), $result); } + public function testSelfHasNested() + { + $model = new EloquentBuilderTestModelSelfRelatedStub(); + + $nestedSql = $model->whereHas('parentFoo', function ($q) { + $q->has('childFoo'); + })->toSql(); + + $dotSql = $model->has('parentFoo.childFoo')->toSql(); + + // alias has a dynamic hash, so replace with a static string for comparison + $alias = 'self_alias_hash'; + $aliasRegex = '/\b(self_[a-f0-9]{32})(\b|$)/i'; + + $nestedSql = preg_replace($aliasRegex, $alias, $nestedSql); + $dotSql = preg_replace($aliasRegex, $alias, $dotSql); + + $this->assertEquals($nestedSql, $dotSql); + } + + public function testSelfHasNestedUsesAlias() + { + $model = new EloquentBuilderTestModelSelfRelatedStub(); + + $sql = $model->has('parentFoo.childFoo')->toSql(); + + // alias has a dynamic hash, so replace with a static string for comparison + $alias = 'self_alias_hash'; + $aliasRegex = '/\b(self_[a-f0-9]{32})(\b|$)/i'; + + $sql = preg_replace($aliasRegex, $alias, $sql); + $this->assertContains('"self_related_stubs"."parent_id" = "self_alias_hash"."id"', $sql); + } + protected function mockConnectionForModel($model, $database) { $grammarClass = 'Illuminate\Database\Query\Grammars\\'.$database.'Grammar'; @@ -582,3 +616,38 @@ public function baz() class EloquentBuilderTestModelFarRelatedStub extends Illuminate\Database\Eloquent\Model { } + +class EloquentBuilderTestModelSelfRelatedStub extends Illuminate\Database\Eloquent\Model +{ + protected $table = 'self_related_stubs'; + + public function parentFoo() + { + return $this->belongsTo('EloquentBuilderTestModelSelfRelatedStub', 'parent_id', 'id', 'parent'); + } + + public function childFoo() + { + return $this->hasOne('EloquentBuilderTestModelSelfRelatedStub', 'parent_id', 'id', 'child'); + } + + public function childFoos() + { + return $this->hasMany('EloquentBuilderTestModelSelfRelatedStub', 'parent_id', 'id', 'children'); + } + + public function parentBars() + { + return $this->belongsToMany('EloquentBuilderTestModelSelfRelatedStub', 'self_pivot', 'child_id', 'parent_id', 'parent_bars'); + } + + public function childBars() + { + return $this->belongsToMany('EloquentBuilderTestModelSelfRelatedStub', 'self_pivot', 'parent_id', 'child_id', 'child_bars'); + } + + public function bazes() + { + return $this->hasMany('EloquentBuilderTestModelFarRelatedStub', 'foreign_key', 'id', 'bar'); + } +} \ No newline at end of file
true
Other
laravel
framework
116c1ebbdd8d3f2ca7d27ce3afd1402337cd5390.json
Add tests for self relationships.
tests/Database/DatabaseEloquentIntegrationTest.php
@@ -271,6 +271,68 @@ public function testHasOnSelfReferencingBelongsToManyRelationship() $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); } + public function testWhereHasOnSelfReferencingBelongsToManyRelationship() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + + $results = EloquentTestUser::whereHas('friends', function ($query) { + $query->where('email', 'abigailotwell@gmail.com'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testHasOnNestedSelfReferencingBelongsToManyRelationship() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + $nestedFriend = $friend->friends()->create(['email' => 'foo@gmail.com']); + + $results = EloquentTestUser::has('friends.friends')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testWhereHasOnNestedSelfReferencingBelongsToManyRelationship() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + $nestedFriend = $friend->friends()->create(['email' => 'foo@gmail.com']); + + $results = EloquentTestUser::whereHas('friends.friends', function ($query) { + $query->where('email', 'foo@gmail.com'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testHasOnSelfReferencingBelongsToManyRelationshipWithWherePivot() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + + $results = EloquentTestUser::has('friendsOne')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testHasOnNestedSelfReferencingBelongsToManyRelationshipWithWherePivot() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + $nestedFriend = $friend->friends()->create(['email' => 'foo@gmail.com']); + + $results = EloquentTestUser::has('friendsOne.friendsTwo')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + public function testHasOnSelfReferencingBelongsToRelationship() { $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); @@ -282,6 +344,45 @@ public function testHasOnSelfReferencingBelongsToRelationship() $this->assertEquals('Child Post', $results->first()->name); } + public function testWhereHasOnSelfReferencingBelongsToRelationship() + { + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 2]); + + $results = EloquentTestPost::whereHas('parentPost', function ($query) { + $query->where('name', 'Parent Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Child Post', $results->first()->name); + } + + public function testHasOnNestedSelfReferencingBelongsToRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::has('parentPost.parentPost')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Child Post', $results->first()->name); + } + + public function testWhereHasOnNestedSelfReferencingBelongsToRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::whereHas('parentPost.parentPost', function ($query) { + $query->where('name', 'Grandparent Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Child Post', $results->first()->name); + } + public function testHasOnSelfReferencingHasManyRelationship() { $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); @@ -293,6 +394,45 @@ public function testHasOnSelfReferencingHasManyRelationship() $this->assertEquals('Parent Post', $results->first()->name); } + public function testWhereHasOnSelfReferencingHasManyRelationship() + { + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 2]); + + $results = EloquentTestPost::whereHas('childPosts', function ($query) { + $query->where('name', 'Child Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Parent Post', $results->first()->name); + } + + public function testHasOnNestedSelfReferencingHasManyRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::has('childPosts.childPosts')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Grandparent Post', $results->first()->name); + } + + public function testWhereHasOnNestedSelfReferencingHasManyRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::whereHas('childPosts.childPosts', function ($query) { + $query->where('name', 'Child Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Grandparent Post', $results->first()->name); + } + public function testBelongsToManyRelationshipModelsAreProperlyHydratedOverChunkedRequest() { $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); @@ -318,6 +458,26 @@ public function testBasicHasManyEagerLoading() $this->assertEquals('taylorotwell@gmail.com', $post->first()->user->email); } + public function testBasicNestedSelfReferencingHasManyEagerLoading() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $post = $user->posts()->create(['name' => 'First Post']); + $post->childPosts()->create(['name' => 'Child Post', 'user_id' => $user->id]); + + $user = EloquentTestUser::with('posts.childPosts')->where('email', 'taylorotwell@gmail.com')->first(); + + $this->assertNotNull($user->posts->first()); + $this->assertEquals('First Post', $user->posts->first()->name); + + $this->assertNotNull($user->posts->first()->childPosts->first()); + $this->assertEquals('Child Post', $user->posts->first()->childPosts->first()->name); + + $post = EloquentTestPost::with('parentPost.user')->where('name', 'Child Post')->get(); + $this->assertNotNull($post->first()->parentPost); + $this->assertNotNull($post->first()->parentPost->user); + $this->assertEquals('taylorotwell@gmail.com', $post->first()->parentPost->user->email); + } + public function testBasicMorphManyRelationship() { $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); @@ -605,6 +765,16 @@ public function friends() return $this->belongsToMany('EloquentTestUser', 'friends', 'user_id', 'friend_id'); } + public function friendsOne() + { + return $this->belongsToMany('EloquentTestUser', 'friends', 'user_id', 'friend_id')->wherePivot('user_id', 1); + } + + public function friendsTwo() + { + return $this->belongsToMany('EloquentTestUser', 'friends', 'user_id', 'friend_id')->wherePivot('user_id', 2); + } + public function posts() { return $this->hasMany('EloquentTestPost', 'user_id');
true
Other
laravel
framework
d686c9147a87a9ad9da423a13df6c5a40471666a.json
accept collection of models in belongToMany attach
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -896,6 +896,10 @@ public function attach($id, array $attributes = [], $touch = true) $id = $id->getKey(); } + if ($id instanceof Collection) { + $id = $id->modelKeys(); + } + $query = $this->newPivotStatement(); $query->insert($this->createAttachRecords((array) $id, $attributes));
true
Other
laravel
framework
d686c9147a87a9ad9da423a13df6c5a40471666a.json
accept collection of models in belongToMany attach
tests/Database/DatabaseEloquentBelongsToManyTest.php
@@ -158,6 +158,31 @@ public function testAttachMultipleInsertsPivotTableRecord() $relation->attach([2, 3 => ['baz' => 'boom']], ['foo' => 'bar']); } + public function testAttachMethodConvertsCollectionToArrayOfKeys() + { + $relation = $this->getMock('Illuminate\Database\Eloquent\Relations\BelongsToMany', ['touchIfTouching'], $this->getRelationArguments()); + $query = m::mock('stdClass'); + $query->shouldReceive('from')->once()->with('user_role')->andReturn($query); + $query->shouldReceive('insert')->once()->with( + [ + ['user_id' => 1, 'role_id' => 1], + ['user_id' => 1, 'role_id' => 2], + ['user_id' => 1, 'role_id' => 3], + ] + )->andReturn(true); + $relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass')); + $mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query); + $relation->expects($this->once())->method('touchIfTouching'); + + $collection = new Collection([ + m::mock(['getKey' => 1]), + m::mock(['getKey' => 2]), + m::mock(['getKey' => 3]), + ]); + + $relation->attach($collection); + } + public function testAttachInsertsPivotTableRecordWithTimestampsWhenNecessary() { $relation = $this->getMock('Illuminate\Database\Eloquent\Relations\BelongsToMany', ['touchIfTouching'], $this->getRelationArguments());
true
Other
laravel
framework
f73e6e4b6bb89a14bac2f5b92dc0f5f8d2b8a6b1.json
Fix Eloquent Builder accessing $orders property $orders and $unionOrders are properties of Illuminate\Database\Query\Builder and not defined in Illuminate\Database\Eloquent\Builder. Doing this solve my problem. Is there any problem doing this?
src/Illuminate/Database/Eloquent/Builder.php
@@ -297,7 +297,7 @@ public function chunk($count, callable $callback) */ public function each(callable $callback, $count = 1000) { - if (is_null($this->orders) && is_null($this->unionOrders)) { + if (is_null($this->query->orders) && is_null($this->query->unionOrders)) { $this->orderBy($this->model->getQualifiedKeyName(), 'asc'); }
false
Other
laravel
framework
1f2124ef57bdd647979ab75a2863ce448118cca3.json
fix bug with file conversion
src/Illuminate/Http/Request.php
@@ -410,6 +410,10 @@ public function allFiles() protected function convertUploadedFiles(array $files) { return array_map(function ($file) { + if (is_array($file) && empty(array_filter($file))) { + return $file; + } + return is_array($file) ? $this->convertUploadedFiles($file) : UploadedFile::createFromBase($file);
false
Other
laravel
framework
b3a0d7d6c0510e8fa55b3a98d7cc23f745839110.json
organize methods and make public
src/Illuminate/Validation/Validator.php
@@ -2185,6 +2185,27 @@ protected function replaceAfter($message, $attribute, $rule, $parameters) return $this->replaceBefore($message, $attribute, $rule, $parameters); } + /** + * Get all attributes. + * + * @return array + */ + public function attributes() + { + return array_merge($this->data, $this->files); + } + + /** + * Checks if an attribute exists. + * + * @param string $attribute + * @return bool + */ + public function hasAttribute($attribute) + { + return Arr::has($this->attributes(), $attribute); + } + /** * Determine if the given attribute has a rule in the given set. * @@ -2803,25 +2824,4 @@ public function __call($method, $parameters) throw new BadMethodCallException("Method [$method] does not exist."); } - - /** - * Get all attributes. - * - * @return array - */ - protected function attributes() - { - return array_merge($this->data, $this->files); - } - - /** - * Checks if an attribute exists. - * - * @param string $attribute - * @return bool - */ - protected function hasAttribute($attribute) - { - return Arr::has($this->attributes(), $attribute); - } }
false
Other
laravel
framework
4c55494e675ee2d15c9067b1f235efd188fa1d9e.json
Add attributes() and hasAttribute() functions
src/Illuminate/Validation/Validator.php
@@ -252,7 +252,7 @@ public function after($callback) */ public function sometimes($attribute, $rules, callable $callback) { - $payload = new Fluent(array_merge($this->data, $this->files)); + $payload = new Fluent($this->attributes()); if (call_user_func($callback, $payload)) { foreach ((array) $attribute as $key) { @@ -295,7 +295,7 @@ public function each($attribute, $rules) */ protected function initializeAttributeOnData($attribute) { - if (! str_contains($attribute, '*') || ends_with($attribute, '*')) { + if (! Str::contains($attribute, '*') || Str::endsWith($attribute, '*')) { return $this->data; } @@ -852,7 +852,7 @@ protected function validateAccepted($attribute, $value) */ protected function validateArray($attribute, $value) { - if (! Arr::has(array_merge($this->data, $this->files), $attribute)) { + if (! $this->hasAttribute($attribute)) { return true; } @@ -868,7 +868,7 @@ protected function validateArray($attribute, $value) */ protected function validateBoolean($attribute, $value) { - if (! Arr::has(array_merge($this->data, $this->files), $attribute)) { + if (! $this->hasAttribute($attribute)) { return true; } @@ -886,7 +886,7 @@ protected function validateBoolean($attribute, $value) */ protected function validateInteger($attribute, $value) { - if (! Arr::has(array_merge($this->data, $this->files), $attribute)) { + if (! $this->hasAttribute($attribute)) { return true; } @@ -902,7 +902,7 @@ protected function validateInteger($attribute, $value) */ protected function validateNumeric($attribute, $value) { - if (! Arr::has(array_merge($this->data, $this->files), $attribute)) { + if (! $this->hasAttribute($attribute)) { return true; } @@ -918,7 +918,7 @@ protected function validateNumeric($attribute, $value) */ protected function validateString($attribute, $value) { - if (! Arr::has(array_merge($this->data, $this->files), $attribute)) { + if (! $this->hasAttribute($attribute)) { return true; } @@ -2803,4 +2803,25 @@ public function __call($method, $parameters) throw new BadMethodCallException("Method [$method] does not exist."); } + + /** + * Get all attributes. + * + * @return array + */ + protected function attributes() + { + return array_merge($this->data, $this->files); + } + + /** + * Checks if an attribute exists. + * + * @param string $attribute + * @return bool + */ + protected function hasAttribute($attribute) + { + return Arr::has($this->attributes(), $attribute); + } }
false
Other
laravel
framework
c26b755d2794fe9f7a8a76ffae620b852394382e.json
Use Str method rather than helper
src/Illuminate/Database/QueryException.php
@@ -3,6 +3,7 @@ namespace Illuminate\Database; use PDOException; +use Illuminate\Support\Str; class QueryException extends PDOException { @@ -53,7 +54,7 @@ public function __construct($sql, array $bindings, $previous) */ protected function formatMessage($sql, $bindings, $previous) { - return $previous->getMessage().' (SQL: '.str_replace_array('?', $bindings, $sql).')'; + return $previous->getMessage().' (SQL: '.Str::replaceArray('?', $bindings, $sql).')'; } /**
false
Other
laravel
framework
38d5f726bfb669962094acc54a25f9d83da8768a.json
Create a data_fill helper function
src/Illuminate/Support/helpers.php
@@ -378,6 +378,21 @@ function collect($value = null) } } +if (! function_exists('data_fill')) { + /** + * Fill in data where it's missing. + * + * @param mixed $target + * @param string|array $key + * @param mixed $value + * @return mixed + */ + function data_fill(&$target, $key, $value) + { + return data_set($target, $key, $value, false); + } +} + if (! function_exists('data_get')) { /** * Get an item from an array or object using "dot" notation.
true
Other
laravel
framework
38d5f726bfb669962094acc54a25f9d83da8768a.json
Create a data_fill helper function
tests/Support/SupportHelpersTest.php
@@ -400,6 +400,78 @@ public function testDataGetWithDoubleNestedArraysCollapsesResult() $this->assertEquals([], data_get($array, 'posts.*.users.*.name')); } + public function testDataFill() + { + $data = ['foo' => 'bar']; + + $this->assertEquals(['foo' => 'bar', 'baz' => 'boom'], data_fill($data, 'baz', 'boom')); + $this->assertEquals(['foo' => 'bar', 'baz' => 'boom'], data_fill($data, 'baz', 'noop')); + $this->assertEquals(['foo' => [], 'baz' => 'boom'], data_fill($data, 'foo.*', 'noop')); + $this->assertEquals( + ['foo' => ['bar' => 'kaboom'], 'baz' => 'boom'], + data_fill($data, 'foo.bar', 'kaboom') + ); + } + + public function testDataFillWithStar() + { + $data = ['foo' => 'bar']; + + $this->assertEquals( + ['foo' => []], + data_fill($data, 'foo.*.bar', 'noop') + ); + + $this->assertEquals( + ['foo' => [], 'bar' => [['baz' => 'original'], []]], + data_fill($data, 'bar', [['baz' => 'original'], []]) + ); + + $this->assertEquals( + ['foo' => [], 'bar' => [['baz' => 'original'], ['baz' => 'boom']]], + data_fill($data, 'bar.*.baz', 'boom') + ); + } + + public function testDataFillWithDoubleStar() + { + $data = [ + 'posts' => [ + (object) [ + 'comments' => [ + (object) ['name' => 'First'], + (object) [], + ], + ], + (object) [ + 'comments' => [ + (object) [], + (object) ['name' => 'Second'], + ], + ], + ], + ]; + + data_fill($data, 'posts.*.comments.*.name', 'Filled'); + + $this->assertEquals([ + 'posts' => [ + (object) [ + 'comments' => [ + (object) ['name' => 'First'], + (object) ['name' => 'Filled'], + ], + ], + (object) [ + 'comments' => [ + (object) ['name' => 'Filled'], + (object) ['name' => 'Second'], + ], + ], + ], + ], $data); + } + public function testDataSet() { $data = ['foo' => 'bar'];
true
Other
laravel
framework
df945ea3a74cd2d79885b21cf5af994c61088a41.json
Expand tests for Str::startsWith etc. * tests array of needles is actually iterated * it also tests one match is sufficient * tests needle of Str::contains can be the full subject
tests/Support/SupportStrTest.php
@@ -40,6 +40,7 @@ public function testStartsWith() $this->assertTrue(Str::startsWith('jason', 'jas')); $this->assertTrue(Str::startsWith('jason', 'jason')); $this->assertTrue(Str::startsWith('jason', ['jas'])); + $this->assertTrue(Str::startsWith('jason', ['day', 'jas'])); $this->assertFalse(Str::startsWith('jason', 'day')); $this->assertFalse(Str::startsWith('jason', ['day'])); $this->assertFalse(Str::startsWith('jason', '')); @@ -50,6 +51,7 @@ public function testEndsWith() $this->assertTrue(Str::endsWith('jason', 'on')); $this->assertTrue(Str::endsWith('jason', 'jason')); $this->assertTrue(Str::endsWith('jason', ['on'])); + $this->assertTrue(Str::endsWith('jason', ['no', 'on'])); $this->assertFalse(Str::endsWith('jason', 'no')); $this->assertFalse(Str::endsWith('jason', ['no'])); $this->assertFalse(Str::endsWith('jason', '')); @@ -59,7 +61,9 @@ public function testEndsWith() public function testStrContains() { $this->assertTrue(Str::contains('taylor', 'ylo')); + $this->assertTrue(Str::contains('taylor', 'taylor')); $this->assertTrue(Str::contains('taylor', ['ylo'])); + $this->assertTrue(Str::contains('taylor', ['xxx', 'ylo'])); $this->assertFalse(Str::contains('taylor', 'xxx')); $this->assertFalse(Str::contains('taylor', ['xxx'])); $this->assertFalse(Str::contains('taylor', ''));
false
Other
laravel
framework
5062a9b42632e55ee90b7397141c0b12622447e1.json
remove testing accessor.
src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php
@@ -5,10 +5,10 @@ use Exception; use Illuminate\Support\Str; use InvalidArgumentException; +use Illuminate\Http\UploadedFile; use Symfony\Component\DomCrawler\Form; use Symfony\Component\DomCrawler\Crawler; use Illuminate\Foundation\Testing\HttpException; -use Symfony\Component\HttpFoundation\File\UploadedFile; use PHPUnit_Framework_ExpectationFailedException as PHPUnitException; trait InteractsWithPages @@ -825,7 +825,7 @@ protected function convertUploadsForTesting(Form $form, array $uploads) * @param array $file * @param array $uploads * @param string $name - * @return \Symfony\Component\HttpFoundation\File\UploadedFile + * @return \Illuminate\Http\UploadedFile */ protected function getUploadedFileForTesting($file, $uploads, $name) {
true
Other
laravel
framework
5062a9b42632e55ee90b7397141c0b12622447e1.json
remove testing accessor.
src/Illuminate/Http/Request.php
@@ -5,7 +5,6 @@ use Closure; use ArrayAccess; use SplFileInfo; -use ReflectionClass; use RuntimeException; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -408,15 +407,10 @@ public function allFiles() */ protected function convertUploadedFiles(array $files) { - // Pending "test" property of Symfony's becoming accessible... - $property = (new ReflectionClass(SymfonyUploadedFile::class))->getProperty('test'); - - $property->setAccessible(true); - - return array_map(function ($file) use ($property) { + return array_map(function ($file) { return is_array($file) ? $this->convertUploadedFiles($file) - : UploadedFile::createFromBase($file, $property->getValue($file)); + : UploadedFile::createFromBase($file); }, $files); }
true
Other
laravel
framework
5062a9b42632e55ee90b7397141c0b12622447e1.json
remove testing accessor.
src/Illuminate/Http/UploadedFile.php
@@ -43,14 +43,13 @@ public function hashName() * Create a new file instance from a base instance. * * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file - * @param bool $testing * @return static */ - public static function createFromBase(SymfonyUploadedFile $file, $testing = false) + public static function createFromBase(SymfonyUploadedFile $file) { return $file instanceof static ? $file : new static( $file->getRealPath(), $file->getClientOriginalName(), $file->getClientMimeType(), - $file->getClientSize(), $file->getError(), $testing + $file->getClientSize(), $file->getError() ); } }
true
Other
laravel
framework
7f73b2dcd816e6c45ca65172011f8739ab210ba4.json
Remove Countable use and add trailing slash
src/Illuminate/Foundation/helpers.php
@@ -664,7 +664,7 @@ function trans($id = null, $parameters = [], $domain = 'messages', $locale = nul * Translates the given message based on a count. * * @param string $id - * @param int|array|Countable $number + * @param int|array|\Countable $number * @param array $parameters * @param string $domain * @param string $locale
true
Other
laravel
framework
7f73b2dcd816e6c45ca65172011f8739ab210ba4.json
Remove Countable use and add trailing slash
src/Illuminate/Translation/Translator.php
@@ -2,7 +2,6 @@ namespace Illuminate\Translation; -use Countable; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Support\Collection; @@ -185,7 +184,7 @@ protected function sortReplacements(array $replace) * Get a translation according to an integer value. * * @param string $key - * @param int|array|Countable $number + * @param int|array|\Countable $number * @param array $replace * @param string $locale * @return string @@ -194,7 +193,7 @@ public function choice($key, $number, array $replace = [], $locale = null) { $line = $this->get($key, $replace, $locale = $locale ?: $this->locale ?: $this->fallback); - if (is_array($number) || $number instanceof Countable) { + if (is_array($number) || $number instanceof \Countable) { $number = count($number); } @@ -221,7 +220,7 @@ public function trans($id, array $parameters = [], $domain = 'messages', $locale * Get a translation according to an integer value. * * @param string $id - * @param int|array|Countable $number + * @param int|array|\Countable $number * @param array $parameters * @param string $domain * @param string $locale
true
Other
laravel
framework
414f3da9bb548b4b8f8553bf3645dd5b2d796db0.json
support local driver in url method.
src/Illuminate/Filesystem/FilesystemAdapter.php
@@ -9,6 +9,7 @@ use League\Flysystem\FilesystemInterface; use League\Flysystem\AwsS3v3\AwsS3Adapter; use League\Flysystem\FileNotFoundException; +use League\Flysystem\Adapter\Local as LocalAdapter; use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract; use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract; use Illuminate\Contracts\Filesystem\FileNotFoundException as ContractFileNotFoundException; @@ -227,13 +228,13 @@ public function url($path) { $adapter = $this->driver->getAdapter(); - if (! $adapter instanceof AwsS3Adapter) { + if ($adapter instanceof AwsS3Adapter) { + return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path); + } elseif ($adapter instanceof LocalAdapter) { + return '/storage/'.$path; + } else { throw new RuntimeException('This driver does not support retrieving URLs.'); } - - $bucket = $adapter->getBucket(); - - return $adapter->getClient()->getObjectUrl($bucket, $path); } /**
false
Other
laravel
framework
5f27c24bf153db3dbd33f1d925d3ca128885ffc2.json
Create a data_set helper function
src/Illuminate/Support/helpers.php
@@ -433,6 +433,57 @@ function data_get($target, $key, $default = null) } } +if (! function_exists('data_set')) { + /** + * Set an item on an array or object using dot notation. + * + * @param mixed $target + * @param string|array $key + * @param mixed $value + * @return mixed + */ + function data_set(&$target, $key, $value) + { + $segments = is_array($key) ? $key : explode('.', $key); + + if (($segment = array_shift($segments)) === '*') { + if (! Arr::accessible($target)) { + $target = []; + } elseif ($segments) { + foreach ($target as &$inner) { + data_set($inner, $segments, $value); + } + } else { + foreach ($target as &$inner) { + $inner = $value; + } + } + } elseif (Arr::accessible($target)) { + if ($segments) { + if (! Arr::exists($target, $segment)) { + $target[$segment] = []; + } + + data_set($target[$segment], $segments, $value); + } elseif (! Arr::exists($target, $segment)) { + $target[$segment] = $value; + } + } elseif (is_object($target)) { + if ($segments) { + if (! isset($target->{$segment})) { + $target->{$segment} = []; + } + + data_set($target->{$segment}, $segments, $value); + } elseif (! isset($target->{$segment})) { + $target->{$segment} = $value; + } + } + + return $target; + } +} + if (! function_exists('dd')) { /** * Dump the passed variables and end the script.
true
Other
laravel
framework
5f27c24bf153db3dbd33f1d925d3ca128885ffc2.json
Create a data_set helper function
tests/Support/SupportHelpersTest.php
@@ -400,6 +400,78 @@ public function testDataGetWithDoubleNestedArraysCollapsesResult() $this->assertEquals([], data_get($array, 'posts.*.users.*.name')); } + public function testDataSet() + { + $data = ['foo' => 'bar']; + + $this->assertEquals(['foo' => 'bar', 'baz' => 'boom'], data_set($data, 'baz', 'boom')); + $this->assertEquals(['foo' => 'bar', 'baz' => 'boom'], data_set($data, 'baz', 'noop')); + $this->assertEquals(['foo' => [], 'baz' => 'boom'], data_set($data, 'foo.*', 'noop')); + $this->assertEquals( + ['foo' => ['bar' => 'kaboom'], 'baz' => 'boom'], + data_set($data, 'foo.bar', 'kaboom') + ); + } + + public function testDataSetWithStar() + { + $data = ['foo' => 'bar']; + + $this->assertEquals( + ['foo' => []], + data_set($data, 'foo.*.bar', 'noop') + ); + + $this->assertEquals( + ['foo' => [], 'bar' => [['baz' => 'original'], []]], + data_set($data, 'bar', [['baz' => 'original'], []]) + ); + + $this->assertEquals( + ['foo' => [], 'bar' => [['baz' => 'original'], ['baz' => 'boom']]], + data_set($data, 'bar.*.baz', 'boom') + ); + } + + public function testDataSetWithDoubleStar() + { + $data = [ + 'posts' => [ + (object) [ + 'comments' => [ + (object) ['name' => 'First'], + (object) [], + ], + ], + (object) [ + 'comments' => [ + (object) [], + (object) ['name' => 'Second'], + ], + ], + ], + ]; + + data_set($data, 'posts.*.comments.*.name', 'Filled'); + + $this->assertEquals([ + 'posts' => [ + (object) [ + 'comments' => [ + (object) ['name' => 'First'], + (object) ['name' => 'Filled'], + ], + ], + (object) [ + 'comments' => [ + (object) ['name' => 'Filled'], + (object) ['name' => 'Second'], + ], + ], + ], + ], $data); + } + public function testArraySort() { $array = [
true
Other
laravel
framework
7aa750e465816d2fd158085fe578f258600176ff.json
add sane helper methods to uploaded file.
src/Illuminate/Http/UploadedFile.php
@@ -10,6 +10,36 @@ class UploadedFile extends SymfonyUploadedFile { use Macroable; + /** + * Get the fully qualified path to the file. + * + * @return string + */ + public function path() + { + return $this->getRealPath(); + } + + /** + * Get the file's extension. + * + * @return string + */ + public function extension() + { + return $this->guessClientExtension(); + } + + /** + * Get a filename for the file that is the MD5 hash of the contents. + * + * @return string + */ + public function hashName() + { + return md5_file($this->path()).'.'.$this->extension(); + } + /** * Create a new file instance from a base instance. *
false
Other
laravel
framework
caa75f37309e7fc32c3d9e6e0de60b466780abe3.json
Add an `exists` method to the Arr class
src/Illuminate/Support/Arr.php
@@ -120,6 +120,22 @@ public static function except($array, $keys) return $array; } + /** + * Determine if the given key exists in the provided array. + * + * @param array|\ArrayAccess $array + * @param string|int $key + * @return bool + */ + public static function exists($array, $key) + { + if (is_array($array)) { + return array_key_exists($key, $array); + } + + return $array->offsetExists($key); + } + /** * Return the first element in an array passing a given truth test. *
true
Other
laravel
framework
caa75f37309e7fc32c3d9e6e0de60b466780abe3.json
Add an `exists` method to the Arr class
tests/Support/SupportArrayTest.php
@@ -31,6 +31,20 @@ public function testExcept() $this->assertEquals(['name' => 'Desk'], $array); } + public function testExists() + { + $this->assertTrue(Arr::exists([1], 0)); + $this->assertTrue(Arr::exists([null], 0)); + $this->assertTrue(Arr::exists(['a' => 1], 'a')); + $this->assertTrue(Arr::exists(['a' => null], 'a')); + $this->assertTrue(Arr::exists(new Collection(['a' => null]), 'a')); + + $this->assertFalse(Arr::exists([1], 1)); + $this->assertFalse(Arr::exists([null], 1)); + $this->assertFalse(Arr::exists(['a' => 1], 0)); + $this->assertFalse(Arr::exists(new Collection(['a' => null]), 'b')); + } + public function testFirst() { $array = [100, 200, 300];
true
Other
laravel
framework
70f1a5ddbaa213650f69d665fcf55d1eb7175084.json
Add an `is` method to the Arr class
src/Illuminate/Support/Arr.php
@@ -139,6 +139,17 @@ public static function first($array, callable $callback, $default = null) return value($default); } + /** + * Determine whether the given value is array-like. + * + * @param mixed $value + * @return bool + */ + public static function is($value) + { + return is_array($value) || $value instanceof ArrayAccess; + } + /** * Return the last element in an array passing a given truth test. *
true
Other
laravel
framework
70f1a5ddbaa213650f69d665fcf55d1eb7175084.json
Add an `is` method to the Arr class
tests/Support/SupportArrayTest.php
@@ -42,6 +42,19 @@ public function testFirst() $this->assertEquals(200, $value); } + public function testIs() + { + $this->assertTrue(Arr::is([])); + $this->assertTrue(Arr::is([1, 2])); + $this->assertTrue(Arr::is(['a' => 1, 'b' => 2])); + $this->assertTrue(Arr::is(new Collection)); + + $this->assertFalse(Arr::is(null)); + $this->assertFalse(Arr::is('abc')); + $this->assertFalse(Arr::is(new stdClass)); + $this->assertFalse(Arr::is((object) ['a' => 1, 'b' => 2])); + } + public function testLast() { $array = [100, 200, 300];
true
Other
laravel
framework
0b7c22f898ac445eaeb9a3f4c2bae7edfd5459bb.json
Remove undeeded method.
src/Illuminate/Validation/Validator.php
@@ -312,46 +312,6 @@ protected function initializeAttributeOnData($attribute) return $data; } - /** - * Fill a missing field in an array with null. - * - * This to make sure the "required" rule is effective if the array does not have the key - * - * @param array $originalData - * @param string $field - * @param array $levelData - * @param array $segments - * @param string $lastSegment - * @param array $keysArray - * @return void - */ - protected function fillMissingArrayKeys(&$originalData, $field, $levelData, $segments, $lastSegment, $keysArray = []) - { - foreach ($levelData as $key => $levelValues) { - if ($key !== $lastSegment) { - if (! is_array($levelValues) || (! is_numeric($key) && ! in_array($key, $segments))) { - continue; - } - - // If the last key is numeric then a previous root was checked and we are moving - // into a following root thus we need to reset our index. - if (is_numeric(last($keysArray))) { - array_pop($keysArray); - } - - $keysArray[] = $key; - $this->fillMissingArrayKeys($originalData, $field, $levelValues, $segments, $lastSegment, $keysArray); - } else { - foreach ($levelValues as $i => $rootValue) { - if (! isset($rootValue[$field])) { - $keysArray = array_merge($keysArray, [$lastSegment, $i, $field]); - $originalData[implode('.', $keysArray)] = null; - } - } - } - } - } - /** * Merge additional rules into a given attribute. *
false
Other
laravel
framework
5d26f491b27accedb44e2c444820c18d8771a49e.json
Import Closure at the top
src/Illuminate/Database/Eloquent/FactoryBuilder.php
@@ -2,6 +2,7 @@ namespace Illuminate\Database\Eloquent; +use Closure; use Faker\Generator as Faker; use InvalidArgumentException; @@ -146,7 +147,7 @@ protected function makeInstance(array $attributes = []) protected function evaluateClosures(array $attributes) { return array_map(function ($attribute) use ($attributes) { - return $attribute instanceof \Closure ? $attribute($attributes) : $attribute; + return $attribute instanceof Closure ? $attribute($attributes) : $attribute; }, $attributes); } }
false
Other
laravel
framework
71ed829db93dc6460a8ce3831ecfe5464eb2b56b.json
Replace foreach loop with array_map
src/Illuminate/Database/Eloquent/FactoryBuilder.php
@@ -145,12 +145,8 @@ protected function makeInstance(array $attributes = []) */ protected function evaluateClosures(array $attributes) { - foreach ($attributes as &$attribute) { - if ($attribute instanceof \Closure) { - $attribute = $attribute($attributes); - } - } - - return $attributes; + return array_map(function ($attribute) use ($attributes) { + return $attribute instanceof \Closure ? $attribute($attributes) : $attribute; + }, $attributes); } }
false
Other
laravel
framework
6e759658a78a5461e446c2efd047a175119b6365.json
Add cloud() method. This adds a quick way to get the default “cloud” driver via the Storage facade.
src/Illuminate/Filesystem/FilesystemManager.php
@@ -74,6 +74,18 @@ public function disk($name = null) return $this->disks[$name] = $this->get($name); } + /** + * Get a default cloud filesystem instance. + * + * @return \Illuminate\Contracts\Filesystem\Filesystem + */ + public function cloud() + { + $name = $this->getDefaultCloudDriver(); + + return $this->disks[$name] = $this->get($name); + } + /** * Attempt to get the disk from the local cache. * @@ -276,6 +288,16 @@ public function getDefaultDriver() return $this->app['config']['filesystems.default']; } + /** + * Get the default cloud driver name. + * + * @return string + */ + public function getDefaultCloudDriver() + { + return $this->app['config']['filesystems.cloud']; + } + /** * Register a custom driver creator Closure. *
false
Other
laravel
framework
3d38e2f2d96f3c592b4085cc346ee43fae7a18fc.json
Delay closures evaluation after merging attributes
src/Illuminate/Database/Eloquent/FactoryBuilder.php
@@ -130,8 +130,28 @@ protected function makeInstance(array $attributes = []) } $definition = call_user_func($this->definitions[$this->class][$this->name], $this->faker, $attributes); + + $evaluated = $this->evaluateClosures(array_merge($definition, $attributes)); - return new $this->class(array_merge($definition, $attributes)); + return new $this->class($evaluated); }); } + + /** + * Delay closures evaluation after merging to avoid duplication. + * + * @param array $attributes + * + * @return array + */ + protected function evaluateClosures(array $attributes) + { + foreach ($attributes as &$attribute) { + if ($attribute instanceof \Closure) { + $attribute = $attribute($attributes); + } + } + + return $attributes; + } }
false
Other
laravel
framework
1c2f33316ac8e2ff0d7ff765ef086cd52b04a8fd.json
Simplify code of Kernel::hasMiddleware
src/Illuminate/Foundation/Http/Kernel.php
@@ -245,7 +245,7 @@ protected function dispatchToRouter() */ public function hasMiddleware($middleware) { - return array_key_exists($middleware, array_flip($this->middleware)); + return in_array($middleware, $this->middleware); } /**
false
Other
laravel
framework
7f73bd2bc1eeefab73e38503f4f2d9419ecbefb6.json
Add diffKeys() method. Uses keys instead of item values for comparison.
src/Illuminate/Support/Collection.php
@@ -123,6 +123,17 @@ public function diff($items) return new static(array_diff($this->items, $this->getArrayableItems($items))); } + /** + * Get the items in the collection whose keys are not present in the given items. + * + * @param mixed $items + * @return static + */ + public function diffKeys($items) + { + return new static(array_diff_key($this->items, $this->getArrayableItems($items))); + } + /** * Execute a callback over each item. *
false
Other
laravel
framework
ef81c531512de75214e3723fa0725c2b64ad6395.json
add the url method for sanity
src/Illuminate/Filesystem/FilesystemAdapter.php
@@ -6,6 +6,7 @@ use Illuminate\Support\Collection; use League\Flysystem\AdapterInterface; use League\Flysystem\FilesystemInterface; +use League\Flysystem\AwsS3v3\AwsS3Adapter; use League\Flysystem\FileNotFoundException; use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract; use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract; @@ -215,6 +216,23 @@ public function lastModified($path) return $this->driver->getTimestamp($path); } + /** + * Get the URL for the file at the given path. + * + * @param string $path + * @return string + */ + public function url($path) + { + if (! $this->driver->getAdapter() instanceof AwsS3Adapter) { + throw new RuntimeException("This driver does not support retrieving URLs."); + } + + $bucket = $this->driver->getAdapter()->getBucket(); + + return $this->driver->getAdapter()->getClient()->getObjectUrl($bucket, $path); + } + /** * Get an array of all files in a directory. *
false
Other
laravel
framework
e76168d60dfcda3341503998e21ac0608caed92c.json
Update doc for findOrNew method This function returns \Illuminate\Database\Eloquent\Model and not a Collection in case the model exists.
src/Illuminate/Database/Eloquent/Model.php
@@ -672,7 +672,7 @@ public static function all($columns = ['*']) * * @param mixed $id * @param array $columns - * @return \Illuminate\Support\Collection|static + * @return \Illuminate\Database\Eloquent\Model|static */ public static function findOrNew($id, $columns = ['*']) {
false
Other
laravel
framework
dcd02818805175725aecc01a14ec2bb7340f7586.json
add messages method to message bag.
src/Illuminate/Support/MessageBag.php
@@ -209,11 +209,21 @@ protected function checkFormat($format) * * @return array */ - public function getMessages() + public function messages() { return $this->messages; } + /** + * Get the raw messages in the container. + * + * @return array + */ + public function getMessages() + { + return $this->messages(); + } + /** * Get the messages for the instance. *
false
Other
laravel
framework
094c7a7504522b85146cee68e0d73e671beb6919.json
Fix remaining failing test
tests/Database/DatabaseMySqlSchemaGrammarTest.php
@@ -64,6 +64,7 @@ public function testCharsetCollationCreateTable() $conn = $this->getConnection(); $conn->shouldReceive('getConfig')->once()->with('charset')->andReturn('utf8'); $conn->shouldReceive('getConfig')->once()->with('collation')->andReturn('utf8_unicode_ci'); + $conn->shouldReceive('getConfig')->once()->with('engine')->andReturn(null); $statements = $blueprint->toSql($conn, $this->getGrammar());
false
Other
laravel
framework
6f8ad3ca95e5f1037c78adee593bcef5ed3f1ad1.json
Add tests for self relationships.
tests/Database/DatabaseEloquentBuilderTest.php
@@ -517,6 +517,41 @@ public function testOrHasNested() $this->assertEquals($builder->toSql(), $result); } + public function testSelfHasNested() + { + $model = new EloquentBuilderTestModelSelfRelatedStub; + + $nestedSql = $model->whereHas('parentFoo', function ($q) { + $q->has('childFoo'); + })->toSql(); + + $dotSql = $model->has('parentFoo.childFoo')->toSql(); + + // alias has a dynamic hash, so replace with a static string for comparison + $alias = 'self_alias_hash'; + $aliasRegex = '/\b(self_[a-f0-9]{32})(\b|$)/i'; + + $nestedSql = preg_replace($aliasRegex, $alias, $nestedSql); + $dotSql = preg_replace($aliasRegex, $alias, $dotSql); + + $this->assertEquals($nestedSql, $dotSql); + } + + public function testSelfHasNestedUsesAlias() + { + $model = new EloquentBuilderTestModelSelfRelatedStub; + + $sql = $model->has('parentFoo.childFoo')->toSql(); + + // alias has a dynamic hash, so replace with a static string for comparison + $alias = 'self_alias_hash'; + $aliasRegex = '/\b(self_[a-f0-9]{32})(\b|$)/i'; + + $sql = preg_replace($aliasRegex, $alias, $sql); + + $this->assertContains('"self_related_stubs"."parent_id" = "self_alias_hash"."id"', $sql); + } + protected function mockConnectionForModel($model, $database) { $grammarClass = 'Illuminate\Database\Query\Grammars\\'.$database.'Grammar'; @@ -611,3 +646,38 @@ public function baz() class EloquentBuilderTestModelFarRelatedStub extends Illuminate\Database\Eloquent\Model { } + +class EloquentBuilderTestModelSelfRelatedStub extends Illuminate\Database\Eloquent\Model +{ + protected $table = 'self_related_stubs'; + + public function parentFoo() + { + return $this->belongsTo('EloquentBuilderTestModelSelfRelatedStub', 'parent_id', 'id', 'parent'); + } + + public function childFoo() + { + return $this->hasOne('EloquentBuilderTestModelSelfRelatedStub', 'parent_id', 'id', 'child'); + } + + public function childFoos() + { + return $this->hasMany('EloquentBuilderTestModelSelfRelatedStub', 'parent_id', 'id', 'children'); + } + + public function parentBars() + { + return $this->belongsToMany('EloquentBuilderTestModelSelfRelatedStub', 'self_pivot', 'child_id', 'parent_id', 'parent_bars'); + } + + public function childBars() + { + return $this->belongsToMany('EloquentBuilderTestModelSelfRelatedStub', 'self_pivot', 'parent_id', 'child_id', 'child_bars'); + } + + public function bazes() + { + return $this->hasMany('EloquentBuilderTestModelFarRelatedStub', 'foreign_key', 'id', 'bar'); + } +}
true
Other
laravel
framework
6f8ad3ca95e5f1037c78adee593bcef5ed3f1ad1.json
Add tests for self relationships.
tests/Database/DatabaseEloquentIntegrationTest.php
@@ -286,6 +286,68 @@ public function testHasOnSelfReferencingBelongsToManyRelationship() $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); } + public function testWhereHasOnSelfReferencingBelongsToManyRelationship() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + + $results = EloquentTestUser::whereHas('friends', function ($query) { + $query->where('email', 'abigailotwell@gmail.com'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testHasOnNestedSelfReferencingBelongsToManyRelationship() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + $nestedFriend = $friend->friends()->create(['email' => 'foo@gmail.com']); + + $results = EloquentTestUser::has('friends.friends')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testWhereHasOnNestedSelfReferencingBelongsToManyRelationship() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + $nestedFriend = $friend->friends()->create(['email' => 'foo@gmail.com']); + + $results = EloquentTestUser::whereHas('friends.friends', function ($query) { + $query->where('email', 'foo@gmail.com'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testHasOnSelfReferencingBelongsToManyRelationshipWithWherePivot() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + + $results = EloquentTestUser::has('friendsOne')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + + public function testHasOnNestedSelfReferencingBelongsToManyRelationshipWithWherePivot() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $friend = $user->friends()->create(['email' => 'abigailotwell@gmail.com']); + $nestedFriend = $friend->friends()->create(['email' => 'foo@gmail.com']); + + $results = EloquentTestUser::has('friendsOne.friendsTwo')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('taylorotwell@gmail.com', $results->first()->email); + } + public function testHasOnSelfReferencingBelongsToRelationship() { $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); @@ -297,6 +359,45 @@ public function testHasOnSelfReferencingBelongsToRelationship() $this->assertEquals('Child Post', $results->first()->name); } + public function testWhereHasOnSelfReferencingBelongsToRelationship() + { + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 2]); + + $results = EloquentTestPost::whereHas('parentPost', function ($query) { + $query->where('name', 'Parent Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Child Post', $results->first()->name); + } + + public function testHasOnNestedSelfReferencingBelongsToRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::has('parentPost.parentPost')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Child Post', $results->first()->name); + } + + public function testWhereHasOnNestedSelfReferencingBelongsToRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::whereHas('parentPost.parentPost', function ($query) { + $query->where('name', 'Grandparent Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Child Post', $results->first()->name); + } + public function testHasOnSelfReferencingHasManyRelationship() { $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); @@ -308,6 +409,45 @@ public function testHasOnSelfReferencingHasManyRelationship() $this->assertEquals('Parent Post', $results->first()->name); } + public function testWhereHasOnSelfReferencingHasManyRelationship() + { + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'user_id' => 1]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 2]); + + $results = EloquentTestPost::whereHas('childPosts', function ($query) { + $query->where('name', 'Child Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Parent Post', $results->first()->name); + } + + public function testHasOnNestedSelfReferencingHasManyRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::has('childPosts.childPosts')->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Grandparent Post', $results->first()->name); + } + + public function testWhereHasOnNestedSelfReferencingHasManyRelationship() + { + $grandParentPost = EloquentTestPost::create(['name' => 'Grandparent Post', 'user_id' => 1]); + $parentPost = EloquentTestPost::create(['name' => 'Parent Post', 'parent_id' => $grandParentPost->id, 'user_id' => 2]); + $childPost = EloquentTestPost::create(['name' => 'Child Post', 'parent_id' => $parentPost->id, 'user_id' => 3]); + + $results = EloquentTestPost::whereHas('childPosts.childPosts', function ($query) { + $query->where('name', 'Child Post'); + })->get(); + + $this->assertEquals(1, count($results)); + $this->assertEquals('Grandparent Post', $results->first()->name); + } + public function testBelongsToManyRelationshipModelsAreProperlyHydratedOverChunkedRequest() { $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); @@ -333,6 +473,26 @@ public function testBasicHasManyEagerLoading() $this->assertEquals('taylorotwell@gmail.com', $post->first()->user->email); } + public function testBasicNestedSelfReferencingHasManyEagerLoading() + { + $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); + $post = $user->posts()->create(['name' => 'First Post']); + $post->childPosts()->create(['name' => 'Child Post', 'user_id' => $user->id]); + + $user = EloquentTestUser::with('posts.childPosts')->where('email', 'taylorotwell@gmail.com')->first(); + + $this->assertNotNull($user->posts->first()); + $this->assertEquals('First Post', $user->posts->first()->name); + + $this->assertNotNull($user->posts->first()->childPosts->first()); + $this->assertEquals('Child Post', $user->posts->first()->childPosts->first()->name); + + $post = EloquentTestPost::with('parentPost.user')->where('name', 'Child Post')->get(); + $this->assertNotNull($post->first()->parentPost); + $this->assertNotNull($post->first()->parentPost->user); + $this->assertEquals('taylorotwell@gmail.com', $post->first()->parentPost->user->email); + } + public function testBasicMorphManyRelationship() { $user = EloquentTestUser::create(['email' => 'taylorotwell@gmail.com']); @@ -646,6 +806,16 @@ public function friends() return $this->belongsToMany('EloquentTestUser', 'friends', 'user_id', 'friend_id'); } + public function friendsOne() + { + return $this->belongsToMany('EloquentTestUser', 'friends', 'user_id', 'friend_id')->wherePivot('user_id', 1); + } + + public function friendsTwo() + { + return $this->belongsToMany('EloquentTestUser', 'friends', 'user_id', 'friend_id')->wherePivot('user_id', 2); + } + public function posts() { return $this->hasMany('EloquentTestPost', 'user_id');
true
Other
laravel
framework
ed3154d8af8f1b9dbb034e2dc92100a0f8f5d4b2.json
Catch more things
src/Illuminate/View/View.php
@@ -92,6 +92,10 @@ public function render(callable $callback = null) } catch (Exception $e) { $this->factory->flushSections(); + throw $e; + } catch (Throwable $e) { + $this->factory->flushSections(); + throw $e; } }
false
Other
laravel
framework
ab61c759a4b1e4513af31b899263d7efdb23a08f.json
fix flush bug
src/Illuminate/View/Factory.php
@@ -643,6 +643,8 @@ public function yieldContent($section, $default = '') */ public function flushSections() { + $this->renderCount = 0; + $this->sections = []; $this->sectionStack = [];
false
Other
laravel
framework
f80d6f89a3b4b35933892b29857d7cad1cda29bd.json
Use argument unpacking
src/Illuminate/Support/Facades/Facade.php
@@ -210,24 +210,6 @@ public static function __callStatic($method, $args) throw new RuntimeException('A facade root has not been set.'); } - switch (count($args)) { - case 0: - return $instance->$method(); - - case 1: - return $instance->$method($args[0]); - - case 2: - return $instance->$method($args[0], $args[1]); - - case 3: - return $instance->$method($args[0], $args[1], $args[2]); - - case 4: - return $instance->$method($args[0], $args[1], $args[2], $args[3]); - - default: - return call_user_func_array([$instance, $method], $args); - } + return $instance->$method(...$args); } }
false
Other
laravel
framework
d020a40b977b49ce7adee04c6f520bb794804353.json
fix method order.
src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
@@ -48,19 +48,6 @@ public function postLogin(Request $request) return $this->login($request); } - /** - * Validate user login attributes. - * - * @param \Illuminate\Http\Request $request - * @return null - */ - protected function validateLogin($request) - { - $this->validate($request, [ - $this->loginUsername() => 'required', 'password' => 'required', - ]); - } - /** * Handle a login request to the application. * @@ -98,6 +85,19 @@ public function login(Request $request) return $this->sendFailedLoginResponse($request); } + /** + * Validate the user login request. + * + * @param \Illuminate\Http\Request $request + * @return void + */ + protected function validateLogin(Request $request) + { + $this->validate($request, [ + $this->loginUsername() => 'required', 'password' => 'required', + ]); + } + /** * Send the response after the user was authenticated. *
false
Other
laravel
framework
89722e3639d459bb0ebf092c1e640d3080e34b6c.json
Add validateLogin function for easy override. I have added a function validateLogin split from the login function. So that I can override it in my AuthController to add some other data such as costom attribute.Like this: ```php protected function validateLogin($request){ $this->validate($request, [ $this->loginUsername() => 'required', 'password' => 'required', ],[],[ 'name' => '用户名', 'password' => '密码', 'email' => '邮箱' ]); } ```
src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
@@ -47,6 +47,18 @@ public function postLogin(Request $request) { return $this->login($request); } + + /** + * Validate user login attributes + * + * @param \Illuminate\Http\Request $request + * @return null + */ + protected function validateLogin($request){ + $this->validate($request, [ + $this->loginUsername() => 'required', 'password' => 'required', + ]); + } /** * Handle a login request to the application. @@ -56,9 +68,7 @@ public function postLogin(Request $request) */ public function login(Request $request) { - $this->validate($request, [ - $this->loginUsername() => 'required', 'password' => 'required', - ]); + $this->validateLogin($request); // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and
false
Other
laravel
framework
f8114e342b010a454d3d68685bd279f0cf661144.json
Fix some route docblocks
src/Illuminate/Routing/Route.php
@@ -752,7 +752,7 @@ public function getUri() * Set the URI that the route responds to. * * @param string $uri - * @return \Illuminate\Routing\Route + * @return $this */ public function setUri($uri) { @@ -798,7 +798,7 @@ public function name($name) * Set the handler for the route. * * @param \Closure|string $action - * @return \Illuminate\Routing\Route + * @return $this */ public function uses($action) {
false
Other
laravel
framework
d0e8a56624a0e581aa7a46b07cc5acfee57a9376.json
remove old method
src/Illuminate/Console/Scheduling/Event.php
@@ -145,18 +145,6 @@ public function run(Container $container) $this->runCommandInForeground($container); } - /** - * Run the command in the background using exec. - * - * @return void - */ - protected function runCommandInBackground() - { - chdir(base_path()); - - exec($this->buildCommand()); - } - /** * Run the command in the foreground. *
false
Other
laravel
framework
65cf2fd5e8f9334831bb3ccb3e12549a80faba7f.json
change method order
src/Illuminate/Foundation/Auth/ThrottlesLogins.php
@@ -95,17 +95,6 @@ protected function clearLoginAttempts(Request $request) ); } - /** - * Fire an event when a lockout occurs. - * - * @param \Illuminate\Http\Request $request - * @return void - */ - protected function fireLockoutEvent(Request $request) - { - event(new Lockout($request)); - } - /** * Get the throttle key for the given request. * @@ -136,4 +125,15 @@ protected function lockoutTime() { return property_exists($this, 'lockoutTime') ? $this->lockoutTime : 60; } + + /** + * Fire an event when a lockout occurs. + * + * @param \Illuminate\Http\Request $request + * @return void + */ + protected function fireLockoutEvent(Request $request) + { + event(new Lockout($request)); + } }
false
Other
laravel
framework
7e87c21dca063b21a49337c77e8e23b6a2b20da5.json
Return collection from the query builder
src/Illuminate/Database/Eloquent/Builder.php
@@ -272,7 +272,7 @@ public function chunk($count, callable $callback) { $results = $this->forPage($page = 1, $count)->get(); - while (count($results) > 0) { + while (! $results->isEmpty()) { // On each chunk result set, we will pass them to the callback and then let the // developer take care of everything within the callback, which allows us to // keep the memory low for spinning through large result sets for working. @@ -324,15 +324,13 @@ public function pluck($column, $key = null) // If the model has a mutator for the requested column, we will spin through // the results and mutate the values so that the mutated version of these // columns are returned as you would expect from these Eloquent models. - if ($this->model->hasGetMutator($column)) { - foreach ($results as $key => &$value) { - $fill = [$column => $value]; - - $value = $this->model->newFromBuilder($fill)->$column; - } + if (! $this->model->hasGetMutator($column)) { + return $results; } - return collect($results); + return $results->map(function ($value) use ($column) { + return $this->model->newFromBuilder([$column => $value])->$column; + }); } /** @@ -486,7 +484,7 @@ public function onDelete(Closure $callback) */ public function getModels($columns = ['*']) { - $results = $this->query->get($columns); + $results = $this->query->get($columns)->all(); $connection = $this->model->getConnectionName();
true
Other
laravel
framework
7e87c21dca063b21a49337c77e8e23b6a2b20da5.json
Return collection from the query builder
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -772,7 +772,7 @@ public function sync($ids, $detaching = true) // First we need to attach any of the associated models that are not currently // in this joining table. We'll spin through the given IDs, checking to see // if they exist in the array of current ones, and if not we will insert. - $current = $this->newPivotQuery()->pluck($this->otherKey); + $current = $this->newPivotQuery()->pluck($this->otherKey)->all(); $records = $this->formatSyncList($ids);
true
Other
laravel
framework
7e87c21dca063b21a49337c77e8e23b6a2b20da5.json
Return collection from the query builder
src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php
@@ -50,7 +50,7 @@ public function getRan() return $this->table() ->orderBy('batch', 'asc') ->orderBy('migration', 'asc') - ->pluck('migration'); + ->pluck('migration')->all(); } /** @@ -62,7 +62,7 @@ public function getLast() { $query = $this->table()->where('batch', $this->getLastBatchNumber()); - return $query->orderBy('migration', 'desc')->get(); + return $query->orderBy('migration', 'desc')->get()->all(); } /**
true
Other
laravel
framework
7e87c21dca063b21a49337c77e8e23b6a2b20da5.json
Return collection from the query builder
src/Illuminate/Database/Query/Builder.php
@@ -1421,20 +1421,18 @@ public function value($column) * Execute the query and get the first result. * * @param array $columns - * @return mixed|static + * @return \stdClass|array|null */ public function first($columns = ['*']) { - $results = $this->take(1)->get($columns); - - return count($results) > 0 ? reset($results) : null; + return $this->take(1)->get($columns)->first(); } /** * Execute the query as a "select" statement. * * @param array $columns - * @return array|static[] + * @return \Illuminate\Support\Collection */ public function get($columns = ['*']) { @@ -1448,7 +1446,7 @@ public function get($columns = ['*']) $this->columns = $original; - return $results; + return collect($results); } /** @@ -1518,7 +1516,7 @@ public function getCountForPagination($columns = ['*']) $this->aggregate = ['function' => 'count', 'columns' => $this->clearSelectAliases($columns)]; - $results = $this->get(); + $results = $this->get()->all(); $this->aggregate = null; @@ -1595,7 +1593,7 @@ public function chunk($count, callable $callback) { $results = $this->forPage($page = 1, $count)->get(); - while (count($results) > 0) { + while (! $results->isEmpty()) { // On each chunk result set, we will pass them to the callback and then let the // developer take care of everything within the callback, which allows us to // keep the memory low for spinning through large result sets for working. @@ -1640,7 +1638,7 @@ public function each(callable $callback, $count = 1000) * * @param string $column * @param string|null $key - * @return array + * @return \Illuminate\Support\Collection */ public function pluck($column, $key = null) { @@ -1649,8 +1647,7 @@ public function pluck($column, $key = null) // If the columns are qualified with a table or have an alias, we cannot use // those directly in the "pluck" operations since the results from the DB // are only keyed by the column itself. We'll strip the table out here. - return Arr::pluck( - $results, + return $results->pluck( $this->stripTableForPluck($column), $this->stripTableForPluck($key) ); @@ -1676,7 +1673,7 @@ protected function stripTableForPluck($column) */ public function implode($column, $glue = '') { - return implode($glue, $this->pluck($column)); + return $this->pluck($column)->implode($glue); } /** @@ -1802,7 +1799,7 @@ public function aggregate($function, $columns = ['*']) $this->bindings['select'] = $previousSelectBindings; - if (isset($results[0])) { + if (! $results->isEmpty()) { $result = array_change_key_case((array) $results[0]); return $result['aggregate'];
true
Other
laravel
framework
7e87c21dca063b21a49337c77e8e23b6a2b20da5.json
Return collection from the query builder
src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php
@@ -65,7 +65,7 @@ public function log($connection, $queue, $payload) */ public function all() { - return $this->getTable()->orderBy('id', 'desc')->get(); + return $this->getTable()->orderBy('id', 'desc')->get()->all(); } /**
true
Other
laravel
framework
36618f99b3b022806c587328d6122768afadb10d.json
Implement retriesLeft correctly
src/Illuminate/Cache/RateLimiter.php
@@ -72,6 +72,24 @@ public function attempts($key) return $this->cache->get($key, 0); } + /** + * Get the number of retries left for the given key. + * + * @param string $key + * @param int $maxAttempts + * @return int + */ + public function retriesLeft($key, $maxAttempts) + { + $attempts = $this->attempts($key); + + if ($attempts == 0) { + return $maxAttempts; + } + + return $maxAttempts - $attempts + 1; + } + /** * Clear the hits and lockout for the given key. *
true
Other
laravel
framework
36618f99b3b022806c587328d6122768afadb10d.json
Implement retriesLeft correctly
src/Illuminate/Foundation/Auth/ThrottlesLogins.php
@@ -43,11 +43,10 @@ protected function incrementLoginAttempts(Request $request) */ protected function retriesLeft(Request $request) { - $attempts = app(RateLimiter::class)->attempts( - $this->getThrottleKey($request) + return app(RateLimiter::class)->retriesLeft( + $this->getThrottleKey($request), + $this->maxLoginAttempts() ); - - return $this->maxLoginAttempts() - $attempts + 1; } /**
true
Other
laravel
framework
1ca85ae11919520859cde39375d50690614633a1.json
Prefer an early return
src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
@@ -426,19 +426,19 @@ protected function seeCookie($cookieName, $value = null, $encrypted = true) $this->assertTrue($exist, "Cookie [{$cookieName}] not present on response."); - if ($exist && ! is_null($value)) { - $cookieValue = $cookie->getValue(); + if (! $exist || is_null($value)) { + return $this; + } - $actual = $encrypted - ? $this->app['encrypter']->decrypt($cookieValue) : $cookieValue; + $cookieValue = $cookie->getValue(); - $this->assertEquals( - $actual, $value, - "Cookie [{$cookieName}] was found, but value [{$actual}] does not match [{$value}]." - ); - } + $actual = $encrypted + ? $this->app['encrypter']->decrypt($cookieValue) : $cookieValue; - return $this; + return $this->assertEquals( + $actual, $value, + "Cookie [{$cookieName}] was found, but value [{$actual}] does not match [{$value}]." + ); } /**
false
Other
laravel
framework
eefb41ef2c2606b2e88adf33e7e43a135346be8c.json
trigger an event when authentication is throttled
src/Illuminate/Auth/Events/Lockout.php
@@ -0,0 +1,26 @@ +<?php + +namespace Illuminate\Auth\Events; + +use Illuminate\Http\Request; + +class Lockout +{ + /** + * The throttled request. + * + * @var \Illuminate\Http\Request + */ + public $request; + + /** + * Create a new event instance. + * + * @param \Illuminate\Http\Request $request + * @return void + */ + public function __construct(Request $request) + { + $this->request = $request; + } +}
true
Other
laravel
framework
eefb41ef2c2606b2e88adf33e7e43a135346be8c.json
trigger an event when authentication is throttled
src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
@@ -66,6 +66,8 @@ public function login(Request $request) $throttles = $this->isUsingThrottlesLoginsTrait(); if ($throttles && $this->hasTooManyLoginAttempts($request)) { + $this->fireLockoutEvent($request); + return $this->sendLockoutResponse($request); }
true
Other
laravel
framework
eefb41ef2c2606b2e88adf33e7e43a135346be8c.json
trigger an event when authentication is throttled
src/Illuminate/Foundation/Auth/ThrottlesLogins.php
@@ -4,6 +4,7 @@ use Illuminate\Http\Request; use Illuminate\Cache\RateLimiter; +use Illuminate\Auth\Events\Lockout; use Illuminate\Support\Facades\Lang; trait ThrottlesLogins @@ -95,6 +96,17 @@ protected function clearLoginAttempts(Request $request) ); } + /** + * Fire an event when a lockout occurs. + * + * @param \Illuminate\Http\Request $request + * @return void + */ + protected function fireLockoutEvent(Request $request) + { + event(new Lockout($request)); + } + /** * Get the throttle key for the given request. *
true
Other
laravel
framework
318a04646baea45d8d3d2e52fbdf08339d56061e.json
Improve behavior of MySQL flag, add config
src/Illuminate/Database/Connectors/MySqlConnector.php
@@ -2,6 +2,8 @@ namespace Illuminate\Database\Connectors; +use PDO; + class MySqlConnector extends Connector implements ConnectorInterface { /** @@ -46,16 +48,7 @@ public function connect(array $config) )->execute(); } - // If the "strict" option has been configured for the connection we will setup - // strict mode for this session. Strict mode enforces some extra rules when - // using the MySQL database system and is a quicker way to enforce them. - if (isset($config['strict'])) { - if ($config['strict']) { - $connection->prepare("set session sql_mode='STRICT_ALL_TABLES'")->execute(); - } else { - $connection->prepare("set session sql_mode=''")->execute(); - } - } + $this->setModes($connection, $config); return $connection; } @@ -109,4 +102,25 @@ protected function getHostDsn(array $config) ? "mysql:host={$host};port={$port};dbname={$database}" : "mysql:host={$host};dbname={$database}"; } + + /** + * Set the modes for the connection. + * + * @param \PDO $connection + * @param array $config + * @return void + */ + protected function setModes(PDO $connection, array $config) + { + if (isset($config['modes'])) { + $modes = implode(',', $config['modes']); + $connection->prepare("set session sql_mode='".$modes."'")->execute(); + } elseif (isset($config['strict'])) { + if ($config['strict']) { + $connection->prepare("set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'")->execute(); + } else { + $connection->prepare("set session sql_mode='NO_ENGINE_SUBSTITUTION'")->execute(); + } + } + } }
true
Other
laravel
framework
318a04646baea45d8d3d2e52fbdf08339d56061e.json
Improve behavior of MySQL flag, add config
tests/Database/DatabaseConnectorTest.php
@@ -22,7 +22,7 @@ public function testOptionResolution() public function testMySqlConnectCallsCreateConnectionWithProperArguments($dsn, $config) { $connector = $this->getMock('Illuminate\Database\Connectors\MySqlConnector', ['createConnection', 'getOptions']); - $connection = m::mock('stdClass'); + $connection = m::mock('PDO'); $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)); $connection->shouldReceive('prepare')->once()->with('set names \'utf8\' collate \'utf8_unicode_ci\'')->andReturn($connection);
true
Other
laravel
framework
9332c6003d47dee946b180360668fdfd1dd36f0c.json
Put docblock @return parameters in correct order
src/Illuminate/Routing/Route.php
@@ -261,7 +261,7 @@ protected function extractOptionalParameters() * Get or set the middlewares attached to the route. * * @param array|string|null $middleware - * @return array|$this + * @return $this|array */ public function middleware($middleware = null) {
false
Other
laravel
framework
83b7dfd3fa3106b53f85ac4483d33ba2abdc4a34.json
Fix fluent interface on Route->middleware() Fix for `5.1` LTE. This is still present in `5.2` and `master`. PhpStorm doesn't correctly resolve the fluent interface following the call to `middleware()`: ```php Route::get('/{subs?}', [function () { return view('layout'); }]) ->middleware('auth') ->where(['subs' => '.*']) // Method 'where' not found in class array ->name('dashboard'); ``` cc: @danielstqry
src/Illuminate/Routing/Route.php
@@ -261,7 +261,7 @@ protected function extractOptionalParameters() * Get or set the middlewares attached to the route. * * @param array|string|null $middleware - * @return array + * @return array|$this */ public function middleware($middleware = null) {
false
Other
laravel
framework
b70228b0dbd11a862a3cb6e29bac9c61ed9d4eef.json
Fix typo in Builder each()
src/Illuminate/Database/Query/Builder.php
@@ -1628,7 +1628,7 @@ public function each(callable $callback, $count = 1000) return $this->chunk($count, function ($results) use ($callback) { foreach ($results as $key => $value) { - if ($callback($item, $key) === false) { + if ($callback($value, $key) === false) { return false; } }
false
Other
laravel
framework
c1b2a7b8887a3e28096ea3d4b36d8861a050e1f9.json
Apply global scopes on update/delete
src/Illuminate/Database/Eloquent/Builder.php
@@ -407,7 +407,7 @@ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'p */ public function update(array $values) { - return $this->query->update($this->addUpdatedAtColumn($values)); + return $this->toBase()->update($this->addUpdatedAtColumn($values)); } /** @@ -468,7 +468,7 @@ public function delete() return call_user_func($this->onDelete, $this); } - return $this->query->delete(); + return $this->toBase()->delete(); } /**
false
Other
laravel
framework
c251ba15b3c9f8d301c5f9d0a34182e961cb96a9.json
create tests for BS4 pagination presenters
tests/Pagination/PaginationPaginatorTest.php
@@ -5,6 +5,7 @@ use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator as Paginator; use Illuminate\Pagination\BootstrapThreePresenter as BootstrapPresenter; +use Illuminate\Pagination\BootstrapFourPresenter as BootstrapFourPresenter; class PaginationPaginatorTest extends PHPUnit_Framework_TestCase { @@ -105,6 +106,18 @@ public function testBootstrapPresenterCanGeneratorLinksForSlider() $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/slider.html')), $presenter->render()); } + public function testBootstrapFourPresenterCanGeneratorLinksForSlider() + { + $array = []; + for ($i = 1; $i <= 13; $i++) { + $array[$i] = 'item'.$i; + } + $p = new LengthAwarePaginator($array, count($array), 1, 7); + $presenter = new BootstrapFourPresenter($p); + + $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/slider_bs4.html')), $presenter->render()); + } + public function testCustomPresenter() { $p = new LengthAwarePaginator([], 1, 1, 1); @@ -133,6 +146,18 @@ public function testBootstrapPresenterCanGeneratorLinksForTooCloseToBeginning() $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/beginning.html')), $presenter->render()); } + public function testBootstrapFourPresenterCanGeneratorLinksForTooCloseToBeginning() + { + $array = []; + for ($i = 1; $i <= 13; $i++) { + $array[$i] = 'item'.$i; + } + $p = new LengthAwarePaginator($array, count($array), 1, 2); + $presenter = new BootstrapFourPresenter($p); + + $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/beginning_bs4.html')), $presenter->render()); + } + public function testBootstrapPresenterCanGeneratorLinksForTooCloseToEnding() { $array = []; @@ -145,6 +170,18 @@ public function testBootstrapPresenterCanGeneratorLinksForTooCloseToEnding() $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/ending.html')), $presenter->render()); } + public function testBootstrapFourPresenterCanGeneratorLinksForTooCloseToEnding() + { + $array = []; + for ($i = 1; $i <= 13; $i++) { + $array[$i] = 'item'.$i; + } + $p = new LengthAwarePaginator($array, count($array), 1, 12); + $presenter = new BootstrapFourPresenter($p); + + $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/ending_bs4.html')), $presenter->render()); + } + public function testBootstrapPresenterCanGeneratorLinksForWhenOnLastPage() { $array = []; @@ -157,6 +194,18 @@ public function testBootstrapPresenterCanGeneratorLinksForWhenOnLastPage() $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/last_page.html')), $presenter->render()); } + public function testBootstrapFourPresenterCanGeneratorLinksForWhenOnLastPage() + { + $array = []; + for ($i = 1; $i <= 13; $i++) { + $array[$i] = 'item'.$i; + } + $p = new LengthAwarePaginator($array, count($array), 1, 13); + $presenter = new BootstrapFourPresenter($p); + + $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/last_page_bs4.html')), $presenter->render()); + } + public function testBootstrapPresenterCanGeneratorLinksForWhenOnFirstPage() { $array = []; @@ -169,6 +218,18 @@ public function testBootstrapPresenterCanGeneratorLinksForWhenOnFirstPage() $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/first_page.html')), $presenter->render()); } + public function testBootstrapFourPresenterCanGeneratorLinksForWhenOnFirstPage() + { + $array = []; + for ($i = 1; $i <= 13; $i++) { + $array[$i] = 'item'.$i; + } + $p = new LengthAwarePaginator($array, count($array), 1, 1); + $presenter = new BootstrapFourPresenter($p); + + $this->assertEquals(trim(file_get_contents(__DIR__.'/fixtures/first_page_bs4.html')), $presenter->render()); + } + public function testSimplePaginatorReturnsRelevantContextInformation() { $p = new Paginator($array = ['item3', 'item4', 'item5'], 2, 2);
true
Other
laravel
framework
c251ba15b3c9f8d301c5f9d0a34182e961cb96a9.json
create tests for BS4 pagination presenters
tests/Pagination/fixtures/beginning_bs4.html
@@ -0,0 +1 @@ +<ul class="pagination"><li class="page-item"><a class="page-link" href="/?page=1" rel="prev">&laquo;</a></li> <li class="page-item"><a class="page-link" href="/?page=1">1</a></li><li class="page-item active"><a class="page-link">2</a></li><li class="page-item"><a class="page-link" href="/?page=3">3</a></li><li class="page-item"><a class="page-link" href="/?page=4">4</a></li><li class="page-item"><a class="page-link" href="/?page=5">5</a></li><li class="page-item"><a class="page-link" href="/?page=6">6</a></li><li class="page-item"><a class="page-link" href="/?page=7">7</a></li><li class="page-item"><a class="page-link" href="/?page=8">8</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/?page=12">12</a></li><li class="page-item"><a class="page-link" href="/?page=13">13</a></li> <li class="page-item"><a class="page-link" href="/?page=3" rel="next">&raquo;</a></li></ul>
true
Other
laravel
framework
c251ba15b3c9f8d301c5f9d0a34182e961cb96a9.json
create tests for BS4 pagination presenters
tests/Pagination/fixtures/ending_bs4.html
@@ -0,0 +1 @@ +<ul class="pagination"><li class="page-item"><a class="page-link" href="/?page=11" rel="prev">&laquo;</a></li> <li class="page-item"><a class="page-link" href="/?page=1">1</a></li><li class="page-item"><a class="page-link" href="/?page=2">2</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/?page=5">5</a></li><li class="page-item"><a class="page-link" href="/?page=6">6</a></li><li class="page-item"><a class="page-link" href="/?page=7">7</a></li><li class="page-item"><a class="page-link" href="/?page=8">8</a></li><li class="page-item"><a class="page-link" href="/?page=9">9</a></li><li class="page-item"><a class="page-link" href="/?page=10">10</a></li><li class="page-item"><a class="page-link" href="/?page=11">11</a></li><li class="page-item active"><a class="page-link">12</a></li><li class="page-item"><a class="page-link" href="/?page=13">13</a></li> <li class="page-item"><a class="page-link" href="/?page=13" rel="next">&raquo;</a></li></ul>
true
Other
laravel
framework
c251ba15b3c9f8d301c5f9d0a34182e961cb96a9.json
create tests for BS4 pagination presenters
tests/Pagination/fixtures/first_page_bs4.html
@@ -0,0 +1 @@ +<ul class="pagination"><li class="page-item disabled"><a class="page-link">&laquo;</a></li> <li class="page-item active"><a class="page-link">1</a></li><li class="page-item"><a class="page-link" href="/?page=2">2</a></li><li class="page-item"><a class="page-link" href="/?page=3">3</a></li><li class="page-item"><a class="page-link" href="/?page=4">4</a></li><li class="page-item"><a class="page-link" href="/?page=5">5</a></li><li class="page-item"><a class="page-link" href="/?page=6">6</a></li><li class="page-item"><a class="page-link" href="/?page=7">7</a></li><li class="page-item"><a class="page-link" href="/?page=8">8</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/?page=12">12</a></li><li class="page-item"><a class="page-link" href="/?page=13">13</a></li> <li class="page-item"><a class="page-link" href="/?page=2" rel="next">&raquo;</a></li></ul>
true
Other
laravel
framework
c251ba15b3c9f8d301c5f9d0a34182e961cb96a9.json
create tests for BS4 pagination presenters
tests/Pagination/fixtures/last_page_bs4.html
@@ -0,0 +1 @@ +<ul class="pagination"><li class="page-item"><a class="page-link" href="/?page=12" rel="prev">&laquo;</a></li> <li class="page-item"><a class="page-link" href="/?page=1">1</a></li><li class="page-item"><a class="page-link" href="/?page=2">2</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/?page=5">5</a></li><li class="page-item"><a class="page-link" href="/?page=6">6</a></li><li class="page-item"><a class="page-link" href="/?page=7">7</a></li><li class="page-item"><a class="page-link" href="/?page=8">8</a></li><li class="page-item"><a class="page-link" href="/?page=9">9</a></li><li class="page-item"><a class="page-link" href="/?page=10">10</a></li><li class="page-item"><a class="page-link" href="/?page=11">11</a></li><li class="page-item"><a class="page-link" href="/?page=12">12</a></li><li class="page-item active"><a class="page-link">13</a></li> <li class="page-item disabled"><a class="page-link">&raquo;</a></li></ul>
true
Other
laravel
framework
c251ba15b3c9f8d301c5f9d0a34182e961cb96a9.json
create tests for BS4 pagination presenters
tests/Pagination/fixtures/slider_bs4.html
@@ -0,0 +1 @@ +<ul class="pagination"><li class="page-item"><a class="page-link" href="/?page=6" rel="prev">&laquo;</a></li> <li class="page-item"><a class="page-link" href="/?page=1">1</a></li><li class="page-item"><a class="page-link" href="/?page=2">2</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/?page=4">4</a></li><li class="page-item"><a class="page-link" href="/?page=5">5</a></li><li class="page-item"><a class="page-link" href="/?page=6">6</a></li><li class="page-item active"><a class="page-link">7</a></li><li class="page-item"><a class="page-link" href="/?page=8">8</a></li><li class="page-item"><a class="page-link" href="/?page=9">9</a></li><li class="page-item"><a class="page-link" href="/?page=10">10</a></li><li class="page-item disabled"><a class="page-link">...</a></li><li class="page-item"><a class="page-link" href="/?page=12">12</a></li><li class="page-item"><a class="page-link" href="/?page=13">13</a></li> <li class="page-item"><a class="page-link" href="/?page=8" rel="next">&raquo;</a></li></ul>
true
Other
laravel
framework
05e96ce203f403f99da5634fc7c155ce5208a7d9.json
remove tab in realtion.php
src/Illuminate/Database/Eloquent/Relations/Relation.php
@@ -336,7 +336,7 @@ public function __call($method, $parameters) return $result; } - + /** * Force a clone of the underlying query builder when cloning. *
false
Other
laravel
framework
d25b456d2767bc73f1c6c571daff28d2f50f3f30.json
Add lots of tests for RouteCollection
tests/Routing/RouteCollectionTest.php
@@ -0,0 +1,182 @@ +<?php + +use Illuminate\Routing\Route; +use Illuminate\Routing\RouteCollection; + +class RouteCollectionTest extends PHPUnit_Framework_TestCase +{ + /** + * @var \Illuminate\Routing\RouteCollection + */ + protected $routeCollection; + + public function setUp() + { + parent::setUp(); + + $this->routeCollection = new RouteCollection(); + } + + public function testRouteCollectionCanBeConstructed() + { + $this->assertInstanceOf(RouteCollection::class, $this->routeCollection); + } + + public function testRouteCollectionCanAddRoute() + { + $this->routeCollection->add(new Route('GET', 'foo', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ])); + $this->assertCount(1, $this->routeCollection); + } + + public function testRouteCollectionAddReturnsTheRoute() + { + $outputRoute = $this->routeCollection->add($inputRoute = new Route('GET', 'foo', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ])); + $this->assertInstanceOf(Route::class, $outputRoute); + $this->assertEquals($inputRoute, $outputRoute); + } + + public function testRouteCollectionAddRouteChangesCount() + { + $this->routeCollection->add(new Route('GET', 'foo', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ])); + $this->assertSame(1, $this->routeCollection->count()); + } + + public function testRouteCollectionIsCountable() + { + $this->routeCollection->add(new Route('GET', 'foo', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ])); + $this->assertCount(1, $this->routeCollection); + } + + public function testRouteCollectionCanRetrieveByName() + { + $this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', [ + 'uses' => 'FooController@index', + 'as' => 'route_name', + ])); + + $this->assertSame('route_name', $routeIndex->getName()); + $this->assertSame('route_name', $this->routeCollection->getByName('route_name')->getName()); + $this->assertEquals($routeIndex, $this->routeCollection->getByName('route_name')); + } + + public function testRouteCollectionCanRetrieveByAction() + { + $this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', $action = [ + 'uses' => 'FooController@index', + 'as' => 'route_name', + ])); + + $this->assertSame($action, $routeIndex->getAction()); + } + + public function testRouteCollectionCanGetIterator() + { + $this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ])); + $this->assertEquals([$routeIndex], $this->routeCollection->getRoutes()); + } + + public function testRouteCollectionCanGetIteratorWhenEMpty() + { + $this->assertCount(0, $this->routeCollection); + $this->assertInstanceOf(ArrayIterator::class, $this->routeCollection->getIterator()); + } + + public function testRouteCollectionCanGetIteratorWhenRouteAreAdded() + { + $this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ])); + $this->assertCount(1, $this->routeCollection); + + $this->routeCollection->add($routeShow = new Route('GET', 'bar/show', [ + 'uses' => 'BarController@show', + 'as' => 'bar_show', + ])); + $this->assertCount(2, $this->routeCollection); + + $this->assertInstanceOf(ArrayIterator::class, $this->routeCollection->getIterator()); + } + + public function testRouteCollectionCanHandleSameRoute() + { + $routeIndex = new Route('GET', 'foo/index', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ]); + + $this->routeCollection->add($routeIndex); + $this->assertCount(1, $this->routeCollection); + + // Add exactly the same route + $this->routeCollection->add($routeIndex); + $this->assertCount(1, $this->routeCollection); + + // Add a non-existing route + $this->routeCollection->add(new Route('GET', 'bar/show', [ + 'uses' => 'BarController@show', + 'as' => 'bar_show', + ])); + $this->assertCount(2, $this->routeCollection); + } + + public function testRouteCollectionCanRefreshNameLookups() + { + $routeIndex = new Route('GET', 'foo/index', [ + 'uses' => 'FooController@index', + ]); + + // The name of the route is not yet set. It will be while adding if to the RouteCollection. + $this->assertNull($routeIndex->getName()); + + // The route name is set by calling \Illuminate\Routing\Route::name() + $this->routeCollection->add($routeIndex)->name('route_name'); + + // No route is found. This is normal, as no refresh as been done. + $this->assertNull($this->routeCollection->getByName('route_name')); + + // After the refresh, the name will be properly set to the route. + $this->routeCollection->refreshNameLookups(); + $this->assertEquals($routeIndex, $this->routeCollection->getByName('route_name')); + } + + public function testRouteCollectionCanGetAllRoutes() + { + $this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', [ + 'uses' => 'FooController@index', + 'as' => 'foo_index', + ])); + + $this->routeCollection->add($routeShow = new Route('GET', 'foo/show', [ + 'uses' => 'FooController@show', + 'as' => 'foo_show', + ])); + + $this->routeCollection->add($routeNew = new Route('POST', 'bar', [ + 'uses' => 'BarController@create', + 'as' => 'bar_create', + ])); + + $allRoutes = [ + $routeIndex, + $routeShow, + $routeNew, + ]; + $this->assertEquals($allRoutes, $this->routeCollection->getRoutes()); + } +}
false
Other
laravel
framework
eb8ab1a0e461488fa33cc1747324f053b327957c.json
add wildcard support to seeJsonStructure
src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
@@ -260,7 +260,13 @@ public function seeJsonStructure(array $structure = null, $responseData = null) } foreach ($structure as $key => $value) { - if (is_array($value)) { + if (is_array($value) && $key === '*') { + $this->assertInternalType('array', $responseData); + + foreach ($responseData as $responseDataItem) { + $this->seeJsonStructure($structure['*'], $responseDataItem); + } + } elseif (is_array($value)) { $this->assertArrayHasKey($key, $responseData); $this->seeJsonStructure($structure[$key], $responseData[$key]); } else {
true
Other
laravel
framework
eb8ab1a0e461488fa33cc1747324f053b327957c.json
add wildcard support to seeJsonStructure
tests/Foundation/FoundationCrawlerTraitJsonTest.php
@@ -0,0 +1,65 @@ +<?php + +use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests; + +class FoundationCrawlerTraitJsonTest extends PHPUnit_Framework_TestCase +{ + use MakesHttpRequests; + + public function testSeeJsonStructure() + { + $this->response = new \Illuminate\Http\Response(new JsonSerializableMixedResourcesStub); + + // At root + $this->seeJsonStructure(['foo']); + + // Nested + $this->seeJsonStructure(['foobar' => ['foobar_foo', 'foobar_bar']]); + + // Wildcard (repeating structure) + $this->seeJsonStructure(['bars' => ['*' => ['bar', 'foo']]]); + + // Nested after wildcard + $this->seeJsonStructure(['baz' => ['*' => ['foo', 'bar' => ['foo', 'bar']]]]); + + // Wildcard (repeating structure) at root + $this->response = new \Illuminate\Http\Response(new JsonSerializableSingleResourceStub); + $this->seeJsonStructure(['*' => ['foo', 'bar', 'foobar']]); + } +} + +class JsonSerializableMixedResourcesStub implements JsonSerializable +{ + public function jsonSerialize() + { + return [ + 'foo' => 'bar', + 'foobar' => [ + 'foobar_foo' => 'foo', + 'foobar_bar' => 'bar', + ], + 'bars' => [ + ['bar' => 'foo 0', 'foo' => 'bar 0'], + ['bar' => 'foo 1', 'foo' => 'bar 1'], + ['bar' => 'foo 2', 'foo' => 'bar 2'], + ], + 'baz' => [ + ['foo' => 'bar 0', 'bar' => ['foo' => 'bar 0', 'bar' => 'foo 0']], + ['foo' => 'bar 1', 'bar' => ['foo' => 'bar 1', 'bar' => 'foo 1']], + ], + ]; + } +} + +class JsonSerializableSingleResourceStub implements JsonSerializable +{ + public function jsonSerialize() + { + return [ + ['foo' => 'foo 0', 'bar' => 'bar 0', 'foobar' => 'foobar 0'], + ['foo' => 'foo 1', 'bar' => 'bar 1', 'foobar' => 'foobar 1'], + ['foo' => 'foo 2', 'bar' => 'bar 2', 'foobar' => 'foobar 2'], + ['foo' => 'foo 3', 'bar' => 'bar 3', 'foobar' => 'foobar 3'], + ]; + } +}
true
Other
laravel
framework
9440d9f9bbf5f81a4d34b6c4bb8eaabf4a5670e4.json
Add settings for *.md files
.editorconfig
@@ -8,6 +8,9 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true +[*.md] +trim_trailing_whitespace = false + [*.yml] indent_style = space indent_size = 2
false
Other
laravel
framework
cfbc233215fb0800f4c0104bb7f748605e95d8f1.json
Fix phpdoc return type
src/Illuminate/Mail/Mailer.php
@@ -425,7 +425,7 @@ protected function createMessage() * * @param string $view * @param array $data - * @return \Illuminate\View\View + * @return string */ protected function getView($view, $data) {
false
Other
laravel
framework
1d8463250f8a44868d19df77aa701df8f39f1fe7.json
Add doesntExpectJobs method Now MockApplicationServices provides methods for testing both expected and unexpected events and jobs by mocking the underlying dispatchers. The trait has been refactored to share the common functionalities.
src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php
@@ -14,6 +14,13 @@ trait MocksApplicationServices */ protected $firedEvents = []; + /** + * All of the dispatched jobs. + * + * @var array + */ + protected $dispatchedJobs = []; + /** * Specify a list of events that should be fired for the given operation. * @@ -94,53 +101,123 @@ protected function withoutEvents() */ protected function getFiredEvents(array $events) { - return array_filter($events, function ($event) { - return $this->wasFired($event); - }); + return $this->getDispatched($events, $this->firedEvents); } /** - * Check if the given event is fired. + * Specify a list of jobs that should be dispatched for the given operation. * - * @param object|string $event - * @return bool + * These jobs will be mocked, so that handlers will not actually be executed. + * + * @param array|string $jobs + * @return $this */ - protected function wasFired($event) + protected function expectsJobs($jobs) { - foreach ($this->firedEvents as $called) { - if ((is_string($called) && $called === $event) || - (is_string($called) && is_subclass_of($called, $event)) || - (is_object($called) && $called instanceof $event)) { - return true; + $jobs = is_array($jobs) ? $jobs : func_get_args(); + + $this->withoutJobs(); + + $this->beforeApplicationDestroyed(function () use ($jobs) { + $dispatched = $this->getDispatchedJobs($jobs); + + if ($jobsNotDispatched = array_diff($jobs, $dispatched)) { + throw new Exception( + 'These expected jobs were not dispatched: ['.implode(', ', $jobsNotDispatched).']' + ); } - } + }); - return false; + return $this; } /** - * Specify a list of jobs that should be dispatched for the given operation. + * Specify a list of jobs that should not be dispatched for the given operation. * * These jobs will be mocked, so that handlers will not actually be executed. * * @param array|string $jobs * @return $this */ - protected function expectsJobs($jobs) + protected function doesntExpectJobs($jobs) { $jobs = is_array($jobs) ? $jobs : func_get_args(); - $mock = Mockery::mock('Illuminate\Bus\Dispatcher[dispatch]', [$this->app]); + $this->withoutJobs(); - foreach ($jobs as $job) { - $mock->shouldReceive('dispatch')->atLeast()->once() - ->with(Mockery::type($job)); - } + $this->beforeApplicationDestroyed(function () use ($jobs) { + if ($dispatched = $this->getDispatchedJobs($jobs)) { + throw new Exception( + 'These unexpected jobs were dispatched: ['.implode(', ', $dispatched).']' + ); + } + }); + + return $this; + } + + /** + * Mock the job dispatcher so all jobs are silenced and collected. + * + * @return $this + */ + protected function withoutJobs() + { + $mock = Mockery::mock('Illuminate\Contracts\Bus\Dispatcher'); + + $mock->shouldReceive('dispatch')->andReturnUsing(function ($dispatched) { + $this->dispatchedJobs[] = $dispatched; + }); $this->app->instance( 'Illuminate\Contracts\Bus\Dispatcher', $mock ); return $this; } + + /** + * Filter the given jobs against the dispatched jobs. + * + * @param array $jobs + * @return array + */ + protected function getDispatchedJobs(array $jobs) + { + return $this->getDispatched($jobs, $this->dispatchedJobs); + } + + /** + * Filter the given classes against an array of dispatched classes. + * + * @param array $classes + * @param array $dispatched + * @return array + */ + protected function getDispatched(array $classes, array $dispatched) + { + return array_filter($classes, function ($class) use ($dispatched) { + return $this->wasDispatched($class, $dispatched); + }); + } + + /** + * Check if the given class exists in an array of dispatched classes. + * + * @param string $needle + * @param array $haystack + * @return bool + */ + protected function wasDispatched($needle, array $haystack) + { + foreach ($haystack as $dispatched) { + if ((is_string($dispatched) && $dispatched === $needle) || + (is_string($dispatched) && is_subclass_of($dispatched, $needle)) || + (is_object($dispatched) && $dispatched instanceof $needle)) { + return true; + } + } + + return false; + } }
false
Other
laravel
framework
8cb8de2609f00c7c4e335e932d88f432e4f047d2.json
fix auth helper
src/Illuminate/Foundation/helpers.php
@@ -100,7 +100,11 @@ function asset($path, $secure = null) */ function auth($guard = null) { - return app(AuthFactory::class)->guard($guard); + if (is_null($guard)) { + return app(AuthFactory::class); + } else { + return app(AuthFactory::class)->guard($guard); + } } }
false
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Auth/AuthManager.php
@@ -62,6 +62,8 @@ public function guard($name = null) * * @param string $name * @return \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard + * + * @throws \InvalidArgumentException */ protected function resolve($name) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Auth/Passwords/PasswordBrokerManager.php
@@ -55,6 +55,8 @@ public function broker($name = null) * * @param string $name * @return \Illuminate\Contracts\Auth\PasswordBroker + * + * @throws \InvalidArgumentException */ protected function resolve($name) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Console/Parser.php
@@ -14,6 +14,8 @@ class Parser * * @param string $expression * @return array + * + * @throws \InvalidArgumentException */ public static function parse($expression) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Console/Scheduling/CallbackEvent.php
@@ -28,6 +28,8 @@ class CallbackEvent extends Event * @param string $callback * @param array $parameters * @return void + * + * @throws \InvalidArgumentException */ public function __construct($callback, array $parameters = []) { @@ -82,6 +84,8 @@ protected function removeMutex() * Do not allow the event to overlap each other. * * @return $this + * + * @throws \LogicException */ public function withoutOverlapping() {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Container/Container.php
@@ -587,6 +587,8 @@ protected function addDependencyForCallParameter(ReflectionParameter $parameter, * @param array $parameters * @param string|null $defaultMethod * @return mixed + * + * @throws \InvalidArgumentException */ protected function callClass($target, array $parameters = [], $defaultMethod = null) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Database/Connection.php
@@ -463,7 +463,7 @@ public function prepareBindings(array $bindings) * @param \Closure $callback * @return mixed * - * @throws \Throwable + * @throws \Exception|\Throwable */ public function transaction(Closure $callback) { @@ -868,6 +868,8 @@ public function getReadPdo() * * @param \PDO|null $pdo * @return $this + * + * @throws \RuntimeException */ public function setPdo($pdo) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Database/Eloquent/FactoryBuilder.php
@@ -119,6 +119,8 @@ public function make(array $attributes = []) * * @param array $attributes * @return \Illuminate\Database\Eloquent\Model + * + * @throws \InvalidArgumentException */ protected function makeInstance(array $attributes = []) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Database/Eloquent/QueueEntityResolver.php
@@ -13,6 +13,8 @@ class QueueEntityResolver implements EntityResolverContract * @param string $type * @param mixed $id * @return mixed + * + * @throws \Illuminate\Contracts\Queue\EntityNotFoundException */ public function resolve($type, $id) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Database/Query/Builder.php
@@ -258,6 +258,8 @@ public function selectRaw($expression, array $bindings = []) * @param \Closure|\Illuminate\Database\Query\Builder|string $query * @param string $as * @return \Illuminate\Database\Query\Builder|static + * + * @throws \InvalidArgumentException */ public function selectSub($query, $as) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Database/Schema/Grammars/Grammar.php
@@ -277,6 +277,8 @@ protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $sch * @param \Illuminate\Support\Fluent $command * @param \Illuminate\Database\Connection $connection * @return array + * + * @throws \RuntimeException */ public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Database/SqlServerConnection.php
@@ -18,7 +18,7 @@ class SqlServerConnection extends Connection * @param \Closure $callback * @return mixed * - * @throws \Throwable + * @throws \Exception|\Throwable */ public function transaction(Closure $callback) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Encryption/EncryptionServiceProvider.php
@@ -11,6 +11,8 @@ class EncryptionServiceProvider extends ServiceProvider * Register the service provider. * * @return void + * + * @throws \RuntimeException */ public function register() {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Filesystem/FilesystemAdapter.php
@@ -318,6 +318,7 @@ protected function filterContentsByType($contents, $type) * * @param string|null $visibility * @return string|null + * * @throws \InvalidArgumentException */ protected function parseVisibility($visibility)
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Foundation/Http/FormRequest.php
@@ -89,6 +89,8 @@ protected function getValidatorInstance() * * @param \Illuminate\Contracts\Validation\Validator $validator * @return mixed + * + * @throws \Illuminate\Http\Exception\HttpResponseException */ protected function failedValidation(Validator $validator) { @@ -115,6 +117,8 @@ protected function passesAuthorization() * Handle a failed authorization attempt. * * @return mixed + * + * @throws \\Illuminate\Http\Exception\HttpResponseExceptio */ protected function failedAuthorization() {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php
@@ -150,6 +150,8 @@ protected function seePageIs($uri) * @param string $uri * @param string|null $message * @return void + * + * @throws \Illuminate\Foundation\Testing\HttpException */ protected function assertPageLoaded($uri, $message = null) { @@ -555,6 +557,8 @@ protected function isChecked($selector) * * @param string $name * @return $this + * + * @throws \InvalidArgumentException */ protected function click($name) { @@ -684,6 +688,8 @@ protected function fillForm($buttonText, $inputs = []) * * @param string|null $buttonText * @return \Symfony\Component\DomCrawler\Form + * + * @throws \InvalidArgumentException */ protected function getForm($buttonText = null) { @@ -723,6 +729,8 @@ protected function storeInput($element, $text) * * @param string $filter * @return void + * + * @throws \InvalidArgumentException */ protected function assertFilterProducesResults($filter) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php
@@ -14,6 +14,8 @@ trait MocksApplicationServices * * @param array|string $events * @return $this + * + * @throws \Exception */ public function expectsEvents($events) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Foundation/Testing/WithoutEvents.php
@@ -6,6 +6,9 @@ trait WithoutEvents { + /** + * @throws \Exception + */ public function disableEventsForAllTests() { if (method_exists($this, 'withoutEvents')) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Foundation/Testing/WithoutMiddleware.php
@@ -6,6 +6,9 @@ trait WithoutMiddleware { + /** + * @throws \Exception + */ public function disableMiddlewareForAllTests() { if (method_exists($this, 'withoutMiddleware')) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Foundation/Validation/ValidatesRequests.php
@@ -25,8 +25,6 @@ trait ValidatesRequests * @param array $messages * @param array $customAttributes * @return void - * - * @throws \Illuminate\Foundation\Validation\ValidationException */ public function validate(Request $request, array $rules, array $messages = [], array $customAttributes = []) {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Foundation/helpers.php
@@ -225,7 +225,7 @@ function csrf_field() * * @return string * - * @throws RuntimeException + * @throws \RuntimeException */ function csrf_token() {
true
Other
laravel
framework
99da7163fa53631b0449b11569fddc660e4806a7.json
Add missing throws docblocks.
src/Illuminate/Http/Request.php
@@ -810,6 +810,8 @@ public function route($param = null) * Get a unique fingerprint for the request / route / IP address. * * @return string + * + * @throws \RuntimeException */ public function fingerprint() {
true