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
da7048f0673c0c5dc8b6ec65c104b9fbfc9d1ec3.json
install phpredis extension via pecl
.travis.yml
@@ -30,7 +30,7 @@ services: before_install: - if [[ $TRAVIS_PHP_VERSION != 7.1 ]] ; then phpenv config-rm xdebug.ini; fi - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - pecl install -f redis - travis_retry composer self-update install:
false
Other
laravel
framework
d6cb75c057009c6316d4efd865dccb3c4a5c7b36.json
fix faking of model events
src/Illuminate/Support/Facades/Event.php
@@ -2,6 +2,7 @@ namespace Illuminate\Support\Facades; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Testing\Fakes\EventFake; /** @@ -16,7 +17,9 @@ class Event extends Facade */ public static function fake() { - static::swap(new EventFake); + static::swap($fake = new EventFake); + + Model::setEventDispatcher($fake); } /**
false
Other
laravel
framework
74cd4cd1f4458fcc1c6ad1f526025c2a5aab018b.json
fix broken shortcut
src/Illuminate/Foundation/Console/ListenerMakeCommand.php
@@ -113,7 +113,7 @@ protected function getOptions() return [ ['event', 'e', InputOption::VALUE_REQUIRED, 'The event class being listened for.'], - ['queued', 'q', InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'], + ['queued', null, InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'], ]; } }
false
Other
laravel
framework
4df653ef08ce2d6035acb21c4192bb2886e3f6e1.json
add check for simple equals
src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
@@ -982,7 +982,9 @@ protected function originalIsEquivalent($key, $current) return false; } - $original = $this->getOriginal($key); + if ($current === $original = $this->getOriginal($key)) { + return true; + } if ($this->isDateAttribute($key)) { return $this->fromDateTime($current) === $this->fromDateTime($original);
false
Other
laravel
framework
a0402824bf479dc5135b40a7f40095d4e2bbb265.json
add date and cast check for dirty
src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
@@ -960,11 +960,8 @@ public function getDirty() { $dirty = []; - foreach ($this->attributes as $key => $value) { - if (! array_key_exists($key, $this->original)) { - $dirty[$key] = $value; - } elseif ($value !== $this->original[$key] && - ! $this->originalIsNumericallyEquivalent($key)) { + foreach ($this->getAttributes() as $key => $value) { + if (! $this->originalIsEquivalent($key, $value)) { $dirty[$key] = $value; } } @@ -973,16 +970,27 @@ public function getDirty() } /** - * Determine if the new and old values for a given key are numerically equivalent. + * Determine if the new and old values for a given key are equivalent. * - * @param string $key + * @param string $key + * @param mixed $current * @return bool */ - protected function originalIsNumericallyEquivalent($key) + protected function originalIsEquivalent($key, $current) { - $current = $this->attributes[$key]; + if (! array_key_exists($key, $this->original)) { + return false; + } + + $original = $this->getOriginal($key); - $original = $this->original[$key]; + if ($this->isDateAttribute($key)) { + return $this->fromDateTime($current) === $this->fromDateTime($original); + } + + if ($this->hasCast($key)) { + return $this->castAttribute($key, $current) === $this->castAttribute($key, $original); + } // This method checks if the two values are numerically equivalent even if they // are different types. This is in case the two values are not the same type
false
Other
laravel
framework
3aa2adc7574b0ff6f4f3b3a75de4b3f9c19a9737.json
fix various problems with belongs to many (#18380)
src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
@@ -284,15 +284,15 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey = * * @param string $related * @param string $table - * @param string $foreignKey - * @param string $relatedKey + * @param string $foreignPivotKey + * @param string $relatedPivotKey * @param string $parentKey - * @param string $localKey + * @param string $relatedKey * @param string $relation * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function belongsToMany($related, $table = null, $foreignKey = null, $relatedKey = null, - $parentKey = null, $localKey = null, $relation = null) + public function belongsToMany($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, + $parentKey = null, $relatedKey = null, $relation = null) { // If no relationship name was passed, we will pull backtraces to get the // name of the calling function. We will use that function name as the @@ -306,9 +306,9 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $rela // instances as well as the relationship instances we need for this. $instance = $this->newRelatedInstance($related); - $foreignKey = $foreignKey ?: $this->getForeignKey(); + $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey(); - $relatedKey = $relatedKey ?: $instance->getForeignKey(); + $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey(); // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names @@ -318,9 +318,9 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $rela } return new BelongsToMany( - $instance->newQuery(), $this, $table, $foreignKey, - $relatedKey, $parentKey ?: $this->getKeyName(), - $localKey ?: $instance->getKeyName(), $relation + $instance->newQuery(), $this, $table, $foreignPivotKey, + $relatedPivotKey, $parentKey ?: $this->getKeyName(), + $relatedKey ?: $instance->getKeyName(), $relation ); } @@ -330,12 +330,16 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $rela * @param string $related * @param string $name * @param string $table - * @param string $foreignKey + * @param string $foreignPivotKey + * @param string $relatedPivotKey + * @param string $parentKey * @param string $relatedKey * @param bool $inverse * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ - public function morphToMany($related, $name, $table = null, $foreignKey = null, $relatedKey = null, $inverse = false) + public function morphToMany($related, $name, $table = null, $foreignPivotKey = null, + $relatedPivotKey = null, $parentKey = null, + $relatedKey = null, $inverse = false) { $caller = $this->guessBelongsToManyRelation(); @@ -344,9 +348,9 @@ public function morphToMany($related, $name, $table = null, $foreignKey = null, // instances, as well as the relationship instances we need for these. $instance = $this->newRelatedInstance($related); - $foreignKey = $foreignKey ?: $name.'_id'; + $foreignPivotKey = $foreignPivotKey ?: $name.'_id'; - $relatedKey = $relatedKey ?: $instance->getForeignKey(); + $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey(); // Now we're ready to create a new query builder for this related model and // the relationship instances for this relation. This relations will set @@ -355,7 +359,8 @@ public function morphToMany($related, $name, $table = null, $foreignKey = null, return new MorphToMany( $instance->newQuery(), $this, $name, $table, - $foreignKey, $relatedKey, $caller, $inverse + $foreignPivotKey, $relatedPivotKey, $parentKey ?: $this->getKeyName(), + $relatedKey ?: $instance->getKeyName(), $caller, $inverse ); } @@ -365,20 +370,26 @@ public function morphToMany($related, $name, $table = null, $foreignKey = null, * @param string $related * @param string $name * @param string $table - * @param string $foreignKey + * @param string $foreignPivotKey + * @param string $relatedPivotKey + * @param string $parentKey * @param string $relatedKey * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ - public function morphedByMany($related, $name, $table = null, $foreignKey = null, $relatedKey = null) + public function morphedByMany($related, $name, $table = null, $foreignPivotKey = null, + $relatedPivotKey = null, $parentKey = null, $relatedKey = null) { - $foreignKey = $foreignKey ?: $this->getForeignKey(); + $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey(); // For the inverse of the polymorphic many-to-many relations, we will change // the way we determine the foreign and other keys, as it is the opposite // of the morph-to-many method since we're figuring out these inverses. - $relatedKey = $relatedKey ?: $name.'_id'; + $relatedPivotKey = $relatedPivotKey ?: $name.'_id'; - return $this->morphToMany($related, $name, $table, $foreignKey, $relatedKey, true); + return $this->morphToMany( + $related, $name, $table, $foreignPivotKey, + $relatedPivotKey, $parentKey, $relatedKey, true + ); } /**
true
Other
laravel
framework
3aa2adc7574b0ff6f4f3b3a75de4b3f9c19a9737.json
fix various problems with belongs to many (#18380)
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -25,14 +25,14 @@ class BelongsToMany extends Relation * * @var string */ - protected $foreignKey; + protected $foreignPivotKey; /** * The associated key of the relation. * * @var string */ - protected $relatedKey; + protected $relatedPivotKey; /** * The key name of the parent model. @@ -46,7 +46,7 @@ class BelongsToMany extends Relation * * @var string */ - protected $localKey; + protected $relatedKey; /** * The "name" of the relationship. @@ -117,15 +117,15 @@ class BelongsToMany extends Relation * @param string $relationName * @return void */ - public function __construct(Builder $query, Model $parent, $table, $foreignKey, - $relatedKey, $parentKey, $localKey, $relationName = null) + public function __construct(Builder $query, Model $parent, $table, $foreignPivotKey, + $relatedPivotKey, $parentKey, $relatedKey, $relationName = null) { $this->table = $table; - $this->localKey = $localKey; $this->parentKey = $parentKey; $this->relatedKey = $relatedKey; - $this->foreignKey = $foreignKey; $this->relationName = $relationName; + $this->relatedPivotKey = $relatedPivotKey; + $this->foreignPivotKey = $foreignPivotKey; parent::__construct($query, $parent); } @@ -159,9 +159,9 @@ protected function performJoin($query = null) // model instance. Then we can set the "where" for the parent models. $baseTable = $this->related->getTable(); - $key = $baseTable.'.'.$this->localKey; + $key = $baseTable.'.'.$this->relatedKey; - $query->join($this->table, $key, '=', $this->getQualifiedRelatedKeyName()); + $query->join($this->table, $key, '=', $this->getQualifiedRelatedPivotKeyName()); return $this; } @@ -174,7 +174,7 @@ protected function performJoin($query = null) protected function addWhereConstraints() { $this->query->where( - $this->getQualifiedForeignKeyName(), '=', $this->parent->{$this->parentKey} + $this->getQualifiedForeignPivotKeyName(), '=', $this->parent->{$this->parentKey} ); return $this; @@ -188,7 +188,7 @@ protected function addWhereConstraints() */ public function addEagerConstraints(array $models) { - $this->query->whereIn($this->getQualifiedForeignKeyName(), $this->getKeys($models)); + $this->query->whereIn($this->getQualifiedForeignPivotKeyName(), $this->getKeys($models)); } /** @@ -247,7 +247,7 @@ protected function buildDictionary(Collection $results) $dictionary = []; foreach ($results as $result) { - $dictionary[$result->pivot->{$this->foreignKey}][] = $result; + $dictionary[$result->pivot->{$this->foreignPivotKey}][] = $result; } return $dictionary; @@ -540,7 +540,7 @@ protected function shouldSelect(array $columns = ['*']) */ protected function aliasedPivotColumns() { - $defaults = [$this->foreignKey, $this->relatedKey]; + $defaults = [$this->foreignPivotKey, $this->relatedPivotKey]; return collect(array_merge($defaults, $this->pivotColumns))->map(function ($column) { return $this->table.'.'.$column.' as pivot_'.$column; @@ -840,7 +840,7 @@ public function getRelationExistenceQueryForSelfJoin(Builder $query, Builder $pa */ public function getExistenceCompareKey() { - return $this->getQualifiedForeignKeyName(); + return $this->getQualifiedForeignPivotKeyName(); } /** @@ -893,19 +893,19 @@ public function updatedAt() * * @return string */ - public function getQualifiedForeignKeyName() + public function getQualifiedForeignPivotKeyName() { - return $this->table.'.'.$this->foreignKey; + return $this->table.'.'.$this->foreignPivotKey; } /** * Get the fully qualified "related key" for the relation. * * @return string */ - public function getQualifiedRelatedKeyName() + public function getQualifiedRelatedPivotKeyName() { - return $this->table.'.'.$this->relatedKey; + return $this->table.'.'.$this->relatedPivotKey; } /**
true
Other
laravel
framework
3aa2adc7574b0ff6f4f3b3a75de4b3f9c19a9737.json
fix various problems with belongs to many (#18380)
src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php
@@ -29,7 +29,7 @@ public function toggle($ids, $touch = true) // checking which of the given ID/records is in the list of current records // and removing all of those rows from this "intermediate" joining table. $detach = array_values(array_intersect( - $this->newPivotQuery()->pluck($this->relatedKey)->all(), + $this->newPivotQuery()->pluck($this->relatedPivotKey)->all(), array_keys($records) )); @@ -89,7 +89,7 @@ public function sync($ids, $detaching = true) // in this joining table. We'll spin through the given IDs, checking to see // if they exist in the array of current ones, and if not we will insert. $current = $this->newPivotQuery()->pluck( - $this->relatedKey + $this->relatedPivotKey )->all(); $detach = array_diff($current, array_keys( @@ -287,9 +287,9 @@ protected function extractAttachIdAndAttributes($key, $value, array $attributes) */ protected function baseAttachRecord($id, $timed) { - $record[$this->relatedKey] = $id; + $record[$this->relatedPivotKey] = $id; - $record[$this->foreignKey] = $this->parent->getKey(); + $record[$this->foreignPivotKey] = $this->parent->getKey(); // If the record needs to have creation and update timestamps, we will make // them by calling the parent model's "freshTimestamp" method which will @@ -353,7 +353,7 @@ public function detach($ids = null, $touch = true) return 0; } - $query->whereIn($this->relatedKey, (array) $ids); + $query->whereIn($this->relatedPivotKey, (array) $ids); } // Once we have all of the conditions set on the statement, we are ready @@ -381,7 +381,7 @@ public function newPivot(array $attributes = [], $exists = false) $this->parent, $attributes, $this->table, $exists, $this->using ); - return $pivot->setPivotKeys($this->foreignKey, $this->relatedKey); + return $pivot->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey); } /** @@ -413,7 +413,7 @@ public function newPivotStatement() */ public function newPivotStatementForId($id) { - return $this->newPivotQuery()->where($this->relatedKey, $id); + return $this->newPivotQuery()->where($this->relatedPivotKey, $id); } /** @@ -433,7 +433,7 @@ protected function newPivotQuery() call_user_func_array([$query, 'whereIn'], $arguments); } - return $query->where($this->foreignKey, $this->parent->getKey()); + return $query->where($this->foreignPivotKey, $this->parent->getKey()); } /**
true
Other
laravel
framework
3aa2adc7574b0ff6f4f3b3a75de4b3f9c19a9737.json
fix various problems with belongs to many (#18380)
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -38,22 +38,25 @@ class MorphToMany extends BelongsToMany * @param \Illuminate\Database\Eloquent\Model $parent * @param string $name * @param string $table - * @param string $foreignKey - * @param string $relatedKey + * @param string $foreignPivotKey + * @param string $relatedPivotKey * @param string $parentKey - * @param string $localKey + * @param string $relatedKey * @param string $relationName * @param bool $inverse * @return void */ - public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, - $relatedKey, $parentKey, $localKey, $relationName = null, $inverse = false) + public function __construct(Builder $query, Model $parent, $name, $table, $foreignPivotKey, + $relatedPivotKey, $parentKey, $relatedKey, $relationName = null, $inverse = false) { $this->inverse = $inverse; $this->morphType = $name.'_type'; $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass(); - parent::__construct($query, $parent, $table, $foreignKey, $relatedKey, $parentKey, $localKey, $relationName); + parent::__construct( + $query, $parent, $table, $foreignPivotKey, + $relatedPivotKey, $parentKey, $relatedKey, $relationName + ); } /** @@ -136,7 +139,7 @@ public function newPivot(array $attributes = [], $exists = false) $pivot = $using ? $using::fromRawAttributes($this->parent, $attributes, $this->table, $exists) : new MorphPivot($this->parent, $attributes, $this->table, $exists); - $pivot->setPivotKeys($this->foreignKey, $this->relatedKey) + $pivot->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey) ->setMorphType($this->morphType) ->setMorphClass($this->morphClass);
true
Other
laravel
framework
3aa2adc7574b0ff6f4f3b3a75de4b3f9c19a9737.json
fix various problems with belongs to many (#18380)
tests/Database/DatabaseEloquentModelTest.php
@@ -1015,17 +1015,17 @@ public function testBelongsToManyCreatesProperRelation() $this->addMockConnection($model); $relation = $model->belongsToMany('Illuminate\Tests\Database\EloquentModelSaveStub'); - $this->assertEquals('eloquent_model_save_stub_eloquent_model_stub.eloquent_model_stub_id', $relation->getQualifiedForeignKeyName()); - $this->assertEquals('eloquent_model_save_stub_eloquent_model_stub.eloquent_model_save_stub_id', $relation->getQualifiedRelatedKeyName()); + $this->assertEquals('eloquent_model_save_stub_eloquent_model_stub.eloquent_model_stub_id', $relation->getQualifiedForeignPivotKeyName()); + $this->assertEquals('eloquent_model_save_stub_eloquent_model_stub.eloquent_model_save_stub_id', $relation->getQualifiedRelatedPivotKeyName()); $this->assertSame($model, $relation->getParent()); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentModelSaveStub', $relation->getQuery()->getModel()); $this->assertEquals(__FUNCTION__, $relation->getRelationName()); $model = new EloquentModelStub; $this->addMockConnection($model); $relation = $model->belongsToMany('Illuminate\Tests\Database\EloquentModelSaveStub', 'table', 'foreign', 'other'); - $this->assertEquals('table.foreign', $relation->getQualifiedForeignKeyName()); - $this->assertEquals('table.other', $relation->getQualifiedRelatedKeyName()); + $this->assertEquals('table.foreign', $relation->getQualifiedForeignPivotKeyName()); + $this->assertEquals('table.other', $relation->getQualifiedRelatedPivotKeyName()); $this->assertSame($model, $relation->getParent()); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentModelSaveStub', $relation->getQuery()->getModel()); }
true
Other
laravel
framework
420609a83efd0eb59b7c3643d30e7242333837cb.json
add ability to pretty print response it is very difficult to view the failure response, since everything is printed inline. this allows the options to ‘pretty print’ the JSON output, just like is done in the ‘additional info’.
src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php
@@ -63,7 +63,7 @@ public function failureDescription($table) { return sprintf( "a row in the table [%s] matches the attributes %s.\n\n%s", - $table, $this->toString(), $this->getAdditionalInfo($table) + $table, $this->toString(JSON_PRETTY_PRINT), $this->getAdditionalInfo($table) ); } @@ -93,10 +93,11 @@ protected function getAdditionalInfo($table) /** * Get a string representation of the object. * + * @param int $options * @return string */ - public function toString() + public function toString($options = 0) { - return json_encode($this->data); + return json_encode($this->data, $options); } }
false
Other
laravel
framework
7b84baa5093e18fe988724bd27e1a58f191e000a.json
add assertion for soft deleted models - add new method assertion to the `InteractsWithDatabase` trait - create new constraint for soft deletes that checks that `deleted_at` is not null - a couple of tests for the new assertion
src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php
@@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Testing\Concerns; +use Illuminate\Foundation\Testing\Constraints\HasSoftDeletedInDatabase; use PHPUnit_Framework_Constraint_Not as ReverseConstraint; use Illuminate\Foundation\Testing\Constraints\HasInDatabase; @@ -43,6 +44,23 @@ protected function assertDatabaseMissing($table, array $data, $connection = null return $this; } + /** + * Assert that a given where condition exists in the database. + * + * @param string $table + * @param array $data + * @param string $connection + * @return $this + */ + protected function assertDatabaseHasSoftDelete($table, array $data, $connection = null) + { + $this->assertThat( + $table, new HasSoftDeletedInDatabase($this->getConnection($connection), $data) + ); + + return $this; + } + /** * Get the database connection. *
true
Other
laravel
framework
7b84baa5093e18fe988724bd27e1a58f191e000a.json
add assertion for soft deleted models - add new method assertion to the `InteractsWithDatabase` trait - create new constraint for soft deletes that checks that `deleted_at` is not null - a couple of tests for the new assertion
src/Illuminate/Foundation/Testing/Constraints/HasSoftDeletedInDatabase.php
@@ -0,0 +1,102 @@ +<?php + +namespace Illuminate\Foundation\Testing\Constraints; + +use PHPUnit_Framework_Constraint; +use Illuminate\Database\Connection; + +class HasSoftDeletedInDatabase extends PHPUnit_Framework_Constraint +{ + /** + * Number of records that will be shown in the console in case of failure. + * + * @var int + */ + protected $show = 3; + + /** + * The database connection. + * + * @var \Illuminate\Database\Connection + */ + protected $database; + + /** + * The data that will be used to narrow the search in the database table. + * + * @var array + */ + protected $data; + + /** + * Create a new constraint instance. + * + * @param \Illuminate\Database\Connection $database + * @param array $data + * @return void + */ + public function __construct(Connection $database, array $data) + { + $this->data = $data; + + $this->database = $database; + } + + /** + * Check if the data is found in the given table. + * + * @param string $table + * @return bool + */ + public function matches($table) + { + return $this->database->table($table)->where($this->data)->whereNotNull('deleted_at')->count() > 0; + } + + /** + * Get the description of the failure. + * + * @param string $table + * @return string + */ + public function failureDescription($table) + { + return sprintf( + "a soft deleted row in the table [%s] matches the attributes %s.\n\n%s", + $table, $this->toString(), $this->getAdditionalInfo($table) + ); + } + + /** + * Get additional info about the records found in the database table. + * + * @param string $table + * @return string + */ + protected function getAdditionalInfo($table) + { + $results = $this->database->table($table)->get(); + + if ($results->isEmpty()) { + return 'The table is empty'; + } + + $description = 'Found: '.json_encode($results->take($this->show), JSON_PRETTY_PRINT); + + if ($results->count() > $this->show) { + $description .= sprintf(' and %s others', $results->count() - $this->show); + } + + return $description; + } + + /** + * Get a string representation of the object. + * + * @return string + */ + public function toString() + { + return json_encode($this->data); + } +}
true
Other
laravel
framework
7b84baa5093e18fe988724bd27e1a58f191e000a.json
add assertion for soft deleted models - add new method assertion to the `InteractsWithDatabase` trait - create new constraint for soft deletes that checks that `deleted_at` is not null - a couple of tests for the new assertion
tests/Foundation/FoundationInteractsWithDatabaseTest.php
@@ -101,17 +101,39 @@ public function testDontSeeInDatabaseFindsResults() $this->assertDatabaseMissing($this->table, $this->data); } + public function testSeeSoftDeletedInDatabaseFindsResults() + { + $this->mockCountBuilder(1); + + $this->assertDatabaseHasSoftDelete($this->table, $this->data); + } + + /** + * @expectedException \PHPUnit_Framework_ExpectationFailedException + * @expectedExceptionMessage The table is empty. + */ + public function testSeeSoftDeletedInDatabaseDoesNotFindResults() + { + $builder = $this->mockCountBuilder(0); + + $builder->shouldReceive('get')->andReturn(collect()); + + $this->assertDatabaseHasSoftDelete($this->table, $this->data); + } + protected function mockCountBuilder($countResult) { $builder = m::mock(Builder::class); $builder->shouldReceive('where')->with($this->data)->andReturnSelf(); + $builder->shouldReceive('whereNotNull')->with('deleted_at')->andReturnSelf(); + $builder->shouldReceive('count')->andReturn($countResult); $this->connection->shouldReceive('table') - ->with($this->table) - ->andReturn($builder); + ->with($this->table) + ->andReturn($builder); return $builder; }
true
Other
laravel
framework
4df49b483b3d7747f5bedcf396457ebe1dbf40b5.json
Apply fixes from StyleCI (#18323)
tests/Mail/MailMailableDataTest.php
@@ -12,13 +12,13 @@ public function testMailableDataIsNotLost() $testData = ['first_name' => 'James']; $mailable = new MailableStub; - $mailable->build(function($m) use ($testData) { + $mailable->build(function ($m) use ($testData) { $m->view('view', $testData); }); $this->assertSame($testData, $mailable->buildViewData()); $mailable = new MailableStub; - $mailable->build(function($m) use ($testData) { + $mailable->build(function ($m) use ($testData) { $m->view('view', $testData) ->text('text-view'); }); @@ -37,4 +37,4 @@ public function build($builder) { $builder($this); } -} \ No newline at end of file +}
false
Other
laravel
framework
c79a84e5ece3007ae24ec9617198bc67bbed575e.json
Reset Response content-type. (#18314)
src/Illuminate/Http/Response.php
@@ -23,6 +23,10 @@ public function setContent($content) { $this->original = $content; + if ($this->headers->get('Content-Type') === 'application/json') { + $this->headers->remove('Content-Type'); + } + // If the content is "JSONable" we will set the appropriate header and convert // the content to JSON. This is useful when returning something like models // from routes that will be automatically transformed to their JSON form. @@ -39,7 +43,9 @@ public function setContent($content) $content = $content->render(); } - return parent::setContent($content); + parent::setContent($content); + + return $this; } /**
true
Other
laravel
framework
c79a84e5ece3007ae24ec9617198bc67bbed575e.json
Reset Response content-type. (#18314)
tests/Http/HttpResponseTest.php
@@ -41,6 +41,17 @@ public function testJsonResponsesAreConvertedAndHeadersAreSet() $this->assertEquals('application/json', $response->headers->get('Content-Type')); } + public function testResponseHeaderTypeIsReset() + { + $response = new \Illuminate\Http\Response(new ArrayableStub); + $this->assertEquals('{"foo":"bar"}', $response->getContent()); + $this->assertEquals('application/json', $response->headers->get('Content-Type')); + + $response->setContent('foo'); + $this->assertEquals('foo', $response->getContent()); + $this->assertNotEquals('application/json', $response->headers->get('Content-Type')); + } + public function testRenderablesAreRendered() { $mock = m::mock('Illuminate\Contracts\Support\Renderable');
true
Other
laravel
framework
563af376828934fb796e400c9f69a0ef439d53c9.json
Avoid aliases. (#18312)
src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php
@@ -189,7 +189,7 @@ public function withCount($relations) // Finally we will add the proper result column alias to the query and run the subselect // statement against the query builder. Then we will return the builder instance back // to the developer for further constraint chaining that needs to take place on it. - $column = isset($alias) ? $alias : snake_case($name.'_count'); + $column = isset($alias) ? $alias : Str::snake($name.'_count'); $this->selectSub($query->toBase(), $column); }
false
Other
laravel
framework
d3befb99db7b6a2abd2ca6198fada8e1b786bb00.json
remove unused import
src/Illuminate/Console/Scheduling/Schedule.php
@@ -5,7 +5,6 @@ use Illuminate\Console\Application; use Illuminate\Container\Container; use Symfony\Component\Process\ProcessUtils; -use Illuminate\Contracts\Cache\Repository as Cache; class Schedule {
false
Other
laravel
framework
41df68e606e946d096bf851068d2b988a1a18717.json
apply StyleCI fixes
src/Illuminate/Console/Scheduling/CallbackEvent.php
@@ -5,7 +5,6 @@ use LogicException; use InvalidArgumentException; use Illuminate\Contracts\Container\Container; -use Illuminate\Contracts\Cache\Repository as Cache; class CallbackEvent extends Event {
true
Other
laravel
framework
41df68e606e946d096bf851068d2b988a1a18717.json
apply StyleCI fixes
src/Illuminate/Console/Scheduling/OverlappingStrategy.php
@@ -5,23 +5,23 @@ interface OverlappingStrategy { /** - * prevents overlapping for the given event + * prevents overlapping for the given event. * * @param Event $event * @return void */ public function prevent(Event $event); /** - * checks if the given event's command is already running + * checks if the given event's command is already running. * * @param Event $event * @return bool */ public function overlaps(Event $event); /** - * resets the overlapping strategy for the given event + * resets the overlapping strategy for the given event. * * @param Event $event * @return void
true
Other
laravel
framework
41df68e606e946d096bf851068d2b988a1a18717.json
apply StyleCI fixes
src/Illuminate/Console/Scheduling/Schedule.php
@@ -32,7 +32,7 @@ public function __construct() { $container = Container::getInstance(); - if (!$container->bound(OverlappingStrategy::class)) { + if (! $container->bound(OverlappingStrategy::class)) { $this->overlappingStrategy = $container->make(CacheOverlappingStrategy::class); } else { $this->overlappingStrategy = $container->make(OverlappingStrategy::class);
true
Other
laravel
framework
41df68e606e946d096bf851068d2b988a1a18717.json
apply StyleCI fixes
tests/Console/ConsoleEventSchedulerTest.php
@@ -2,7 +2,6 @@ namespace Illuminate\Tests\Console; -use Illuminate\Container\Container; use Mockery as m; use PHPUnit\Framework\TestCase; use Illuminate\Console\Scheduling\Schedule;
true
Other
laravel
framework
41df68e606e946d096bf851068d2b988a1a18717.json
apply StyleCI fixes
tests/Console/Scheduling/CacheOverlappingStrategyTest.php
@@ -2,10 +2,10 @@ namespace Illuminate\Tests\Console\Scheduling; -use Illuminate\Console\Scheduling\CacheOverlappingStrategy; -use Illuminate\Console\Scheduling\Event; -use PHPUnit\Framework\TestCase; use Mockery as m; +use PHPUnit\Framework\TestCase; +use Illuminate\Console\Scheduling\Event; +use Illuminate\Console\Scheduling\CacheOverlappingStrategy; class CacheOverlappingStrategyTest extends TestCase {
true
Other
laravel
framework
781d4c03b2cf56ee6b90d68e8a5766496b91799c.json
add tests for CacheOverlappingStrategy
tests/Console/Scheduling/CacheOverlappingStrategyTest.php
@@ -0,0 +1,73 @@ +<?php + +namespace Illuminate\Tests\Console\Scheduling; + +use Illuminate\Console\Scheduling\CacheOverlappingStrategy; +use Illuminate\Console\Scheduling\Event; +use PHPUnit\Framework\TestCase; +use Mockery as m; + +class CacheOverlappingStrategyTest extends TestCase +{ + /** + * @var CacheOverlappingStrategy + */ + protected $cacheOverlappingStrategy; + + /** + * @var \Illuminate\Contracts\Cache\Repository + */ + protected $cacheRepository; + + public function setUp() + { + parent::setUp(); + + $this->cacheRepository = m::mock('Illuminate\Contracts\Cache\Repository'); + $this->cacheOverlappingStrategy = new CacheOverlappingStrategy($this->cacheRepository); + } + + public function testPreventOverlap() + { + $cacheOverlappingStrategy = $this->cacheOverlappingStrategy; + + $this->cacheRepository->shouldReceive('put'); + + $event = new Event($this->cacheOverlappingStrategy, 'command'); + + $cacheOverlappingStrategy->prevent($event); + } + + public function testOverlapsForNonRunningTask() + { + $cacheOverlappingStrategy = $this->cacheOverlappingStrategy; + + $this->cacheRepository->shouldReceive('has')->andReturn(false); + + $event = new Event($this->cacheOverlappingStrategy, 'command'); + + $this->assertFalse($cacheOverlappingStrategy->overlaps($event)); + } + + public function testOverlapsForRunningTask() + { + $cacheOverlappingStrategy = $this->cacheOverlappingStrategy; + + $this->cacheRepository->shouldReceive('has')->andReturn(true); + + $event = new Event($this->cacheOverlappingStrategy, 'command'); + + $this->assertTrue($cacheOverlappingStrategy->overlaps($event)); + } + + public function testResetOverlap() + { + $cacheOverlappingStrategy = $this->cacheOverlappingStrategy; + + $this->cacheRepository->shouldReceive('forget'); + + $event = new Event($this->cacheOverlappingStrategy, 'command'); + + $cacheOverlappingStrategy->reset($event); + } +}
false
Other
laravel
framework
42d5c856067368fe3fda0a43477a964866b073c5.json
fix broken schedule tests
tests/Console/ConsoleEventSchedulerTest.php
@@ -2,6 +2,7 @@ namespace Illuminate\Tests\Console; +use Illuminate\Container\Container; use Mockery as m; use PHPUnit\Framework\TestCase; use Illuminate\Console\Scheduling\Schedule; @@ -12,8 +13,12 @@ public function setUp() { parent::setUp(); - \Illuminate\Container\Container::getInstance()->instance( - 'Illuminate\Console\Scheduling\Schedule', $this->schedule = new Schedule(m::mock('Illuminate\Contracts\Cache\Repository')) + $container = \Illuminate\Container\Container::getInstance(); + + $container->instance('Illuminate\Console\Scheduling\OverlappingStrategy', m::mock('Illuminate\Console\Scheduling\CacheOverlappingStrategy')); + + $container->instance( + 'Illuminate\Console\Scheduling\Schedule', $this->schedule = new Schedule(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy')) ); }
true
Other
laravel
framework
42d5c856067368fe3fda0a43477a964866b073c5.json
fix broken schedule tests
tests/Console/ConsoleScheduledEventTest.php
@@ -35,7 +35,7 @@ public function testBasicCronCompilation() $app->shouldReceive('isDownForMaintenance')->andReturn(false); $app->shouldReceive('environment')->andReturn('production'); - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertEquals('* * * * * *', $event->getExpression()); $this->assertTrue($event->isDue($app)); $this->assertTrue($event->skip(function () { @@ -45,25 +45,25 @@ public function testBasicCronCompilation() return true; })->filtersPass($app)); - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertEquals('* * * * * *', $event->getExpression()); $this->assertFalse($event->environments('local')->isDue($app)); - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertEquals('* * * * * *', $event->getExpression()); $this->assertFalse($event->when(function () { return false; })->filtersPass($app)); // chained rules should be commutative - $eventA = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); - $eventB = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $eventA = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); + $eventB = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertEquals( $eventA->daily()->hourly()->getExpression(), $eventB->hourly()->daily()->getExpression()); - $eventA = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); - $eventB = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $eventA = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); + $eventB = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertEquals( $eventA->weekdays()->hourly()->getExpression(), $eventB->hourly()->weekdays()->getExpression()); @@ -76,11 +76,11 @@ public function testEventIsDueCheck() $app->shouldReceive('environment')->andReturn('production'); Carbon::setTestNow(Carbon::create(2015, 1, 1, 0, 0, 0)); - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertEquals('* * * * 4 *', $event->thursdays()->getExpression()); $this->assertTrue($event->isDue($app)); - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertEquals('0 19 * * 3 *', $event->wednesdays()->at('19:00')->timezone('EST')->getExpression()); $this->assertTrue($event->isDue($app)); } @@ -92,7 +92,7 @@ public function testTimeBetweenChecks() $app->shouldReceive('environment')->andReturn('production'); Carbon::setTestNow(Carbon::now()->startOfDay()->addHours(9)); - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo'); $this->assertTrue($event->between('8:00', '10:00')->filtersPass($app)); $this->assertTrue($event->between('9:00', '9:00')->filtersPass($app)); $this->assertFalse($event->between('10:00', '11:00')->filtersPass($app));
true
Other
laravel
framework
42d5c856067368fe3fda0a43477a964866b073c5.json
fix broken schedule tests
tests/Console/Scheduling/EventTest.php
@@ -17,14 +17,14 @@ public function testBuildCommand() { $quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'"; - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php -i'); $defaultOutput = (DIRECTORY_SEPARATOR == '\\') ? 'NUL' : '/dev/null'; $this->assertSame("php -i > {$quote}{$defaultOutput}{$quote} 2>&1", $event->buildCommand()); $quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'"; - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php -i'); $event->runInBackground(); $defaultOutput = (DIRECTORY_SEPARATOR == '\\') ? 'NUL' : '/dev/null'; @@ -35,12 +35,12 @@ public function testBuildCommandSendOutputTo() { $quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'"; - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php -i'); $event->sendOutputTo('/dev/null'); $this->assertSame("php -i > {$quote}/dev/null{$quote} 2>&1", $event->buildCommand()); - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php -i'); $event->sendOutputTo('/my folder/foo.log'); $this->assertSame("php -i > {$quote}/my folder/foo.log{$quote} 2>&1", $event->buildCommand()); @@ -50,7 +50,7 @@ public function testBuildCommandAppendOutput() { $quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'"; - $event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i'); + $event = new Event(m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php -i'); $event->appendOutputTo('/dev/null'); $this->assertSame("php -i >> {$quote}/dev/null{$quote} 2>&1", $event->buildCommand());
true
Other
laravel
framework
42d5c856067368fe3fda0a43477a964866b073c5.json
fix broken schedule tests
tests/Console/Scheduling/FrequencyTest.php
@@ -16,7 +16,7 @@ class FrequencyTest extends TestCase public function setUp() { $this->event = new Event( - m::mock('Illuminate\Contracts\Cache\Repository'), + m::mock('Illuminate\Console\Scheduling\OverlappingStrategy'), 'php foo' ); }
true
Other
laravel
framework
4a9e58918332bd33c71c931a3305f8a3a978b294.json
Return the insertId of released jobs (#18288)
src/Illuminate/Queue/Jobs/DatabaseJob.php
@@ -45,15 +45,15 @@ public function __construct(Container $container, DatabaseQueue $database, $job, * Release the job back into the queue. * * @param int $delay - * @return void + * @return mixed */ public function release($delay = 0) { parent::release($delay); $this->delete(); - $this->database->release($this->queue, $this->job, $delay); + return $this->database->release($this->queue, $this->job, $delay); } /**
false
Other
laravel
framework
c3cb531df1717c92bd1d70d30f2c018e56fd6b57.json
Apply fixes from StyleCI (#18287)
src/Illuminate/Notifications/NotificationSender.php
@@ -82,7 +82,7 @@ public function sendNow($notifiables, $notification, array $channels = null) if (empty($viaChannels = $channels ?: $notification->via($notifiable))) { continue; } - + $notificationId = Uuid::uuid4()->toString(); foreach ($viaChannels as $channel) {
false
Other
laravel
framework
9aa8da045fe3fd976f6766675e2f64aed82d16dd.json
Apply fixes from StyleCI (#18283)
src/Illuminate/Foundation/Console/VendorPublishCommand.php
@@ -90,7 +90,7 @@ protected function determineWhatShouldBePublished() } [$this->provider, $this->tags] = [ - $this->option('provider'), (array) $this->option('tag') + $this->option('provider'), (array) $this->option('tag'), ]; if (! $this->provider && ! $this->tags) {
false
Other
laravel
framework
a03088928d1d6b3680c10727d169817324e45967.json
Apply fixes from StyleCI (#18281)
tests/Validation/ValidationValidatorTest.php
@@ -1976,10 +1976,10 @@ public function testValidateMimetypes() $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock(); $file->expects($this->any())->method('guessExtension')->will($this->returnValue('php')); - + $v = new Validator($trans, ['x' => $file], ['x' => 'mimetypes:text/x-php']); $this->assertTrue($v->passes()); - + $v = new Validator($trans, ['x' => $file], ['x' => 'mimetypes:text/*']); $this->assertTrue($v->passes()); }
false
Other
laravel
framework
fe1ef6570d10c955da8e90c8be429d96ad5574ee.json
allow wildcard mime types
src/Illuminate/Validation/Concerns/ValidatesAttributes.php
@@ -926,7 +926,9 @@ protected function validateMimetypes($attribute, $value, $parameters) return false; } - return $value->getPath() != '' && (in_array($value->getMimeType(), $parameters) || in_array(explode('/', $value->getMimeType())[0] . '/*', $parameters)); + return $value->getPath() != '' && + (in_array($value->getMimeType(), $parameters) || + in_array(explode('/', $value->getMimeType())[0].'/*', $parameters)); } /**
false
Other
laravel
framework
394f0fecfa84764f66c49c3b025dd7eb26aa61cd.json
Replace custom implementation
src/Illuminate/Console/ConfirmableTrait.php
@@ -26,9 +26,7 @@ public function confirmToProceed($warning = 'Application In Production!', $callb return true; } - $this->comment(str_repeat('*', strlen($warning) + 12)); - $this->comment('* '.$warning.' *'); - $this->comment(str_repeat('*', strlen($warning) + 12)); + $this->alert($warning); $this->output->writeln(''); $confirmed = $this->confirm('Do you really wish to run this command?');
false
Other
laravel
framework
ec938862f165f1c2b69c1dea55d1ec2b419bde6e.json
Add alert method
src/Illuminate/Console/Command.php
@@ -433,6 +433,19 @@ public function comment($string, $verbosity = null) $this->line($string, 'comment', $verbosity); } + /** + * Write a string in an alert box. + * + * @param string $string + * @return void + */ + public function alert($string) + { + $this->comment(str_repeat('*', strlen($string) + 12)); + $this->comment('* '.$string.' *'); + $this->comment(str_repeat('*', strlen($string) + 12)); + } + /** * Write a string as question output. *
false
Other
laravel
framework
5c85962b75f5737f674c3e39b234e1f8c614353c.json
Update HttpJsonResponseTest.php (#18261)
tests/Http/HttpJsonResponseTest.php
@@ -9,23 +9,23 @@ class HttpJsonResponseTest extends TestCase { - public function testSeAndRetrieveJsonableData() + public function testSetAndRetrieveJsonableData() { $response = new \Illuminate\Http\JsonResponse(new JsonResponseTestJsonableObject); $data = $response->getData(); $this->assertInstanceOf('StdClass', $data); $this->assertEquals('bar', $data->foo); } - public function testSeAndRetrieveJsonSerializeData() + public function testSetAndRetrieveJsonSerializeData() { $response = new \Illuminate\Http\JsonResponse(new JsonResponseTestJsonSerializeObject); $data = $response->getData(); $this->assertInstanceOf('StdClass', $data); $this->assertEquals('bar', $data->foo); } - public function testSeAndRetrieveArrayableData() + public function testSetAndRetrieveArrayableData() { $response = new \Illuminate\Http\JsonResponse(new JsonResponseTestArrayableObject); $data = $response->getData();
false
Other
laravel
framework
117fe4501d93119022f2e653e55dd961dddb22ff.json
Show publishable tags in addition to providers
src/Illuminate/Foundation/Console/VendorPublishCommand.php
@@ -18,6 +18,20 @@ class VendorPublishCommand extends Command */ protected $files; + /** + * The provider to publish. + * + * @var string + */ + protected $provider = null; + + /** + * The tags to publish. + * + * @var array + */ + protected $tags = []; + /** * The console command signature. * @@ -55,52 +69,100 @@ public function __construct(Filesystem $files) */ public function fire() { - $tags = $this->option('tag') ?: [null]; + $this->setProviderOrTagsToPublish(); + + $tags = $this->tags ?: [null]; - foreach ((array) $tags as $tag) { + foreach ($tags as $tag) { $this->publishTag($tag); } + + $this->info('Publishing complete.'); } /** - * Publishes the assets for a tag. + * Determine the provider or tag(s) to publish. * - * @param string $tag - * @return mixed + * @return void */ - protected function publishTag($tag) + protected function setProviderOrTagsToPublish() { - foreach ($this->pathsToPublish($tag) as $from => $to) { - $this->publishItem($from, $to); + if ($this->option('all')) { + return; } - $this->info('Publishing complete.'); + $this->provider = $this->option('provider'); + + $this->tags = (array) $this->option('tag'); + + if ($this->provider || $this->tags) { + return; + } + + $this->promptForProviderOrTag(); } /** - * Determine the provider to publish. + * Prompt for which provider or tag to publish. * - * @return mixed + * @return void */ - protected function providerToPublish() + protected function promptForProviderOrTag() { - if ($this->option('all')) { - return null; - } + $choice = $this->choice( + "Which provider or tag's files would you like to publish?", + $choices = $this->publishableChoices() + ); - if ($this->option('provider')) { - return $this->option('provider'); + if ($choice == $choices[0]) { + return; } - $choice = $this->choice( - "Which package's files would you like to publish?", - array_merge( - [$all = '<comment>Publish files from all packages listed below</comment>'], - ServiceProvider::providersAvailableToPublish() - ) + $this->parseChoice($choice); + } + + /** + * The choices available via the prompt. + * + * @return array + */ + protected function publishableChoices() + { + return array_merge( + ['<comment>Publish files from all providers and tags listed below</comment>'], + preg_filter('/^/', '<comment>Provider: </comment>', ServiceProvider::publishableProviders()), + preg_filter('/^/', '<comment>Tag: </comment>', ServiceProvider::publishableGroups()) ); + } + + /** + * Parse the answer that was given via the prompt. + * + * @param string $choice + * @return void + */ + protected function parseChoice($choice) + { + list($type, $value) = explode(': ', strip_tags($choice)); + + if ($type == 'Provider') { + $this->provider = $value; + } elseif ($type == 'Tag') { + $this->tags = [$value]; + } + } - return $choice == $all ? null : $choice; + /** + * Publishes the assets for a tag. + * + * @param string $tag + * @return mixed + */ + protected function publishTag($tag) + { + foreach ($this->pathsToPublish($tag) as $from => $to) { + $this->publishItem($from, $to); + } } /** @@ -112,7 +174,7 @@ protected function providerToPublish() protected function pathsToPublish($tag) { return ServiceProvider::pathsToPublish( - $this->providerToPublish(), $tag + $this->provider, $tag ); }
true
Other
laravel
framework
117fe4501d93119022f2e653e55dd961dddb22ff.json
Show publishable tags in addition to providers
src/Illuminate/Support/ServiceProvider.php
@@ -169,11 +169,21 @@ protected function addPublishGroup($group, $paths) * * @return array */ - public static function providersAvailableToPublish() + public static function publishableProviders() { return array_keys(static::$publishes); } + /** + * Get the groups available for publishing. + * + * @return array + */ + public static function publishableGroups() + { + return array_keys(static::$publishGroups); + } + /** * Get the paths to publish. *
true
Other
laravel
framework
117fe4501d93119022f2e653e55dd961dddb22ff.json
Show publishable tags in addition to providers
tests/Support/SupportServiceProviderTest.php
@@ -22,14 +22,20 @@ public function tearDown() m::close(); } - public function testGetAvailableServiceProvidersToPublish() + public function testPublishableServiceProviders() { - $availableToPublish = ServiceProvider::providersAvailableToPublish(); + $toPublish = ServiceProvider::publishableProviders(); $expected = [ 'Illuminate\Tests\Support\ServiceProviderForTestingOne', 'Illuminate\Tests\Support\ServiceProviderForTestingTwo', ]; - $this->assertEquals($expected, $availableToPublish, 'Publishable service providers do not return expected set of providers.'); + $this->assertEquals($expected, $toPublish, 'Publishable service providers do not return expected set of providers.'); + } + + public function testPublishableGroups() + { + $toPublish = ServiceProvider::publishableGroups(); + $this->assertEquals(['some_tag'], $toPublish, 'Publishable groups do not return expected set of groups.'); } public function testSimpleAssetsArePublishedCorrectly()
true
Other
laravel
framework
b4f000516166b0694e842d64f5b2fde1167d4690.json
change exception type
src/Illuminate/Foundation/ProviderRepository.php
@@ -2,8 +2,8 @@ namespace Illuminate\Foundation; +use Exception; use Illuminate\Filesystem\Filesystem; -use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Contracts\Foundation\Application as ApplicationContract; class ProviderRepository @@ -181,12 +181,12 @@ protected function freshManifest(array $providers) * * @param array $manifest * @return array - * @throws FileNotFoundException + * @throws Exception */ public function writeManifest($manifest) { if (! is_writable(dirname($this->manifestPath))) { - throw new FileNotFoundException('The bootstrap/cache directory must be present and writable.'); + throw new Exception('The bootstrap/cache directory must be present and writable.'); } $this->files->put(
false
Other
laravel
framework
52016015ad9d51278bbe91310b9cf5315d2a7289.json
allow scheduling of queued jobs
src/Illuminate/Console/Scheduling/Schedule.php
@@ -4,6 +4,7 @@ use Illuminate\Console\Application; use Illuminate\Container\Container; +use Illuminate\Contracts\Queue\ShouldQueue; use Symfony\Component\Process\ProcessUtils; use Illuminate\Contracts\Cache\Repository as Cache; @@ -48,6 +49,19 @@ public function call($callback, array $parameters = []) return $event; } + /** + * Add a new queued job callback event to the schedule. + * + * @param \Illuminate\Contracts\Queue\ShouldQueue $job + * @return \Illuminate\Console\Scheduling\Event + */ + public function job(ShouldQueue $job) + { + return $this->call(function() use($job) { + dispatch($job); + })->name(get_class($job)); + } + /** * Add a new Artisan command event to the schedule. *
false
Other
laravel
framework
a74c4439a0762722b3173ac5ed58eecb43f49aad.json
Prefix an option `0` that publishes all
src/Illuminate/Foundation/Console/VendorPublishCommand.php
@@ -92,10 +92,15 @@ protected function providerToPublish() return $this->option('provider'); } - return $this->choice( + $choice = $this->choice( "Which package's files would you like to publish?", - ServiceProvider::providersAvailableToPublish() + array_merge( + [$all = '<comment>Publish files from all packages listed below</comment>'], + ServiceProvider::providersAvailableToPublish() + ) ); + + return $choice == $all ? null : $choice; } /**
false
Other
laravel
framework
8784966b45f018d6880c809fa488b4a68d01d33b.json
Add any() method to ViewErrorBag
src/Illuminate/Support/ViewErrorBag.php
@@ -70,6 +70,16 @@ public function count() return $this->getBag('default')->count(); } + /** + * Determine if the default message bag has any messages. + * + * @return bool + */ + public function any() + { + return $this->count() > 0; + } + /** * Dynamically call methods on the default bag. *
false
Other
laravel
framework
bd7c0a94db7888a21d2c05f73d57e32d582044a9.json
Apply fixes from StyleCI (#18174)
src/Illuminate/Http/ResponseTrait.php
@@ -6,7 +6,6 @@ use Symfony\Component\HttpFoundation\HeaderBag; use Illuminate\Http\Exceptions\HttpResponseException; - trait ResponseTrait { /**
false
Other
laravel
framework
d2b6c8bc5cc443e41bcfe344973e105b728bebb5.json
Fix MySQL deletes with JOIN and ALias
src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
@@ -242,7 +242,13 @@ protected function compileDeleteWithJoins($query, $table, $where) { $joins = ' '.$this->compileJoins($query, $query->joins); - return trim("delete {$table} from {$table}{$joins} {$where}"); + $alias = $table; + + if (strpos(strtolower($table), ' as ') !== false) { + $alias = explode(' as ', $table)[1]; + } + + return trim("delete {$alias} from {$table}{$joins} {$where}"); } /**
true
Other
laravel
framework
d2b6c8bc5cc443e41bcfe344973e105b728bebb5.json
Fix MySQL deletes with JOIN and ALias
tests/Database/DatabaseQueryBuilderTest.php
@@ -1433,6 +1433,11 @@ public function testDeleteWithJoinMethod() $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->where('email', '=', 'foo')->orderBy('id')->limit(1)->delete(); $this->assertEquals(1, $result); + $builder = $this->getMySqlBuilder(); + $builder->getConnection()->shouldReceive('delete')->once()->with('delete `a` from `users` as `a` inner join `users` as `b` on `a`.`id` = `b`.`user_id` where `email` = ?', ['foo'])->andReturn(1); + $result = $builder->from('users AS a')->join('users AS b', 'a.id', '=', 'b.user_id')->where('email', '=', 'foo')->orderBy('id')->limit(1)->delete(); + $this->assertEquals(1, $result); + $builder = $this->getMySqlBuilder(); $builder->getConnection()->shouldReceive('delete')->once()->with('delete `users` from `users` inner join `contacts` on `users`.`id` = `contacts`.`id` where `users`.`id` = ?', [1])->andReturn(1); $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->orderBy('id')->take(1)->delete(1);
true
Other
laravel
framework
4d4040b601b9e5eb469af8c221c372abd8e9948a.json
Add whereNotIn() to Collection (#18157)
src/Illuminate/Support/Collection.php
@@ -416,6 +416,35 @@ public function whereInStrict($key, $values) return $this->whereIn($key, $values, true); } + /** + * Filter items by the given key value pair. + * + * @param string $key + * @param mixed $values + * @param bool $strict + * @return static + */ + public function whereNotIn($key, $values, $strict = false) + { + $values = $this->getArrayableItems($values); + + return $this->reject(function ($item) use ($key, $values, $strict) { + return in_array(data_get($item, $key), $values, $strict); + }); + } + + /** + * Filter items by the given key value pair using strict comparison. + * + * @param string $key + * @param mixed $values + * @return static + */ + public function whereNotInStrict($key, $values) + { + return $this->whereNotIn($key, $values, true); + } + /** * Get the first item from the collection. *
true
Other
laravel
framework
4d4040b601b9e5eb469af8c221c372abd8e9948a.json
Add whereNotIn() to Collection (#18157)
tests/Support/SupportCollectionTest.php
@@ -397,6 +397,18 @@ public function testWhereInStrict() $this->assertEquals([['v' => 1], ['v' => 3]], $c->whereInStrict('v', [1, 3])->values()->all()); } + public function testWhereNotIn() + { + $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); + $this->assertEquals([['v' => 2], ['v' => 4]], $c->whereNotIn('v', [1, 3])->values()->all()); + } + + public function testWhereNotInStrict() + { + $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); + $this->assertEquals([['v' => 2], ['v' => '3'], ['v' => 4]], $c->whereNotInStrict('v', [1, 3])->values()->all()); + } + public function testValues() { $c = new Collection([['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']]);
true
Other
laravel
framework
886f7ab114794140128ae47db1c16bb03482e690.json
Fix Spelling mistake (#18164)
src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php
@@ -145,7 +145,7 @@ public function isFillable($key) } // If the attribute is explicitly listed in the "guarded" array then we can - // retunr false immediately. This means this attribute is definitely not + // return false immediately. This means this attribute is definitely not // fillable and there is no point in going any further in this method. if ($this->isGuarded($key)) { return false;
false
Other
laravel
framework
05e4e9e43857adacffd87f4066a10b2ceccae774.json
Convert rule object to string once
src/Illuminate/Validation/ValidationRuleParser.php
@@ -82,9 +82,9 @@ protected function explodeExplicitRule($rule) if (is_string($rule)) { return explode('|', $rule); } elseif (is_object($rule)) { - return [$rule]; + return [strval($rule)]; } else { - return $rule; + return array_map('strval', $rule); } }
false
Other
laravel
framework
c5a62901589e313474376e241549ac31d9d3c695.json
fix bug with has events
src/Illuminate/Database/Eloquent/Concerns/HasEvents.php
@@ -138,7 +138,11 @@ protected function fireModelEvent($event, $halt = true) $result = $this->fireCustomModelEvent($event, $method); - return ! is_null($result) ? $result : static::$dispatcher->{$method}( + if ($result === false) { + return false; + } + + return ! empty($result) ? $result : static::$dispatcher->{$method}( "eloquent.{$event}: ".static::class, $this ); }
false
Other
laravel
framework
063e5ae341c32220d4679d0215ab9b263d0c8a33.json
make fix in other location
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -130,7 +130,7 @@ public function newPivot(array $attributes = [], $exists = false) { $using = $this->using; - $pivot = $using ? new $using($this->parent, $attributes, $this->table, $exists) + $pivot = $using ? $using::fromRawAttributes($this->parent, $attributes, $this->table, $exists) : new MorphPivot($this->parent, $attributes, $this->table, $exists); $pivot->setPivotKeys($this->foreignKey, $this->relatedKey)
false
Other
laravel
framework
8be9acfbb802a74b4939eb84c24c4f151c30512a.json
Add getActionMethod to Route.php (#18105) * Update Route.php * Update Route.php * Update Route.php
src/Illuminate/Routing/Route.php
@@ -647,6 +647,16 @@ public function getActionName() return isset($this->action['controller']) ? $this->action['controller'] : 'Closure'; } + /** + * Get the method name of the route action. + * + * @return string + */ + public function getActionMethod() + { + return array_last(explode('@', $this->getActionName())); + } + /** * Get the action array for the route. *
false
Other
laravel
framework
862c80de2c84c360b35ee814a0ce101e89dcb038.json
Highlight breaking changes
CHANGELOG-5.5.md
@@ -3,35 +3,38 @@ ## [Unreleased] ### General -- Require PHP 7+ ([06907a0](https://github.com/laravel/framework/pull/17048/commits/06907a055e3d28c219f6b6ab97902f0be3e8a4ef), [39809ce](https://github.com/laravel/framework/pull/17048/commits/39809cea81a5564d196c16a87cbc25de88dd3d1c)) -- Removed deprecated `ServiceProvider::compile()` method ([10da428](https://github.com/laravel/framework/pull/17048/commits/10da428eb344191608474f1c12ee7edb0290e80a)) -- Removed deprecated `Str::quickRandom()` method ([2ef257a](https://github.com/laravel/framework/pull/17048/commits/2ef257a4197b7e6efeb0d6ac4a3958f82b7fed39)) +- ⚠️ Require PHP 7+ ([06907a0](https://github.com/laravel/framework/pull/17048/commits/06907a055e3d28c219f6b6ab97902f0be3e8a4ef), [39809ce](https://github.com/laravel/framework/pull/17048/commits/39809cea81a5564d196c16a87cbc25de88dd3d1c)) +- ⚠️ Removed deprecated `ServiceProvider::compile()` method ([10da428](https://github.com/laravel/framework/pull/17048/commits/10da428eb344191608474f1c12ee7edb0290e80a)) +- ⚠️ Removed deprecated `Str::quickRandom()` method ([2ef257a](https://github.com/laravel/framework/pull/17048/commits/2ef257a4197b7e6efeb0d6ac4a3958f82b7fed39)) - Removed `build` scripts ([7c16b15](https://github.com/laravel/framework/pull/17048/commits/7c16b154ede10ff9a37756e32d7dddf317524634)) - Removed usages of the `with()` helper ([#17888](https://github.com/laravel/framework/pull/17888)) ### Eloquent -- Indicate soft deleted models as existing ([#17613](https://github.com/laravel/framework/pull/17613)) -- Added `$localKey` parameter to `HasRelationships::belongsToMany()` and `BelongsToMany` ([#17903](https://github.com/laravel/framework/pull/17903), [7c7c3bc](https://github.com/laravel/framework/commit/7c7c3bc4be3052afe0889fe323230dfd92f81000)) +- ⚠️ Indicate soft deleted models as existing ([#17613](https://github.com/laravel/framework/pull/17613)) +- ⚠️ Added `$localKey` parameter to `HasRelationships::belongsToMany()` and `BelongsToMany` ([#17903](https://github.com/laravel/framework/pull/17903), [7c7c3bc](https://github.com/laravel/framework/commit/7c7c3bc4be3052afe0889fe323230dfd92f81000)) - Renamed `$parent` property to `$pivotParent` in `Pivot` class ([#17933](https://github.com/laravel/framework/pull/17933)) -- Don't add `_count` suffix to column name when using `withCount()` with an alias ([#17871](https://github.com/laravel/framework/pull/17871)) +- ⚠️ Don't add `_count` suffix to column name when using `withCount()` with an alias ([#17871](https://github.com/laravel/framework/pull/17871)) ### Events -- Removed calling queue method on handlers ([0360cb1](https://github.com/laravel/framework/commit/0360cb1c6b71ec89d406517b19d1508511e98fb5), [ec96979](https://github.com/laravel/framework/commit/ec969797878f2c731034455af2397110732d14c4), [d9be4bf](https://github.com/laravel/framework/commit/d9be4bfe0367a8e07eed4931bdabf135292abb1b)) +- ⚠️ Removed calling queue method on handlers ([0360cb1](https://github.com/laravel/framework/commit/0360cb1c6b71ec89d406517b19d1508511e98fb5), [ec96979](https://github.com/laravel/framework/commit/ec969797878f2c731034455af2397110732d14c4), [d9be4bf](https://github.com/laravel/framework/commit/d9be4bfe0367a8e07eed4931bdabf135292abb1b)) ### HTTP -- Ensure `Arrayable` and `Jsonable` return a `JsonResponse` ([#17875](https://github.com/laravel/framework/pull/17875)) -- Ensure `Arrayable` objects are also morphed by `Response` ([#17868](https://github.com/laravel/framework/pull/17868)) +- ⚠️ Ensure `Arrayable` and `Jsonable` return a `JsonResponse` ([#17875](https://github.com/laravel/framework/pull/17875)) +- ⚠️ Ensure `Arrayable` objects are also morphed by `Response` ([#17868](https://github.com/laravel/framework/pull/17868)) - Added `SameSite` support to `CookieJar` ([#18040](https://github.com/laravel/framework/pull/18040)) ### Queue -- Removed redundant `$queue` parameter from `Queue::createPayload()` ([#17948](https://github.com/laravel/framework/pull/17948)) +- ⚠️ Removed redundant `$queue` parameter from `Queue::createPayload()` ([#17948](https://github.com/laravel/framework/pull/17948)) ### Redis - Removed `PhpRedisConnection::proxyToEval()` method ([#17360](https://github.com/laravel/framework/pull/17360)) ### Routing -- Bind empty optional route parameter to `null` instead of empty model instance ([#17521](https://github.com/laravel/framework/pull/17521)) +- ⚠️ Bind empty optional route parameter to `null` instead of empty model instance ([#17521](https://github.com/laravel/framework/pull/17521)) ### Testing -- Switched to PHPUnit 6 ([#17755](https://github.com/laravel/framework/pull/17755), [#17864](https://github.com/laravel/framework/pull/17864)) -- Renamed authentication assertion methods ([#17924](https://github.com/laravel/framework/pull/17924), [494a177](https://github.com/laravel/framework/commit/494a1774f217f0cd6b4efade63e200e3ac65f201)) +- ⚠️ Switched to PHPUnit 6 ([#17755](https://github.com/laravel/framework/pull/17755), [#17864](https://github.com/laravel/framework/pull/17864)) +- ⚠️ Renamed authentication assertion methods ([#17924](https://github.com/laravel/framework/pull/17924), [494a177](https://github.com/laravel/framework/commit/494a1774f217f0cd6b4efade63e200e3ac65f201)) + +### Views +- ⚠️ Camel case variables names passed to views ([#18083](https://github.com/laravel/framework/pull/18083))
false
Other
laravel
framework
e4c0de68cab03c5e683ac42e405b91eeee733d57.json
Ensure Illumitate\Contracts is required. (#18087)
src/Illuminate/Translation/composer.json
@@ -15,6 +15,7 @@ ], "require": { "php": ">=5.6.4", + "illuminate/contracts": "5.4.*", "illuminate/filesystem": "5.4.*", "illuminate/support": "5.4.*" },
false
Other
laravel
framework
2a728804ccc1ef63fcf4fae3b4d5d73eda04dbba.json
remove strange test
tests/Routing/RoutingRouteTest.php
@@ -309,24 +309,6 @@ public function testClassesCanBeInjectedIntoRoutes() unset($_SERVER['__test.route_inject']); } - public function testClassesAndVariablesCanBeInjectedIntoRoutes() - { - unset($_SERVER['__test.route_inject']); - $router = $this->getRouter(); - $router->get('foo/{var}/{bar?}/{baz?}', function (stdClass $foo, $var, $bar = 'test', Request $baz = null) { - $_SERVER['__test.route_inject'] = func_get_args(); - - return 'hello'; - }); - $this->assertEquals('hello', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent()); - $this->assertInstanceOf('stdClass', $_SERVER['__test.route_inject'][0]); - $this->assertEquals('bar', $_SERVER['__test.route_inject'][1]); - $this->assertEquals('test', $_SERVER['__test.route_inject'][2]); - $this->assertArrayHasKey(3, $_SERVER['__test.route_inject']); - $this->assertInstanceOf('Illuminate\Http\Request', $_SERVER['__test.route_inject'][3]); - unset($_SERVER['__test.route_inject']); - } - public function testOptionsResponsesAreGeneratedByDefault() { $router = $this->getRouter();
false
Other
laravel
framework
e4d46c030628cbf06c48a5fb742a7fd1d8dc302b.json
add more tests
tests/View/Blade/BladeIncludeWhenTest.php
@@ -18,6 +18,8 @@ public function testIncludeWhensAreCompiled() $compiler = new BladeCompiler($this->getFiles(), __DIR__); $this->assertEquals('<?php if (true) echo $__env->make(\'foo\', array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeWhen(true, \'foo\')')); $this->assertEquals('<?php if (true) echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeWhen(true, name(foo))')); + $this->assertEquals('<?php if (foo((\'foo\'))) echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeWhen(foo((\'foo\')), name(foo))')); + $this->assertEquals('<?php if (\'true, false\') echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeWhen(\'true, false\', name(foo))')); } protected function getFiles()
false
Other
laravel
framework
5fe39aa3bac01f49ffaf5d44bf03688690106dbe.json
Add includeWhen directive
src/Illuminate/View/Compilers/Concerns/CompilesIncludes.php
@@ -40,4 +40,23 @@ protected function compileIncludeIf($expression) return "<?php if (\$__env->exists({$expression})) echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; } + + /** + * Compile the include-when statements into valid PHP. + * + * @param string $expression + * @return string + */ + protected function compileIncludeWhen($expression) + { + $expression = $this->stripParentheses($expression); + + preg_match('/ *(.*), *(.*)$/is', $expression, $matches); + + $when = trim($matches[1]); + + $arguments = trim($matches[2]); + + return "<?php if ({$when}) echo \$__env->make({$arguments}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; + } }
true
Other
laravel
framework
5fe39aa3bac01f49ffaf5d44bf03688690106dbe.json
Add includeWhen directive
tests/View/Blade/BladeIncludeWhenTest.php
@@ -0,0 +1,27 @@ +<?php + +namespace Illuminate\Tests\Blade; + +use Mockery as m; +use PHPUnit\Framework\TestCase; +use Illuminate\View\Compilers\BladeCompiler; + +class BladeIncludeWhenTest extends TestCase +{ + public function tearDown() + { + m::close(); + } + + public function testIncludeWhensAreCompiled() + { + $compiler = new BladeCompiler($this->getFiles(), __DIR__); + $this->assertEquals('<?php if (true) echo $__env->make(\'foo\', array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeWhen(true, \'foo\')')); + $this->assertEquals('<?php if (true) echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeWhen(true, name(foo))')); + } + + protected function getFiles() + { + return m::mock('Illuminate\Filesystem\Filesystem'); + } +}
true
Other
laravel
framework
2f4135d8db5ded851d1f4f611124c53b768a3c08.json
Update HasRelations::morphInstanceTo() (#18058) I changed this line so that the static method getActualClassNameForMorph can be overridden. In my case, the morph relationship is idetified by integers, so I rewrote the static method getActualClassNameForMorph.
src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
@@ -176,7 +176,7 @@ protected function morphEagerTo($name, $type, $id) protected function morphInstanceTo($target, $name, $type, $id) { $instance = $this->newRelatedInstance( - Model::getActualClassNameForMorph($target) + static::getActualClassNameForMorph($target) ); return new MorphTo(
false
Other
laravel
framework
4994f37c782672bd9d32b6d4277f9613e14d8429.json
Apply fixes from StyleCI (#18039)
src/Illuminate/Contracts/Queue/Job.php
@@ -68,7 +68,7 @@ public function maxTries(); * @return int|null */ public function timeout(); - + /** * Get the name of the queued job class. *
false
Other
laravel
framework
8eecd3fba0dcedd9e5abcded780a6eab0a86344a.json
improve the expression (#18017)
src/Illuminate/Queue/Worker.php
@@ -264,7 +264,7 @@ protected function runJob($job, $connectionName, WorkerOptions $options) } /** - * Process a given job from the queue. + * Process the given job from the queue. * * @param string $connectionName * @param \Illuminate\Contracts\Queue\Job $job
false
Other
laravel
framework
544faace7a605ab2dbf91365f4d46502194357f8.json
Fix route bidnings
src/Illuminate/Routing/RouteDependencyResolverTrait.php
@@ -31,21 +31,30 @@ protected function resolveClassMethodDependencies(array $parameters, $instance, /** * Resolve the given method's type-hinted dependencies. * - * @param array $parameters + * @param array $originalParameters * @param \ReflectionFunctionAbstract $reflector * @return array */ - public function resolveMethodDependencies(array $parameters, ReflectionFunctionAbstract $reflector) + public function resolveMethodDependencies(array $originalParameters, ReflectionFunctionAbstract $reflector) { - $originalParameters = $parameters; + $parameters = []; + + $values = array_values($originalParameters); + + $instancesCount = 0; foreach ($reflector->getParameters() as $key => $parameter) { $instance = $this->transformDependency( - $parameter, $parameters, $originalParameters + $parameter, $originalParameters ); if (! is_null($instance)) { - $this->spliceIntoParameters($parameters, $key, $instance); + $instancesCount++; + + $parameters[] = $instance; + } else { + $parameters[] = isset($values[$key - $instancesCount]) + ? $values[$key - $instancesCount] : $parameter->getDefaultValue(); } } @@ -57,10 +66,9 @@ public function resolveMethodDependencies(array $parameters, ReflectionFunctionA * * @param \ReflectionParameter $parameter * @param array $parameters - * @param array $originalParameters * @return mixed */ - protected function transformDependency(ReflectionParameter $parameter, $parameters, $originalParameters) + protected function transformDependency(ReflectionParameter $parameter, $parameters) { $class = $parameter->getClass(); @@ -85,19 +93,4 @@ protected function alreadyInParameters($class, array $parameters) return $value instanceof $class; })); } - - /** - * Splice the given value into the parameter list. - * - * @param array $parameters - * @param string $key - * @param mixed $instance - * @return void - */ - protected function spliceIntoParameters(array &$parameters, $key, $instance) - { - array_splice( - $parameters, $key, 0, [$instance] - ); - } }
true
Other
laravel
framework
544faace7a605ab2dbf91365f4d46502194357f8.json
Fix route bidnings
tests/Routing/RoutingRouteTest.php
@@ -309,6 +309,24 @@ public function testClassesCanBeInjectedIntoRoutes() unset($_SERVER['__test.route_inject']); } + public function testClassesAndVariablesCanBeInjectedIntoRoutes() + { + unset($_SERVER['__test.route_inject']); + $router = $this->getRouter(); + $router->get('foo/{var}/{bar?}/{baz?}', function (stdClass $foo, $var, $bar = 'test', Request $baz = null) { + $_SERVER['__test.route_inject'] = func_get_args(); + + return 'hello'; + }); + $this->assertEquals('hello', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent()); + $this->assertInstanceOf('stdClass', $_SERVER['__test.route_inject'][0]); + $this->assertEquals('bar', $_SERVER['__test.route_inject'][1]); + $this->assertEquals('test', $_SERVER['__test.route_inject'][2]); + $this->assertArrayHasKey(3, $_SERVER['__test.route_inject']); + $this->assertInstanceOf('Illuminate\Http\Request', $_SERVER['__test.route_inject'][3]); + unset($_SERVER['__test.route_inject']); + } + public function testOptionsResponsesAreGeneratedByDefault() { $router = $this->getRouter();
true
Other
laravel
framework
a8e8b75ea7bc77919968300410b9739e7e6076f8.json
Add replaceDimensions for validator messages * Added tests for that
src/Illuminate/Validation/Concerns/ReplacesAttributes.php
@@ -355,4 +355,25 @@ protected function replaceAfterOrEqual($message, $attribute, $rule, $parameters) { return $this->replaceBefore($message, $attribute, $rule, $parameters); } + + /** + * Replace all place-holders for the dimensions rule. + * + * @param string $message + * @param string $attribute + * @param string $rule + * @param array $parameters + * @return string + */ + protected function replaceDimensions($message, $attribute, $rule, $parameters) + { + $nesteds = $this->parseNamedParameters($parameters); + if (is_array($nesteds)) { + foreach ($nesteds as $key => $value) { + $message = str_replace(':'.$key, $value, $message); + } + } + + return $message; + } }
true
Other
laravel
framework
a8e8b75ea7bc77919968300410b9739e7e6076f8.json
Add replaceDimensions for validator messages * Added tests for that
tests/Validation/ValidationValidatorTest.php
@@ -215,6 +215,26 @@ public function testClassBasedCustomReplacers() $this->assertEquals('replaced!', $v->messages()->first('name')); } + public function testNestedAttributesAreReplacedInDimensions() + { + // Knowing that demo image.gif has width = 3 and height = 2 + $uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.gif', '', null, null, null, true); + + $trans = $this->getIlluminateArrayTranslator(); + $trans->addLines(['validation.dimensions' => ':min_width :max_height :ratio'], 'en'); + $v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:min_width=10,max_height=20,ratio=1']); + $v->messages()->setFormat(':message'); + $this->assertTrue($v->fails()); + $this->assertEquals('10 20 1', $v->messages()->first('x')); + + $trans = $this->getIlluminateArrayTranslator(); + $trans->addLines(['validation.dimensions' => ':width :height :ratio'], 'en'); + $v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:min_width=10,max_height=20,ratio=1']); + $v->messages()->setFormat(':message'); + $this->assertTrue($v->fails()); + $this->assertEquals(':width :height 1', $v->messages()->first('x')); + } + public function testAttributeNamesAreReplaced() { $trans = $this->getIlluminateArrayTranslator();
true
Other
laravel
framework
dbaf3b10f1daa483a1db840c60ec95337c9a1f6e.json
add asssertion for session errors
src/Illuminate/Foundation/Testing/TestResponse.php
@@ -428,6 +428,32 @@ public function assertSessionHasAll(array $bindings) return $this; } + /** + * Assert that the session has the given errors. + * + * @param string|array $keys + * @param mixed $format + * @return $this + */ + public function assertSessionHasErrors($keys = [], $format = null) + { + $this->assertSessionHas('errors'); + + $keys = (array) $keys; + + $errors = app('session.store')->get('errors'); + + foreach ($keys as $key => $value) { + if (is_int($key)) { + PHPUnit::assertTrue($errors->has($value), "Session missing error: $value"); + } else { + PHPUnit::assertContains($value, $errors->get($key, $format)); + } + } + + return $this; + } + /** * Assert that the session does not have a given key. *
false
Other
laravel
framework
29a181fd64a1d07e071351e61e8403bf00ea4b3c.json
Change property name in Pivot class (#17933) Make it possible to use ‘parent’ as a relation
src/Illuminate/Database/Eloquent/Relations/Pivot.php
@@ -12,7 +12,7 @@ class Pivot extends Model * * @var \Illuminate\Database\Eloquent\Model */ - protected $parent; + protected $pivotParent; /** * The name of the foreign key column. @@ -59,7 +59,7 @@ public function __construct(Model $parent, $attributes, $table, $exists = false) // We store off the parent instance so we will access the timestamp column names // for the model, since the pivot model timestamps aren't easily configurable // from the developer's point of view. We can use the parents to get these. - $this->parent = $parent; + $this->pivotParent = $parent; $this->exists = $exists; @@ -183,7 +183,7 @@ public function hasTimestampAttributes() */ public function getCreatedAtColumn() { - return $this->parent->getCreatedAtColumn(); + return $this->pivotParent->getCreatedAtColumn(); } /** @@ -193,6 +193,6 @@ public function getCreatedAtColumn() */ public function getUpdatedAtColumn() { - return $this->parent->getUpdatedAtColumn(); + return $this->pivotParent->getUpdatedAtColumn(); } }
false
Other
laravel
framework
64cf746c54417707854106df52a4f41d4ed437de.json
Fix typo in comments
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -592,7 +592,7 @@ protected function hydratePivotRelation(array $models) { // To hydrate the pivot relationship, we will just gather the pivot attributes // and create a new Pivot model, which is basically a dynamic model that we - // will set the attributes, table, and connections on so it they be used. + // will set the attributes, table, and connections on so they can be used. foreach ($models as $model) { $model->setRelation('pivot', $this->newExistingPivot( $this->migratePivotAttributes($model)
false
Other
laravel
framework
3cf02fa30ff6087ad14111c6d73e917dcb2920a6.json
Add a when method to Collection (#17917)
src/Illuminate/Support/Collection.php
@@ -308,6 +308,22 @@ public function filter(callable $callback = null) return new static(array_filter($this->items)); } + /** + * Apply the callback if the value is truthy. + * + * @param bool $value + * @param callable $callback + * @return mixed + */ + public function when($value, callable $callback) + { + if ($value) { + return $callback($this); + } + + return $this; + } + /** * Filter items by the given key value pair. *
true
Other
laravel
framework
3cf02fa30ff6087ad14111c6d73e917dcb2920a6.json
Add a when method to Collection (#17917)
tests/Support/SupportCollectionTest.php
@@ -1895,6 +1895,25 @@ public function testTap() $this->assertSame([1], $fromTap); $this->assertSame([1, 2, 3], $collection->toArray()); } + + public function testWhen() + { + $collection = new Collection(['michael', 'tom']); + + $collection->when(true, function ($collection) { + return $collection->push('adam'); + }); + + $this->assertSame(['michael', 'tom', 'adam'], $collection->toArray()); + + $collection = new Collection(['michael', 'tom']); + + $collection->when(false, function ($collection) { + return $collection->push('adam'); + }); + + $this->assertSame(['michael', 'tom'], $collection->toArray()); + } } class TestSupportCollectionHigherOrderItem
true
Other
laravel
framework
20950646e0b8108599c1f87607d030af4152992e.json
Fix zRangeByScore syntax for PhpRedis (#17912)
src/Illuminate/Redis/Connections/PhpRedisConnection.php
@@ -200,10 +200,18 @@ public function disconnect() */ public function __call($method, $parameters) { + $method = strtolower($method); + if ($method == 'eval') { return $this->proxyToEval($parameters); } + if ($method == 'zrangebyscore' || $method == 'zrevrangebyscore') { + $parameters = array_map(function ($parameter) { + return is_array($parameter) ? array_change_key_case($parameter) : $parameter; + }, $parameters); + } + return parent::__call($method, $parameters); } }
false
Other
laravel
framework
c0f425cd5838d9b00c10c51137e99a88b5f28c93.json
add $localKey to MorphToMany relation
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -40,19 +40,19 @@ class MorphToMany extends BelongsToMany * @param string $table * @param string $foreignKey * @param string $relatedKey - * @param string $localKey * @param string $parentKey + * @param string $localKey * @param string $relationName * @param bool $inverse * @return void */ - public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $relatedKey, $localKey, $parentKey, $relationName = null, $inverse = false) + public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $relatedKey, $parentKey, $localKey, $relationName = null, $inverse = false) { $this->inverse = $inverse; $this->morphType = $name.'_type'; $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass(); - parent::__construct($query, $parent, $table, $foreignKey, $relatedKey, $localKey, $parentKey, $relationName); + parent::__construct($query, $parent, $table, $foreignKey, $relatedKey, $parentKey, $localKey, $relationName); } /**
false
Other
laravel
framework
36e89bd842173b1e7aaa49a351626d6df4fe62ae.json
fix some docs
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -112,8 +112,8 @@ class BelongsToMany extends Relation * @param string $table * @param string $foreignKey * @param string $relatedKey - * @param string $localKey * @param string $parentKey + * @param string $localKey * @param string $relationName * @return void */
true
Other
laravel
framework
36e89bd842173b1e7aaa49a351626d6df4fe62ae.json
fix some docs
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -41,6 +41,7 @@ class MorphToMany extends BelongsToMany * @param string $foreignKey * @param string $relatedKey * @param string $localKey + * @param string $parentKey * @param string $relationName * @param bool $inverse * @return void
true
Other
laravel
framework
0eb18d4bf2dd65ad08a471d5ecf4fc8d1f6324c3.json
add protected property
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -34,6 +34,13 @@ class BelongsToMany extends Relation */ protected $relatedKey; + /** + * The local key of the parent model. + * + * @var string + */ + protected $localKey; + /** * The "name" of the relationship. *
false
Other
laravel
framework
7c7c3bc4be3052afe0889fe323230dfd92f81000.json
fix missing things
src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
@@ -286,6 +286,7 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey = * @param string $table * @param string $foreignKey * @param string $relatedKey + * @param string $localKey * @param string $relation * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ @@ -307,8 +308,6 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $rela $relatedKey = $relatedKey ?: $instance->getForeignKey(); - $localKey = $localKey ?: $this->getKeyName(); - // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names // are transformed to snake case from their default CamelCase also. @@ -317,7 +316,8 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $rela } return new BelongsToMany( - $instance->newQuery(), $this, $table, $foreignKey, $relatedKey, $localKey, $relation + $instance->newQuery(), $this, $table, $foreignKey, + $relatedKey, $localKey ?: $this->getKeyName(), $relation ); }
true
Other
laravel
framework
7c7c3bc4be3052afe0889fe323230dfd92f81000.json
fix missing things
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -98,16 +98,17 @@ class BelongsToMany extends Relation * @param string $table * @param string $foreignKey * @param string $relatedKey + * @param string $localKey * @param string $relationName * @return void */ public function __construct(Builder $query, Model $parent, $table, $foreignKey, $relatedKey, $localKey, $relationName = null) { $this->table = $table; + $this->localKey = $localKey; $this->relatedKey = $relatedKey; $this->foreignKey = $foreignKey; $this->relationName = $relationName; - $this->localKey = $localKey; parent::__construct($query, $parent); }
true
Other
laravel
framework
7c7c3bc4be3052afe0889fe323230dfd92f81000.json
fix missing things
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -40,6 +40,7 @@ class MorphToMany extends BelongsToMany * @param string $table * @param string $foreignKey * @param string $relatedKey + * @param string $localKey * @param string $relationName * @param bool $inverse * @return void
true
Other
laravel
framework
b900c41ecc2baafefaad3b545b51807334c52c15.json
fix MorphToMany test
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -44,13 +44,13 @@ class MorphToMany extends BelongsToMany * @param bool $inverse * @return void */ - public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $relatedKey, $relationName = null, $inverse = false) + public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $relatedKey, $localKey, $relationName = null, $inverse = false) { $this->inverse = $inverse; $this->morphType = $name.'_type'; $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass(); - parent::__construct($query, $parent, $table, $foreignKey, $relatedKey, $relationName); + parent::__construct($query, $parent, $table, $foreignKey, $relatedKey, $localKey, $relationName); } /**
true
Other
laravel
framework
b900c41ecc2baafefaad3b545b51807334c52c15.json
fix MorphToMany test
tests/Database/DatabaseEloquentMorphToManyTest.php
@@ -74,7 +74,7 @@ public function getRelation() { list($builder, $parent) = $this->getRelationArguments(); - return new MorphToMany($builder, $parent, 'taggable', 'taggables', 'taggable_id', 'tag_id'); + return new MorphToMany($builder, $parent, 'taggable', 'taggables', 'taggable_id', 'tag_id', 'id'); } public function getRelationArguments() @@ -98,7 +98,7 @@ public function getRelationArguments() $builder->shouldReceive('where')->once()->with('taggables.taggable_id', '=', 1); $builder->shouldReceive('where')->once()->with('taggables.taggable_type', get_class($parent)); - return [$builder, $parent, 'taggable', 'taggables', 'taggable_id', 'tag_id', 'relation_name', false]; + return [$builder, $parent, 'taggable', 'taggables', 'taggable_id', 'tag_id', 'id', 'relation_name', false]; } }
true
Other
laravel
framework
81053b46ff3a3ebb6571cef2d6ec7c8f7f18deea.json
fix code style
src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
@@ -307,7 +307,7 @@ public function belongsToMany($related, $table = null, $foreignKey = null, $rela $relatedKey = $relatedKey ?: $instance->getForeignKey(); - $localKey = $localKey ?: $this->getKeyName(); + $localKey = $localKey ?: $this->getKeyName(); // If no table name was provided, we can guess it by concatenating the two // models using underscores in alphabetical order. The two model names
true
Other
laravel
framework
81053b46ff3a3ebb6571cef2d6ec7c8f7f18deea.json
fix code style
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -107,7 +107,7 @@ public function __construct(Builder $query, Model $parent, $table, $foreignKey, $this->relatedKey = $relatedKey; $this->foreignKey = $foreignKey; $this->relationName = $relationName; - $this->localKey = $localKey; + $this->localKey = $localKey; parent::__construct($query, $parent); }
true
Other
laravel
framework
89b296b58b1fd8cd4a1c0e3993f091b5322caaf8.json
Handle model instance in Authorize middleware. This will help extending Middleware capabilities by giving it directly the Model to check. Implementation example : ```php <?php namespace App\Http\Middleware; use Closure; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Middleware\Authorize; class AuthorizeCommand extends Authorize { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, $ability = null, ...$models) { if ((null !== $command = $request->route('command')) && $command instanceof Model ) { return parent::handle($request, $next, 'access', $command); } return $next($request); } } ```
src/Illuminate/Auth/Middleware/Authorize.php
@@ -4,6 +4,7 @@ use Closure; use Illuminate\Contracts\Auth\Access\Gate; +use Illuminate\Database\Eloquent\Model; use Illuminate\Contracts\Auth\Factory as Auth; class Authorize @@ -70,7 +71,9 @@ protected function getGateArguments($request, $models) } return collect($models)->map(function ($model) use ($request) { - return $this->getModel($request, $model); + return $model instanceof Model + ?$model + :$this->getModel($request, $model); })->all(); }
true
Other
laravel
framework
89b296b58b1fd8cd4a1c0e3993f091b5322caaf8.json
Handle model instance in Authorize middleware. This will help extending Middleware capabilities by giving it directly the Model to check. Implementation example : ```php <?php namespace App\Http\Middleware; use Closure; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Middleware\Authorize; class AuthorizeCommand extends Authorize { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, $ability = null, ...$models) { if ((null !== $command = $request->route('command')) && $command instanceof Model ) { return parent::handle($request, $next, 'access', $command); } return $next($request); } } ```
tests/Auth/AuthorizeMiddlewareTest.php
@@ -187,6 +187,28 @@ public function testModelAuthorized() $this->assertEquals($response->content(), 'success'); } + public function testModelInstanceAsParameter() + { + $instance = m::mock(\Illuminate\Database\Eloquent\Model::class); + + $this->gate()->define('success', function ($user, $model) use ($instance) { + $this->assertSame($model, $instance); + + return true; + }); + + $request = m::mock(Request::class); + + $nextParam = null; + + $next = function ($param) use (&$nextParam) { + $nextParam = $param; + }; + + (new Authorize($this->container->make(Auth::class), $this->gate())) + ->handle($request, $next, 'success', $instance); + } + /** * Get the Gate instance from the container. *
true
Other
laravel
framework
a01bb86c9b17ebb145d3fca50e8017d3387701a5.json
Add missing method to Dispatcher contract (#17893)
src/Illuminate/Contracts/Bus/Dispatcher.php
@@ -28,4 +28,12 @@ public function dispatchNow($command, $handler = null); * @return $this */ public function pipeThrough(array $pipes); + + /** + * Retrieve the handler for a command. + * + * @param mixed $command + * @return bool|mixed + */ + public function getCommandHandler($command); }
false
Other
laravel
framework
ec4f39de207ea53f67a14e634ea492849b313c65.json
Replace double quotes with single quotes.
tests/Database/DatabaseQueryBuilderTest.php
@@ -462,8 +462,8 @@ public function testUnions() $builder = $this->getSQLiteBuilder(); $expectedSql = 'select * from (select "name" from "users" where "id" = ?) union select * from (select "name" from "users" where "id" = ?)'; - $builder->select('name')->from("users")->where('id', '=', 1); - $builder->union($this->getSQLiteBuilder()->select('name')->from("users")->where('id', '=', 2)); + $builder->select('name')->from('users')->where('id', '=', 1); + $builder->union($this->getSQLiteBuilder()->select('name')->from('users')->where('id', '=', 2)); $this->assertEquals($expectedSql, $builder->toSql()); $this->assertEquals([0 => 1, 1 => 2], $builder->getBindings()); }
false
Other
laravel
framework
96618d42fec5bd2ddd5aa21c3bef4d7d29f4efba.json
Remove empty line.
tests/Database/DatabaseQueryBuilderTest.php
@@ -466,7 +466,6 @@ public function testUnions() $builder->union($this->getSQLiteBuilder()->select('name')->from("users")->where('id', '=', 2)); $this->assertEquals($expectedSql, $builder->toSql()); $this->assertEquals([0 => 1, 1 => 2], $builder->getBindings()); - } public function testUnionAlls()
false
Other
laravel
framework
616baa33e8c2775f2896f062f8a439f8fe8b56b6.json
Remember embedded files to remove duplication
src/Illuminate/Mail/Message.php
@@ -13,6 +13,13 @@ class Message * @var \Swift_Message */ protected $swift; + + /** + * CIDs of files embedded in the message. + * + * @var array + */ + protected $embeddedFiles = []; /** * Create a new message instance. @@ -240,7 +247,15 @@ protected function createAttachmentFromData($data, $name) */ public function embed($file) { - return $this->swift->embed(Swift_Image::fromPath($file)); + if(isset($this->embeddedFiles[$file])) { + return $this->embeddedFiles[$file]; + } + + $cid = $this->swift->embed(Swift_Image::fromPath($file)); + + $this->embeddedFiles[$file] = $cid; + + return $cid; } /**
false
Other
laravel
framework
69f9c4eef64faf473683801b3659e5e4d314e7f3.json
Add tests for assertJsonFragment() (#17873)
tests/Foundation/FoundationTestResponseTest.php
@@ -26,6 +26,25 @@ public function testAssertJsonWithMixed() $response->assertJson($resource->jsonSerialize()); } + public function testAssertJsonFragment() + { + $response = new TestResponse(new JsonSerializableSingleResourceStub); + + $response->assertJsonFragment(['foo' => 'foo 0']); + + $response->assertJsonFragment(['foo' => 'foo 0', 'bar' => 'bar 0', 'foobar' => 'foobar 0']); + + $response = new TestResponse(new JsonSerializableMixedResourcesStub); + + $response->assertJsonFragment(['foo' => 'bar']); + + $response->assertJsonFragment(['foobar_foo' => 'foo']); + + $response->assertJsonFragment(['foobar' => ['foobar_foo' => 'foo', 'foobar_bar' => 'bar']]); + + $response->assertJsonFragment(['foo' => 'bar 0', 'bar' => ['foo' => 'bar 0', 'bar' => 'foo 0']]); + } + public function testAssertJsonStructure() { $response = new TestResponse(new JsonSerializableMixedResourcesStub); @@ -44,6 +63,7 @@ public function testAssertJsonStructure() // Wildcard (repeating structure) at root $response = new TestResponse(new JsonSerializableSingleResourceStub); + $response->assertJsonStructure(['*' => ['foo', 'bar', 'foobar']]); }
false
Other
laravel
framework
d298373a22f95ab5d13cfdf0cb3b3baa0d90e8f5.json
Fix getUrlRange docblock. (#17859)
src/Illuminate/Contracts/Pagination/LengthAwarePaginator.php
@@ -9,7 +9,7 @@ interface LengthAwarePaginator extends Paginator * * @param int $start * @param int $end - * @return string + * @return array */ public function getUrlRange($start, $end);
true
Other
laravel
framework
d298373a22f95ab5d13cfdf0cb3b3baa0d90e8f5.json
Fix getUrlRange docblock. (#17859)
src/Illuminate/Pagination/AbstractPaginator.php
@@ -122,7 +122,7 @@ public function previousPageUrl() * * @param int $start * @param int $end - * @return string + * @return array */ public function getUrlRange($start, $end) {
true
Other
laravel
framework
bb414d3ad37861a660173221beeea980294b9789.json
Bring the pluralization rules back
src/Illuminate/Translation/MessageSelector.php
@@ -11,9 +11,10 @@ class MessageSelector * * @param string $line * @param int $number + * @param string $locale * @return mixed */ - public function choose($line, $number) + public function choose($line, $number, $locale) { $segments = explode('|', $line); @@ -23,8 +24,13 @@ public function choose($line, $number) $segments = $this->stripConditions($segments); - return count($segments) == 1 || $number == 1 - ? $segments[0] : $segments[1]; + $pluralIndex = $this->getPluralIndex($locale, $number); + + if (count($segments) == 1 || ! isset($segments[$pluralIndex])) { + return $segments[0]; + } + + return $segments[$pluralIndex]; } /** @@ -89,4 +95,135 @@ private function stripConditions($segments) return preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part); })->all(); } + + /** + * Get the index to use for pluralization. + * + * The plural rules are derived from code of the Zend Framework (2010-09-25), which + * is subject to the new BSD license (http://framework.zend.com/license/new-bsd). + * Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * + * @param string $locale + * @param int $number + * + * @return int + */ + public function getPluralIndex($locale, $number){ + switch ($locale) { + case 'az': + case 'bo': + case 'dz': + case 'id': + case 'ja': + case 'jv': + case 'ka': + case 'km': + case 'kn': + case 'ko': + case 'ms': + case 'th': + case 'tr': + case 'vi': + case 'zh': + return 0; + break; + case 'af': + case 'bn': + case 'bg': + case 'ca': + case 'da': + case 'de': + case 'el': + case 'en': + case 'eo': + case 'es': + case 'et': + case 'eu': + case 'fa': + case 'fi': + case 'fo': + case 'fur': + case 'fy': + case 'gl': + case 'gu': + case 'ha': + case 'he': + case 'hu': + case 'is': + case 'it': + case 'ku': + case 'lb': + case 'ml': + case 'mn': + case 'mr': + case 'nah': + case 'nb': + case 'ne': + case 'nl': + case 'nn': + case 'no': + case 'om': + case 'or': + case 'pa': + case 'pap': + case 'ps': + case 'pt': + case 'so': + case 'sq': + case 'sv': + case 'sw': + case 'ta': + case 'te': + case 'tk': + case 'ur': + case 'zu': + return ($number == 1) ? 0 : 1; + case 'am': + case 'bh': + case 'fil': + case 'fr': + case 'gun': + case 'hi': + case 'hy': + case 'ln': + case 'mg': + case 'nso': + case 'xbr': + case 'ti': + case 'wa': + return (($number == 0) || ($number == 1)) ? 0 : 1; + case 'be': + case 'bs': + case 'hr': + case 'ru': + case 'sr': + case 'uk': + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); + case 'cs': + case 'sk': + return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2); + case 'ga': + return ($number == 1) ? 0 : (($number == 2) ? 1 : 2); + case 'lt': + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); + case 'sl': + return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3)); + case 'mk': + return ($number % 10 == 1) ? 0 : 1; + case 'mt': + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)); + case 'lv': + return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2); + case 'pl': + return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2); + case 'cy': + return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3)); + case 'ro': + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2); + case 'ar': + return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))); + default: + return 0; + } + } }
true
Other
laravel
framework
bb414d3ad37861a660173221beeea980294b9789.json
Bring the pluralization rules back
src/Illuminate/Translation/Translator.php
@@ -210,7 +210,7 @@ public function choice($key, $number, array $replace = [], $locale = null) $replace['count'] = $number; return $this->makeReplacements( - $this->getSelector()->choose($line, $number), $replace + $this->getSelector()->choose($line, $number, $locale), $replace ); }
true
Other
laravel
framework
bb414d3ad37861a660173221beeea980294b9789.json
Bring the pluralization rules back
tests/Translation/TranslationMessageSelectorTest.php
@@ -14,7 +14,7 @@ public function testChoose($expected, $id, $number) { $selector = new MessageSelector(); - $this->assertEquals($expected, $selector->choose($id, $number)); + $this->assertEquals($expected, $selector->choose($id, $number, 'en')); } public function chooseTestData()
true
Other
laravel
framework
bb414d3ad37861a660173221beeea980294b9789.json
Bring the pluralization rules back
tests/Translation/TranslationTranslatorTest.php
@@ -78,7 +78,7 @@ public function testChoiceMethodProperlyLoadsAndRetrievesItem() $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock(); $t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(['replace']), $this->equalTo('en'))->will($this->returnValue('line')); $t->setSelector($selector = m::mock('Illuminate\Translation\MessageSelector')); - $selector->shouldReceive('choose')->once()->with('line', 10)->andReturn('choiced'); + $selector->shouldReceive('choose')->once()->with('line', 10, 'en')->andReturn('choiced'); $t->choice('foo', 10, ['replace']); } @@ -88,7 +88,7 @@ public function testChoiceMethodProperlyCountsCollectionsAndLoadsAndRetrievesIte $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock(); $t->expects($this->exactly(2))->method('get')->with($this->equalTo('foo'), $this->equalTo(['replace']), $this->equalTo('en'))->will($this->returnValue('line')); $t->setSelector($selector = m::mock('Illuminate\Translation\MessageSelector')); - $selector->shouldReceive('choose')->twice()->with('line', 3)->andReturn('choiced'); + $selector->shouldReceive('choose')->twice()->with('line', 3, 'en')->andReturn('choiced'); $values = ['foo', 'bar', 'baz']; $t->choice('foo', $values, ['replace']);
true
Other
laravel
framework
b2d997dcfb73347670e6261f6d6cae3980aa9181.json
Bring the pluralization rules back
src/Illuminate/Translation/MessageSelector.php
@@ -11,9 +11,10 @@ class MessageSelector * * @param string $line * @param int $number + * @param string $locale * @return mixed */ - public function choose($line, $number) + public function choose($line, $number, $locale) { $segments = explode('|', $line); @@ -23,8 +24,13 @@ public function choose($line, $number) $segments = $this->stripConditions($segments); - return count($segments) == 1 || $number == 1 - ? $segments[0] : $segments[1]; + $pluralIndex = $this->getPluralIndex($locale, $number); + + if (count($segments) == 1 || ! isset($segments[$pluralIndex])) { + return $segments[0]; + } + + return $segments[$pluralIndex]; } /** @@ -89,4 +95,135 @@ private function stripConditions($segments) return preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part); })->all(); } + + /** + * Get the index to use for pluralization. + * + * The plural rules are derived from code of the Zend Framework (2010-09-25), which + * is subject to the new BSD license (http://framework.zend.com/license/new-bsd). + * Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * + * @param string $locale + * @param int $number + * + * @return int + */ + public function getPluralIndex($locale, $number){ + switch ($locale) { + case 'az': + case 'bo': + case 'dz': + case 'id': + case 'ja': + case 'jv': + case 'ka': + case 'km': + case 'kn': + case 'ko': + case 'ms': + case 'th': + case 'tr': + case 'vi': + case 'zh': + return 0; + break; + case 'af': + case 'bn': + case 'bg': + case 'ca': + case 'da': + case 'de': + case 'el': + case 'en': + case 'eo': + case 'es': + case 'et': + case 'eu': + case 'fa': + case 'fi': + case 'fo': + case 'fur': + case 'fy': + case 'gl': + case 'gu': + case 'ha': + case 'he': + case 'hu': + case 'is': + case 'it': + case 'ku': + case 'lb': + case 'ml': + case 'mn': + case 'mr': + case 'nah': + case 'nb': + case 'ne': + case 'nl': + case 'nn': + case 'no': + case 'om': + case 'or': + case 'pa': + case 'pap': + case 'ps': + case 'pt': + case 'so': + case 'sq': + case 'sv': + case 'sw': + case 'ta': + case 'te': + case 'tk': + case 'ur': + case 'zu': + return ($number == 1) ? 0 : 1; + case 'am': + case 'bh': + case 'fil': + case 'fr': + case 'gun': + case 'hi': + case 'hy': + case 'ln': + case 'mg': + case 'nso': + case 'xbr': + case 'ti': + case 'wa': + return (($number == 0) || ($number == 1)) ? 0 : 1; + case 'be': + case 'bs': + case 'hr': + case 'ru': + case 'sr': + case 'uk': + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); + case 'cs': + case 'sk': + return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2); + case 'ga': + return ($number == 1) ? 0 : (($number == 2) ? 1 : 2); + case 'lt': + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); + case 'sl': + return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3)); + case 'mk': + return ($number % 10 == 1) ? 0 : 1; + case 'mt': + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)); + case 'lv': + return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2); + case 'pl': + return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2); + case 'cy': + return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3)); + case 'ro': + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2); + case 'ar': + return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))); + default: + return 0; + } + } }
true
Other
laravel
framework
b2d997dcfb73347670e6261f6d6cae3980aa9181.json
Bring the pluralization rules back
src/Illuminate/Translation/Translator.php
@@ -210,7 +210,7 @@ public function choice($key, $number, array $replace = [], $locale = null) $replace['count'] = $number; return $this->makeReplacements( - $this->getSelector()->choose($line, $number), $replace + $this->getSelector()->choose($line, $number, $locale), $replace ); }
true
Other
laravel
framework
b2d997dcfb73347670e6261f6d6cae3980aa9181.json
Bring the pluralization rules back
tests/Translation/TranslationMessageSelectorTest.php
@@ -14,7 +14,7 @@ public function testChoose($expected, $id, $number) { $selector = new MessageSelector(); - $this->assertEquals($expected, $selector->choose($id, $number)); + $this->assertEquals($expected, $selector->choose($id, $number, 'en')); } public function chooseTestData()
true