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 | dd60e0dcc8059f700cc4c3c0679b1a13d0fae252.json | use method on app | src/Illuminate/Foundation/Support/Providers/EventServiceProvider.php | @@ -102,7 +102,7 @@ public function discoverEvents()
protected function discoverEventsWithin()
{
return [
- app_path('Listeners'),
+ $this->app->path('Listeners'),
];
}
} | false |
Other | laravel | framework | b9de404ce384611e477e4fc5d8fca2a24f2ad562.json | change cache path | src/Illuminate/Foundation/Application.php | @@ -953,7 +953,7 @@ public function eventsAreCached()
*/
public function getCachedEventsPath()
{
- return $_ENV['APP_EVENTS_CACHE'] ?? $this->storagePath().'/framework/cache/events.php';
+ return $_ENV['APP_EVENTS_CACHE'] ?? $this->bootstrapPath().'/cache/events.php';
}
/** | false |
Other | laravel | framework | fd53bf979f46e5c9841e07a44a49c7893be58f5c.json | Apply fixes from StyleCI (#28063) | src/Illuminate/Foundation/Console/EventCacheCommand.php | @@ -3,9 +3,6 @@
namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
-use Illuminate\Support\Collection;
-use Symfony\Component\Finder\Finder;
-use Symfony\Component\Finder\SplFileInfo;
use Illuminate\Foundation\Support\Providers\EventServiceProvider;
class EventCacheCommand extends Command | true |
Other | laravel | framework | fd53bf979f46e5c9841e07a44a49c7893be58f5c.json | Apply fixes from StyleCI (#28063) | src/Illuminate/Foundation/Console/EventClearCommand.php | @@ -2,7 +2,6 @@
namespace Illuminate\Foundation\Console;
-use RuntimeException;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
| true |
Other | laravel | framework | fd53bf979f46e5c9841e07a44a49c7893be58f5c.json | Apply fixes from StyleCI (#28063) | src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | @@ -25,9 +25,9 @@
use Illuminate\Foundation\Console\ViewCacheCommand;
use Illuminate\Foundation\Console\ViewClearCommand;
use Illuminate\Session\Console\SessionTableCommand;
+use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Foundation\Console\EventCacheCommand;
use Illuminate\Foundation\Console\EventClearCommand;
-use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Foundation\Console\PolicyMakeCommand;
use Illuminate\Foundation\Console\RouteCacheCommand;
use Illuminate\Foundation\Console\RouteClearCommand; | true |
Other | laravel | framework | 4aeb89235e594f3b942fc6c136b76de4de7d65cc.json | Fix missed type declaration from base class | src/Illuminate/Http/Request.php | @@ -269,7 +269,7 @@ public function secure()
/**
* Get the client IP address.
*
- * @return string
+ * @return string|null
*/
public function ip()
{ | false |
Other | laravel | framework | 5681fdb9aa1ae1a8958a0bc8f7ed5761f0bdab0d.json | Accept throwable in report helper typehint | src/Illuminate/Foundation/helpers.php | @@ -659,7 +659,7 @@ function redirect($to = null, $status = 302, $headers = [], $secure = null)
/**
* Report an exception.
*
- * @param \Exception $exception
+ * @param \Throwable $exception
* @return void
*/
function report($exception) | false |
Other | laravel | framework | 5df3cff39a6a3c1515f78ee6d8bb10f0368a3c1a.json | move test classes to their own files | tests/Database/DatabaseEloquentIntegrationTest.php | @@ -14,13 +14,13 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Pagination\LengthAwarePaginator;
-use Illuminate\Tests\Integration\Database\Post;
-use Illuminate\Tests\Integration\Database\User;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\ModelNotFoundException;
+use Illuminate\Tests\Integration\Database\Fixtures\Post;
+use Illuminate\Tests\Integration\Database\Fixtures\User;
use Illuminate\Pagination\AbstractPaginator as Paginator;
class DatabaseEloquentIntegrationTest extends TestCase | true |
Other | laravel | framework | 5df3cff39a6a3c1515f78ee6d8bb10f0368a3c1a.json | move test classes to their own files | tests/Integration/Database/EloquentCollectionFreshTest.php | @@ -3,8 +3,8 @@
namespace Illuminate\Tests\Integration\Database;
use Illuminate\Support\Facades\Schema;
-use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Tests\Integration\Database\Fixtures\User;
/**
* @group integration
@@ -35,8 +35,3 @@ public function test_eloquent_collection_fresh()
$this->assertEmpty($collection->fresh()->filter());
}
}
-
-class User extends Model
-{
- protected $guarded = [];
-} | true |
Other | laravel | framework | 5df3cff39a6a3c1515f78ee6d8bb10f0368a3c1a.json | move test classes to their own files | tests/Integration/Database/EloquentDeleteTest.php | @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Tests\Integration\Database\Fixtures\Post;
/**
* @group integration
@@ -80,11 +81,6 @@ public function testForceDeletedEventIsFired()
}
}
-class Post extends Model
-{
- public $table = 'posts';
-}
-
class Comment extends Model
{
public $table = 'comments'; | true |
Other | laravel | framework | 5df3cff39a6a3c1515f78ee6d8bb10f0368a3c1a.json | move test classes to their own files | tests/Integration/Database/Fixtures/Post.php | @@ -0,0 +1,10 @@
+<?php
+
+namespace Illuminate\Tests\Integration\Database\Fixtures;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Post extends Model
+{
+ public $table = 'posts';
+} | true |
Other | laravel | framework | 5df3cff39a6a3c1515f78ee6d8bb10f0368a3c1a.json | move test classes to their own files | tests/Integration/Database/Fixtures/User.php | @@ -0,0 +1,10 @@
+<?php
+
+namespace Illuminate\Tests\Integration\Database\Fixtures;
+
+use Illuminate\Database\Eloquent\Model;
+
+class User extends Model
+{
+ protected $guarded = [];
+} | true |
Other | laravel | framework | 9a4f743ad67073229d8fa1cec645c62d97265331.json | Remove unused methods | src/Illuminate/Database/Query/Builder.php | @@ -909,51 +909,6 @@ public function orWhereNotIn($column, $values)
return $this->whereNotIn($column, $values, 'or');
}
- /**
- * Add a where in with a sub-select to the query.
- *
- * @param string $column
- * @param \Closure $callback
- * @param string $boolean
- * @param bool $not
- * @return $this
- */
- protected function whereInSub($column, Closure $callback, $boolean, $not)
- {
- $type = $not ? 'NotInSub' : 'InSub';
-
- // To create the exists sub-select, we will actually create a query and call the
- // provided callback with the query so the developer may set any of the query
- // conditions they want for the in clause, then we'll put it in this array.
- call_user_func($callback, $query = $this->forSubQuery());
-
- $this->wheres[] = compact('type', 'column', 'query', 'boolean');
-
- $this->addBinding($query->getBindings(), 'where');
-
- return $this;
- }
-
- /**
- * Add an external sub-select to the query.
- *
- * @param string $column
- * @param \Illuminate\Database\Query\Builder|static $query
- * @param string $boolean
- * @param bool $not
- * @return $this
- */
- protected function whereInExistingQuery($column, $query, $boolean, $not)
- {
- $type = $not ? 'NotInSub' : 'InSub';
-
- $this->wheres[] = compact('type', 'column', 'query', 'boolean');
-
- $this->addBinding($query->getBindings(), 'where');
-
- return $this;
- }
-
/**
* Add a "where in raw" clause for integer values to the query.
* | true |
Other | laravel | framework | 9a4f743ad67073229d8fa1cec645c62d97265331.json | Remove unused methods | src/Illuminate/Database/Query/Grammars/Grammar.php | @@ -297,30 +297,6 @@ protected function whereNotInRaw(Builder $query, $where)
return '1 = 1';
}
- /**
- * Compile a where in sub-select clause.
- *
- * @param \Illuminate\Database\Query\Builder $query
- * @param array $where
- * @return string
- */
- protected function whereInSub(Builder $query, $where)
- {
- return $this->wrap($where['column']).' in ('.$this->compileSelect($where['query']).')';
- }
-
- /**
- * Compile a where not in sub-select clause.
- *
- * @param \Illuminate\Database\Query\Builder $query
- * @param array $where
- * @return string
- */
- protected function whereNotInSub(Builder $query, $where)
- {
- return $this->wrap($where['column']).' not in ('.$this->compileSelect($where['query']).')';
- }
-
/**
* Compile a "where in raw" clause.
* | true |
Other | laravel | framework | 70918d60c8923ffa03b29856a6ba4bf6b9575b0a.json | add forPageBeforeId method to query builder | src/Illuminate/Database/Query/Builder.php | @@ -1938,6 +1938,26 @@ public function forPage($page, $perPage = 15)
return $this->skip(($page - 1) * $perPage)->take($perPage);
}
+ /**
+ * Constrain the query to the previous "page" of results before a given ID.
+ *
+ * @param int $perPage
+ * @param int|null $lastId
+ * @param string $column
+ * @return \Illuminate\Database\Query\Builder|static
+ */
+ public function forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')
+ {
+ $this->orders = $this->removeExistingOrdersFor($column);
+
+ if (! is_null($lastId)) {
+ $this->where($column, '<', $lastId);
+ }
+
+ return $this->orderBy($column, 'desc')
+ ->take($perPage);
+ }
+
/**
* Constrain the query to the next "page" of results after a given ID.
* | true |
Other | laravel | framework | 70918d60c8923ffa03b29856a6ba4bf6b9575b0a.json | add forPageBeforeId method to query builder | tests/Database/DatabaseEloquentIntegrationTest.php | @@ -1090,6 +1090,20 @@ public function testGlobalScopeCanBeRemovedByOtherGlobalScope()
$this->assertNotNull(EloquentTestUserWithGlobalScopeRemovingOtherScope::find($user->id));
}
+ public function testForPageBeforeIdCorrectlyPaginates()
+ {
+ EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']);
+ EloquentTestUser::create(['id' => 2, 'email' => 'abigailotwell@gmail.com']);
+
+ $results = EloquentTestUser::forPageBeforeId(15, 2);
+ $this->assertInstanceOf(Builder::class, $results);
+ $this->assertEquals(1, $results->first()->id);
+
+ $results = EloquentTestUser::orderBy('id', 'desc')->forPageBeforeId(15, 2);
+ $this->assertInstanceOf(Builder::class, $results);
+ $this->assertEquals(1, $results->first()->id);
+ }
+
public function testForPageAfterIdCorrectlyPaginates()
{
EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']); | true |
Other | laravel | framework | 9ac88d7a938deeae09584ccb35f69dc6c37af153.json | Pass ReflectionException as previous exception | src/Illuminate/Container/Container.php | @@ -795,7 +795,7 @@ public function build($concrete)
try {
$reflector = new ReflectionClass($concrete);
} catch (ReflectionException $e) {
- throw new BindingResolutionException("Target class [$concrete] does not exist.");
+ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
}
// If the type is not instantiable, the developer is attempting to resolve | false |
Other | laravel | framework | 93abbf579b18b28b70ba18db7468c1dc500b60da.json | Fix unique validation without ignored column | src/Illuminate/Validation/Concerns/ValidatesAttributes.php | @@ -712,7 +712,9 @@ public function validateUnique($attribute, $value, $parameters)
if (isset($parameters[2])) {
[$idColumn, $id] = $this->getUniqueIds($parameters);
- $id = stripslashes($id);
+ if (! is_null($id)) {
+ $id = stripslashes($id);
+ }
}
// The presence verifier is responsible for counting rows within this store | true |
Other | laravel | framework | 93abbf579b18b28b70ba18db7468c1dc500b60da.json | Fix unique validation without ignored column | tests/Validation/ValidationValidatorTest.php | @@ -1889,7 +1889,9 @@ public function testValidateUnique()
$v = new Validator($trans, ['email' => 'foo'], ['email' => 'Unique:users,email_addr,NULL,id_col,foo,bar']);
$mock = m::mock(PresenceVerifierInterface::class);
$mock->shouldReceive('setConnection')->once()->with(null);
- $mock->shouldReceive('getCount')->once()->with('users', 'email_addr', 'foo', null, 'id_col', ['foo' => 'bar'])->andReturn(2);
+ $mock->shouldReceive('getCount')->once()->withArgs(function () {
+ return func_get_args() === ['users', 'email_addr', 'foo', null, 'id_col', ['foo' => 'bar']];
+ })->andReturn(2);
$v->setPresenceVerifier($mock);
$this->assertFalse($v->passes());
} | true |
Other | laravel | framework | 2edeb3ac8d840d26948df7f1a4362d11f0fb11a2.json | Add use Exception. | tests/Integration/Cache/RedisCacheLockTest.php | @@ -2,6 +2,7 @@
namespace Illuminate\Tests\Integration\Cache;
+use Exception;
use Illuminate\Support\Carbon;
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\Cache;
@@ -80,9 +81,9 @@ public function test_redis_locks_with_failed_block_callback_are_released()
try {
$firstLock->block(1, function () {
- throw new \Exception('failed');
+ throw new Exception('failed');
});
- } catch (\Exception $e) {
+ } catch (Exception $e) {
// Not testing the exception, just testing the lock
// is released regardless of the how the exception
// thrown by the callback was handled. | false |
Other | laravel | framework | 7a7cacc3fd02d7d4c596c1a0f8af3c5b7a2990b4.json | Use Null coalescing operator to refactor | src/Illuminate/Http/Concerns/InteractsWithInput.php | @@ -309,9 +309,7 @@ public function allFiles()
{
$files = $this->files->all();
- return $this->convertedFiles
- ? $this->convertedFiles
- : $this->convertedFiles = $this->convertUploadedFiles($files);
+ return $this->convertedFiles = $this->convertedFiles ?? $this->convertUploadedFiles($files);
}
/** | false |
Other | laravel | framework | 20b12e7e5ef705633cea1eb768eca9b9578c3f0c.json | Correct collection sort key test | tests/Support/SupportCollectionTest.php | @@ -983,14 +983,20 @@ public function testSortKeys()
{
$data = new Collection(['b' => 'dayle', 'a' => 'taylor']);
- $this->assertEquals(['a' => 'taylor', 'b' => 'dayle'], $data->sortKeys()->all());
+ $sortData = $data->sortKeys()->all();
+
+ $this->assertEquals(['a' => 'taylor', 'b' => 'dayle'], $sortData);
+ $this->assertEquals(['a', 'b'], array_keys($sortData));
}
public function testSortKeysDesc()
{
$data = new Collection(['a' => 'taylor', 'b' => 'dayle']);
- $this->assertEquals(['b' => 'dayle', 'a' => 'taylor'], $data->sortKeys()->all());
+ $sortData = $data->sortKeysDesc()->all();
+
+ $this->assertEquals(['b' => 'dayle', 'a' => 'taylor'], $sortData);
+ $this->assertEquals(['b', 'a'], array_keys($sortData));
}
public function testReverse() | false |
Other | laravel | framework | d460423467951c935ef00288d04fe3fd04b1794e.json | Support nullable unique indexes in SQL Server | src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php | @@ -105,10 +105,11 @@ public function compilePrimary(Blueprint $blueprint, Fluent $command)
*/
public function compileUnique(Blueprint $blueprint, Fluent $command)
{
- return sprintf('create unique index %s on %s (%s)',
+ return sprintf('create unique index %s on %s (%s) where "%s" is not null',
$this->wrap($command->index),
$this->wrapTable($blueprint),
- $this->columnize($command->columns)
+ $this->columnize($command->columns),
+ implode('" is not null and "', $command->columns)
);
}
| false |
Other | laravel | framework | da4d4a468eee174bd619b4a04aab57e419d10ff4.json | remove commas from values | src/Illuminate/Validation/Rules/Unique.php | @@ -35,8 +35,8 @@ public function ignore($id, $idColumn = null)
return $this->ignoreModel($id, $idColumn);
}
- $this->ignore = $id;
- $this->idColumn = $idColumn ?? 'id';
+ $this->ignore = str_replace(',', '', $id);
+ $this->idColumn = str_replace(',', '', $idColumn ?? 'id');
return $this;
}
@@ -50,8 +50,8 @@ public function ignore($id, $idColumn = null)
*/
public function ignoreModel($model, $idColumn = null)
{
- $this->idColumn = $idColumn ?? $model->getKeyName();
- $this->ignore = $model->{$this->idColumn};
+ $this->idColumn = str_replace(',', '', $idColumn ?? $model->getKeyName());
+ $this->ignore = str_replace(',', '', $model->{$this->idColumn});
return $this;
} | true |
Other | laravel | framework | da4d4a468eee174bd619b4a04aab57e419d10ff4.json | remove commas from values | tests/Validation/ValidationUniqueRuleTest.php | @@ -17,7 +17,7 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule = new Unique('table', 'column');
$rule->ignore('Taylor, Otwell', 'id_column');
$rule->where('foo', 'bar');
- $this->assertEquals('unique:table,column,"Taylor, Otwell",id_column,foo,bar', (string) $rule);
+ $this->assertEquals('unique:table,column,"Taylor Otwell",id_column,foo,bar', (string) $rule);
$rule = new Unique('table', 'column');
$rule->ignore(null, 'id_column'); | true |
Other | laravel | framework | 021b9158a1dd11bb32ee358de18eff06e883fa13.json | Avoid double path checking | src/Illuminate/Foundation/helpers.php | @@ -131,7 +131,7 @@ function app($abstract = null, array $parameters = [])
*/
function app_path($path = '')
{
- return app('path').($path ? DIRECTORY_SEPARATOR.$path : $path);
+ return app()->path($path);
}
}
@@ -190,7 +190,7 @@ function back($status = 302, $headers = [], $fallback = false)
*/
function base_path($path = '')
{
- return app()->basePath().($path ? DIRECTORY_SEPARATOR.$path : $path);
+ return app()->basePath($path);
}
}
@@ -293,7 +293,7 @@ function config($key = null, $default = null)
*/
function config_path($path = '')
{
- return app()->make('path.config').($path ? DIRECTORY_SEPARATOR.$path : $path);
+ return app()->configPath($path);
}
}
| false |
Other | laravel | framework | ad3bdfe0a7eeeacec18c1a6a73bcfe873e1c1edc.json | Fix updateOrInsert method for Query Builder
Now it correctly works with empty values array.
Before it created syntactically wrong SQL, now it simply returns 'true'. | src/Illuminate/Database/Query/Builder.php | @@ -2678,6 +2678,10 @@ public function updateOrInsert(array $attributes, array $values = [])
return $this->insert(array_merge($attributes, $values));
}
+ if (empty($values)) {
+ return true;
+ }
+
return (bool) $this->take(1)->update($values);
}
| true |
Other | laravel | framework | ad3bdfe0a7eeeacec18c1a6a73bcfe873e1c1edc.json | Fix updateOrInsert method for Query Builder
Now it correctly works with empty values array.
Before it created syntactically wrong SQL, now it simply returns 'true'. | tests/Database/DatabaseQueryBuilderTest.php | @@ -2003,6 +2003,34 @@ public function testUpdateOrInsertMethod()
$this->assertTrue($builder->updateOrInsert(['email' => 'foo'], ['name' => 'bar']));
}
+ public function testUpdateOrInsertMethodWorksWithEmptyUpdateValues()
+ {
+ $builder = m::mock(Builder::class.'[where,exists,insert]', [
+ m::mock(ConnectionInterface::class),
+ new Grammar,
+ m::mock(Processor::class),
+ ]);
+
+ $builder->shouldReceive('where')->once()->with(['email' => 'foo'])->andReturn(m::self());
+ $builder->shouldReceive('exists')->once()->andReturn(false);
+ $builder->shouldReceive('insert')->once()->with(['email' => 'foo', 'name' => 'bar'])->andReturn(true);
+
+ $this->assertTrue($builder->updateOrInsert(['email' => 'foo'], ['name' => 'bar']));
+
+ $builder = m::mock(Builder::class.'[where,exists,update]', [
+ m::mock(ConnectionInterface::class),
+ new Grammar,
+ m::mock(Processor::class),
+ ]);
+
+ $builder->shouldReceive('where')->once()->with(['email' => 'foo'])->andReturn(m::self());
+ $builder->shouldReceive('exists')->once()->andReturn(true);
+ $builder->shouldReceive('take')->andReturnSelf();
+ $builder->shouldNotReceive('update')->with([]);
+
+ $this->assertTrue($builder->updateOrInsert(['email' => 'foo']));
+ }
+
public function testDeleteMethod()
{
$builder = $this->getBuilder(); | true |
Other | laravel | framework | cd9a86b4c0dfea64b59b56effacaca49769c5ed6.json | Correct phpDoc code style | src/Illuminate/Foundation/Testing/TestResponse.php | @@ -633,8 +633,8 @@ public function assertJsonCount(int $count, $key = null)
/**
* Assert that the response has the given JSON validation errors for the given keys.
*
- * @param string|array $keys
- * @param string $responseKey
+ * @param string|array $keys
+ * @param string $responseKey
* @return $this
*/
public function assertJsonValidationErrors($keys, string $responseKey = 'errors')
@@ -664,8 +664,8 @@ public function assertJsonValidationErrors($keys, string $responseKey = 'errors'
/**
* Assert that the response has no JSON validation errors for the given keys.
*
- * @param string|array $keys
- * @param string $responseKey
+ * @param string|array $keys
+ * @param string $responseKey
* @return $this
*/
public function assertJsonMissingValidationErrors($keys = null, string $responseKey = 'errors') | false |
Other | laravel | framework | d0b1cfea1843bac76aabe55e3c3c35b727fd89bb.json | Add custom errors key to validation test | src/Illuminate/Foundation/Testing/TestResponse.php | @@ -633,27 +633,28 @@ public function assertJsonCount(int $count, $key = null)
/**
* Assert that the response has the given JSON validation errors for the given keys.
*
- * @param string|array $keys
+ * @param string|array $keys
+ * @param string $responseKey
* @return $this
*/
- public function assertJsonValidationErrors($keys)
+ public function assertJsonValidationErrors($keys, $responseKey = 'errors')
{
$keys = Arr::wrap($keys);
PHPUnit::assertNotEmpty($keys, 'No keys were provided.');
- $errors = $this->json()['errors'] ?? [];
+ $errors = $this->json()[$responseKey] ?? [];
$errorMessage = $errors
- ? 'Response has the following JSON validation errors:'.
- PHP_EOL.PHP_EOL.json_encode($errors, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE).PHP_EOL
- : 'Response does not have JSON validation errors.';
+ ? 'Response has the following JSON validation errors:' .
+ PHP_EOL . PHP_EOL . json_encode($errors, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL
+ : 'Response does not have JSON validation errors.';
foreach ($keys as $key) {
PHPUnit::assertArrayHasKey(
$key,
$errors,
- "Failed to find a validation error in the response for key: '{$key}'".PHP_EOL.PHP_EOL.$errorMessage
+ "Failed to find a validation error in the response for key: '{$key}'" . PHP_EOL . PHP_EOL . $errorMessage
);
}
@@ -663,24 +664,25 @@ public function assertJsonValidationErrors($keys)
/**
* Assert that the response has no JSON validation errors for the given keys.
*
- * @param string|array $keys
+ * @param string|array $keys
+ * @param string $responseKey
* @return $this
*/
- public function assertJsonMissingValidationErrors($keys = null)
+ public function assertJsonMissingValidationErrors($keys = null, string $responseKey = 'errors')
{
$json = $this->json();
- if (! array_key_exists('errors', $json)) {
- PHPUnit::assertArrayNotHasKey('errors', $json);
+ if (!array_key_exists($responseKey, $json)) {
+ PHPUnit::assertArrayNotHasKey($responseKey, $json);
return $this;
}
- $errors = $json['errors'];
+ $errors = $json[$responseKey];
if (is_null($keys) && count($errors) > 0) {
PHPUnit::fail(
- 'Response has unexpected validation errors: '.PHP_EOL.PHP_EOL.
+ 'Response has unexpected validation errors: ' . PHP_EOL . PHP_EOL .
json_encode($errors, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
);
} | true |
Other | laravel | framework | d0b1cfea1843bac76aabe55e3c3c35b727fd89bb.json | Add custom errors key to validation test | tests/Foundation/FoundationTestResponseTest.php | @@ -315,6 +315,20 @@ public function testAssertJsonValidationErrors()
$testResponse->assertJsonValidationErrors('foo');
}
+ public function testAssertJsonValidationErrorsCustomErrorsName()
+ {
+ $data = [
+ 'status' => 'ok',
+ 'data' => ['foo' => 'oops'],
+ ];
+
+ $testResponse = TestResponse::fromBaseResponse(
+ (new Response)->setContent(json_encode($data))
+ );
+
+ $testResponse->assertJsonValidationErrors('foo','data');
+ }
+
public function testAssertJsonValidationErrorsCanFail()
{
$this->expectException(AssertionFailedError::class);
@@ -446,6 +460,20 @@ public function testAssertJsonMissingValidationErrorsWithoutArgumentCanFail()
$testResponse->assertJsonMissingValidationErrors();
}
+ public function testAssertJsonMissingValidationErrorsCustomErrorsName()
+ {
+ $data = [
+ 'status' => 'ok',
+ 'data' => ['foo' => 'oops'],
+ ];
+
+ $testResponse = TestResponse::fromBaseResponse(
+ (new Response)->setContent(json_encode($data))
+ );
+
+ $testResponse->assertJsonMissingValidationErrors('bar','data');
+ }
+
public function testMacroable()
{
TestResponse::macro('foo', function () { | true |
Other | laravel | framework | bc53915ed5fa4d315ee6faa047c1762cc7d1454b.json | Restore maintenance message on error page | src/Illuminate/Foundation/Exceptions/views/503.blade.php | @@ -2,4 +2,4 @@
@section('title', __('Service Unavailable'))
@section('code', '503')
-@section('message', __('Service Unavailable'))
+@section('message', __($exception->getMessage() ?: 'Service Unavailable')) | false |
Other | laravel | framework | a32792233dd7db53a0177ac5a9ae3f3a13d53662.json | Add replacement for lower danish "æ" | src/Illuminate/Support/Str.php | @@ -723,8 +723,8 @@ protected static function languageSpecificCharsArray($language)
['h', 'H', 'sht', 'SHT', 'a', 'А', 'y', 'Y'],
],
'da' => [
- ['ø', 'å', 'Æ', 'Ø', 'Å'],
- ['oe', 'aa', 'Ae', 'Oe', 'Aa'],
+ ['æ', 'ø', 'å', 'Æ', 'Ø', 'Å'],
+ ['ae', 'oe', 'aa', 'Ae', 'Oe', 'Aa'],
],
'de' => [
['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'], | false |
Other | laravel | framework | d432cfcf57136129940d49be5ea37140e652d601.json | Add tests for count aggregate | tests/Integration/Database/EloquentPaginateTest.php | @@ -49,6 +49,7 @@ public function test_pagination_with_distinct()
$query = Post::query()->distinct();
$this->assertEquals(6, $query->get()->count());
+ $this->assertEquals(6, $query->count());
$this->assertEquals(6, $query->paginate()->total());
}
@@ -63,6 +64,7 @@ public function test_pagination_with_distinct_and_select()
$query = Post::query()->distinct()->select('title');
$this->assertEquals(2, $query->get()->count());
+ $this->assertEquals(6, $query->count());
$this->assertEquals(6, $query->paginate()->total());
}
@@ -76,6 +78,7 @@ public function test_pagination_with_distinct_columns_and_select()
$query = Post::query()->distinct('title')->select('title');
$this->assertEquals(2, $query->get()->count());
+ $this->assertEquals(2, $query->count());
$this->assertEquals(2, $query->paginate()->total());
}
@@ -95,6 +98,7 @@ public function test_pagination_with_distinct_columns_and_select_and_join()
->distinct('users.id')->select('users.*');
$this->assertEquals(5, $query->get()->count());
+ $this->assertEquals(5, $query->count());
$this->assertEquals(5, $query->paginate()->total());
}
} | false |
Other | laravel | framework | dc263d4fe2580306ab35ecf164158863bc3d6958.json | Use correct syntax and move Postgres grammar | src/Illuminate/Database/Query/Grammars/Grammar.php | @@ -110,7 +110,7 @@ protected function compileAggregate(Builder $query, $aggregate)
// we need to prepend "distinct" onto the column name so that the query takes
// it into account when it performs the aggregating operations on the data.
if (is_array($query->distinct)) {
- $column = 'distinct ('.$this->columnize($query->distinct).')';
+ $column = 'distinct '.$this->columnize($query->distinct).'';
} elseif ($query->distinct && $column !== '*') {
$column = 'distinct '.$column;
}
@@ -134,9 +134,7 @@ protected function compileColumns(Builder $query, $columns)
return;
}
- if (is_array($query->distinct)) {
- $select = 'select distinct ('.$this->columnize($query->distinct).'), ';
- } elseif ($query->distinct) {
+ if ($query->distinct) {
$select = 'select distinct ';
} else {
$select = 'select '; | true |
Other | laravel | framework | dc263d4fe2580306ab35ecf164158863bc3d6958.json | Use correct syntax and move Postgres grammar | src/Illuminate/Database/Query/Grammars/PostgresGrammar.php | @@ -125,6 +125,33 @@ public function compileSelect(Builder $query)
return $sql;
}
+ /**
+ * Compile the "select *" portion of the query.
+ *
+ * @param \Illuminate\Database\Query\Builder $query
+ * @param array $columns
+ * @return string|null
+ */
+ protected function compileColumns(Builder $query, $columns)
+ {
+ // If the query is actually performing an aggregating select, we will let that
+ // compiler handle the building of the select clauses, as it will need some
+ // more syntax that is best handled by that function to keep things neat.
+ if (! is_null($query->aggregate)) {
+ return;
+ }
+
+ if (is_array($query->distinct)) {
+ $select = 'select distinct on ('.$this->columnize($query->distinct).') ';
+ } elseif ($query->distinct) {
+ $select = 'select distinct ';
+ } else {
+ $select = 'select ';
+ }
+
+ return $select.$this->columnize($columns);
+ }
+
/**
* Compile a single union statement.
* | true |
Other | laravel | framework | dc263d4fe2580306ab35ecf164158863bc3d6958.json | Use correct syntax and move Postgres grammar | tests/Database/DatabaseQueryBuilderTest.php | @@ -119,11 +119,15 @@ public function testBasicSelectDistinct()
$this->assertEquals('select distinct "foo", "bar" from "users"', $builder->toSql());
}
- public function testBasicSelectDistinctWithColumns()
+ public function testBasicSelectDistinctOnColumns()
{
$builder = $this->getBuilder();
$builder->distinct('foo')->select('foo', 'bar')->from('users');
- $this->assertEquals('select distinct ("foo"), "foo", "bar" from "users"', $builder->toSql());
+ $this->assertEquals('select distinct "foo", "bar" from "users"', $builder->toSql());
+
+ $builder = $this->getPostgresBuilder();
+ $builder->distinct('foo')->select('foo', 'bar')->from('users');
+ $this->assertEquals('select distinct on ("foo") "foo", "bar" from "users"', $builder->toSql());
}
public function testBasicAlias() | true |
Other | laravel | framework | 67cb3a4695c71112810c0e010e7f35e3b439ac2c.json | Fix StyleCI warnings | src/Illuminate/Auth/Access/Gate.php | @@ -305,7 +305,7 @@ public function any($abilities, $arguments = [])
public function none($abilities, $arguments = [])
{
return ! $this->any($abilities, $arguments);
- }
+ }
/**
* Determine if the given ability should be granted for the current user. | false |
Other | laravel | framework | 203172477fc99d541a6def73449c8cacc3718ca6.json | fix whitespace errors | src/Illuminate/Auth/Access/Gate.php | @@ -295,7 +295,7 @@ public function any($abilities, $arguments = [])
});
}
- /**
+ /**
* Determine if any one of the given abilities should be denied for the current user.
*
* @param iterable|string $abilities
@@ -305,7 +305,7 @@ public function any($abilities, $arguments = [])
public function none($abilities, $arguments = [])
{
return ! $this->any($abilities, $arguments);
- }
+ }
/**
* Determine if the given ability should be granted for the current user. | false |
Other | laravel | framework | 8412218059b94c3f781fdeee3f0eb507a66550d4.json | Create getter for the http route middlewares
This getter allows to create tests for the route
middlewares, which is currently not possible
because the property is protected.
For example, if you want to ensure that a route middleware has been
registered, with this getter you can write:
```php
/** @test */
public function it_registers_a_custom_route_middleware()
{
$middlewares = resolve(\App\Http\Kernel::class)->getRouteMiddleware();
$this->assertArrayHasKey('custom', $middlewares);
$this->assertEquals(\App\Http\Middleware\Custom::class, $middlewares['custom']);
}
``` | src/Illuminate/Foundation/Http/Kernel.php | @@ -336,6 +336,16 @@ public function getMiddlewareGroups()
return $this->middlewareGroups;
}
+ /**
+ * Get the application's route middleware.
+ *
+ * @return array
+ */
+ public function getRouteMiddleware()
+ {
+ return $this->routeMiddleware;
+ }
+
/**
* Get the Laravel application instance.
* | true |
Other | laravel | framework | 8412218059b94c3f781fdeee3f0eb507a66550d4.json | Create getter for the http route middlewares
This getter allows to create tests for the route
middlewares, which is currently not possible
because the property is protected.
For example, if you want to ensure that a route middleware has been
registered, with this getter you can write:
```php
/** @test */
public function it_registers_a_custom_route_middleware()
{
$middlewares = resolve(\App\Http\Kernel::class)->getRouteMiddleware();
$this->assertArrayHasKey('custom', $middlewares);
$this->assertEquals(\App\Http\Middleware\Custom::class, $middlewares['custom']);
}
``` | tests/Foundation/Http/KernelTest.php | @@ -17,6 +17,13 @@ public function testGetMiddlewareGroups()
$this->assertEquals([], $kernel->getMiddlewareGroups());
}
+ public function testGetRouteMiddleware()
+ {
+ $kernel = new Kernel($this->getApplication(), $this->getRouter());
+
+ $this->assertEquals([], $kernel->getRouteMiddleware());
+ }
+
/**
* @return \Illuminate\Contracts\Foundation\Application
*/ | true |
Other | laravel | framework | 9bcad4a9b505188a6c4bbb684a42062f36eb60cc.json | Use latest versions | .github/ISSUE_TEMPLATE/1_Bug_report.md | @@ -1,6 +1,6 @@
---
name: "🐛 Bug Report"
-about: 'Report a general framework issue. Please first check if your Laravel version is still supported: https://laravel.com/docs/5.8/releases#support-policy'
+about: 'Report a general framework issue. Please first check if your Laravel version is still supported: https://laravel.com/docs/releases#support-policy'
---
| true |
Other | laravel | framework | 9bcad4a9b505188a6c4bbb684a42062f36eb60cc.json | Use latest versions | .github/PULL_REQUEST_TEMPLATE.md | @@ -1,7 +1,7 @@
<!--
-Please only send in a PR to branches which are currently supported: https://laravel.com/docs/5.8/releases#support-policy
+Please only send in a PR to branches which are currently supported: https://laravel.com/docs/releases#support-policy
-If you are unsure to which branch you want to send a PR please read: https://laravel.com/docs/5.8/contributions#which-branch
+If you are unsure to which branch you want to send a PR please read: https://laravel.com/docs/contributions#which-branch
Pull Requests without a descriptive title, thorough description, or tests will be closed.
| true |
Other | laravel | framework | 19206efaaf31ee3368a42c51d0825db03d8490d2.json | Use proper link in docs issue template | .github/ISSUE_TEMPLATE/4_Documentation_issue.md | @@ -1,6 +1,6 @@
---
name: "📚 Documentation Issue"
-about: 'For documentation issues, see: https://github.com/laravel/docs/issues'
+about: 'For documentation issues, open a pull request at https://github.com/laravel/docs'
---
| false |
Other | laravel | framework | bd76f38ec46e27f72c247636fbb49e3f5289606c.json | Clarify support policy in issue template | .github/ISSUE_TEMPLATE/1_Bug_report.md | @@ -1,11 +1,11 @@
---
name: "🐛 Bug Report"
-about: Report a general framework issue
+about: 'Report a general framework issue. We currently only offer support for Laravel 5.5 (LTS) and 5.8 as per our support policy: https://laravel.com/docs/5.8/releases#support-policy'
---
- Laravel Version: #.#.#
-- PHP Version:
+- PHP Version: #.#.#
- Database Driver & Version:
### Description: | false |
Other | laravel | framework | 02623f89912017f4dcea3c040139544bb74c14fa.json | Fix DateTime typehints | src/Illuminate/Contracts/Mail/Mailable.php | @@ -25,7 +25,7 @@ public function queue(Queue $queue);
/**
* Deliver the queued message after the given delay.
*
- * @param \DateTime|int $delay
+ * @param \DateTimeInterface|\DateInterval|int $delay
* @param \Illuminate\Contracts\Queue\Factory $queue
* @return mixed
*/ | true |
Other | laravel | framework | 02623f89912017f4dcea3c040139544bb74c14fa.json | Fix DateTime typehints | src/Illuminate/Foundation/Bus/PendingDispatch.php | @@ -79,7 +79,7 @@ public function allOnQueue($queue)
/**
* Set the desired delay for the job.
*
- * @param \DateTime|int|null $delay
+ * @param \DateTimeInterface|\DateInterval|int|null $delay
* @return $this
*/
public function delay($delay) | true |
Other | laravel | framework | 02623f89912017f4dcea3c040139544bb74c14fa.json | Fix DateTime typehints | src/Illuminate/Support/Testing/Fakes/QueueFake.php | @@ -263,7 +263,7 @@ public function pushRaw($payload, $queue = null, array $options = [])
/**
* Push a new job onto the queue after a delay.
*
- * @param \DateTime|int $delay
+ * @param \DateTimeInterface|\DateInterval|int $delay
* @param string $job
* @param mixed $data
* @param string $queue
@@ -291,7 +291,7 @@ public function pushOn($queue, $job, $data = '')
* Push a new job onto the queue after a delay.
*
* @param string $queue
- * @param \DateTime|int $delay
+ * @param \DateTimeInterface|\DateInterval|int $delay
* @param string $job
* @param mixed $data
* @return mixed | true |
Other | laravel | framework | 7b4e5acd0b067da29261d08b1c3fc83617e18348.json | Fix method signatures on Cache facade
To bring them inline with the recent cache changes. | src/Illuminate/Support/Facades/Cache.php | @@ -8,12 +8,12 @@
* @method static bool missing(string $key)
* @method static mixed get(string $key, mixed $default = null)
* @method static mixed pull(string $key, mixed $default = null)
- * @method static void put(string $key, $value, \DateTimeInterface|\DateInterval|int $seconds)
- * @method static bool add(string $key, $value, \DateTimeInterface|\DateInterval|int $seconds)
+ * @method static bool put(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl)
+ * @method static bool add(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl)
* @method static int|bool increment(string $key, $value = 1)
* @method static int|bool decrement(string $key, $value = 1)
- * @method static void forever(string $key, $value)
- * @method static mixed remember(string $key, \DateTimeInterface|\DateInterval|int $seconds, \Closure $callback)
+ * @method static bool forever(string $key, $value)
+ * @method static mixed remember(string $key, \DateTimeInterface|\DateInterval|int $ttl, \Closure $callback)
* @method static mixed sear(string $key, \Closure $callback)
* @method static mixed rememberForever(string $key, \Closure $callback)
* @method static bool forget(string $key) | false |
Other | laravel | framework | 153390164e8f93f6c7a49da03f244448f51c01c9.json | Extract a method | src/Illuminate/Session/Middleware/StartSession.php | @@ -62,7 +62,7 @@ public function handle($request, Closure $next)
// Again, if the session has been configured we will need to close out the session
// so that the attributes may be persisted to some storage medium. We will also
// add the session identifier cookie to the application response headers now.
- $this->manager->driver()->save();
+ $this->saveSession();
return $response;
}
@@ -205,4 +205,14 @@ protected function sessionIsPersistent(array $config = null)
return ! in_array($config['driver'], [null, 'array']);
}
+
+ /**
+ * Save the session data to storage.
+ *
+ * @return void
+ */
+ protected function saveSession()
+ {
+ $this->manager->driver()->save();
+ }
} | false |
Other | laravel | framework | 7b8e123462675e1d7b319f61c895be7f61b15c71.json | Add `countBy` method to Collection | src/Illuminate/Support/Collection.php | @@ -1890,6 +1890,28 @@ public function count()
return count($this->items);
}
+ /**
+ * Count the number of items in the collection by some predicate.
+ *
+ * @param callable|null
+ * @return static
+ */
+ public function countBy($predicate = null)
+ {
+ if (is_null($predicate)) {
+ $predicate = function ($val, $key) {
+ return $val;
+ };
+ }
+
+ return new static(
+ $this->groupBy($predicate)
+ ->map(function ($val, $key) {
+ return $val->count();
+ })
+ );
+ }
+
/**
* Add an item to the collection.
* | true |
Other | laravel | framework | 7b8e123462675e1d7b319f61c895be7f61b15c71.json | Add `countBy` method to Collection | tests/Support/SupportCollectionTest.php | @@ -307,6 +307,31 @@ public function testCountable()
$this->assertCount(2, $c);
}
+ public function testCountableByWithoutPredicate()
+ {
+ $c = new Collection([ 'foo', 'foo', 'foo', 'bar', 'bar', 'foobar' ]);
+ $this->assertEquals([ 'foo' => 3, 'bar' => 2, 'foobar' => 1 ], $c->countBy()->all());
+
+ $c = new Collection([ true, true, false, false, false ]);
+ $this->assertEquals([ true => 2, false => 3, ], $c->countBy()->all());
+
+ $c = new Collection([ 1, 5, 1, 5, 5, 1 ]);
+ $this->assertEquals([ 1 => 3, 5 => 3, ], $c->countBy()->all());
+ }
+
+ public function testCountableByWithPredicate()
+ {
+ $c = new Collection([ 'alice', 'aaron', 'bob', 'carla' ]);
+ $this->assertEquals([ 'a' => 2, 'b' => 1, 'c' => 1 ], $c->countBy(function ($name) {
+ return substr($name, 0, 1);
+ })->all());
+
+ $c = new Collection([ 1, 2, 3, 4, 5 ]);
+ $this->assertEquals([ true => 2, false => 3 ], $c->countBy(function ($i) {
+ return $i % 2 === 0;
+ })->all());
+ }
+
public function testIterable()
{
$c = new Collection(['foo']); | true |
Other | laravel | framework | 6d700974d27da0af2729e68520ad901020acdf96.json | Add test for guesser callback transfer | tests/Auth/AuthAccessGateTest.php | @@ -507,6 +507,32 @@ public function test_for_user_method_attaches_a_new_user_to_a_new_gate_instance(
$this->assertTrue($gate->forUser((object) ['id' => 2])->check('foo'));
}
+ public function test_for_user_method_attaches_a_new_user_to_a_new_gate_instance_with_guess_callback()
+ {
+ $gate = $this->getBasicGate();
+
+ $gate->define('foo', function () {
+ return true;
+ });
+
+ $counter = 0;
+ $guesserCallback = function () use (&$counter) {
+ $counter++;
+ };
+ $gate->guessPolicyNamesUsing($guesserCallback);
+ $gate->getPolicyFor('fooClass');
+ $this->assertEquals(1, $counter);
+
+ // now the guesser callback should be present on the new gate as well
+ $newGate = $gate->forUser((object) ['id' => 1]);
+
+ $newGate->getPolicyFor('fooClass');
+ $this->assertEquals(2, $counter);
+
+ $newGate->getPolicyFor('fooClass');
+ $this->assertEquals(3, $counter);
+ }
+
/**
* @dataProvider notCallableDataProvider
*/ | false |
Other | laravel | framework | 2d7b81c3ada809d87a955556bac2299a02ba3035.json | add join method to collection | src/Illuminate/Support/Collection.php | @@ -296,6 +296,34 @@ public function containsStrict($key, $value = null)
return in_array($key, $this->items, true);
}
+ /**
+ * Join all items from the collection using a string. The final items can use a separate glue string.
+ *
+ * @param string $glue
+ * @param string $finalGlue
+ * @return string
+ */
+ public function join($glue, $finalGlue = '')
+ {
+ if ($finalGlue === '') {
+ return $this->implode($glue);
+ }
+
+ if ($this->count() === 0) {
+ return '';
+ }
+
+ if ($this->count() === 1) {
+ return $this->last();
+ }
+
+ $collection = new static($this->items);
+
+ $finalItem = $collection->pop();
+
+ return $collection->implode($glue).$finalGlue.$finalItem;
+ }
+
/**
* Cross join with the given lists, returning all possible permutations.
* | true |
Other | laravel | framework | 2d7b81c3ada809d87a955556bac2299a02ba3035.json | add join method to collection | tests/Support/SupportCollectionTest.php | @@ -878,6 +878,19 @@ public function testCollapseWithNestedCollections()
$this->assertEquals([1, 2, 3, 4, 5, 6], $data->collapse()->all());
}
+ public function testJoin()
+ {
+ $this->assertEquals('a, b, c', (new Collection(['a', 'b', 'c']))->join(', '));
+
+ $this->assertEquals('a, b and c', (new Collection(['a', 'b', 'c']))->join(', ', ' and '));
+
+ $this->assertEquals('a and b', (new Collection(['a', 'b']))->join(', ', ' and '));
+
+ $this->assertEquals('a', (new Collection(['a']))->join(', ', ' and '));
+
+ $this->assertEquals('', (new Collection([]))->join(', ', ' and '));
+ }
+
public function testCrossJoin()
{
// Cross join with an array | true |
Other | laravel | framework | 586345a52f6639dfcf5cba6effa87889b8862b4f.json | Fix StyleCI failure | tests/Notifications/NotificationSenderTest.php | @@ -2,8 +2,8 @@
namespace Illuminate\Tests\Notifications;
-use Illuminate\Bus\Queueable;
use Mockery as m;
+use Illuminate\Bus\Queueable;
use PHPUnit\Framework\TestCase;
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification; | false |
Other | laravel | framework | 84b438c432531dc41d4d71f18d396636addebedb.json | Fix a bug with string via in queued notifications
A queued notification with a string via currently fails because it's not converted to an array. I've added a test which proves the failure.
Reported via https://github.com/laravel/docs/pull/5023 | src/Illuminate/Notifications/NotificationSender.php | @@ -179,7 +179,7 @@ protected function queueNotification($notifiables, $notification)
foreach ($notifiables as $notifiable) {
$notificationId = Str::uuid()->toString();
- foreach ($original->via($notifiable) as $channel) {
+ foreach ((array) $original->via($notifiable) as $channel) {
$notification = clone $original;
$notification->id = $notificationId; | true |
Other | laravel | framework | 84b438c432531dc41d4d71f18d396636addebedb.json | Fix a bug with string via in queued notifications
A queued notification with a string via currently fails because it's not converted to an array. I've added a test which proves the failure.
Reported via https://github.com/laravel/docs/pull/5023 | tests/Notifications/NotificationSenderTest.php | @@ -0,0 +1,54 @@
+<?php
+
+namespace Illuminate\Tests\Notifications;
+
+use Illuminate\Bus\Queueable;
+use Mockery as m;
+use PHPUnit\Framework\TestCase;
+use Illuminate\Notifications\Notifiable;
+use Illuminate\Notifications\Notification;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Notifications\ChannelManager;
+use Illuminate\Notifications\NotificationSender;
+use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
+use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
+
+class NotificationSenderTest extends TestCase
+{
+ protected function tearDown(): void
+ {
+ parent::tearDown();
+
+ m::close();
+ }
+
+ public function test_it_can_send_queued_notifications_with_a_string_via()
+ {
+ $notifiable = m::mock(Notifiable::class);
+ $manager = m::mock(ChannelManager::class);
+ $bus = m::mock(BusDispatcher::class);
+ $bus->shouldReceive('dispatch');
+ $events = m::mock(EventDispatcher::class);
+
+ $sender = new NotificationSender($manager, $bus, $events);
+
+ $sender->send($notifiable, new DummyQueuedNotificationWithStringVia());
+ }
+}
+
+class DummyQueuedNotificationWithStringVia extends Notification implements ShouldQueue
+{
+ use Queueable;
+
+ /**
+ * Get the notification channels.
+ *
+ * @param mixed $notifiable
+ * @return array|string
+ * @return array|string
+ */
+ public function via($notifiable)
+ {
+ return 'mail';
+ }
+} | true |
Other | laravel | framework | ed91b7ddaedcde80dcfda261d8f125fd1ee19c4f.json | Push 7th argument to new line | src/Illuminate/Auth/Access/Gate.php | @@ -703,7 +703,8 @@ public function forUser($user)
return new static(
$this->container, $callback, $this->abilities,
- $this->policies, $this->beforeCallbacks, $this->afterCallbacks, $this->guessPolicyNamesUsingCallback
+ $this->policies, $this->beforeCallbacks, $this->afterCallbacks,
+ $this->guessPolicyNamesUsingCallback
);
}
| false |
Other | laravel | framework | 887916ba7815e6bf7e2feec44e0d49d85e9ab671.json | Add support for single-quoted string | src/Illuminate/Support/helpers.php | @@ -662,7 +662,7 @@ function env($key, $default = null)
return;
}
- if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') {
+ if (($valueLength = strlen($value)) > 1 && ($value[0] === '"' && $value[$valueLength - 1] === '"' || $value[0] === "'" && $value[$valueLength - 1] === "'")) {
return substr($value, 1, -1);
}
| true |
Other | laravel | framework | 887916ba7815e6bf7e2feec44e0d49d85e9ab671.json | Add support for single-quoted string | tests/Support/SupportHelpersTest.php | @@ -576,6 +576,9 @@ public function testEnvEscapedString()
{
$_SERVER['foo'] = '"null"';
$this->assertSame('null', env('foo'));
+
+ $_SERVER['foo'] = "'null'";
+ $this->assertSame('null', env('foo'));
}
public function testGetFromENVFirst() | true |
Other | laravel | framework | b0d163f078145c6f1ae943bd487bb512b4e493b5.json | Add test for escaped environment variable string | tests/Support/SupportHelpersTest.php | @@ -572,6 +572,12 @@ public function testEnvNull()
$this->assertNull(env('foo'));
}
+ public function testEnvEscapedString()
+ {
+ $_SERVER['foo'] = '"null"';
+ $this->assertSame('null', env('foo'));
+ }
+
public function testGetFromENVFirst()
{
$_ENV['foo'] = 'From $_ENV'; | false |
Other | laravel | framework | 8ab09fb6377eb5b6dab45ab38b0a62446b08e8ae.json | Update changelog 1 (#27682)
[5.7] update changelog | CHANGELOG-5.7.md | @@ -3,7 +3,7 @@
## [Unreleased](https://github.com/laravel/framework/compare/v5.7.28...5.7)
-## [v5.7.28 (2019-02-28)](https://github.com/laravel/framework/compare/v5.7.27...v5.7.28)
+## [v5.7.28 (2019-02-26)](https://github.com/laravel/framework/compare/v5.7.27...v5.7.28)
### Added
- Add support for `Pheanstalk 4.x` ([#27622](https://github.com/laravel/framework/pull/27622)) | false |
Other | laravel | framework | 81895941a5ee83e89c1e707cdd5d06515d276b4d.json | Return fake objects from facades | src/Illuminate/Support/Facades/Bus.php | @@ -20,11 +20,13 @@ class Bus extends Facade
/**
* Replace the bound instance with a fake.
*
- * @return void
+ * @return BusFake
*/
public static function fake()
{
- static::swap(new BusFake);
+ static::swap($fake = new BusFake);
+
+ return $fake;
}
/** | true |
Other | laravel | framework | 81895941a5ee83e89c1e707cdd5d06515d276b4d.json | Return fake objects from facades | src/Illuminate/Support/Facades/Event.php | @@ -24,13 +24,15 @@ class Event extends Facade
* Replace the bound instance with a fake.
*
* @param array|string $eventsToFake
- * @return void
+ * @return EventFake
*/
public static function fake($eventsToFake = [])
{
static::swap($fake = new EventFake(static::getFacadeRoot(), $eventsToFake));
Model::setEventDispatcher($fake);
+
+ return $fake;
}
/** | true |
Other | laravel | framework | 81895941a5ee83e89c1e707cdd5d06515d276b4d.json | Return fake objects from facades | src/Illuminate/Support/Facades/Mail.php | @@ -31,11 +31,13 @@ class Mail extends Facade
/**
* Replace the bound instance with a fake.
*
- * @return void
+ * @return MailFake
*/
public static function fake()
{
- static::swap(new MailFake);
+ static::swap($fake = new MailFake);
+
+ return $fake;
}
/** | true |
Other | laravel | framework | 81895941a5ee83e89c1e707cdd5d06515d276b4d.json | Return fake objects from facades | src/Illuminate/Support/Facades/Queue.php | @@ -24,11 +24,13 @@ class Queue extends Facade
/**
* Replace the bound instance with a fake.
*
- * @return void
+ * @return QueueFake
*/
public static function fake()
{
- static::swap(new QueueFake(static::getFacadeApplication()));
+ static::swap($fake = new QueueFake(static::getFacadeApplication()));
+
+ return $fake;
}
/** | true |
Other | laravel | framework | 81895941a5ee83e89c1e707cdd5d06515d276b4d.json | Return fake objects from facades | src/Illuminate/Support/Facades/Storage.php | @@ -16,7 +16,7 @@ class Storage extends Facade
*
* @param string|null $disk
*
- * @return void
+ * @return Filesystem
*/
public static function fake($disk = null)
{
@@ -26,22 +26,26 @@ public static function fake($disk = null)
$root = storage_path('framework/testing/disks/'.$disk)
);
- static::set($disk, self::createLocalDriver(['root' => $root]));
+ static::set($disk, $fake = self::createLocalDriver(['root' => $root]));
+
+ return $fake;
}
/**
* Replace the given disk with a persistent local testing disk.
*
* @param string|null $disk
- * @return void
+ * @return Filesystem
*/
public static function persistentFake($disk = null)
{
$disk = $disk ?: self::$app['config']->get('filesystems.default');
- static::set($disk, self::createLocalDriver([
+ static::set($disk, $fake = self::createLocalDriver([
'root' => storage_path('framework/testing/disks/'.$disk),
]));
+
+ return $fake;
}
/** | true |
Other | laravel | framework | fa51cef12c67cdc29cee3974943b0f00e8c80192.json | Remove unnecessary type attribute in link element | src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub | @@ -14,7 +14,7 @@
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
- <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
+ <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet"> | false |
Other | laravel | framework | 56f40cff16b2d0adbbd7fedb44015b3395e74b62.json | Change doctype to lowercase | src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub | @@ -1,4 +1,4 @@
-<!DOCTYPE html>
+<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8"> | false |
Other | laravel | framework | 970c9ed70b053aec7d69487a825577ed6f0329d1.json | remove broken code | src/Illuminate/Auth/RequestGuard.php | @@ -80,10 +80,6 @@ public function validate(array $credentials = [])
*/
public function setRequest(Request $request)
{
- if ($this->request !== $request) {
- $this->user = null;
- }
-
$this->request = $request;
return $this; | false |
Other | laravel | framework | d88dfe1e5925fa61f62837359e1b26f799e4110b.json | Support multiple guesses for Policy resolution | src/Illuminate/Auth/Access/Gate.php | @@ -538,8 +538,10 @@ public function getPolicyFor($class)
return $this->resolvePolicy($this->policies[$class]);
}
- if (class_exists($guessedPolicy = $this->guessPolicyName($class))) {
- return $this->resolvePolicy($guessedPolicy);
+ foreach ($this->guessPolicyName($class) as $guessedPolicy) {
+ if (class_exists($guessedPolicy)) {
+ return $this->resolvePolicy($guessedPolicy);
+ }
}
foreach ($this->policies as $expected => $policy) {
@@ -553,17 +555,17 @@ public function getPolicyFor($class)
* Guess the policy name for the given class.
*
* @param string $class
- * @return string
+ * @return array
*/
protected function guessPolicyName($class)
{
if ($this->guessPolicyNamesUsingCallback) {
- return call_user_func($this->guessPolicyNamesUsingCallback, $class);
+ return Arr::wrap(call_user_func($this->guessPolicyNamesUsingCallback, $class));
}
$classDirname = str_replace('/', '\\', dirname(str_replace('\\', '/', $class)));
- return $classDirname.'\\Policies\\'.class_basename($class).'Policy';
+ return [$classDirname.'\\Policies\\'.class_basename($class).'Policy'];
}
/** | true |
Other | laravel | framework | d88dfe1e5925fa61f62837359e1b26f799e4110b.json | Support multiple guesses for Policy resolution | tests/Integration/Auth/GatePolicyResolutionTest.php | @@ -19,4 +19,31 @@ public function testPolicyCanBeGuessedUsingClassConventions()
Gate::getPolicyFor(AuthenticationTestUser::class)
);
}
+
+ public function testPolicyCanBeGuessedUsingCallback()
+ {
+ Gate::guessPolicyNamesUsing(function () {
+ return AuthenticationTestUserPolicy::class;
+ });
+
+ $this->assertInstanceOf(
+ AuthenticationTestUserPolicy::class,
+ Gate::getPolicyFor(AuthenticationTestUser::class)
+ );
+ }
+
+ public function testPolicyCanBeGuessedMultipleTimes()
+ {
+ Gate::guessPolicyNamesUsing(function () {
+ return [
+ 'App\\Policies\\TestUserPolicy',
+ AuthenticationTestUserPolicy::class
+ ];
+ });
+
+ $this->assertInstanceOf(
+ AuthenticationTestUserPolicy::class,
+ Gate::getPolicyFor(AuthenticationTestUser::class)
+ );
+ }
} | true |
Other | laravel | framework | 604dfa79648e966a6511e08ad6b71cdd742bb282.json | Remove mock request and use an instance. | tests/Foundation/FoundationExceptionsHandlerTest.php | @@ -6,6 +6,7 @@
use Exception;
use Mockery as m;
use RuntimeException;
+use Illuminate\Http\Request;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
use Illuminate\Routing\Redirector;
@@ -141,39 +142,40 @@ public function testValidateFileMethod()
$argumentExpected = ['input' => 'My input value'];
$argumentActual = null;
- $this->container->singleton('redirect', function () use ($argumentExpected, &$argumentActual) {
+ $this->container->singleton('redirect', function () use (&$argumentActual) {
$redirector = m::mock(Redirector::class);
$redirector->shouldReceive('to')->once()
->andReturn($responser = m::mock(RedirectResponse::class));
- $responser->shouldReceive('withInput')->once()->with(m::on(function ($argument) use ($argumentExpected, &$argumentActual) {
- $argumentActual = $argument;
+ $responser->shouldReceive('withInput')->once()->with(m::on(
+ function ($argument) use (&$argumentActual) {
+ $argumentActual = $argument;
- return true;
- }))->andReturn($responser);
+ return true;
+ }))->andReturn($responser);
$responser->shouldReceive('withErrors')->once()
->andReturn($responser);
return $redirector;
});
- $this->request->shouldReceive('expectsJson')->once()->andReturn(false);
- $this->request->shouldReceive('input')->once()->andReturn($argumentExpected);
-
$file = m::mock(UploadedFile::class);
- $file->shouldReceive('isValid')->zeroOrMoreTimes()->andReturn(false);
- $file->shouldReceive('getPathname')->zeroOrMoreTimes()->andReturn('photo.jpg');
- $file->shouldReceive('getClientOriginalName')->zeroOrMoreTimes()->andReturn('photo.jpg');
+ $file->shouldReceive('getPathname')->andReturn('photo.jpg');
+ $file->shouldReceive('getClientOriginalName')->andReturn('photo.jpg');
+ $file->shouldReceive('getClientMimeType')->andReturn(null);
+ $file->shouldReceive('getError')->andReturn(null);
+
+ $request = Request::create('/', 'POST', $argumentExpected, [], ['photo' => $file]);
$validator = m::mock(Validator::class);
$validator->shouldReceive('errors')->andReturn(new MessageBag(['error' => 'My custom validation exception']));
$validationException = new ValidationException($validator);
$validationException->redirectTo = '/';
- $this->handler->render($this->request, $validationException);
+ $this->handler->render($request, $validationException);
$this->assertEquals($argumentExpected, $argumentActual);
} | false |
Other | laravel | framework | 97b2899ed23cb2ddd679702c349108c375525c99.json | Use safe container getter on Pipeline carry | src/Illuminate/Pipeline/Pipeline.php | @@ -164,7 +164,7 @@ protected function carry()
: $pipe(...$parameters);
return $response instanceof Responsable
- ? $response->toResponse($this->container->make(Request::class))
+ ? $response->toResponse($this->getContainer()->make(Request::class))
: $response;
};
}; | false |
Other | laravel | framework | 838a47599dd7fb0597656cf71ce4e18c7d9051b0.json | Fix BoundMethod dockblock | src/Illuminate/Container/BoundMethod.php | @@ -17,6 +17,9 @@ class BoundMethod
* @param array $parameters
* @param string|null $defaultMethod
* @return mixed
+ *
+ * @throws \ReflectionException
+ * @throws \InvalidArgumentException
*/
public static function call($container, $callback, array $parameters = [], $defaultMethod = null)
{
@@ -107,6 +110,8 @@ protected static function normalizeMethod($callback)
* @param callable|string $callback
* @param array $parameters
* @return array
+ *
+ * @throws \ReflectionException
*/
protected static function getMethodDependencies($container, $callback, array $parameters = [])
{ | false |
Other | laravel | framework | 275dc0831fa39a70ab74a989b069cee659a14841.json | Move Arr tests to the right location | tests/Support/SupportArrTest.php | @@ -29,12 +29,18 @@ public function testAdd()
{
$array = Arr::add(['name' => 'Desk'], 'price', 100);
$this->assertEquals(['name' => 'Desk', 'price' => 100], $array);
+
+ $this->assertEquals(['surname' => 'Mövsümov'], Arr::add([], 'surname', 'Mövsümov'));
+ $this->assertEquals(['developer' => ['name' => 'Ferid']], Arr::add([], 'developer.name', 'Ferid'));
}
public function testCollapse()
{
$data = [['foo', 'bar'], ['baz']];
$this->assertEquals(['foo', 'bar', 'baz'], Arr::collapse($data));
+
+ $array = [[1], [2], [3], ['foo', 'bar'], collect(['baz', 'boom'])];
+ $this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], Arr::collapse($array));
}
public function testCrossJoin()
@@ -102,13 +108,21 @@ public function testDot()
$array = Arr::dot(['foo' => ['bar' => []]]);
$this->assertEquals(['foo.bar' => []], $array);
+
+ $array = Arr::dot(['name' => 'taylor', 'languages' => ['php' => true]]);
+ $this->assertEquals($array, ['name' => 'taylor', 'languages.php' => true]);
}
public function testExcept()
{
- $array = ['name' => 'Desk', 'price' => 100];
- $array = Arr::except($array, ['price']);
- $this->assertEquals(['name' => 'Desk'], $array);
+ $array = ['name' => 'taylor', 'age' => 26];
+ $this->assertEquals(['age' => 26], Arr::except($array, ['name']));
+ $this->assertEquals(['age' => 26], Arr::except($array, 'name'));
+
+ $array = ['name' => 'taylor', 'framework' => ['language' => 'PHP', 'name' => 'Laravel']];
+ $this->assertEquals(['name' => 'taylor'], Arr::except($array, 'framework'));
+ $this->assertEquals(['name' => 'taylor', 'framework' => ['name' => 'Laravel']], Arr::except($array, 'framework.language'));
+ $this->assertEquals(['framework' => ['language' => 'PHP']], Arr::except($array, ['name', 'framework.name']));
}
public function testExists()
@@ -282,6 +296,13 @@ public function testGet()
];
$this->assertEquals('desk', Arr::get($array, 'products.0.name'));
$this->assertEquals('chair', Arr::get($array, 'products.1.name'));
+
+ // Test return default value for non-existing key.
+ $array = ['names' => ['developer' => 'taylor']];
+ $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', 'dayle'));
+ $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', function () {
+ return 'dayle';
+ }));
}
public function testHas()
@@ -361,10 +382,45 @@ public function testOnly()
$array = ['name' => 'Desk', 'price' => 100, 'orders' => 10];
$array = Arr::only($array, ['name', 'price']);
$this->assertEquals(['name' => 'Desk', 'price' => 100], $array);
+ $this->assertEmpty(Arr::only($array, ['nonExistingKey']));
}
public function testPluck()
{
+ $data = [
+ 'post-1' => [
+ 'comments' => [
+ 'tags' => [
+ '#foo', '#bar',
+ ],
+ ],
+ ],
+ 'post-2' => [
+ 'comments' => [
+ 'tags' => [
+ '#baz',
+ ],
+ ],
+ ],
+ ];
+
+ $this->assertEquals([
+ 0 => [
+ 'tags' => [
+ '#foo', '#bar',
+ ],
+ ],
+ 1 => [
+ 'tags' => [
+ '#baz',
+ ],
+ ],
+ ], Arr::pluck($data, 'comments'));
+
+ $this->assertEquals([['#foo', '#bar'], ['#baz']], Arr::pluck($data, 'comments.tags'));
+ $this->assertEquals([null, null], Arr::pluck($data, 'foo'));
+ $this->assertEquals([null, null], Arr::pluck($data, 'foo.bar'));
+
$array = [
['developer' => ['name' => 'Taylor']],
['developer' => ['name' => 'Abigail']],
@@ -415,6 +471,45 @@ public function testPluckWithCarbonKeys()
$this->assertEquals(['2017-07-25 00:00:00' => '2017-07-30 00:00:00'], $array);
}
+ public function testArrayPluckWithArrayAndObjectValues()
+ {
+ $array = [(object) ['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']];
+ $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'name'));
+ $this->assertEquals(['taylor' => 'foo', 'dayle' => 'bar'], Arr::pluck($array, 'email', 'name'));
+ }
+
+ public function testArrayPluckWithNestedKeys()
+ {
+ $array = [['user' => ['taylor', 'otwell']], ['user' => ['dayle', 'rees']]];
+ $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'user.0'));
+ $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, ['user', 0]));
+ $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, 'user.1', 'user.0'));
+ $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, ['user', 1], ['user', 0]));
+ }
+
+ public function testArrayPluckWithNestedArrays()
+ {
+ $array = [
+ [
+ 'account' => 'a',
+ 'users' => [
+ ['first' => 'taylor', 'last' => 'otwell', 'email' => 'taylorotwell@gmail.com'],
+ ],
+ ],
+ [
+ 'account' => 'b',
+ 'users' => [
+ ['first' => 'abigail', 'last' => 'otwell'],
+ ['first' => 'dayle', 'last' => 'rees'],
+ ],
+ ],
+ ];
+
+ $this->assertEquals([['taylor'], ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first'));
+ $this->assertEquals(['a' => ['taylor'], 'b' => ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first', 'account'));
+ $this->assertEquals([['taylorotwell@gmail.com'], [null, null]], Arr::pluck($array, 'users.*.email'));
+ }
+
public function testPrepend()
{
$array = Arr::prepend(['one', 'two', 'three', 'four'], 'zero');
@@ -633,7 +728,7 @@ public function testWhere()
return is_string($value);
});
- $this->assertEquals([1 => 200, 3 => 400], $array);
+ $this->assertEquals([1 => '200', 3 => '400'], $array);
}
public function testWhereKey() | true |
Other | laravel | framework | 275dc0831fa39a70ab74a989b069cee659a14841.json | Move Arr tests to the right location | tests/Support/SupportHelpersTest.php | @@ -6,7 +6,6 @@
use ArrayAccess;
use Mockery as m;
use RuntimeException;
-use Illuminate\Support\Arr;
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Optional;
use Illuminate\Contracts\Support\Htmlable;
@@ -18,196 +17,6 @@ protected function tearDown(): void
m::close();
}
- public function testArrayDot()
- {
- $array = Arr::dot(['name' => 'taylor', 'languages' => ['php' => true]]);
- $this->assertEquals($array, ['name' => 'taylor', 'languages.php' => true]);
- }
-
- public function testArrayGet()
- {
- $array = ['names' => ['developer' => 'taylor']];
- $this->assertEquals('taylor', Arr::get($array, 'names.developer'));
- $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', 'dayle'));
- $this->assertEquals('dayle', Arr::get($array, 'names.otherDeveloper', function () {
- return 'dayle';
- }));
- }
-
- public function testArrayHas()
- {
- $array = ['names' => ['developer' => 'taylor']];
- $this->assertTrue(Arr::has($array, 'names'));
- $this->assertTrue(Arr::has($array, 'names.developer'));
- $this->assertFalse(Arr::has($array, 'foo'));
- $this->assertFalse(Arr::has($array, 'foo.bar'));
- }
-
- public function testArraySet()
- {
- $array = [];
- Arr::set($array, 'names.developer', 'taylor');
- $this->assertEquals('taylor', $array['names']['developer']);
- }
-
- public function testArrayForget()
- {
- $array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle']];
- Arr::forget($array, 'names.developer');
- $this->assertFalse(isset($array['names']['developer']));
- $this->assertTrue(isset($array['names']['otherDeveloper']));
-
- $array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle', 'thirdDeveloper' => 'Lucas']];
- Arr::forget($array, ['names.developer', 'names.otherDeveloper']);
- $this->assertFalse(isset($array['names']['developer']));
- $this->assertFalse(isset($array['names']['otherDeveloper']));
- $this->assertTrue(isset($array['names']['thirdDeveloper']));
-
- $array = ['names' => ['developer' => 'taylor', 'otherDeveloper' => 'dayle'], 'otherNames' => ['developer' => 'Lucas', 'otherDeveloper' => 'Graham']];
- Arr::forget($array, ['names.developer', 'otherNames.otherDeveloper']);
- $expected = ['names' => ['otherDeveloper' => 'dayle'], 'otherNames' => ['developer' => 'Lucas']];
- $this->assertEquals($expected, $array);
- }
-
- public function testArrayPluckWithArrayAndObjectValues()
- {
- $array = [(object) ['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']];
- $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'name'));
- $this->assertEquals(['taylor' => 'foo', 'dayle' => 'bar'], Arr::pluck($array, 'email', 'name'));
- }
-
- public function testArrayPluckWithNestedKeys()
- {
- $array = [['user' => ['taylor', 'otwell']], ['user' => ['dayle', 'rees']]];
- $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, 'user.0'));
- $this->assertEquals(['taylor', 'dayle'], Arr::pluck($array, ['user', 0]));
- $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, 'user.1', 'user.0'));
- $this->assertEquals(['taylor' => 'otwell', 'dayle' => 'rees'], Arr::pluck($array, ['user', 1], ['user', 0]));
- }
-
- public function testArrayPluckWithNestedArrays()
- {
- $array = [
- [
- 'account' => 'a',
- 'users' => [
- ['first' => 'taylor', 'last' => 'otwell', 'email' => 'taylorotwell@gmail.com'],
- ],
- ],
- [
- 'account' => 'b',
- 'users' => [
- ['first' => 'abigail', 'last' => 'otwell'],
- ['first' => 'dayle', 'last' => 'rees'],
- ],
- ],
- ];
-
- $this->assertEquals([['taylor'], ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first'));
- $this->assertEquals(['a' => ['taylor'], 'b' => ['abigail', 'dayle']], Arr::pluck($array, 'users.*.first', 'account'));
- $this->assertEquals([['taylorotwell@gmail.com'], [null, null]], Arr::pluck($array, 'users.*.email'));
- }
-
- public function testArrayExcept()
- {
- $array = ['name' => 'taylor', 'age' => 26];
- $this->assertEquals(['age' => 26], Arr::except($array, ['name']));
- $this->assertEquals(['age' => 26], Arr::except($array, 'name'));
-
- $array = ['name' => 'taylor', 'framework' => ['language' => 'PHP', 'name' => 'Laravel']];
- $this->assertEquals(['name' => 'taylor'], Arr::except($array, 'framework'));
- $this->assertEquals(['name' => 'taylor', 'framework' => ['name' => 'Laravel']], Arr::except($array, 'framework.language'));
- $this->assertEquals(['framework' => ['language' => 'PHP']], Arr::except($array, ['name', 'framework.name']));
- }
-
- public function testArrayOnly()
- {
- $array = ['name' => 'taylor', 'age' => 26];
- $this->assertEquals(['name' => 'taylor'], Arr::only($array, ['name']));
- $this->assertEmpty(Arr::only($array, ['nonExistingKey']));
- }
-
- public function testArrayCollapse()
- {
- $array = [[1], [2], [3], ['foo', 'bar'], collect(['baz', 'boom'])];
- $this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], Arr::collapse($array));
- }
-
- public function testArrayDivide()
- {
- $array = ['name' => 'taylor'];
- [$keys, $values] = Arr::divide($array);
- $this->assertEquals(['name'], $keys);
- $this->assertEquals(['taylor'], $values);
- }
-
- public function testArrayFirst()
- {
- $array = ['name' => 'taylor', 'otherDeveloper' => 'dayle'];
- $this->assertEquals('dayle', Arr::first($array, function ($value) {
- return $value == 'dayle';
- }));
- }
-
- public function testArrayLast()
- {
- $array = [100, 250, 290, 320, 500, 560, 670];
- $this->assertEquals(670, Arr::last($array, function ($value) {
- return $value > 320;
- }));
- }
-
- public function testArrayPluck()
- {
- $data = [
- 'post-1' => [
- 'comments' => [
- 'tags' => [
- '#foo', '#bar',
- ],
- ],
- ],
- 'post-2' => [
- 'comments' => [
- 'tags' => [
- '#baz',
- ],
- ],
- ],
- ];
-
- $this->assertEquals([
- 0 => [
- 'tags' => [
- '#foo', '#bar',
- ],
- ],
- 1 => [
- 'tags' => [
- '#baz',
- ],
- ],
- ], Arr::pluck($data, 'comments'));
-
- $this->assertEquals([['#foo', '#bar'], ['#baz']], Arr::pluck($data, 'comments.tags'));
- $this->assertEquals([null, null], Arr::pluck($data, 'foo'));
- $this->assertEquals([null, null], Arr::pluck($data, 'foo.bar'));
- }
-
- public function testArrayPrepend()
- {
- $array = Arr::prepend(['one', 'two', 'three', 'four'], 'zero');
- $this->assertEquals(['zero', 'one', 'two', 'three', 'four'], $array);
-
- $array = Arr::prepend(['one' => 1, 'two' => 2], 0, 'zero');
- $this->assertEquals(['zero' => 0, 'one' => 1, 'two' => 2], $array);
- }
-
- public function testArrayFlatten()
- {
- $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten([['#foo', '#bar'], ['#baz']]));
- }
-
public function testE()
{
$str = 'A \'quote\' is <b>bold</b>';
@@ -499,76 +308,6 @@ public function testDataSetWithDoubleStar()
], $data);
}
- public function testArraySort()
- {
- $array = [
- ['name' => 'baz'],
- ['name' => 'foo'],
- ['name' => 'bar'],
- ];
-
- $this->assertEquals([
- ['name' => 'bar'],
- ['name' => 'baz'],
- ['name' => 'foo'], ],
- array_values(Arr::sort($array, function ($v) {
- return $v['name'];
- })));
- }
-
- public function testArraySortRecursive()
- {
- $array = [
- [
- 'foo',
- 'bar',
- 'baz',
- ],
- [
- 'baz',
- 'foo',
- 'bar',
- ],
- ];
-
- $assumedArray = [
- [
- 'bar',
- 'baz',
- 'foo',
- ],
- [
- 'bar',
- 'baz',
- 'foo',
- ],
- ];
-
- $this->assertEquals($assumedArray, Arr::sortRecursive($array));
- }
-
- public function testArrayWhere()
- {
- $array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8];
- $this->assertEquals(['b' => 2, 'd' => 4, 'f' => 6, 'h' => 8], Arr::where(
- $array,
- function ($value, $key) {
- return $value % 2 === 0;
- }
- ));
- }
-
- public function testArrayWrap()
- {
- $string = 'a';
- $array = ['a'];
- $object = new stdClass;
- $object->value = 'a';
- $this->assertEquals(['a'], Arr::wrap($string));
- $this->assertEquals($array, Arr::wrap($array));
- $this->assertEquals([$object], Arr::wrap($object));
- }
-
public function testHead()
{
$array = ['a', 'b', 'c'];
@@ -609,19 +348,6 @@ public function testClassUsesRecursiveReturnParentTraitsFirst()
class_uses_recursive(SupportTestClassThree::class));
}
- public function testArrayAdd()
- {
- $this->assertEquals(['surname' => 'Mövsümov'], Arr::add([], 'surname', 'Mövsümov'));
- $this->assertEquals(['developer' => ['name' => 'Ferid']], Arr::add([], 'developer.name', 'Ferid'));
- }
-
- public function testArrayPull()
- {
- $developer = ['firstname' => 'Ferid', 'surname' => 'Mövsümov'];
- $this->assertEquals('Mövsümov', Arr::pull($developer, 'surname'));
- $this->assertEquals(['firstname' => 'Ferid'], $developer);
- }
-
public function testTap()
{
$object = (object) ['id' => 1]; | true |
Other | laravel | framework | 27164a6bdb0d5571d0d01abd92a53d321d729d26.json | Use proper method name for Pheanstalk | src/Illuminate/Queue/Connectors/BeanstalkdConnector.php | @@ -32,7 +32,7 @@ public function connect(array $config)
*/
protected function pheanstalk(array $config)
{
- return Pheanstalk::connect(
+ return Pheanstalk::create(
$config['host'],
$config['port'] ?? Pheanstalk::DEFAULT_PORT,
$config['timeout'] ?? Connection::DEFAULT_CONNECT_TIMEOUT | false |
Other | laravel | framework | 09e9f8ee8132a727bfe4e0f1c8e36ed67952bad7.json | Apply fixes from StyleCI (#27629) | tests/Queue/QueueBeanstalkdQueueTest.php | @@ -9,7 +9,6 @@
use Illuminate\Container\Container;
use Illuminate\Queue\BeanstalkdQueue;
use Illuminate\Queue\Jobs\BeanstalkdJob;
-use Pheanstalk\Contract\PheanstalkInterface;
class QueueBeanstalkdQueueTest extends TestCase
{ | false |
Other | laravel | framework | f0504da67feda7c77fcdddb5c3130d6308b50308.json | Apply fixes from StyleCI (#27628) | tests/Database/DatabaseEloquentModelTest.php | @@ -8,7 +8,6 @@
use Mockery as m;
use LogicException;
use ReflectionClass;
-use RuntimeException;
use DateTimeImmutable;
use DateTimeInterface;
use InvalidArgumentException; | false |
Other | laravel | framework | db20d3d754fa212605fad0cbcba833c714fda2e9.json | Remove unused imports | tests/Support/SupportHelpersTest.php | @@ -7,7 +7,6 @@
use Mockery as m;
use RuntimeException;
use Illuminate\Support\Arr;
-use Illuminate\Support\Str;
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Optional;
use Illuminate\Contracts\Support\Htmlable; | false |
Other | laravel | framework | e70162b405a767d10b43e597c3de4753c9b87d83.json | Move str tests | tests/Support/SupportHelpersTest.php | @@ -209,48 +209,6 @@ public function testArrayFlatten()
$this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten([['#foo', '#bar'], ['#baz']]));
}
- public function testStrIs()
- {
- $this->assertTrue(Str::is('*.dev', 'localhost.dev'));
- $this->assertTrue(Str::is('a', 'a'));
- $this->assertTrue(Str::is('/', '/'));
- $this->assertTrue(Str::is('*dev*', 'localhost.dev'));
- $this->assertTrue(Str::is('foo?bar', 'foo?bar'));
- $this->assertFalse(Str::is('*something', 'foobar'));
- $this->assertFalse(Str::is('foo', 'bar'));
- $this->assertFalse(Str::is('foo.*', 'foobar'));
- $this->assertFalse(Str::is('foo.ar', 'foobar'));
- $this->assertFalse(Str::is('foo?bar', 'foobar'));
- $this->assertFalse(Str::is('foo?bar', 'fobar'));
-
- $this->assertTrue(Str::is([
- '*.dev',
- '*oc*',
- ], 'localhost.dev'));
-
- $this->assertFalse(Str::is([
- '/',
- 'a*',
- ], 'localhost.dev'));
-
- $this->assertFalse(Str::is([], 'localhost.dev'));
- }
-
- public function testStrRandom()
- {
- $result = Str::random(20);
- $this->assertIsString($result);
- $this->assertEquals(20, strlen($result));
- }
-
- public function testStartsWith()
- {
- $this->assertTrue(Str::startsWith('jason', 'jas'));
- $this->assertTrue(Str::startsWith('jason', ['jas']));
- $this->assertFalse(Str::startsWith('jason', 'day'));
- $this->assertFalse(Str::startsWith('jason', ['day']));
- }
-
public function testE()
{
$str = 'A \'quote\' is <b>bold</b>';
@@ -260,80 +218,6 @@ public function testE()
$this->assertEquals($str, e($html));
}
- public function testEndsWith()
- {
- $this->assertTrue(Str::endsWith('jason', 'on'));
- $this->assertTrue(Str::endsWith('jason', ['on']));
- $this->assertFalse(Str::endsWith('jason', 'no'));
- $this->assertFalse(Str::endsWith('jason', ['no']));
- }
-
- public function testStrAfter()
- {
- $this->assertEquals('nah', Str::after('hannah', 'han'));
- $this->assertEquals('nah', Str::after('hannah', 'n'));
- $this->assertEquals('hannah', Str::after('hannah', 'xxxx'));
- }
-
- public function testStrContains()
- {
- $this->assertTrue(Str::contains('taylor', 'ylo'));
- $this->assertTrue(Str::contains('taylor', ['ylo']));
- $this->assertFalse(Str::contains('taylor', 'xxx'));
- $this->assertFalse(Str::contains('taylor', ['xxx']));
- $this->assertTrue(Str::contains('taylor', ['xxx', 'taylor']));
- }
-
- public function testStrFinish()
- {
- $this->assertEquals('test/string/', Str::finish('test/string', '/'));
- $this->assertEquals('test/string/', Str::finish('test/string/', '/'));
- $this->assertEquals('test/string/', Str::finish('test/string//', '/'));
- }
-
- public function testStrStart()
- {
- $this->assertEquals('/test/string', Str::start('test/string', '/'));
- $this->assertEquals('/test/string', Str::start('/test/string', '/'));
- $this->assertEquals('/test/string', Str::start('//test/string', '/'));
- }
-
- public function testSnakeCase()
- {
- $this->assertEquals('foo_bar', Str::snake('fooBar'));
- $this->assertEquals('foo_bar', Str::snake('fooBar')); // test cache
- }
-
- public function testStrLimit()
- {
- $string = 'The PHP framework for web artisans.';
- $this->assertEquals('The PHP...', Str::limit($string, 7));
- $this->assertEquals('The PHP', Str::limit($string, 7, ''));
- $this->assertEquals('The PHP framework for web artisans.', Str::limit($string, 100));
-
- $nonAsciiString = '这是一段中文';
- $this->assertEquals('这是一...', Str::limit($nonAsciiString, 6));
- $this->assertEquals('这是一', Str::limit($nonAsciiString, 6, ''));
- }
-
- public function testCamelCase()
- {
- $this->assertEquals('fooBar', Str::camel('FooBar'));
- $this->assertEquals('fooBar', Str::camel('foo_bar'));
- $this->assertEquals('fooBar', Str::camel('foo_bar')); // test cache
- $this->assertEquals('fooBarBaz', Str::camel('Foo-barBaz'));
- $this->assertEquals('fooBarBaz', Str::camel('foo-bar_baz'));
- }
-
- public function testStudlyCase()
- {
- $this->assertEquals('FooBar', Str::studly('fooBar'));
- $this->assertEquals('FooBar', Str::studly('foo_bar'));
- $this->assertEquals('FooBar', Str::studly('foo_bar')); // test cache
- $this->assertEquals('FooBarBaz', Str::studly('foo-barBaz'));
- $this->assertEquals('FooBarBaz', Str::studly('foo-bar_baz'));
- }
-
public function testClassBasename()
{
$this->assertEquals('Baz', class_basename('Foo\Bar\Baz')); | true |
Other | laravel | framework | e70162b405a767d10b43e597c3de4753c9b87d83.json | Move str tests | tests/Support/SupportStrTest.php | @@ -145,6 +145,13 @@ public function testSlug()
$this->assertEquals('سلام-دنیا', Str::slug('سلام دنیا', '-', null));
}
+ public function testStrStart()
+ {
+ $this->assertEquals('/test/string', Str::start('test/string', '/'));
+ $this->assertEquals('/test/string', Str::start('/test/string', '/'));
+ $this->assertEquals('/test/string', Str::start('//test/string', '/'));
+ }
+
public function testFinish()
{
$this->assertEquals('abbc', Str::finish('ab', 'bc'));
@@ -207,6 +214,15 @@ public function testLimit()
{
$this->assertEquals('Laravel is...', Str::limit('Laravel is a free, open source PHP web application framework.', 10));
$this->assertEquals('这是一...', Str::limit('这是一段中文', 6));
+
+ $string = 'The PHP framework for web artisans.';
+ $this->assertEquals('The PHP...', Str::limit($string, 7));
+ $this->assertEquals('The PHP', Str::limit($string, 7, ''));
+ $this->assertEquals('The PHP framework for web artisans.', Str::limit($string, 100));
+
+ $nonAsciiString = '这是一段中文';
+ $this->assertEquals('这是一...', Str::limit($nonAsciiString, 6));
+ $this->assertEquals('这是一', Str::limit($nonAsciiString, 6, ''));
}
public function testLength()
@@ -274,6 +290,12 @@ public function testStudly()
$this->assertEquals('LaravelPhpFramework', Str::studly('laravel_php_framework'));
$this->assertEquals('LaravelPhPFramework', Str::studly('laravel-phP-framework'));
$this->assertEquals('LaravelPhpFramework', Str::studly('laravel -_- php -_- framework '));
+
+ $this->assertEquals('FooBar', Str::studly('fooBar'));
+ $this->assertEquals('FooBar', Str::studly('foo_bar'));
+ $this->assertEquals('FooBar', Str::studly('foo_bar')); // test cache
+ $this->assertEquals('FooBarBaz', Str::studly('foo-barBaz'));
+ $this->assertEquals('FooBarBaz', Str::studly('foo-bar_baz'));
}
public function testCamel()
@@ -282,6 +304,12 @@ public function testCamel()
$this->assertEquals('laravelPhpFramework', Str::camel('Laravel_php_framework'));
$this->assertEquals('laravelPhPFramework', Str::camel('Laravel-phP-framework'));
$this->assertEquals('laravelPhpFramework', Str::camel('Laravel -_- php -_- framework '));
+
+ $this->assertEquals('fooBar', Str::camel('FooBar'));
+ $this->assertEquals('fooBar', Str::camel('foo_bar'));
+ $this->assertEquals('fooBar', Str::camel('foo_bar')); // test cache
+ $this->assertEquals('fooBarBaz', Str::camel('Foo-barBaz'));
+ $this->assertEquals('fooBarBaz', Str::camel('foo-bar_baz'));
}
public function testSubstr() | true |
Other | laravel | framework | 8cfb90fc06c3166f89ffe0e23c30d49a6453fac2.json | fix failing tests on windows | tests/Integration/Mail/RenderingMailWithLocaleTest.php | @@ -31,14 +31,14 @@ public function testMailableRendersInDefaultLocale()
{
$mail = new RenderedTestMail;
- $this->assertStringContainsString("name\n", $mail->render());
+ $this->assertStringContainsString('name'.PHP_EOL, $mail->render());
}
public function testMailableRendersInSelectedLocale()
{
$mail = (new RenderedTestMail)->locale('es');
- $this->assertStringContainsString("nombre\n", $mail->render());
+ $this->assertStringContainsString('nombre'.PHP_EOL, $mail->render());
}
public function testMailableRendersInAppSelectedLocale()
@@ -47,7 +47,7 @@ public function testMailableRendersInAppSelectedLocale()
$mail = new RenderedTestMail;
- $this->assertStringContainsString("nombre\n", $mail->render());
+ $this->assertStringContainsString('nombre'.PHP_EOL, $mail->render());
}
}
| false |
Other | laravel | framework | e2e3dffbe0b3062620b7f6fd1e25f04e4f461909.json | Use new fromShellCommandline method | src/Illuminate/Console/Scheduling/Event.php | @@ -208,9 +208,7 @@ protected function runCommandInForeground(Container $container)
{
$this->callBeforeCallbacks($container);
- (new Process(
- $this->buildCommand(), base_path(), null, null, null
- ))->run();
+ Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
$this->callAfterCallbacks($container);
}
@@ -225,9 +223,7 @@ protected function runCommandInBackground(Container $container)
{
$this->callBeforeCallbacks($container);
- (new Process(
- $this->buildCommand(), base_path(), null, null, null
- ))->run();
+ Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
}
/** | false |
Other | laravel | framework | 9a9b43e610dbfbcab5b77d584539321f61883097.json | Fix incorrect param type | src/Illuminate/Queue/Listener.php | @@ -126,7 +126,7 @@ public function makeProcess($connection, $queue, ListenerOptions $options)
/**
* Add the environment option to the given command.
*
- * @param string $command
+ * @param array $command
* @param \Illuminate\Queue\ListenerOptions $options
* @return array
*/ | false |
Other | laravel | framework | c821cbf6f20fca4c50aa9d8fb08f71425afc07b8.json | Add union and union all tests for Postgres | tests/Database/DatabaseQueryBuilderTest.php | @@ -772,6 +772,13 @@ public function testUnions()
$this->assertEquals($expectedSql, $builder->toSql());
$this->assertEquals([0 => 10, 1 => 1, 2 => 11, 3 => 2], $builder->getBindings());
+ $builder = $this->getPostgresBuilder();
+ $expectedSql = '(select "name" from "users" where "id" = ?) union (select "name" from "users" where "id" = ?)';
+ $builder->select('name')->from('users')->where('id', '=', 1);
+ $builder->union($this->getPostgresBuilder()->select('name')->from('users')->where('id', '=', 2));
+ $this->assertEquals($expectedSql, $builder->toSql());
+ $this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
+
$builder = $this->getSQLiteBuilder();
$expectedSql = 'select * from (select "name" from "users" where "id" = ?) union select * from (select "name" from "users" where "id" = ?)';
$builder->select('name')->from('users')->where('id', '=', 1);
@@ -787,6 +794,13 @@ public function testUnionAlls()
$builder->unionAll($this->getBuilder()->select('*')->from('users')->where('id', '=', 2));
$this->assertEquals('select * from "users" where "id" = ? union all select * from "users" where "id" = ?', $builder->toSql());
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
+
+ $expectedSql = '(select * from "users" where "id" = ?) union all (select * from "users" where "id" = ?)';
+ $builder = $this->getPostgresBuilder();
+ $builder->select('*')->from('users')->where('id', '=', 1);
+ $builder->unionAll($this->getBuilder()->select('*')->from('users')->where('id', '=', 2));
+ $this->assertEquals($expectedSql, $builder->toSql());
+ $this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
}
public function testMultipleUnions() | false |
Other | laravel | framework | 06d37a4ee79da306d30f7daa89a612a3f859b34a.json | Add union with limit and offset test for Postgres | tests/Database/DatabaseQueryBuilderTest.php | @@ -826,6 +826,20 @@ public function testUnionLimitsAndOffsets()
$builder->union($this->getBuilder()->select('*')->from('dogs'));
$builder->skip(5)->take(10);
$this->assertEquals('select * from "users" union select * from "dogs" limit 10 offset 5', $builder->toSql());
+
+ $expectedSql = '(select * from "users") union (select * from "dogs") limit 10 offset 5';
+ $builder = $this->getPostgresBuilder();
+ $builder->select('*')->from('users');
+ $builder->union($this->getBuilder()->select('*')->from('dogs'));
+ $builder->skip(5)->take(10);
+ $this->assertEquals($expectedSql, $builder->toSql());
+
+ $expectedSql = '(select * from "users" limit 11) union (select * from "dogs" limit 22) limit 10 offset 5';
+ $builder = $this->getPostgresBuilder();
+ $builder->select('*')->from('users')->limit(11);
+ $builder->union($this->getBuilder()->select('*')->from('dogs')->limit(22));
+ $builder->skip(5)->take(10);
+ $this->assertEquals($expectedSql, $builder->toSql());
}
public function testUnionWithJoin() | false |
Other | laravel | framework | e7aa0e9785214aaeefb3c2822e35b84a2d944ba5.json | Improve union all queries in Postgres grammar | src/Illuminate/Database/Query/Grammars/PostgresGrammar.php | @@ -8,6 +8,25 @@
class PostgresGrammar extends Grammar
{
+ /**
+ * The components that make up a select clause.
+ *
+ * @var array
+ */
+ protected $selectComponents = [
+ 'aggregate',
+ 'columns',
+ 'from',
+ 'joins',
+ 'wheres',
+ 'groups',
+ 'havings',
+ 'orders',
+ 'limit',
+ 'offset',
+ 'lock',
+ ];
+
/**
* All of the available clause operators.
*
@@ -85,6 +104,40 @@ protected function dateBasedWhere($type, Builder $query, $where)
return 'extract('.$type.' from '.$this->wrap($where['column']).') '.$where['operator'].' '.$value;
}
+ /**
+ * Compile a select query into SQL.
+ *
+ * @param \Illuminate\Database\Query\Builder $query
+ * @return string
+ */
+ public function compileSelect(Builder $query)
+ {
+ if ($query->unions && $query->aggregate) {
+ return $this->compileUnionAggregate($query);
+ }
+
+ $sql = parent::compileSelect($query);
+
+ if ($query->unions) {
+ $sql = '('.$sql.') '.$this->compileUnions($query);
+ }
+
+ return $sql;
+ }
+
+ /**
+ * Compile a single union statement.
+ *
+ * @param array $union
+ * @return string
+ */
+ protected function compileUnion(array $union)
+ {
+ $conjunction = $union['all'] ? ' union all ' : ' union ';
+
+ return $conjunction.'('.$union['query']->toSql().')';
+ }
+
/**
* Compile a "JSON contains" statement into SQL.
* | false |
Other | laravel | framework | 76c3d4cc2697c64d02e0e2239274ebf84656b857.json | return whatever the mailer returns | src/Illuminate/Mail/Mailable.php | @@ -147,10 +147,10 @@ class Mailable implements MailableContract, Renderable
*/
public function send(MailerContract $mailer)
{
- $this->withLocale($this->locale, function () use ($mailer) {
+ return $this->withLocale($this->locale, function () use ($mailer) {
Container::getInstance()->call([$this, 'build']);
- $mailer->send($this->buildView(), $this->buildViewData(), function ($message) {
+ return $mailer->send($this->buildView(), $this->buildViewData(), function ($message) {
$this->buildFrom($message)
->buildRecipients($message)
->buildSubject($message) | false |
Other | laravel | framework | 0c7879c305c2ad65fab1a617fabcee68d91cf6f5.json | update hash param | src/Illuminate/Auth/AuthManager.php | @@ -156,7 +156,8 @@ public function createTokenDriver($name, $config)
$this->createUserProvider($config['provider'] ?? null),
$this->app['request'],
$config['input_key'] ?? 'api_token',
- $config['storage_key'] ?? 'api_token'
+ $config['storage_key'] ?? 'api_token',
+ $config['hash'] ?? false
);
$this->app->refresh('request', $guard, 'setRequest'); | false |
Other | laravel | framework | fe1d67b0fbda54c78f3e1ee217a2fc36edd3c79c.json | Apply fixes from StyleCI (#27587) | tests/Auth/AuthTokenGuardTest.php | @@ -33,7 +33,6 @@ public function testUserCanBeRetrievedByQueryStringVariable()
$this->assertEquals(1, $guard->id());
}
-
public function testTokenCanBeHashed()
{
$provider = m::mock(UserProvider::class); | false |
Other | laravel | framework | e2e16744bea55dab43a4b2093f6de67720e6a28d.json | add support for sha256 hashing on token guard | src/Illuminate/Auth/TokenGuard.php | @@ -31,17 +31,31 @@ class TokenGuard implements Guard
*/
protected $storageKey;
+ /**
+ * Indicates if the API token is hashed in storage.
+ *
+ * @var bool
+ */
+ protected $hash = false;
+
/**
* Create a new authentication guard.
*
* @param \Illuminate\Contracts\Auth\UserProvider $provider
* @param \Illuminate\Http\Request $request
* @param string $inputKey
* @param string $storageKey
+ * @param bool $hash
* @return void
*/
- public function __construct(UserProvider $provider, Request $request, $inputKey = 'api_token', $storageKey = 'api_token')
+ public function __construct(
+ UserProvider $provider,
+ Request $request,
+ $inputKey = 'api_token',
+ $storageKey = 'api_token',
+ $hash = false)
{
+ $this->hash = $hash;
$this->request = $request;
$this->provider = $provider;
$this->inputKey = $inputKey;
@@ -68,7 +82,7 @@ public function user()
if (! empty($token)) {
$user = $this->provider->retrieveByCredentials([
- $this->storageKey => $token,
+ $this->storageKey => $this->hash ? hash('sha256', $token) : $token,
]);
}
| true |
Other | laravel | framework | e2e16744bea55dab43a4b2093f6de67720e6a28d.json | add support for sha256 hashing on token guard | tests/Auth/AuthTokenGuardTest.php | @@ -33,6 +33,25 @@ public function testUserCanBeRetrievedByQueryStringVariable()
$this->assertEquals(1, $guard->id());
}
+
+ public function testTokenCanBeHashed()
+ {
+ $provider = m::mock(UserProvider::class);
+ $user = new AuthTokenGuardTestUser;
+ $user->id = 1;
+ $provider->shouldReceive('retrieveByCredentials')->once()->with(['api_token' => hash('sha256', 'foo')])->andReturn($user);
+ $request = Request::create('/', 'GET', ['api_token' => 'foo']);
+
+ $guard = new TokenGuard($provider, $request, 'api_token', 'api_token', $hash = true);
+
+ $user = $guard->user();
+
+ $this->assertEquals(1, $user->id);
+ $this->assertTrue($guard->check());
+ $this->assertFalse($guard->guest());
+ $this->assertEquals(1, $guard->id());
+ }
+
public function testUserCanBeRetrievedByAuthHeaders()
{
$provider = m::mock(UserProvider::class); | true |
Other | laravel | framework | 1db746d0a8273720632f5cd46a32ef451111e8d5.json | Apply fixes from StyleCI (#27586) | src/Illuminate/Auth/TokenGuard.php | @@ -68,7 +68,7 @@ public function user()
if (! empty($token)) {
$user = $this->provider->retrieveByCredentials([
- $this->storageKey => $token
+ $this->storageKey => $token,
]);
}
| false |
Other | laravel | framework | ad027d845fe3eec20cecdbe6f00d971a065d30c3.json | Allow configuration of token guard keys
This change allows users to configure the token guard input and storage keys in the auth guard configuration. It's useful they want something else than the default `api_token` name. | src/Illuminate/Auth/AuthManager.php | @@ -154,7 +154,9 @@ public function createTokenDriver($name, $config)
// user in the database or another persistence layer where users are.
$guard = new TokenGuard(
$this->createUserProvider($config['provider'] ?? null),
- $this->app['request']
+ $this->app['request'],
+ $config['input_key'] ?? 'api_token',
+ $config['storage_key'] ?? 'api_token'
);
$this->app->refresh('request', $guard, 'setRequest'); | false |
Other | laravel | framework | 150a63d491c89f73a8153c4548406e776e5f150a.json | allow registration of guesser callback' | src/Illuminate/Auth/Access/Gate.php | @@ -64,6 +64,13 @@ class Gate implements GateContract
*/
protected $stringCallbacks = [];
+ /**
+ * The callback to be used to guess policy names.
+ *
+ * @var callable|null
+ */
+ protected $guessPolicyNamesUsingCallback;
+
/**
* Create a new gate instance.
*
@@ -550,11 +557,28 @@ public function getPolicyFor($class)
*/
protected function guessPolicyName($class)
{
+ if ($this->guessPolicyNamesUsingCallback) {
+ return call_user_func($this->guessPolicyNamesUsingCallback, $class);
+ }
+
$classDirname = str_replace('/', '\\', dirname(str_replace('\\', '/', $class)));
return $classDirname.'\\Policies\\'.class_basename($class).'Policy';
}
+ /**
+ * Specify a callback to be used to guess policy names.
+ *
+ * @param callable $callback
+ * @return $this
+ */
+ public function guessPolicyNamesUsing(callable $callback)
+ {
+ $this->guessPolicyNamesUsingCallback = $callback;
+
+ return $this;
+ }
+
/**
* Build a policy class instance of the given type.
* | false |
Other | laravel | framework | dee4d82e0259b270413573c7792d92d49b51fe2a.json | add tests for policy resolution | src/Illuminate/Auth/Access/Gate.php | @@ -550,7 +550,7 @@ public function getPolicyFor($class)
*/
protected function guessPolicyName($class)
{
- return dirname(str_replace('\\', '/', $class)).'\\Policies\\'.class_basename($class).'Policy';
+ return str_replace('/', '\\', dirname(str_replace('\\', '/', $class)).'\\Policies\\'.class_basename($class).'Policy');
}
/** | true |
Other | laravel | framework | dee4d82e0259b270413573c7792d92d49b51fe2a.json | add tests for policy resolution | tests/Integration/Auth/Fixtures/Policies/AuthenticationTestUserPolicy.php | @@ -0,0 +1,8 @@
+<?php
+
+namespace Illuminate\Tests\Integration\Auth\Fixtures\Policies;
+
+class AuthenticationTestUserPolicy
+{
+ //
+} | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.