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 | bf02037b77fc4075a067ca08d565349d391557bb.json | update validation component | src/Illuminate/Validation/composer.json | @@ -16,7 +16,7 @@
"require": {
"php": "^7.1.3",
"ext-json": "*",
- "egulias/email-validator": "~2.0",
+ "egulias/email-validator": "^2.0",
"illuminate/container": "5.8.*",
"illuminate/contracts": "5.8.*",
"illuminate/support": "5.8.*", | false |
Other | laravel | framework | c071123617c02d5cf9db082015ad10f81029cb55.json | Use a library for email validation (#26503) | composer.json | @@ -21,6 +21,7 @@
"ext-openssl": "*",
"doctrine/inflector": "^1.1",
"dragonmantank/cron-expression": "^2.0",
+ "egulias/email-validator": "~2.0",
"erusev/parsedown": "^1.7",
"league/flysystem": "^1.0.8",
"monolog/monolog": "^1.12", | true |
Other | laravel | framework | c071123617c02d5cf9db082015ad10f81029cb55.json | Use a library for email validation (#26503) | src/Illuminate/Validation/Concerns/ValidatesAttributes.php | @@ -16,7 +16,9 @@
use Illuminate\Validation\Rules\Exists;
use Illuminate\Validation\Rules\Unique;
use Illuminate\Validation\ValidationData;
+use Egulias\EmailValidator\EmailValidator;
use Symfony\Component\HttpFoundation\File\File;
+use Egulias\EmailValidator\Validation\RFCValidation;
use Symfony\Component\HttpFoundation\File\UploadedFile;
trait ValidatesAttributes
@@ -590,7 +592,7 @@ public function validateDistinct($attribute, $value, $parameters)
*/
public function validateEmail($attribute, $value)
{
- return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
+ return (new EmailValidator)->isValid($value, new RFCValidation);
}
/** | true |
Other | laravel | framework | c071123617c02d5cf9db082015ad10f81029cb55.json | Use a library for email validation (#26503) | src/Illuminate/Validation/composer.json | @@ -16,6 +16,7 @@
"require": {
"php": "^7.1.3",
"ext-json": "*",
+ "egulias/email-validator": "~2.0",
"illuminate/container": "5.8.*",
"illuminate/contracts": "5.8.*",
"illuminate/support": "5.8.*", | true |
Other | laravel | framework | c071123617c02d5cf9db082015ad10f81029cb55.json | Use a library for email validation (#26503) | tests/Validation/ValidationValidatorTest.php | @@ -386,10 +386,10 @@ public function testInputIsReplaced()
{
$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.email' => ':input is not a valid email'], 'en');
- $v = new Validator($trans, ['email' => 'a@s'], ['email' => 'email']);
+ $v = new Validator($trans, ['email' => 'a@@s'], ['email' => 'email']);
$this->assertFalse($v->passes());
$v->messages()->setFormat(':message');
- $this->assertEquals('a@s is not a valid email', $v->messages()->first('email'));
+ $this->assertEquals('a@@s is not a valid email', $v->messages()->first('email'));
$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.email' => ':input is not a valid email'], 'en');
@@ -1969,6 +1969,12 @@ public function testValidateEmail()
$this->assertTrue($v->passes());
}
+ public function testValidateEmailWithInternationalCharacters()
+ {
+ $v = new Validator($this->getIlluminateArrayTranslator(), ['x' => 'foo@gmäil.com'], ['x' => 'email']);
+ $this->assertTrue($v->passes());
+ }
+
/**
* @dataProvider validUrls
*/ | true |
Other | laravel | framework | 618b49a38bfc88717ea61869284c2254aca5bbfb.json | Apply fixes from StyleCI (#26512) | tests/Mail/MailLogTransportTest.php | @@ -6,7 +6,6 @@
use Psr\Log\LoggerInterface;
use Orchestra\Testbench\TestCase;
use Monolog\Handler\StreamHandler;
-use Monolog\Handler\RotatingFileHandler;
use Illuminate\Mail\Transport\LogTransport;
class MailLogTransportTest extends TestCase | false |
Other | laravel | framework | d9ad6863ebdc3b4c1edafad3e4046e0822b0bf46.json | Apply style fixes | src/Illuminate/Validation/Concerns/ValidatesAttributes.php | @@ -571,7 +571,7 @@ public function validateDistinct($attribute, $value, $parameters)
$data = $this->getDistinctValues($attribute);
if (in_array('ignore_case', $parameters)) {
- return empty(preg_grep('/^' . preg_quote($value, '/') . '$/iu', $data));
+ return empty(preg_grep('/^'.preg_quote($value, '/').'$/iu', $data));
}
return ! in_array($value, array_values($data)); | false |
Other | laravel | framework | 6ea332b642f480faf3ea9931057506e2c7a5ba25.json | Reset distinctValues after each check | src/Illuminate/Validation/Validator.php | @@ -257,6 +257,7 @@ public function after($callback)
public function passes()
{
$this->messages = new MessageBag;
+ $this->distinctValues = [];
// We'll spin through each rule, validating the attributes attached to that
// rule. Any error messages will be added to the containers with each of | true |
Other | laravel | framework | 6ea332b642f480faf3ea9931057506e2c7a5ba25.json | Reset distinctValues after each check | tests/Validation/ValidationValidatorTest.php | @@ -1798,7 +1798,7 @@ public function testValidateDistinct()
$this->assertFalse($v->passes());
$this->assertCount(4, $v->messages());
- $v = new Validator($trans, ['foo' => ['foo', 'bar'], 'bar' => ['foo', 'bar']], ['foo.*' => 'distinct', 'bar.*' => 'distinct']);
+ $v->setData(['foo' => ['foo', 'bar'], 'bar' => ['foo', 'bar']]);
$this->assertTrue($v->passes());
$v = new Validator($trans, ['foo' => ['foo', 'foo']], ['foo.*' => 'distinct'], ['foo.*.distinct' => 'There is a duplication!']); | true |
Other | laravel | framework | be79e7625c55526db900f4e2105ac5d15a6b4633.json | Apply fixes from StyleCI (#26479) | src/Illuminate/Session/Middleware/StartSession.php | @@ -8,7 +8,6 @@
use Illuminate\Support\Facades\Date;
use Illuminate\Session\SessionManager;
use Illuminate\Contracts\Session\Session;
-use Illuminate\Session\CookieSessionHandler;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
| false |
Other | laravel | framework | 463bb87662143734251923b36a473f5b4cdb5440.json | remove unused method | src/Illuminate/Session/Middleware/StartSession.php | @@ -203,18 +203,4 @@ protected function sessionIsPersistent(array $config = null)
return ! in_array($config['driver'], [null, 'array']);
}
-
- /**
- * Determine if the session is using cookie sessions.
- *
- * @return bool
- */
- protected function usingCookieSessions()
- {
- if ($this->sessionConfigured()) {
- return $this->manager->driver()->getHandler() instanceof CookieSessionHandler;
- }
-
- return false;
- }
} | false |
Other | laravel | framework | d3df6d855d2d98ac1ffb05b0d90e2f153f34ae28.json | Apply fixes from StyleCI (#26478) | tests/Integration/Session/SessionPersistenceTest.php | @@ -55,6 +55,7 @@ class FakeNullSessionHandler extends NullSessionHandler
public function write($sessionId, $data)
{
$this->written = true;
+
return true;
}
} | false |
Other | laravel | framework | f546835092206037ce1d9b4103be204e2e9272cc.json | Add missing docblock (#26464) | src/Illuminate/Foundation/Console/PresetCommand.php | @@ -27,6 +27,8 @@ class PresetCommand extends Command
* Execute the console command.
*
* @return void
+ *
+ * @throws \InvalidArgumentException
*/
public function handle()
{ | false |
Other | laravel | framework | cc188a561bc186ed4fc9811e8d60c71550ff8bbe.json | Add ability to publish error views | src/Illuminate/Foundation/Providers/FoundationServiceProvider.php | @@ -17,6 +17,18 @@ class FoundationServiceProvider extends AggregateServiceProvider
FormRequestServiceProvider::class,
];
+ /**
+ * Boot the service provider.
+ */
+ public function boot()
+ {
+ if ($this->app->runningInConsole()) {
+ $this->publishes([
+ __DIR__.'/../Exceptions/views' => $this->app->resourcePath('views/errors/'),
+ ], 'laravel-errors');
+ }
+ }
+
/**
* Register the service provider.
* | false |
Other | laravel | framework | a40653328d830b92b464540bc1468b6f183b75d4.json | Switch increments to use unsignedBigInteger | src/Illuminate/Database/Schema/Blueprint.php | @@ -526,14 +526,14 @@ public function foreign($columns, $name = null)
}
/**
- * Create a new auto-incrementing integer (4-byte) column on the table.
+ * Create a new auto-incrementing integer column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function increments($column)
{
- return $this->unsignedInteger($column, true);
+ return $this->{Builder::$defaultIncrementsType}($column, true);
}
/**
@@ -569,6 +569,17 @@ public function mediumIncrements($column)
return $this->unsignedMediumInteger($column, true);
}
+ /**
+ * Create a new auto-incrementing integer (4-byte) column on the table.
+ *
+ * @param string $column
+ * @return \Illuminate\Database\Schema\ColumnDefinition
+ */
+ public function integerIncrements($column)
+ {
+ return $this->unsignedInteger($column, true);
+ }
+
/**
* Create a new auto-incrementing big integer (8-byte) column on the table.
* | true |
Other | laravel | framework | a40653328d830b92b464540bc1468b6f183b75d4.json | Switch increments to use unsignedBigInteger | src/Illuminate/Database/Schema/Builder.php | @@ -36,6 +36,13 @@ class Builder
*/
public static $defaultStringLength = 255;
+ /**
+ * The default increments type for migrations.
+ *
+ * @var string
+ */
+ public static $defaultIncrementsType = 'unsignedBigInteger';
+
/**
* Create a new database Schema manager.
*
@@ -59,6 +66,16 @@ public static function defaultStringLength($length)
static::$defaultStringLength = $length;
}
+ /**
+ * Set the default increments type to a 4 byte integer.
+ *
+ * @return void
+ */
+ public static function useIntegerIncrements()
+ {
+ static::$defaultIncrementsType = 'unsignedInteger';
+ }
+
/**
* Determine if the given table exists.
* | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | src/Illuminate/Database/Eloquent/Relations/BelongsTo.php | @@ -111,7 +111,9 @@ public function addEagerConstraints(array $models)
// our eagerly loading query so it returns the proper models from execution.
$key = $this->related->getTable().'.'.$this->ownerKey;
- $this->query->whereIn($key, $this->getEagerModelKeys($models));
+ $whereIn = $this->whereInMethod($this->related, $this->ownerKey);
+
+ $this->query->{$whereIn}($key, $this->getEagerModelKeys($models));
}
/** | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | @@ -209,7 +209,9 @@ protected function addWhereConstraints()
*/
public function addEagerConstraints(array $models)
{
- $this->query->whereIn($this->getQualifiedForeignPivotKeyName(), $this->getKeys($models, $this->parentKey));
+ $whereIn = $this->whereInMethod($this->parent, $this->parentKey);
+
+ $this->query->{$whereIn}($this->getQualifiedForeignPivotKeyName(), $this->getKeys($models, $this->parentKey));
}
/** | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php | @@ -146,7 +146,9 @@ public function throughParentSoftDeletes()
*/
public function addEagerConstraints(array $models)
{
- $this->query->whereIn(
+ $whereIn = $this->whereInMethod($this->farParent, $this->localKey);
+
+ $this->query->{$whereIn}(
$this->getQualifiedFirstKeyName(), $this->getKeys($models, $this->localKey)
);
} | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php | @@ -81,7 +81,7 @@ public function addConstraints()
*/
public function addEagerConstraints(array $models)
{
- $whereIn = in_array($this->parent->getKeyType(), ['int', 'integer']) ? 'whereInRaw' : 'whereIn';
+ $whereIn = $this->whereInMethod($this->parent, $this->localKey);
$this->query->{$whereIn}(
$this->foreignKey, $this->getKeys($models, $this->localKey) | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | src/Illuminate/Database/Eloquent/Relations/Relation.php | @@ -307,6 +307,21 @@ public function relatedUpdatedAt()
return $this->related->getUpdatedAtColumn();
}
+ /**
+ * Get the name of the "where in" method for eager loading.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @param string $key
+ * @return string
+ */
+ protected function whereInMethod(Model $model, $key)
+ {
+ return $model->getKeyName() === last(explode('.', $key))
+ && in_array($model->getKeyType(), ['int', 'integer'])
+ ? 'whereInRaw'
+ : 'whereIn';
+ }
+
/**
* Set or get the morph map for polymorphic relations.
* | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | tests/Database/DatabaseEloquentBelongsToTest.php | @@ -79,15 +79,19 @@ public function testUpdateMethodRetrievesModelAndUpdates()
public function testEagerConstraintsAreProperlyAdded()
{
$relation = $this->getRelation();
- $relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', ['foreign.value', 'foreign.value.two']);
+ $relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
+ $relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', ['foreign.value', 'foreign.value.two']);
$models = [new EloquentBelongsToModelStub, new EloquentBelongsToModelStub, new AnotherEloquentBelongsToModelStub];
$relation->addEagerConstraints($models);
}
public function testIdsInEagerConstraintsCanBeZero()
{
$relation = $this->getRelation();
- $relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', ['foreign.value', 0]);
+ $relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
+ $relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', ['foreign.value', 0]);
$models = [new EloquentBelongsToModelStub, new EloquentBelongsToModelStubWithZeroId];
$relation->addEagerConstraints($models);
}
@@ -154,7 +158,9 @@ public function testAssociateMethodSetsForeignKeyOnModelById()
public function testDefaultEagerConstraintsWhenIncrementing()
{
$relation = $this->getRelation();
- $relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', m::mustBe([null]));
+ $relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
+ $relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', m::mustBe([null]));
$models = [new MissingEloquentBelongsToModelStub, new MissingEloquentBelongsToModelStub];
$relation->addEagerConstraints($models);
}
@@ -170,7 +176,9 @@ public function testDefaultEagerConstraintsWhenIncrementingAndNonIntKeyType()
public function testDefaultEagerConstraintsWhenNotIncrementing()
{
$relation = $this->getRelation(null, false);
- $relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', m::mustBe([null]));
+ $relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
+ $relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', m::mustBe([null]));
$models = [new MissingEloquentBelongsToModelStub, new MissingEloquentBelongsToModelStub];
$relation->addEagerConstraints($models);
} | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | tests/Database/DatabaseEloquentHasManyTest.php | @@ -200,6 +200,7 @@ public function testRelationIsProperlyInitialized()
public function testEagerConstraintsAreProperlyAdded()
{
$relation = $this->getRelation();
+ $relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.foreign_key', [1, 2]);
$model1 = new EloquentHasManyModelStub;
@@ -212,6 +213,7 @@ public function testEagerConstraintsAreProperlyAdded()
public function testEagerConstraintsAreProperlyAddedWithStringKey()
{
$relation = $this->getRelation();
+ $relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('string');
$relation->getQuery()->shouldReceive('whereIn')->once()->with('table.foreign_key', [1, 2]);
$model1 = new EloquentHasManyModelStub; | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | tests/Database/DatabaseEloquentHasOneTest.php | @@ -163,6 +163,7 @@ public function testRelationIsProperlyInitialized()
public function testEagerConstraintsAreProperlyAdded()
{
$relation = $this->getRelation();
+ $relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.foreign_key', [1, 2]);
$model1 = new EloquentHasOneModelStub; | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | tests/Database/DatabaseEloquentMorphTest.php | @@ -28,6 +28,7 @@ public function testMorphOneSetsProperConstraints()
public function testMorphOneEagerConstraintsAreProperlyAdded()
{
$relation = $this->getOneRelation();
+ $relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('string');
$relation->getQuery()->shouldReceive('whereIn')->once()->with('table.morph_id', [1, 2]);
$relation->getQuery()->shouldReceive('where')->once()->with('table.morph_type', get_class($relation->getParent()));
@@ -51,6 +52,7 @@ public function testMorphManySetsProperConstraints()
public function testMorphManyEagerConstraintsAreProperlyAdded()
{
$relation = $this->getManyRelation();
+ $relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.morph_id', [1, 2]);
$relation->getQuery()->shouldReceive('where')->once()->with('table.morph_type', get_class($relation->getParent())); | true |
Other | laravel | framework | 352e8abcf1354e73cbab6473d6467dd92960d38e.json | Improve eager loading performance | tests/Database/DatabaseEloquentMorphToManyTest.php | @@ -18,7 +18,9 @@ public function tearDown()
public function testEagerConstraintsAreProperlyAdded()
{
$relation = $this->getRelation();
- $relation->getQuery()->shouldReceive('whereIn')->once()->with('taggables.taggable_id', [1, 2]);
+ $relation->getParent()->shouldReceive('getKeyName')->andReturn('id');
+ $relation->getParent()->shouldReceive('getKeyType')->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('taggables.taggable_id', [1, 2]);
$relation->getQuery()->shouldReceive('where')->once()->with('taggables.taggable_type', get_class($relation->getParent()));
$model1 = new EloquentMorphToManyModelStub;
$model1->id = 1; | true |
Other | laravel | framework | 96de5cc1753323f4a69ce72d5e7c2a549718670c.json | Provide retry callback with the attempt count
This provides the call back with a attempt count, this can be helpful
for function that need to modify there behavior with each attempt, or
log it some how. | src/Illuminate/Support/helpers.php | @@ -739,19 +739,21 @@ function preg_replace_array($pattern, array $replacements, $subject)
* Retry an operation a given number of times.
*
* @param int $times
- * @param callable $callback
+ * @param callable $callback First parameter is the number of attempt
* @param int $sleep
* @return mixed
*
* @throws \Exception
*/
function retry($times, callable $callback, $sleep = 0)
{
+ $attempt = 0;
$times--;
beginning:
+ $attempt++;
try {
- return $callback();
+ return $callback($attempt);
} catch (Exception $e) {
if (! $times) {
throw $e; | true |
Other | laravel | framework | 96de5cc1753323f4a69ce72d5e7c2a549718670c.json | Provide retry callback with the attempt count
This provides the call back with a attempt count, this can be helpful
for function that need to modify there behavior with each attempt, or
log it some how. | tests/Support/SupportHelpersTest.php | @@ -868,6 +868,25 @@ public function something()
})->present()->something());
}
+ public function testRetry()
+ {
+ $startTime = microtime(true);
+
+ $attempts = retry(2, function ($attempts) {
+ if ($attempts > 1) {
+ return $attempts;
+ }
+
+ throw new RuntimeException;
+ }, 100);
+
+ // Make sure we made two attempts
+ $this->assertEquals(2, $attempts);
+
+ // Make sure we waited 100ms for the first attempt
+ $this->assertTrue(microtime(true) - $startTime >= 0.1);
+ }
+
public function testTransform()
{
$this->assertEquals(10, transform(5, function ($value) { | true |
Other | laravel | framework | a4405e91af27429f9e879d8754769cb68eb208d6.json | Improve eager loading performance on MySQL | src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php | @@ -81,7 +81,9 @@ public function addConstraints()
*/
public function addEagerConstraints(array $models)
{
- $this->query->whereIn(
+ $whereIn = in_array($this->parent->getKeyType(), ['int', 'integer']) ? 'whereInRaw' : 'whereIn';
+
+ $this->query->$whereIn(
$this->foreignKey, $this->getKeys($models, $this->localKey)
);
} | true |
Other | laravel | framework | a4405e91af27429f9e879d8754769cb68eb208d6.json | Improve eager loading performance on MySQL | src/Illuminate/Database/Query/Builder.php | @@ -948,6 +948,30 @@ protected function whereInExistingQuery($column, $query, $boolean, $not)
return $this;
}
+ /**
+ * Add a "where in raw" clause to the query.
+ *
+ * @param string $column
+ * @param array $values
+ * @param string $boolean
+ * @param bool $not
+ * @return $this
+ */
+ public function whereInRaw($column, array $values, $boolean = 'and', $not = false)
+ {
+ $type = $not ? 'NotInRaw' : 'InRaw';
+
+ if ($values instanceof Arrayable) {
+ $values = $values->toArray();
+ }
+
+ $values = array_map('intval', $values);
+
+ $this->wheres[] = compact('type', 'column', 'values', 'boolean');
+
+ return $this;
+ }
+
/**
* Add a "where null" clause to the query.
* | true |
Other | laravel | framework | a4405e91af27429f9e879d8754769cb68eb208d6.json | Improve eager loading performance on MySQL | src/Illuminate/Database/Query/Grammars/Grammar.php | @@ -301,6 +301,22 @@ protected function whereNotInSub(Builder $query, $where)
return $this->wrap($where['column']).' not in ('.$this->compileSelect($where['query']).')';
}
+ /**
+ * Compile a "where in raw" clause.
+ *
+ * @param \Illuminate\Database\Query\Builder $query
+ * @param array $where
+ * @return string
+ */
+ protected function whereInRaw(Builder $query, $where)
+ {
+ if (! empty($where['values'])) {
+ return $this->wrap($where['column']).' in ('.implode(', ', $where['values']).')';
+ }
+
+ return '0 = 1';
+ }
+
/**
* Compile a "where null" clause.
* | true |
Other | laravel | framework | a4405e91af27429f9e879d8754769cb68eb208d6.json | Improve eager loading performance on MySQL | tests/Database/DatabaseEloquentHasManyTest.php | @@ -200,6 +200,19 @@ public function testRelationIsProperlyInitialized()
public function testEagerConstraintsAreProperlyAdded()
{
$relation = $this->getRelation();
+ $relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.foreign_key', [1, 2]);
+ $model1 = new EloquentHasManyModelStub;
+ $model1->id = 1;
+ $model2 = new EloquentHasManyModelStub;
+ $model2->id = 2;
+ $relation->addEagerConstraints([$model1, $model2]);
+ }
+
+ public function testEagerConstraintsAreProperlyAddedWithStringKey()
+ {
+ $relation = $this->getRelation();
+ $relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('string');
$relation->getQuery()->shouldReceive('whereIn')->once()->with('table.foreign_key', [1, 2]);
$model1 = new EloquentHasManyModelStub;
$model1->id = 1; | true |
Other | laravel | framework | a4405e91af27429f9e879d8754769cb68eb208d6.json | Improve eager loading performance on MySQL | tests/Database/DatabaseEloquentHasOneTest.php | @@ -163,7 +163,8 @@ public function testRelationIsProperlyInitialized()
public function testEagerConstraintsAreProperlyAdded()
{
$relation = $this->getRelation();
- $relation->getQuery()->shouldReceive('whereIn')->once()->with('table.foreign_key', [1, 2]);
+ $relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.foreign_key', [1, 2]);
$model1 = new EloquentHasOneModelStub;
$model1->id = 1;
$model2 = new EloquentHasOneModelStub; | true |
Other | laravel | framework | a4405e91af27429f9e879d8754769cb68eb208d6.json | Improve eager loading performance on MySQL | tests/Database/DatabaseEloquentMorphTest.php | @@ -28,6 +28,7 @@ public function testMorphOneSetsProperConstraints()
public function testMorphOneEagerConstraintsAreProperlyAdded()
{
$relation = $this->getOneRelation();
+ $relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('string');
$relation->getQuery()->shouldReceive('whereIn')->once()->with('table.morph_id', [1, 2]);
$relation->getQuery()->shouldReceive('where')->once()->with('table.morph_type', get_class($relation->getParent()));
@@ -50,7 +51,8 @@ public function testMorphManySetsProperConstraints()
public function testMorphManyEagerConstraintsAreProperlyAdded()
{
$relation = $this->getManyRelation();
- $relation->getQuery()->shouldReceive('whereIn')->once()->with('table.morph_id', [1, 2]);
+ $relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
+ $relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.morph_id', [1, 2]);
$relation->getQuery()->shouldReceive('where')->once()->with('table.morph_type', get_class($relation->getParent()));
$model1 = new EloquentMorphResetModelStub; | true |
Other | laravel | framework | a4405e91af27429f9e879d8754769cb68eb208d6.json | Improve eager loading performance on MySQL | tests/Database/DatabaseQueryBuilderTest.php | @@ -693,6 +693,14 @@ public function testEmptyWhereNotIns()
$this->assertEquals([0 => 1], $builder->getBindings());
}
+ public function testWhereInRaw()
+ {
+ $builder = $this->getBuilder();
+ $builder->select('*')->from('users')->whereInRaw('id', ['1a', 2]);
+ $this->assertEquals('select * from "users" where "id" in (1, 2)', $builder->toSql());
+ $this->assertEquals([], $builder->getBindings());
+ }
+
public function testBasicWhereColumn()
{
$builder = $this->getBuilder(); | true |
Other | laravel | framework | 2497ad869a689464e18549d2cf8558df6085f3a2.json | Fix irregular plural in make:policy command | src/Illuminate/Foundation/Console/PolicyMakeCommand.php | @@ -104,7 +104,7 @@ protected function replaceModel($stub, $model)
$stub = str_replace('DummyUser', $dummyUser, $stub);
- return str_replace('DocDummyPluralModel', Str::snake(Str::plural($dummyModel), ' '), $stub);
+ return str_replace('DocDummyPluralModel', Str::snake(Str::pluralStudly($dummyModel), ' '), $stub);
}
/** | false |
Other | laravel | framework | e8f31f149948cad5b3e42aeb5ff3ce1e1ab5514e.json | Fix validate method | src/Illuminate/Contracts/Validation/Validator.php | @@ -13,6 +13,13 @@ interface Validator extends MessageProvider
*/
public function validate();
+ /**
+ * Return validated value.
+ *
+ * @return array
+ */
+ public function validated();
+
/**
* Determine if the data fails the validation rules.
* | true |
Other | laravel | framework | e8f31f149948cad5b3e42aeb5ff3ce1e1ab5514e.json | Fix validate method | src/Illuminate/Foundation/Http/FormRequest.php | @@ -172,7 +172,7 @@ protected function failedAuthorization()
*/
public function validated()
{
- return $this->getValidatorInstance()->validate();
+ return $this->getValidatorInstance()->validated();
}
/** | true |
Other | laravel | framework | e8f31f149948cad5b3e42aeb5ff3ce1e1ab5514e.json | Fix validate method | src/Illuminate/Validation/Validator.php | @@ -306,6 +306,22 @@ public function validate()
throw new ValidationException($this);
}
+ return $this->validated();
+ }
+
+ /**
+ * Return validated value.
+ *
+ * @return array
+ *
+ * @throws \Illuminate\Validation\ValidationException
+ */
+ public function validated()
+ {
+ if ($this->invalid()) {
+ throw new ValidationException($this);
+ }
+
$results = [];
$missingValue = Str::random(10); | true |
Other | laravel | framework | e8f31f149948cad5b3e42aeb5ff3ce1e1ab5514e.json | Fix validate method | tests/Validation/ValidationValidatorTest.php | @@ -4254,6 +4254,37 @@ public function testValidateReturnsValidatedDataNestedArrayRules()
$this->assertEquals(['nested' => [['bar' => 'baz'], ['bar' => 'baz2']]], $data);
}
+ public function testValidateAndValidatedData()
+ {
+ $post = ['first' => 'john', 'preferred'=>'john', 'last' => 'doe', 'type' => 'admin'];
+
+ $v = new Validator($this->getIlluminateArrayTranslator(), $post, ['first' => 'required', 'preferred'=> 'required']);
+ $v->sometimes('type', 'required', function () {
+ return false;
+ });
+ $data = $v->validate();
+ $validatedData = $v->validated();
+
+ $this->assertEquals(['first' => 'john', 'preferred' => 'john'], $data);
+ $this->assertEquals($data, $validatedData);
+ }
+
+ public function testValidatedNotValidateTwiceData()
+ {
+ $post = ['first' => 'john', 'preferred'=>'john', 'last' => 'doe', 'type' => 'admin'];
+
+ $validateCount = 0;
+ $v = new Validator($this->getIlluminateArrayTranslator(), $post, ['first' => 'required', 'preferred'=> 'required']);
+ $v->after(function () use (&$validateCount) {
+ $validateCount++;
+ });
+ $data = $v->validate();
+ $v->validated();
+
+ $this->assertEquals(['first' => 'john', 'preferred' => 'john'], $data);
+ $this->assertEquals(1, $validateCount);
+ }
+
/**
* @dataProvider validUuidList
*/ | true |
Other | laravel | framework | b70ec729f8459140505bae0f6a5699c2fc813ef7.json | Fix multi-word models with irregular plurals | src/Illuminate/Database/Eloquent/Model.php | @@ -1277,13 +1277,9 @@ public static function unsetConnectionResolver()
*/
public function getTable()
{
- if (! isset($this->table)) {
- return str_replace(
- '\\', '', Str::snake(Str::plural(class_basename($this)))
- );
- }
-
- return $this->table;
+ return isset($this->table)
+ ? $this->table
+ : Str::snake(Str::pluralStudly(class_basename($this)));
}
/** | true |
Other | laravel | framework | b70ec729f8459140505bae0f6a5699c2fc813ef7.json | Fix multi-word models with irregular plurals | src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | @@ -766,7 +766,7 @@ protected function touchingParent()
*/
protected function guessInverseRelation()
{
- return Str::camel(Str::plural(class_basename($this->getParent())));
+ return Str::camel(Str::pluralStudly(class_basename($this->getParent())));
}
/** | true |
Other | laravel | framework | b70ec729f8459140505bae0f6a5699c2fc813ef7.json | Fix multi-word models with irregular plurals | src/Illuminate/Foundation/Console/ModelMakeCommand.php | @@ -82,7 +82,7 @@ protected function createFactory()
*/
protected function createMigration()
{
- $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
+ $table = Str::snake(Str::pluralStudly(class_basename($this->argument('name'))));
if ($this->option('pivot')) {
$table = Str::singular($table); | true |
Other | laravel | framework | b70ec729f8459140505bae0f6a5699c2fc813ef7.json | Fix multi-word models with irregular plurals | src/Illuminate/Support/Str.php | @@ -280,6 +280,22 @@ public static function plural($value, $count = 2)
return Pluralizer::plural($value, $count);
}
+ /**
+ * Pluralize the last word of an English, studly caps case string.
+ *
+ * @param string $value
+ * @param int $count
+ * @return string
+ */
+ public static function pluralStudly($value, $count = 2)
+ {
+ $parts = preg_split('/(.)(?=[A-Z])/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE);
+
+ $lastWord = array_pop($parts);
+
+ return implode('', $parts).self::plural($lastWord, $count);
+ }
+
/**
* Generate a more truly "random" alpha-numeric string.
* | true |
Other | laravel | framework | b70ec729f8459140505bae0f6a5699c2fc813ef7.json | Fix multi-word models with irregular plurals | tests/Database/DatabaseEloquentIrregularPluralTest.php | @@ -0,0 +1,117 @@
+<?php
+
+namespace Illuminate\Tests\Database;
+
+use Carbon\Carbon;
+use PHPUnit\Framework\TestCase;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Capsule\Manager as DB;
+
+class DatabaseEloquentIrregularPluralTest extends TestCase
+{
+ public function setUp()
+ {
+ $db = new DB;
+
+ $db->addConnection([
+ 'driver' => 'sqlite',
+ 'database' => ':memory:',
+ ]);
+
+ $db->bootEloquent();
+ $db->setAsGlobal();
+ $this->createSchema();
+ }
+
+ public function createSchema()
+ {
+ $this->schema()->create('irregular_plural_humans', function ($table) {
+ $table->increments('id');
+ $table->string('email')->unique();
+ $table->timestamps();
+ });
+
+ $this->schema()->create('irregular_plural_tokens', function ($table) {
+ $table->increments('id');
+ $table->string('title');
+ });
+
+ $this->schema()->create('irregular_plural_human_irregular_plural_token', function ($table) {
+ $table->integer('irregular_plural_human_id')->unsigned();
+ $table->integer('irregular_plural_token_id')->unsigned();
+ });
+ }
+
+ public function tearDown()
+ {
+ $this->schema()->drop('irregular_plural_tokens');
+ $this->schema()->drop('irregular_plural_humans');
+ $this->schema()->drop('irregular_plural_human_irregular_plural_token');
+ }
+
+ protected function schema()
+ {
+ $connection = Model::getConnectionResolver()->connection();
+
+ return $connection->getSchemaBuilder();
+ }
+
+ /** @test */
+ function it_pluralizes_the_table_name()
+ {
+ $model = new IrregularPluralHuman();
+
+ $this->assertSame('irregular_plural_humans', $model->getTable());
+ }
+
+ /** @test */
+ function it_touches_the_parent_with_an_irregular_plural()
+ {
+ Carbon::setTestNow('2018-05-01 12:13:14');
+
+ IrregularPluralHuman::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']);
+
+ IrregularPluralToken::insert([
+ ['title' => 'The title'],
+ ]);
+
+ $human = IrregularPluralHuman::query()->first();
+
+ $tokenIds = IrregularPluralToken::pluck('id');
+
+ Carbon::setTestNow('2018-05-01 15:16:17');
+
+ $human->irregularPluralTokens()->sync($tokenIds);
+
+ $human->refresh();
+
+ $this->assertSame('2018-05-01 12:13:14', (string) $human->created_at);
+ $this->assertSame('2018-05-01 15:16:17', (string) $human->updated_at);
+ }
+}
+
+class IrregularPluralHuman extends Model
+{
+ protected $guarded = [];
+
+ public function irregularPluralTokens()
+ {
+ return $this->belongsToMany(
+ IrregularPluralToken::class,
+ 'irregular_plural_human_irregular_plural_token',
+ 'irregular_plural_token_id',
+ 'irregular_plural_human_id'
+ );
+ }
+}
+
+class IrregularPluralToken extends Model
+{
+ protected $guarded = [];
+
+ public $timestamps = false;
+
+ protected $touches = [
+ 'irregularPluralHumans',
+ ];
+} | true |
Other | laravel | framework | b70ec729f8459140505bae0f6a5699c2fc813ef7.json | Fix multi-word models with irregular plurals | tests/Support/SupportPluralizerTest.php | @@ -38,6 +38,9 @@ public function testIfEndOfWordPlural()
$this->assertEquals('MatrixFields', Str::plural('MatrixField'));
$this->assertEquals('IndexFields', Str::plural('IndexField'));
$this->assertEquals('VertexFields', Str::plural('VertexField'));
+
+ // This is expected behavior, use "Str::pluralStudly" instead.
+ $this->assertSame('RealHumen', Str::plural('RealHuman'));
}
public function testPluralWithNegativeCount()
@@ -47,4 +50,25 @@ public function testPluralWithNegativeCount()
$this->assertEquals('test', Str::plural('test', -1));
$this->assertEquals('tests', Str::plural('test', -2));
}
+
+ public function testPluralStudly()
+ {
+ $this->assertPluralStudly('RealHumans', 'RealHuman');
+ $this->assertPluralStudly('Models', 'Model');
+ $this->assertPluralStudly('VortexFields', 'VortexField');
+ $this->assertPluralStudly('MultipleWordsInOneStrings', 'MultipleWordsInOneString');
+ }
+
+ public function testPluralStudlyWithCount()
+ {
+ $this->assertPluralStudly('RealHuman', 'RealHuman', 1);
+ $this->assertPluralStudly('RealHumans', 'RealHuman', 2);
+ $this->assertPluralStudly('RealHuman', 'RealHuman', -1);
+ $this->assertPluralStudly('RealHumans', 'RealHuman', -2);
+ }
+
+ private function assertPluralStudly($expected, $value, $count = 2)
+ {
+ $this->assertSame($expected, Str::pluralStudly($value, $count));
+ }
} | true |
Other | laravel | framework | 87ef35362234c47e868fb19e4f7fad5371f0fe42.json | add mix intergration tests (#26416) | tests/Integration/Foundation/FoundationHelpersTest.php | @@ -4,6 +4,7 @@
use Exception;
use Orchestra\Testbench\TestCase;
+use Illuminate\Contracts\Debug\ExceptionHandler;
/**
* @group integration
@@ -37,4 +38,77 @@ public function test(int $a)
$testClass->test([]);
}, 'rescued!'), 'rescued!');
}
+
+ public function testMixReportsExceptionWhenAssetIsMissingFromManifest()
+ {
+ $handler = new FakeHandler;
+ $this->app->instance(ExceptionHandler::class, $handler);
+ $manifest = $this->makeManifest();
+
+ mix('missing.js');
+
+ $this->assertInstanceOf(Exception::class, $handler->reported);
+ $this->assertSame('Unable to locate Mix file: /missing.js.', $handler->reported->getMessage());
+
+ unlink($manifest);
+ }
+
+ public function testMixSilentlyFailsWhenAssetIsMissingFromManifestWhenNotInDebugMode()
+ {
+ $this->app['config']->set('app.debug', false);
+ $manifest = $this->makeManifest();
+
+ $path = mix('missing.js');
+
+ $this->assertSame('/missing.js', $path);
+
+ unlink($manifest);
+ }
+
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Undefined index: /missing.js
+ */
+ public function testMixThrowsExceptionWhenAssetIsMissingFromManifestWhenInDebugMode()
+ {
+ $this->app['config']->set('app.debug', true);
+ $manifest = $this->makeManifest();
+
+ try {
+ mix('missing.js');
+ } catch (\Exception $e) {
+ throw $e;
+ } finally { // make sure we can cleanup the file
+ unlink($manifest);
+ }
+ }
+
+ protected function makeManifest($directory = '')
+ {
+ $this->app->singleton('path.public', function () {
+ return __DIR__;
+ });
+
+ $path = public_path(str_finish($directory, '/').'mix-manifest.json');
+
+ touch($path);
+
+ // Laravel mix prints JSON pretty and with escaped
+ // slashes, so we are doing that here for consistency.
+ $content = json_encode(['/unversioned.css' => '/versioned.css'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+
+ file_put_contents($path, $content);
+
+ return $path;
+ }
+}
+
+class FakeHandler
+{
+ public $reported;
+
+ public function report($exception)
+ {
+ $this->reported = $exception;
+ }
} | false |
Other | laravel | framework | bdfc993c0a5e547d01f76818e439d715a345a1e9.json | fix redis job php doc (#26381) | src/Illuminate/Queue/Jobs/RedisJob.php | @@ -120,7 +120,7 @@ public function getJobId()
/**
* Get the underlying Redis factory implementation.
*
- * @return \Illuminate\Contracts\Redis\Factory
+ * @return \Illuminate\Queue\RedisQueue
*/
public function getRedisQueue()
{ | false |
Other | laravel | framework | 12f3b94c564f174b338c8ed089fc1df89aaa64d8.json | Make View Factory macroable (#26361) | src/Illuminate/View/Factory.php | @@ -5,6 +5,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
+use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\View\Engines\EngineResolver;
@@ -13,7 +14,8 @@
class Factory implements FactoryContract
{
- use Concerns\ManagesComponents,
+ use Macroable,
+ Concerns\ManagesComponents,
Concerns\ManagesEvents,
Concerns\ManagesLayouts,
Concerns\ManagesLoops, | true |
Other | laravel | framework | 12f3b94c564f174b338c8ed089fc1df89aaa64d8.json | Make View Factory macroable (#26361) | tests/View/ViewFactoryTest.php | @@ -653,6 +653,15 @@ public function testIncrementingLoopIndicesOfUncountable()
$this->assertNull($factory->getLoopStack()[0]['last']);
}
+ public function testMacro()
+ {
+ $factory = $this->getFactory();
+ $factory->macro('getFoo', function () {
+ return 'Hello World';
+ });
+ $this->assertEquals('Hello World', $factory->getFoo());
+ }
+
protected function getFactory()
{
return new Factory( | true |
Other | laravel | framework | dfe84e68eee50fa53a8ca886628b6b8a3275a1ad.json | Add whenEmpty + variants to Collection (#26345) | src/Illuminate/Support/Collection.php | @@ -501,6 +501,32 @@ public function when($value, callable $callback, callable $default = null)
return $this;
}
+ /**
+ * Apply the callback if the collection is empty.
+ *
+ * @param bool $value
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function whenEmpty(callable $callback, callable $default = null)
+ {
+ return $this->when($this->isEmpty(), $callback, $default);
+ }
+
+ /**
+ * Apply the callback if the collection is not empty.
+ *
+ * @param bool $value
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function whenNotEmpty(callable $callback, callable $default = null)
+ {
+ return $this->when($this->isNotEmpty(), $callback, $default);
+ }
+
/**
* Apply the callback if the value is falsy.
*
@@ -514,6 +540,32 @@ public function unless($value, callable $callback, callable $default = null)
return $this->when(! $value, $callback, $default);
}
+ /**
+ * Apply the callback unless the collection is empty.
+ *
+ * @param bool $value
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function unlessEmpty(callable $callback, callable $default = null)
+ {
+ return $this->unless($this->isEmpty(), $callback, $default);
+ }
+
+ /**
+ * Apply the callback unless the collection is not empty.
+ *
+ * @param bool $value
+ * @param callable $callback
+ * @param callable $default
+ * @return static|mixed
+ */
+ public function unlessNotEmpty(callable $callback, callable $default = null)
+ {
+ return $this->unless($this->isNotEmpty(), $callback, $default);
+ }
+
/**
* Filter items by the given key value pair.
* | true |
Other | laravel | framework | dfe84e68eee50fa53a8ca886628b6b8a3275a1ad.json | Add whenEmpty + variants to Collection (#26345) | tests/Support/SupportCollectionTest.php | @@ -2693,6 +2693,70 @@ public function testWhenDefault()
$this->assertSame(['michael', 'tom', 'taylor'], $collection->toArray());
}
+ public function testWhenEmpty()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->whenEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame(['michael', 'tom'], $collection->toArray());
+
+ $collection = new Collection;
+
+ $collection->whenEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame(['adam'], $collection->toArray());
+ }
+
+ public function testWhenEmptyDefault()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->whenEmpty(function ($collection) {
+ return $collection->push('adam');
+ }, function ($collection) {
+ return $collection->push('taylor');
+ });
+
+ $this->assertSame(['michael', 'tom', 'taylor'], $collection->toArray());
+ }
+
+ public function testWhenNotEmpty()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->whenNotEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame(['michael', 'tom', 'adam'], $collection->toArray());
+
+ $collection = new Collection;
+
+ $collection->whenNotEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame([], $collection->toArray());
+ }
+
+ public function testWhenNotEmptyDefault()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->whenNotEmpty(function ($collection) {
+ return $collection->push('adam');
+ }, function ($collection) {
+ return $collection->push('taylor');
+ });
+
+ $this->assertSame(['michael', 'tom', 'adam'], $collection->toArray());
+ }
+
public function testUnless()
{
$collection = new Collection(['michael', 'tom']);
@@ -2725,6 +2789,70 @@ public function testUnlessDefault()
$this->assertSame(['michael', 'tom', 'taylor'], $collection->toArray());
}
+ public function testUnlessEmpty()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->unlessEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame(['michael', 'tom', 'adam'], $collection->toArray());
+
+ $collection = new Collection;
+
+ $collection->unlessEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame([], $collection->toArray());
+ }
+
+ public function testUnlessEmptyDefault()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->unlessEmpty(function ($collection) {
+ return $collection->push('adam');
+ }, function ($collection) {
+ return $collection->push('taylor');
+ });
+
+ $this->assertSame(['michael', 'tom', 'adam'], $collection->toArray());
+ }
+
+ public function testUnlessNotEmpty()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->unlessNotEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame(['michael', 'tom'], $collection->toArray());
+
+ $collection = new Collection;
+
+ $collection->unlessNotEmpty(function ($collection) {
+ return $collection->push('adam');
+ });
+
+ $this->assertSame(['adam'], $collection->toArray());
+ }
+
+ public function testUnlessNotEmptyDefault()
+ {
+ $collection = new Collection(['michael', 'tom']);
+
+ $collection->unlessNotEmpty(function ($collection) {
+ return $collection->push('adam');
+ }, function ($collection) {
+ return $collection->push('taylor');
+ });
+
+ $this->assertSame(['michael', 'tom', 'taylor'], $collection->toArray());
+ }
+
public function testHasReturnsValidResults()
{
$collection = new Collection(['foo' => 'one', 'bar' => 'two', 1 => 'three']); | true |
Other | laravel | framework | b4ddc72e9b48e460222277bde5afda2b73830fcc.json | Improve ColumnDefinition (#26338) | src/Illuminate/Database/Schema/ColumnDefinition.php | @@ -12,7 +12,7 @@
* @method ColumnDefinition collation(string $collation) Specify a collation for the column (MySQL/SQL Server)
* @method ColumnDefinition comment(string $comment) Add a comment to the column (MySQL)
* @method ColumnDefinition default(mixed $value) Specify a "default" value for the column
- * @method ColumnDefinition first(string $column) Place the column "first" in the table (MySQL)
+ * @method ColumnDefinition first() Place the column "first" in the table (MySQL)
* @method ColumnDefinition nullable($value = true) Allow NULL values to be inserted into the column
* @method ColumnDefinition storedAs($expression) Create a stored generated column (MySQL)
* @method ColumnDefinition unique() Add a unique index
@@ -22,6 +22,7 @@
* @method ColumnDefinition generatedAs($expression) Create a SQL compliant identity column (PostgreSQL)
* @method ColumnDefinition always() Used as a modifier for generatedAs() (PostgreSQL)
* @method ColumnDefinition index() Add an index
+ * @method ColumnDefinition change() Change the column
*/
class ColumnDefinition extends Fluent
{ | false |
Other | laravel | framework | 52485a0c4a1dd4af7066e4de5ed3b2ee9f26d022.json | Fix container return docblock (#26322) | src/Illuminate/Container/Container.php | @@ -712,7 +712,7 @@ protected function getConcrete($abstract)
* Get the contextual concrete binding for the given abstract.
*
* @param string $abstract
- * @return string|null
+ * @return \Closure|string|null
*/
protected function getContextualConcrete($abstract)
{
@@ -738,7 +738,7 @@ protected function getContextualConcrete($abstract)
* Find the concrete binding for the given abstract in the contextual binding array.
*
* @param string $abstract
- * @return string|null
+ * @return \Closure|string|null
*/
protected function findInContextualBindings($abstract)
{ | false |
Other | laravel | framework | 15d4384e041bcc458ae6443a6becab1d995be60c.json | Fix @param directives for cache store
Some of this docblocks were using 3 spaces instead
of the recommended 2 in the contributions page. | src/Illuminate/Contracts/Cache/Store.php | @@ -26,7 +26,7 @@ public function many(array $keys);
* Store an item in the cache for a given number of minutes.
*
* @param string $key
- * @param mixed $value
+ * @param mixed $value
* @param float|int $minutes
* @return void
*/
@@ -45,7 +45,7 @@ public function putMany(array $values, $minutes);
* Increment the value of an item in the cache.
*
* @param string $key
- * @param mixed $value
+ * @param mixed $value
* @return int|bool
*/
public function increment($key, $value = 1);
@@ -54,7 +54,7 @@ public function increment($key, $value = 1);
* Decrement the value of an item in the cache.
*
* @param string $key
- * @param mixed $value
+ * @param mixed $value
* @return int|bool
*/
public function decrement($key, $value = 1);
@@ -63,7 +63,7 @@ public function decrement($key, $value = 1);
* Store an item in the cache indefinitely.
*
* @param string $key
- * @param mixed $value
+ * @param mixed $value
* @return void
*/
public function forever($key, $value); | false |
Other | laravel | framework | c78004514e56822eec94e006862caf2ff1622aef.json | Update CacheManager::driver @return directive
The driver method only calls the store method which
return type is \Illuminate\Contracts\Cache\Repository,
so this should be the same one. | src/Illuminate/Cache/CacheManager.php | @@ -62,7 +62,7 @@ public function store($name = null)
* Get a cache driver instance.
*
* @param string|null $driver
- * @return mixed
+ * @return \Illuminate\Contracts\Cache\Repository
*/
public function driver($driver = null)
{ | false |
Other | laravel | framework | b6578835c7dfe14bbf2c0b5b32e9c1a3e54e8987.json | Add encrypter throws docblock (#26304) | src/Illuminate/Encryption/Encrypter.php | @@ -114,6 +114,8 @@ public function encrypt($value, $serialize = true)
*
* @param string $value
* @return string
+ *
+ * @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function encryptString($value)
{
@@ -154,6 +156,8 @@ public function decrypt($payload, $unserialize = true)
*
* @param string $payload
* @return string
+ *
+ * @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function decryptString($payload)
{ | false |
Other | laravel | framework | 02d41da1a8013b98d69a7295f239d5f180a6ad4e.json | Fix contextual var docblock (#26305) | src/Illuminate/Container/ContextualBindingBuilder.php | @@ -17,7 +17,7 @@ class ContextualBindingBuilder implements ContextualBindingBuilderContract
/**
* The concrete instance.
*
- * @var string
+ * @var string|array
*/
protected $concrete;
| false |
Other | laravel | framework | 456eefe5bde4b6a99c41928411e4de073a9a6880.json | Fix nested whereDoesntHave() (#26228) | src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php | @@ -74,6 +74,13 @@ protected function hasNested($relations, $operator = '>=', $count = 1, $boolean
{
$relations = explode('.', $relations);
+ $doesntHave = $operator === '<' && $count === 1;
+
+ if ($doesntHave) {
+ $operator = '>=';
+ $count = 1;
+ }
+
$closure = function ($q) use (&$closure, &$relations, $operator, $count, $callback) {
// In order to nest "has", we need to add count relation constraints on the
// callback Closure. We'll do this by simply passing the Closure its own
@@ -83,7 +90,7 @@ protected function hasNested($relations, $operator = '>=', $count = 1, $boolean
: $q->has(array_shift($relations), $operator, $count, 'and', $callback);
};
- return $this->has(array_shift($relations), '>=', 1, $boolean, $closure);
+ return $this->has(array_shift($relations), $doesntHave ? '<' : '>=', 1, $boolean, $closure);
}
/** | true |
Other | laravel | framework | 456eefe5bde4b6a99c41928411e4de073a9a6880.json | Fix nested whereDoesntHave() (#26228) | tests/Database/DatabaseEloquentBuilderTest.php | @@ -876,6 +876,15 @@ public function testDoesntHave()
$this->assertEquals('select * from "eloquent_builder_test_model_parent_stubs" where not exists (select * from "eloquent_builder_test_model_close_related_stubs" where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id")', $builder->toSql());
}
+ public function testDoesntHaveNested()
+ {
+ $model = new EloquentBuilderTestModelParentStub;
+
+ $builder = $model->doesntHave('foo.bar');
+
+ $this->assertEquals('select * from "eloquent_builder_test_model_parent_stubs" where not exists (select * from "eloquent_builder_test_model_close_related_stubs" where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id" and exists (select * from "eloquent_builder_test_model_far_related_stubs" where "eloquent_builder_test_model_close_related_stubs"."id" = "eloquent_builder_test_model_far_related_stubs"."eloquent_builder_test_model_close_related_stub_id"))', $builder->toSql());
+ }
+
public function testOrDoesntHave()
{
$model = new EloquentBuilderTestModelParentStub; | true |
Other | laravel | framework | 456eefe5bde4b6a99c41928411e4de073a9a6880.json | Fix nested whereDoesntHave() (#26228) | tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php | @@ -526,6 +526,14 @@ public function testWhereHasWithNestedDeletedRelationship()
$this->assertCount(1, $users);
}
+ public function testWhereDoesntHaveWithNestedDeletedRelationship()
+ {
+ $this->createUsers();
+
+ $users = SoftDeletesTestUser::doesntHave('posts.comments')->get();
+ $this->assertCount(1, $users);
+ }
+
public function testWhereHasWithNestedDeletedRelationshipAndWithTrashedCondition()
{
$this->createUsers(); | true |
Other | laravel | framework | 68fec90c18d5a4871ad62d6aea5065c8763b988c.json | Apply fixes from StyleCI (#26299) | src/Illuminate/Database/SQLiteConnection.php | @@ -27,6 +27,7 @@ public function __construct($pdo, $database = '', $tablePrefix = '', array $conf
$this->getSchemaBuilder()->enableForeignKeyConstraints();
}
}
+
/**
* Get the default query grammar instance.
*
@@ -84,7 +85,7 @@ protected function getDoctrineDriver()
/**
* Get the database connection foreign key constraints configuration option.
*
- * @return boolean|null
+ * @return bool|null
*/
protected function getForeignKeyConstraintsConfigurationValue()
{ | false |
Other | laravel | framework | 07648ae5ce79d09d1032818cb5af10cd5a5365e7.json | Create getter for the http middleware groups
This getter allows to create tests for the route middleware groups,
which is currently not possible because the property is protected.
For example, if you want to ensure that the web group is using a
middleware to track utm campaigns, with this getter you can write:
```php
/** @test */
public function it_registers_the_track_utm_middleware_in_the_web_group()
{
$groups = resolve(\App\Http\Kernel::class)->getMiddlewareGroups();
$this->assertContains(\App\Http\Middleware\TrackUTM::class, $groups['web']);
}
``` | src/Illuminate/Foundation/Http/Kernel.php | @@ -335,4 +335,14 @@ public function getApplication()
{
return $this->app;
}
+
+ /**
+ * Get the application's route middleware groups.
+ *
+ * @return array
+ */
+ public function getMiddlewareGroups()
+ {
+ return $this->middlewareGroups;
+ }
} | true |
Other | laravel | framework | 07648ae5ce79d09d1032818cb5af10cd5a5365e7.json | Create getter for the http middleware groups
This getter allows to create tests for the route middleware groups,
which is currently not possible because the property is protected.
For example, if you want to ensure that the web group is using a
middleware to track utm campaigns, with this getter you can write:
```php
/** @test */
public function it_registers_the_track_utm_middleware_in_the_web_group()
{
$groups = resolve(\App\Http\Kernel::class)->getMiddlewareGroups();
$this->assertContains(\App\Http\Middleware\TrackUTM::class, $groups['web']);
}
``` | tests/Foundation/Http/KernelTest.php | @@ -0,0 +1,35 @@
+<?php
+
+namespace Illuminate\Tests\Foundation\Http;
+
+use Illuminate\Routing\Router;
+use PHPUnit\Framework\TestCase;
+use Illuminate\Events\Dispatcher;
+use Illuminate\Foundation\Application;
+use Illuminate\Foundation\Http\Kernel;
+
+class KernelTest extends TestCase
+{
+ public function testGetMiddlewareGroups()
+ {
+ $kernel = new Kernel($this->getApplication(), $this->getRouter());
+
+ $this->assertEquals([], $kernel->getMiddlewareGroups());
+ }
+
+ /**
+ * @return \Illuminate\Foundation\Application
+ */
+ protected function getApplication()
+ {
+ return new Application;
+ }
+
+ /**
+ * @return \Illuminate\Routing\Router
+ */
+ protected function getRouter()
+ {
+ return new Router(new Dispatcher);
+ }
+} | true |
Other | laravel | framework | 442c5eea031f4bfdcbe1de790a9f383e1314dcec.json | Improve findOrFail() exceptions (#26182) | src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | @@ -514,7 +514,7 @@ public function findOrFail($id, $columns = ['*'])
return $result;
}
- throw (new ModelNotFoundException)->setModel(get_class($this->related));
+ throw (new ModelNotFoundException)->setModel(get_class($this->related), $id);
}
/** | true |
Other | laravel | framework | 442c5eea031f4bfdcbe1de790a9f383e1314dcec.json | Improve findOrFail() exceptions (#26182) | src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php | @@ -331,7 +331,7 @@ public function findOrFail($id, $columns = ['*'])
return $result;
}
- throw (new ModelNotFoundException)->setModel(get_class($this->related));
+ throw (new ModelNotFoundException)->setModel(get_class($this->related), $id);
}
/** | true |
Other | laravel | framework | 442c5eea031f4bfdcbe1de790a9f383e1314dcec.json | Improve findOrFail() exceptions (#26182) | tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php | @@ -132,7 +132,7 @@ public function testFirstOrFailThrowsAnException()
/**
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
- * @expectedExceptionMessage No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost].
+ * @expectedExceptionMessage No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost] 1
*/
public function testFindOrFailThrowsAnException()
{ | true |
Other | laravel | framework | 437060a048d722c544f71637cd920a2ad20d19fd.json | Add test for decimal cast | tests/Integration/Database/EloquentModelDecimalCastingTest.php | @@ -0,0 +1,58 @@
+<?php
+
+namespace Illuminate\Tests\Integration\Database\EloquentModelDecimalCastingTest;
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Tests\Integration\Database\DatabaseTestCase;
+
+/**
+ * @group integration
+ */
+class EloquentModelDecimalCastingTest extends DatabaseTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ Schema::create('test_model1', function ($table) {
+ $table->increments('id');
+ $table->decimal('decimal_field_2', 8, 2)->nullable();
+ $table->decimal('decimal_field_4', 8, 4)->nullable();
+ });
+ }
+
+ public function test_decimals_are_castable()
+ {
+ $user = TestModel1::create([
+ 'decimal_field_2' => '12',
+ 'decimal_field_4' => '1234',
+ ]);
+
+ $this->assertEquals('12.00', $user->toArray()['decimal_field_2']);
+ $this->assertEquals('1234.0000', $user->toArray()['decimal_field_4']);
+
+ $user->decimal_field_2 = 12;
+ $user->decimal_field_4 = '1234';
+
+ $this->assertEquals('12.00', $user->toArray()['decimal_field_2']);
+ $this->assertEquals('1234.0000', $user->toArray()['decimal_field_4']);
+
+ $this->assertFalse($user->isDirty());
+
+ $user->decimal_field_4 = '1234.1234';
+ $this->assertTrue($user->isDirty());
+ }
+}
+
+class TestModel1 extends Model
+{
+ public $table = 'test_model1';
+ public $timestamps = false;
+ protected $guarded = ['id'];
+
+ public $casts = [
+ 'decimal_field_2' => 'decimal:2',
+ 'decimal_field_4' => 'decimal:4',
+ ];
+} | false |
Other | laravel | framework | 5892daa6e97590ea9a05dfa23b81493c8eaadc1c.json | Replace newQuery() with newModelQuery() (#26158) | src/Illuminate/Database/Eloquent/Model.php | @@ -544,7 +544,7 @@ protected function decrement($column, $amount = 1, array $extra = [])
*/
protected function incrementOrDecrement($column, $amount, $extra, $method)
{
- $query = $this->newQuery();
+ $query = $this->newModelQuery();
if (! $this->exists) {
return $query->{$method}($column, $amount, $extra); | true |
Other | laravel | framework | 5892daa6e97590ea9a05dfa23b81493c8eaadc1c.json | Replace newQuery() with newModelQuery() (#26158) | src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | @@ -788,7 +788,7 @@ public function touch()
// the related model's timestamps, to make sure these all reflect the changes
// to the parent models. This will help us keep any caching synced up here.
if (count($ids = $this->allRelatedIds()) > 0) {
- $this->getRelated()->newQuery()->whereIn($key, $ids)->update($columns);
+ $this->getRelated()->newModelQuery()->whereIn($key, $ids)->update($columns);
}
}
| true |
Other | laravel | framework | 5892daa6e97590ea9a05dfa23b81493c8eaadc1c.json | Replace newQuery() with newModelQuery() (#26158) | src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php | @@ -124,7 +124,7 @@ public function delete()
*/
protected function getDeleteQuery()
{
- return $this->newQuery()->where([
+ return $this->newModelQuery()->where([
$this->foreignKey => $this->getOriginal($this->foreignKey, $this->getAttribute($this->foreignKey)),
$this->relatedKey => $this->getOriginal($this->relatedKey, $this->getAttribute($this->relatedKey)),
]); | true |
Other | laravel | framework | 5892daa6e97590ea9a05dfa23b81493c8eaadc1c.json | Replace newQuery() with newModelQuery() (#26158) | tests/Database/DatabaseEloquentModelTest.php | @@ -1444,13 +1444,13 @@ public function testReplicateCreatesANewModelInstanceWithSameAttributeValues()
public function testIncrementOnExistingModelCallsQueryAndSetsAttribute()
{
- $model = m::mock(EloquentModelStub::class.'[newQuery]');
+ $model = m::mock(EloquentModelStub::class.'[newModelQuery]');
$model->exists = true;
$model->id = 1;
$model->syncOriginalAttribute('id');
$model->foo = 2;
- $model->shouldReceive('newQuery')->andReturn($query = m::mock(stdClass::class));
+ $model->shouldReceive('newModelQuery')->andReturn($query = m::mock(stdClass::class));
$query->shouldReceive('where')->andReturn($query);
$query->shouldReceive('increment');
| true |
Other | laravel | framework | 5892daa6e97590ea9a05dfa23b81493c8eaadc1c.json | Replace newQuery() with newModelQuery() (#26158) | tests/Database/DatabaseEloquentPivotTest.php | @@ -110,14 +110,14 @@ public function testKeysCanBeSetProperly()
public function testDeleteMethodDeletesModelByKeys()
{
- $pivot = $this->getMockBuilder(Pivot::class)->setMethods(['newQuery'])->getMock();
+ $pivot = $this->getMockBuilder(Pivot::class)->setMethods(['newModelQuery'])->getMock();
$pivot->setPivotKeys('foreign', 'other');
$pivot->foreign = 'foreign.value';
$pivot->other = 'other.value';
$query = m::mock(stdClass::class);
$query->shouldReceive('where')->once()->with(['foreign' => 'foreign.value', 'other' => 'other.value'])->andReturn($query);
$query->shouldReceive('delete')->once()->andReturn(true);
- $pivot->expects($this->once())->method('newQuery')->will($this->returnValue($query));
+ $pivot->expects($this->once())->method('newModelQuery')->will($this->returnValue($query));
$this->assertTrue($pivot->delete());
} | true |
Other | laravel | framework | 0ec8c170c8604eb4ae55988b0f97dced8fef6a6f.json | Remove unused import (#26159) | src/Illuminate/Http/Resources/Json/JsonResource.php | @@ -4,7 +4,6 @@
use ArrayAccess;
use JsonSerializable;
-use Illuminate\Support\Collection;
use Illuminate\Container\Container;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Routing\UrlRoutable; | false |
Other | laravel | framework | 6403bea2360361465726a1661a59241fd788176b.json | Remove useless statement. (#26160) | src/Illuminate/Http/Resources/Json/JsonResource.php | @@ -91,9 +91,7 @@ public function resolve($request = null)
$request = $request ?: Container::getInstance()->make('request')
);
- if (is_array($data)) {
- $data = $data;
- } elseif ($data instanceof Arrayable) {
+ if ($data instanceof Arrayable) {
$data = $data->toArray();
} elseif ($data instanceof JsonSerializable) {
$data = $data->jsonSerialize(); | false |
Other | laravel | framework | b723b90889f084c8026e2d92ecb125deb6087816.json | Define mix as const (#26119) | src/Illuminate/Foundation/Console/Presets/react-stubs/webpack.mix.js | @@ -1,4 +1,4 @@
-let mix = require('laravel-mix');
+const mix = require('laravel-mix');
/*
|-------------------------------------------------------------------------- | true |
Other | laravel | framework | b723b90889f084c8026e2d92ecb125deb6087816.json | Define mix as const (#26119) | src/Illuminate/Foundation/Console/Presets/vue-stubs/webpack.mix.js | @@ -1,4 +1,4 @@
-let mix = require('laravel-mix');
+const mix = require('laravel-mix');
/*
|-------------------------------------------------------------------------- | true |
Other | laravel | framework | 3cad3720ca557581bcc60f4264d5f19abb2a0633.json | Add support for identity columns in PostgreSQL 10+
Since PostgreSQL 10 the preferred method of defining auto increment
columns is to use SQL standard identity columns instead of SERIAL psedo-types
COLUMN TYPE GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
See https://www.postgresql.org/docs/10/static/sql-createtable.html
It fixes issues with SERIAL psudo-types:
- CREATE TABLE / LIKE copies default but refers to same sequence
- cannot add/drop serialness with ALTER TABLE
- dropping default does not drop sequence
- need to grant separate privileges to sequence
- other slight weirdnesses because serial is some kind of special macro
As explained by author of the patch in
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=3217327053638085d24dd4d276e7c1f7ac2c4c6b | src/Illuminate/Database/Schema/ColumnDefinition.php | @@ -19,6 +19,8 @@
* @method ColumnDefinition unsigned() Set the INTEGER column as UNSIGNED (MySQL)
* @method ColumnDefinition useCurrent() Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value
* @method ColumnDefinition virtualAs(string $expression) Create a virtual generated column (MySQL)
+ * @method ColumnDefinition generatedAs($expression) Create a SQL compliant identity column (PostgreSQL)
+ * @method ColumnDefinition always() Used as a modifier for generatedAs() (PostgreSQL)
*/
class ColumnDefinition extends Fluent
{ | true |
Other | laravel | framework | 3cad3720ca557581bcc60f4264d5f19abb2a0633.json | Add support for identity columns in PostgreSQL 10+
Since PostgreSQL 10 the preferred method of defining auto increment
columns is to use SQL standard identity columns instead of SERIAL psedo-types
COLUMN TYPE GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
See https://www.postgresql.org/docs/10/static/sql-createtable.html
It fixes issues with SERIAL psudo-types:
- CREATE TABLE / LIKE copies default but refers to same sequence
- cannot add/drop serialness with ALTER TABLE
- dropping default does not drop sequence
- need to grant separate privileges to sequence
- other slight weirdnesses because serial is some kind of special macro
As explained by author of the patch in
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=3217327053638085d24dd4d276e7c1f7ac2c4c6b | src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php | @@ -437,6 +437,38 @@ protected function typeLongText(Fluent $column)
return 'text';
}
+ private function generatableColumn($type, Fluent $column)
+ {
+ if (! $column->autoIncrement && $column->generatedAs === null) {
+ return $type;
+ }
+
+ if ($column->autoIncrement && $column->generatedAs === null) {
+ $serial = [
+ 'integer' => 'serial',
+ 'bigint' => 'bigserial',
+ 'smallint' => 'smallserial',
+ ];
+
+ return $serial[$type];
+ }
+
+ // Identity column but not a primary key
+ $always = $column->always ? 'always' : 'by default';
+ $options = '';
+
+ if (! is_bool($column->generatedAs) && ((string) $column->generatedAs !== '')) {
+ $options = sprintf(' (%s)', $column->generatedAs);
+ }
+
+ return sprintf(
+ '%s generated %s as identity%s',
+ $type,
+ $always,
+ $options
+ );
+ }
+
/**
* Create the column definition for an integer type.
*
@@ -445,7 +477,7 @@ protected function typeLongText(Fluent $column)
*/
protected function typeInteger(Fluent $column)
{
- return $column->autoIncrement ? 'serial' : 'integer';
+ return $this->generatableColumn('integer', $column);
}
/**
@@ -456,7 +488,7 @@ protected function typeInteger(Fluent $column)
*/
protected function typeBigInteger(Fluent $column)
{
- return $column->autoIncrement ? 'bigserial' : 'bigint';
+ return $this->generatableColumn('bigint', $column);
}
/**
@@ -467,7 +499,7 @@ protected function typeBigInteger(Fluent $column)
*/
protected function typeMediumInteger(Fluent $column)
{
- return $column->autoIncrement ? 'serial' : 'integer';
+ return $this->generatableColumn('integer', $column);
}
/**
@@ -478,7 +510,7 @@ protected function typeMediumInteger(Fluent $column)
*/
protected function typeTinyInteger(Fluent $column)
{
- return $column->autoIncrement ? 'smallserial' : 'smallint';
+ return $this->generatableColumn('smallint', $column);
}
/**
@@ -489,7 +521,7 @@ protected function typeTinyInteger(Fluent $column)
*/
protected function typeSmallInteger(Fluent $column)
{
- return $column->autoIncrement ? 'smallserial' : 'smallint';
+ return $this->generatableColumn('smallint', $column);
}
/**
@@ -854,7 +886,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{
- if (in_array($column->type, $this->serials) && $column->autoIncrement) {
+ if ((in_array($column->type, $this->serials) || ($column->generatedAs !== null)) && $column->autoIncrement) {
return ' primary key';
}
} | true |
Other | laravel | framework | 3cad3720ca557581bcc60f4264d5f19abb2a0633.json | Add support for identity columns in PostgreSQL 10+
Since PostgreSQL 10 the preferred method of defining auto increment
columns is to use SQL standard identity columns instead of SERIAL psedo-types
COLUMN TYPE GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
See https://www.postgresql.org/docs/10/static/sql-createtable.html
It fixes issues with SERIAL psudo-types:
- CREATE TABLE / LIKE copies default but refers to same sequence
- cannot add/drop serialness with ALTER TABLE
- dropping default does not drop sequence
- need to grant separate privileges to sequence
- other slight weirdnesses because serial is some kind of special macro
As explained by author of the patch in
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=3217327053638085d24dd4d276e7c1f7ac2c4c6b | tests/Database/DatabasePostgresSchemaGrammarTest.php | @@ -660,6 +660,33 @@ public function testAddingUuid()
$this->assertEquals('alter table "users" add column "foo" uuid not null', $statements[0]);
}
+ public function testAddingGeneratedAs()
+ {
+ $blueprint = new Blueprint('users');
+ $blueprint->increments('foo')->generatedAs();
+ $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
+ $this->assertCount(1, $statements);
+ $this->assertEquals('alter table "users" add column "foo" integer generated by default as identity primary key not null', $statements[0]);
+ // With always modifier
+ $blueprint = new Blueprint('users');
+ $blueprint->increments('foo')->generatedAs()->always();
+ $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
+ $this->assertCount(1, $statements);
+ $this->assertEquals('alter table "users" add column "foo" integer generated always as identity primary key not null', $statements[0]);
+ // With sequence options
+ $blueprint = new Blueprint('users');
+ $blueprint->increments('foo')->generatedAs('increment by 10 start with 100');
+ $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
+ $this->assertCount(1, $statements);
+ $this->assertEquals('alter table "users" add column "foo" integer generated by default as identity (increment by 10 start with 100) primary key not null', $statements[0]);
+ // Not a primary key
+ $blueprint = new Blueprint('users');
+ $blueprint->integer('foo')->generatedAs();
+ $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
+ $this->assertCount(1, $statements);
+ $this->assertEquals('alter table "users" add column "foo" integer generated by default as identity not null', $statements[0]);
+ }
+
public function testAddingIpAddress()
{
$blueprint = new Blueprint('users'); | true |
Other | laravel | framework | 06788ba388a91682dd98d01d30876fccd17ecda4.json | Fix redirect response docblock (#26077) | src/Illuminate/Http/RedirectResponse.php | @@ -37,7 +37,7 @@ class RedirectResponse extends BaseRedirectResponse
*
* @param string|array $key
* @param mixed $value
- * @return \Illuminate\Http\RedirectResponse
+ * @return $this
*/
public function with($key, $value = null)
{
@@ -114,7 +114,7 @@ public function onlyInput()
/**
* Flash an array of input to the session.
*
- * @return \Illuminate\Http\RedirectResponse
+ * @return $this
*/
public function exceptInput()
{
@@ -217,7 +217,7 @@ public function setSession(SessionStore $session)
*
* @param string $method
* @param array $parameters
- * @return $this
+ * @return mixed
*
* @throws \BadMethodCallException
*/ | false |
Other | laravel | framework | 860267cc6b9fa3e41de18ffd7e7326898007ac11.json | REMOVE Size argument from constructor (#26080)
Remove 4th argument from constructor because ErrorException: Passing a size as 4th argument to the constructor is deprecated since 4.1 | src/Illuminate/Http/Testing/File.php | @@ -41,7 +41,7 @@ public function __construct($name, $tempFile)
parent::__construct(
$this->tempFilePath(), $name, $this->getMimeType(),
- filesize($this->tempFilePath()), null, true
+ null, true
);
}
| false |
Other | laravel | framework | 959b547fb26af22aced8358e34c3355a0928f813.json | Fix StyleCI warnings | tests/Integration/Database/EloquentRelationshipsTest.php | @@ -2,7 +2,6 @@
namespace Illuminate\Tests\Integration\Database\EloquentRelationshipsTest;
-use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Orchestra\Testbench\TestCase;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
@@ -14,6 +13,7 @@
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
/** | false |
Other | laravel | framework | fbd80a587323fabab67adffea8e6851065a3a7d7.json | Add extra test for overriding relationship | tests/Integration/Database/EloquentRelationshipsTest.php | @@ -2,6 +2,7 @@
namespace Illuminate\Tests\Integration\Database\EloquentRelationshipsTest;
+use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Orchestra\Testbench\TestCase;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
@@ -34,6 +35,7 @@ public function standard_relationships()
$this->assertInstanceOf(MorphMany::class, $post->likes());
$this->assertInstanceOf(BelongsToMany::class, $post->viewers());
$this->assertInstanceOf(HasManyThrough::class, $post->lovers());
+ $this->assertInstanceOf(HasOneThrough::class, $post->contract());
$this->assertInstanceOf(MorphToMany::class, $post->tags());
$this->assertInstanceOf(MorphTo::class, $post->postable());
}
@@ -52,6 +54,7 @@ public function overridden_relationships()
$this->assertInstanceOf(CustomMorphMany::class, $post->likes());
$this->assertInstanceOf(CustomBelongsToMany::class, $post->viewers());
$this->assertInstanceOf(CustomHasManyThrough::class, $post->lovers());
+ $this->assertInstanceOf(CustomHasOneThrough::class, $post->contract());
$this->assertInstanceOf(CustomMorphToMany::class, $post->tags());
$this->assertInstanceOf(CustomMorphTo::class, $post->postable());
}
@@ -98,6 +101,11 @@ public function lovers()
return $this->hasManyThrough(FakeRelationship::class, FakeRelationship::class);
}
+ public function contract()
+ {
+ return $this->hasOneThrough(FakeRelationship::class, FakeRelationship::class);
+ }
+
public function tags()
{
return $this->morphToMany(FakeRelationship::class, 'taggable');
@@ -148,6 +156,12 @@ protected function newHasManyThrough(Builder $query, Model $farParent, Model $th
return new CustomHasManyThrough($query, $farParent, $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey);
}
+ protected function newHasOneThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey,
+ $secondKey, $localKey, $secondLocalKey
+ ) {
+ return new CustomHasOneThrough($query, $farParent, $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey);
+ }
+
protected function newMorphToMany(Builder $query, Model $parent, $name, $table, $foreignPivotKey,
$relatedPivotKey, $parentKey, $relatedKey, $relationName = null, $inverse = false)
{
@@ -189,6 +203,10 @@ class CustomHasManyThrough extends HasManyThrough
{
}
+class CustomHasOneThrough extends HasOneThrough
+{
+}
+
class CustomMorphToMany extends MorphToMany
{
} | false |
Other | laravel | framework | a9a53a743e5f854d9812f56f55e752f1cbdddb16.json | remove unused code | src/Illuminate/Translation/Translator.php | @@ -6,7 +6,6 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
-use Illuminate\Support\HtmlString;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Translation\Loader;
use Illuminate\Support\NamespacedItemResolver;
@@ -265,8 +264,6 @@ protected function makeReplacements($line, array $replace)
$replace = $this->sortReplacements($replace);
foreach ($replace as $key => $value) {
- // $value = $value instanceof HtmlString ? $value->toHtml() : e($value);
-
$line = str_replace(
[':'.$key, ':'.Str::upper($key), ':'.Str::ucfirst($key)],
[$value, Str::upper($value), Str::ucfirst($value)], | false |
Other | laravel | framework | b0efeb71216761ff8cefa621f45b43b4402702e8.json | Add throws docblock for console kernel (#26034) | src/Illuminate/Foundation/Console/Kernel.php | @@ -242,6 +242,8 @@ public function registerCommand($command)
* @param array $parameters
* @param \Symfony\Component\Console\Output\OutputInterface $outputBuffer
* @return int
+ *
+ * @throws \Symfony\Component\Console\Exception\CommandNotFoundException
*/
public function call($command, array $parameters = [], $outputBuffer = null)
{ | false |
Other | laravel | framework | 6d1f8ce635c4ef8a71abf4f733d08ced092c0d1f.json | add integration test | src/Illuminate/Database/Eloquent/Collection.php | @@ -63,7 +63,7 @@ public function load($relations)
return $this;
}
- /**
+ /**
* Load a set of relationship counts onto the collection.
*
* @param array|string $relations | true |
Other | laravel | framework | 6d1f8ce635c4ef8a71abf4f733d08ced092c0d1f.json | add integration test | tests/Integration/Database/EloquentCollectionLoadCountTest.php | @@ -0,0 +1,128 @@
+<?php
+
+namespace App\Integration\Database;
+
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Tests\Integration\Database\DatabaseTestCase;
+
+/**
+ * @group integration
+ */
+class EloquentCollectionLoadCountTest extends DatabaseTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ Schema::create('posts', function (Blueprint $table) {
+ $table->increments('id');
+ $table->unsignedInteger('some_default_value');
+ $table->softDeletes();
+ });
+
+ Schema::create('comments', function (Blueprint $table) {
+ $table->increments('id');
+ $table->unsignedInteger('post_id');
+ });
+
+ Schema::create('likes', function (Blueprint $table) {
+ $table->increments('id');
+ $table->unsignedInteger('post_id');
+ });
+
+ $post = Post::create();
+ $post->comments()->saveMany([new Comment, new Comment]);
+
+ $post->likes()->save(new Like);
+
+ Post::create();
+ }
+
+ public function testLoadCount()
+ {
+ $posts = Post::all();
+
+ DB::enableQueryLog();
+
+ $posts->loadCount('comments');
+
+ $this->assertCount(1, DB::getQueryLog());
+ $this->assertSame('2', $posts[0]->comments_count);
+ $this->assertSame('0', $posts[1]->comments_count);
+ }
+
+ public function testLoadCountOnDeletedModels()
+ {
+ $posts = Post::all()->each->delete();
+
+ DB::enableQueryLog();
+
+ $posts->loadCount('comments');
+
+ $this->assertCount(1, DB::getQueryLog());
+ $this->assertSame('2', $posts[0]->comments_count);
+ $this->assertSame('0', $posts[1]->comments_count);
+ }
+
+ public function testLoadCountWithArrayOfRelations()
+ {
+ $posts = Post::all();
+
+ DB::enableQueryLog();
+
+ $posts->loadCount(['comments', 'likes']);
+
+ $this->assertCount(1, DB::getQueryLog());
+ $this->assertSame('2', $posts[0]->comments_count);
+ $this->assertSame('1', $posts[0]->likes_count);
+ $this->assertSame('0', $posts[1]->comments_count);
+ $this->assertSame('0', $posts[1]->likes_count);
+ }
+
+ public function testLoadCountDoesNotOverrideAttributesWithDefaultValue()
+ {
+ $post = Post::first();
+ $post->some_default_value = 200;
+
+ Collection::make([$post])->loadCount('comments');
+
+ $this->assertSame(200, $post->some_default_value);
+ $this->assertSame('2', $post->comments_count);
+ }
+}
+
+class Post extends Model
+{
+ use SoftDeletes;
+
+ protected $attributes = [
+ 'some_default_value' => 100,
+ ];
+
+ public $timestamps = false;
+
+ public function comments()
+ {
+ return $this->hasMany(Comment::class);
+ }
+
+ public function likes()
+ {
+ return $this->hasMany(Like::class);
+ }
+}
+
+class Comment extends Model
+{
+ public $timestamps = false;
+}
+
+class Like extends Model
+{
+ public $timestamps = false;
+} | true |
Other | laravel | framework | c9820088e9a785639299e8569cce33592b485b0b.json | Update email.blade.php (#25963) | src/Illuminate/Notifications/resources/views/email.blade.php | @@ -51,12 +51,12 @@
@component('mail::subcopy')
@lang(
"If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\n".
- 'into your web browser: ',
+ 'into your web browser: [:actionURL](:actionURL)',
[
- 'actionText' => $actionText
+ 'actionText' => $actionText,
+ 'actionUrl' => $actionUrl
]
)
-[{{ $actionUrl }}]({!! $actionUrl !!})
@endcomponent
@endisset
@endcomponent | false |
Other | laravel | framework | b34affa78985a2b09449d87190dd583df9ce00ea.json | Fix missing dependency (#25955)
The array class is used in the container and the contextual binding builder. If only the service container is required in another project, `Illuminate\Support\Arr` will not be present after updating or installing Composer dependencies. | src/Illuminate/Container/composer.json | @@ -16,6 +16,7 @@
"require": {
"php": "^7.1.3",
"illuminate/contracts": "5.7.*",
+ "illuminate/support": "5.7.*",
"psr/container": "^1.0"
},
"autoload": { | false |
Other | laravel | framework | 768d3212939dcebba54f9f3304d24dfe315953b7.json | Apply fixes from StyleCI (#25936) | src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php | @@ -299,7 +299,7 @@ protected function retrieveUser($request, $channel)
}
/**
- * Retrieve options for a certain channel
+ * Retrieve options for a certain channel.
*
* @param string $channel
* @return array
@@ -318,7 +318,7 @@ protected function retrieveChannelOptions($channel)
}
/**
- * Check if channel name from request match a pattern from registered channels
+ * Check if channel name from request match a pattern from registered channels.
*
* @param string $channel
* @param string $pattern | true |
Other | laravel | framework | 768d3212939dcebba54f9f3304d24dfe315953b7.json | Apply fixes from StyleCI (#25936) | src/Illuminate/Broadcasting/Broadcasters/UsePusherChannelConventions.php | @@ -7,7 +7,7 @@
trait UsePusherChannelConventions
{
/**
- * Return true if channel is protected by authentication
+ * Return true if channel is protected by authentication.
*
* @param string $channel
* @return bool
@@ -18,7 +18,7 @@ public function isGuardedChannel($channel)
}
/**
- * Remove prefix from channel name
+ * Remove prefix from channel name.
*
* @param string $channel
* @return string
@@ -30,6 +30,7 @@ public function normalizeChannelName($channel)
? Str::replaceFirst('private-', '', $channel)
: Str::replaceFirst('presence-', '', $channel);
}
+
return $channel;
}
} | true |
Other | laravel | framework | 768d3212939dcebba54f9f3304d24dfe315953b7.json | Apply fixes from StyleCI (#25936) | tests/Broadcasting/BroadcasterTest.php | @@ -100,19 +100,22 @@ public function testNotFoundThrowsHttpException()
public function testCanRegisterChannelsWithoutOptions()
{
- $this->broadcaster->channel('somechannel', function () {});
+ $this->broadcaster->channel('somechannel', function () {
+ });
}
public function testCanRegisterChannelsWithOptions()
{
- $options = [ 'a' => [ 'b', 'c' ] ];
- $this->broadcaster->channel('somechannel', function () {}, $options);
+ $options = ['a' => ['b', 'c']];
+ $this->broadcaster->channel('somechannel', function () {
+ }, $options);
}
public function testCanRetrieveChannelsOptions()
{
- $options = [ 'a' => [ 'b', 'c' ] ];
- $this->broadcaster->channel('somechannel', function () {}, $options);
+ $options = ['a' => ['b', 'c']];
+ $this->broadcaster->channel('somechannel', function () {
+ }, $options);
$this->assertEquals(
$options,
@@ -122,8 +125,9 @@ public function testCanRetrieveChannelsOptions()
public function testCanRetrieveChannelsOptionsUsingAChannelNameContainingArgs()
{
- $options = [ 'a' => [ 'b', 'c' ] ];
- $this->broadcaster->channel('somechannel.{id}.test.{text}', function () {}, $options);
+ $options = ['a' => ['b', 'c']];
+ $this->broadcaster->channel('somechannel.{id}.test.{text}', function () {
+ }, $options);
$this->assertEquals(
$options,
@@ -133,9 +137,11 @@ public function testCanRetrieveChannelsOptionsUsingAChannelNameContainingArgs()
public function testCanRetrieveChannelsOptionsWhenMultipleChannelsAreRegistered()
{
- $options = [ 'a' => [ 'b', 'c' ] ];
- $this->broadcaster->channel('somechannel', function () {});
- $this->broadcaster->channel('someotherchannel', function () {}, $options);
+ $options = ['a' => ['b', 'c']];
+ $this->broadcaster->channel('somechannel', function () {
+ });
+ $this->broadcaster->channel('someotherchannel', function () {
+ }, $options);
$this->assertEquals(
$options,
@@ -145,8 +151,9 @@ public function testCanRetrieveChannelsOptionsWhenMultipleChannelsAreRegistered(
public function testDontRetrieveChannelsOptionsWhenChannelDoesntExists()
{
- $options = [ 'a' => [ 'b', 'c' ] ];
- $this->broadcaster->channel('somechannel', function () {}, $options);
+ $options = ['a' => ['b', 'c']];
+ $this->broadcaster->channel('somechannel', function () {
+ }, $options);
$this->assertEquals(
[],
@@ -156,7 +163,8 @@ public function testDontRetrieveChannelsOptionsWhenChannelDoesntExists()
public function testRetrieveUserWithoutGuard()
{
- $this->broadcaster->channel('somechannel', function () {});
+ $this->broadcaster->channel('somechannel', function () {
+ });
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -172,7 +180,8 @@ public function testRetrieveUserWithoutGuard()
public function testRetrieveUserWithOneGuardUsingAStringForSpecifyingGuard()
{
- $this->broadcaster->channel('somechannel', function () {}, ['guards' => 'myguard']);
+ $this->broadcaster->channel('somechannel', function () {
+ }, ['guards' => 'myguard']);
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -188,9 +197,10 @@ public function testRetrieveUserWithOneGuardUsingAStringForSpecifyingGuard()
public function testRetrieveUserWithMultipleGuardsAndRespectGuardsOrder()
{
- $this->broadcaster->channel('somechannel', function () {}, ['guards' => ['myguard1', 'myguard2']]);
- $this->broadcaster->channel('someotherchannel', function () {}, ['guards' => ['myguard2', 'myguard1']]);
-
+ $this->broadcaster->channel('somechannel', function () {
+ }, ['guards' => ['myguard1', 'myguard2']]);
+ $this->broadcaster->channel('someotherchannel', function () {
+ }, ['guards' => ['myguard2', 'myguard1']]);
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -216,7 +226,8 @@ public function testRetrieveUserWithMultipleGuardsAndRespectGuardsOrder()
public function testRetrieveUserDontUseDefaultGuardWhenOneGuardSpecified()
{
- $this->broadcaster->channel('somechannel', function () {}, ['guards' => 'myguard']);
+ $this->broadcaster->channel('somechannel', function () {
+ }, ['guards' => 'myguard']);
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -231,7 +242,8 @@ public function testRetrieveUserDontUseDefaultGuardWhenOneGuardSpecified()
public function testRetrieveUserDontUseDefaultGuardWhenMultipleGuardsSpecified()
{
- $this->broadcaster->channel('somechannel', function () {}, ['guards' => ['myguard1', 'myguard2']]);
+ $this->broadcaster->channel('somechannel', function () {
+ }, ['guards' => ['myguard1', 'myguard2']]);
$request = m::mock(\Illuminate\Http\Request::class);
$request->shouldReceive('user')
@@ -256,7 +268,8 @@ public function testChannelNameMatchPattern($channel, $pattern, $shouldMatch)
$this->assertEquals($shouldMatch, $this->broadcaster->channelNameMatchesPattern($channel, $pattern));
}
- public function channelNameMatchPatternProvider() {
+ public function channelNameMatchPatternProvider()
+ {
return [
['something', 'something', true],
['something.23', 'something.{id}', true],
@@ -358,5 +371,4 @@ public function join($user, BroadcasterTestEloquentModelStub $model, $nonModel)
class DummyUser
{
-
} | true |
Other | laravel | framework | 768d3212939dcebba54f9f3304d24dfe315953b7.json | Apply fixes from StyleCI (#25936) | tests/Broadcasting/PusherBroadcasterTest.php | @@ -2,9 +2,9 @@
namespace Illuminate\Tests\Broadcasting;
-use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
use Mockery as m;
use PHPUnit\Framework\TestCase;
+use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
class PusherBroadcasterTest extends TestCase
{
@@ -25,7 +25,7 @@ public function setUp()
public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCallbackReturnTrue()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return true;
});
@@ -42,7 +42,7 @@ public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCal
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenCallbackReturnFalse()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return false;
});
@@ -56,7 +56,7 @@ public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenCall
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenRequestUserNotFound()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return true;
});
@@ -68,7 +68,7 @@ public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenRequ
public function testAuthCallValidAuthenticationResponseWithPresenceChannelWhenCallbackReturnAnArray()
{
$returnData = [1, 2, 3, 4];
- $this->broadcaster->channel('test', function() use ($returnData) {
+ $this->broadcaster->channel('test', function () use ($returnData) {
return $returnData;
});
@@ -85,8 +85,7 @@ public function testAuthCallValidAuthenticationResponseWithPresenceChannelWhenCa
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPresenceChannelWhenCallbackReturnNull()
{
- $this->broadcaster->channel('test', function() {
- return;
+ $this->broadcaster->channel('test', function () {
});
$this->broadcaster->auth(
@@ -99,7 +98,7 @@ public function testAuthThrowAccessDeniedHttpExceptionWithPresenceChannelWhenCal
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPresenceChannelWhenRequestUserNotFound()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return [1, 2, 3, 4];
});
@@ -113,7 +112,7 @@ public function testValidAuthenticationResponseCallPusherSocketAuthMethodWithPri
$request = $this->getMockRequestWithUserForChannel('private-test');
$data = [
- 'auth' => 'abcd:efgh'
+ 'auth' => 'abcd:efgh',
];
$this->pusher->shouldReceive('socket_auth') | true |
Other | laravel | framework | 768d3212939dcebba54f9f3304d24dfe315953b7.json | Apply fixes from StyleCI (#25936) | tests/Broadcasting/RedisBroadcasterTest.php | @@ -2,9 +2,9 @@
namespace Illuminate\Tests\Broadcasting;
-use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster;
use Mockery as m;
use PHPUnit\Framework\TestCase;
+use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster;
class RedisBroadcasterTest extends TestCase
{
@@ -27,7 +27,7 @@ public function tearDown()
public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCallbackReturnTrue()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return true;
});
@@ -44,7 +44,7 @@ public function testAuthCallValidAuthenticationResponseWithPrivateChannelWhenCal
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenCallbackReturnFalse()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return false;
});
@@ -58,7 +58,7 @@ public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenCall
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenRequestUserNotFound()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return true;
});
@@ -70,7 +70,7 @@ public function testAuthThrowAccessDeniedHttpExceptionWithPrivateChannelWhenRequ
public function testAuthCallValidAuthenticationResponseWithPresenceChannelWhenCallbackReturnAnArray()
{
$returnData = [1, 2, 3, 4];
- $this->broadcaster->channel('test', function() use ($returnData) {
+ $this->broadcaster->channel('test', function () use ($returnData) {
return $returnData;
});
@@ -87,8 +87,7 @@ public function testAuthCallValidAuthenticationResponseWithPresenceChannelWhenCa
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPresenceChannelWhenCallbackReturnNull()
{
- $this->broadcaster->channel('test', function() {
- return;
+ $this->broadcaster->channel('test', function () {
});
$this->broadcaster->auth(
@@ -101,7 +100,7 @@ public function testAuthThrowAccessDeniedHttpExceptionWithPresenceChannelWhenCal
*/
public function testAuthThrowAccessDeniedHttpExceptionWithPresenceChannelWhenRequestUserNotFound()
{
- $this->broadcaster->channel('test', function() {
+ $this->broadcaster->channel('test', function () {
return [1, 2, 3, 4];
});
@@ -136,7 +135,7 @@ public function testValidAuthenticationResponseWithPresenceChannel()
]),
$this->broadcaster->validAuthenticationResponse($request, [
'a' => 'b',
- 'c' => 'd'
+ 'c' => 'd',
])
);
} | true |
Other | laravel | framework | 768d3212939dcebba54f9f3304d24dfe315953b7.json | Apply fixes from StyleCI (#25936) | tests/Broadcasting/UsePusherChannelsNamesTest.php | @@ -2,10 +2,10 @@
namespace Illuminate\Tests\Broadcasting;
-use Illuminate\Broadcasting\Broadcasters\Broadcaster;
-use Illuminate\Broadcasting\Broadcasters\UsePusherChannelConventions;
use Mockery as m;
use PHPUnit\Framework\TestCase;
+use Illuminate\Broadcasting\Broadcasters\Broadcaster;
+use Illuminate\Broadcasting\Broadcasters\UsePusherChannelConventions;
class UsePusherChannelConventionsTest extends TestCase
{
@@ -74,18 +74,18 @@ public function channelsProvider()
foreach ($prefixesInfos as $prefixInfos) {
foreach ($channels as $channel) {
$tests[] = [
- $prefixInfos['prefix'] . $channel,
+ $prefixInfos['prefix'].$channel,
$channel,
$prefixInfos['guarded'],
];
}
}
- $tests[] = ['private-private-test' , 'private-test', true];
- $tests[] = ['private-presence-test' , 'presence-test', true];
- $tests[] = ['presence-private-test' , 'private-test', true];
- $tests[] = ['presence-presence-test' , 'presence-test', true];
- $tests[] = ['public-test' , 'public-test', false];
+ $tests[] = ['private-private-test', 'private-test', true];
+ $tests[] = ['private-presence-test', 'presence-test', true];
+ $tests[] = ['presence-private-test', 'private-test', true];
+ $tests[] = ['presence-presence-test', 'presence-test', true];
+ $tests[] = ['public-test', 'public-test', false];
return $tests;
} | true |
Other | laravel | framework | 477273c72be8b253b6421c69f3e37b5bf4c3a185.json | add some meta data to the notification mails | src/Illuminate/Notifications/Channels/MailChannel.php | @@ -8,6 +8,7 @@
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Notifications\Notification;
+use Illuminate\Contracts\Queue\ShouldQueue;
class MailChannel
{
@@ -60,7 +61,7 @@ public function send($notifiable, Notification $notification)
$this->mailer->send(
$this->buildView($message),
- $message->data(),
+ array_merge($message->data(), $this->additionalMessageData($notification)),
$this->messageBuilder($notifiable, $notification, $message)
);
}
@@ -98,6 +99,22 @@ protected function buildView($message)
];
}
+ /**
+ * Get additional meta-data to pass along with the view data.
+ *
+ * @param \Illuminate\Notifications\Notification $notification
+ * @return array
+ */
+ protected function additionalMessageData($notification)
+ {
+ return [
+ '__laravel_notification' => get_class($notification),
+ '__laravel_notification_queued' => in_array(
+ ShouldQueue::class, class_implements($notification)
+ ),
+ ];
+ }
+
/**
* Build the mail message.
* | false |
Other | laravel | framework | 7bef94e69019b673b00d716ee8af891b84afb734.json | Enable passing options to custom presets
Currently it is not possible to create custom presets with customization | src/Illuminate/Foundation/Console/PresetCommand.php | @@ -12,7 +12,9 @@ class PresetCommand extends Command
*
* @var string
*/
- protected $signature = 'preset { type : The preset type (none, bootstrap, vue, react) }';
+ protected $signature = 'preset
+ { type : The preset type (none, bootstrap, vue, react) }
+ { --pass=* : Pass values to custom preset commands }';
/**
* The console command description. | false |
Other | laravel | framework | fd29db13a8419ca9c163f73b79dc951a3d3b4c7d.json | remove unused variable (#25926) | tests/Support/SupportCollectionTest.php | @@ -1405,18 +1405,18 @@ public function testMapSpread()
{
$c = new Collection([[1, 'a'], [2, 'b']]);
- $result = $c->mapSpread(function ($number, $character) use (&$result) {
+ $result = $c->mapSpread(function ($number, $character) {
return "{$number}-{$character}";
});
$this->assertEquals(['1-a', '2-b'], $result->all());
- $result = $c->mapSpread(function ($number, $character, $key) use (&$result) {
+ $result = $c->mapSpread(function ($number, $character, $key) {
return "{$number}-{$character}-{$key}";
});
$this->assertEquals(['1-a-0', '2-b-1'], $result->all());
$c = new Collection([new Collection([1, 'a']), new Collection([2, 'b'])]);
- $result = $c->mapSpread(function ($number, $character, $key) use (&$result) {
+ $result = $c->mapSpread(function ($number, $character, $key) {
return "{$number}-{$character}-{$key}";
});
$this->assertEquals(['1-a-0', '2-b-1'], $result->all()); | false |
Other | laravel | framework | 21567e538a408717468ce755bb1b054ecda1fb61.json | Fix typo in changelog (#25907) | CHANGELOG-5.7.md | @@ -19,7 +19,7 @@
- Fix `be` method in `InteractsWithAuthentication` trait ([#25873](https://github.com/laravel/framework/pull/25873))
- Fixes the error when $resource is null ([#25838](https://github.com/laravel/framework/pull/25838))
- Attach all disk attachments and not only first one in the `Mail/Mailable.php` ([#25793](https://github.com/laravel/framework/pull/25793))
-- Fixed: in case if one job throw exception, than we will proceed to nex one ([#25820](https://github.com/laravel/framework/pull/25820))
+- Fixed: in case if one job throw exception, than we will proceed to next one ([#25820](https://github.com/laravel/framework/pull/25820))
### Changed
- Trim model class name when passing in `Authorize.php` middleware ([#25849](https://github.com/laravel/framework/pull/25849)) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.