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
b6b56c679435481faf435dd3435b118696aeefe5.json
Fix engine issueing Fix that a view (`welcomeblade.php`) would run the `BladeEngine` instead of the `PhpEngine`.
src/Illuminate/View/Factory.php
@@ -308,7 +308,7 @@ protected function getExtension($path) $extensions = array_keys($this->extensions); return Arr::first($extensions, function ($key, $value) use ($path) { - return Str::endsWith($path, $value); + return Str::endsWith($path, '.'.$value); }); }
false
Other
laravel
framework
c908ea659d8cea35f9376b428efb3188c895017a.json
return null on empty credentials
src/Illuminate/Auth/EloquentUserProvider.php
@@ -86,20 +86,22 @@ public function updateRememberToken(UserContract $user, $token) */ public function retrieveByCredentials(array $credentials) { + if (empty($credentials)) { + return; + } + // First we will add each credential element to the query as a where clause. // Then we can execute the query and, if we found a user, return it in a // Eloquent User "model" that will be utilized by the Guard instances. $query = $this->createModel()->newQuery(); - $wheres = 0; - + foreach ($credentials as $key => $value) { if (! Str::contains($key, 'password')) { $query->where($key, $value); - $wheres += 1; } } - return $wheres === 0 ? null : $query->first(); + return $query->first(); } /**
true
Other
laravel
framework
c908ea659d8cea35f9376b428efb3188c895017a.json
return null on empty credentials
tests/View/ViewBladeCompilerTest.php
@@ -577,7 +577,7 @@ public function testIncludeIfsAreCompiled() { $compiler = new BladeCompiler($this->getFiles(), __DIR__); $this->assertEquals('<?php if ($__env->exists(\'foo\')) echo $__env->make(\'foo\', array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeIf(\'foo\')')); - $this->assertEquals('<?php if ($__env->exists(name(foo)) echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeIf(name(foo))')); + $this->assertEquals('<?php if ($__env->exists(name(foo))) echo $__env->make(name(foo), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $compiler->compileString('@includeIf(name(foo))')); } public function testShowEachAreCompiled()
true
Other
laravel
framework
8b578b8ca1444653f01b415edbe43f5cb579a9aa.json
fix coding style
src/Illuminate/Database/DetectsLostConnections.php
@@ -28,7 +28,7 @@ protected function causedByLostConnection(Exception $e) 'SSL connection has been closed unexpectedly', 'Deadlock found when trying to get lock', 'Error writing data to the connection', - 'Resource deadlock avoided' + 'Resource deadlock avoided', ]); } }
false
Other
laravel
framework
76189fe7c8dafe8a1be63aab032c174db10f0ac2.json
fix variable name and docblock
src/Illuminate/Foundation/helpers.php
@@ -329,20 +329,21 @@ function dispatch($job) * Get the path to a versioned Elixir file. * * @param string $file + * @param string $buildDirectory * @return string * * @throws \InvalidArgumentException */ - function elixir($file, $customFolder = 'build') + function elixir($file, $buildDirectory = 'build') { static $manifest = null; if (is_null($manifest)) { - $manifest = json_decode(file_get_contents(public_path($customFolder.'/rev-manifest.json')), true); + $manifest = json_decode(file_get_contents(public_path($buildDirectory.'/rev-manifest.json')), true); } if (isset($manifest[$file])) { - return '/'.$customFolder.'/'.$manifest[$file]; + return '/'.$buildDirectory.'/'.$manifest[$file]; } throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
false
Other
laravel
framework
027b14da1669ea1b92781ec7d9b178dbcdd905c6.json
Seperate push from section
src/Illuminate/View/Compilers/BladeCompiler.php
@@ -833,7 +833,7 @@ protected function compileInclude($expression) */ protected function compileStack($expression) { - return "<?php echo \$__env->yieldContent{$expression}; ?>"; + return "<?php echo \$__env->yieldPushContent{$expression}; ?>"; } /** @@ -844,7 +844,7 @@ protected function compileStack($expression) */ protected function compilePush($expression) { - return "<?php \$__env->startSection{$expression}; ?>"; + return "<?php \$__env->startPush{$expression}; ?>"; } /** @@ -855,7 +855,7 @@ protected function compilePush($expression) */ protected function compileEndpush($expression) { - return '<?php $__env->appendSection(); ?>'; + return '<?php $__env->stopPush(); ?>'; } /**
true
Other
laravel
framework
027b14da1669ea1b92781ec7d9b178dbcdd905c6.json
Seperate push from section
src/Illuminate/View/Factory.php
@@ -84,13 +84,27 @@ class Factory implements FactoryContract */ protected $sections = []; + /** + * All of the finished, captured push sections. + * + * @var array + */ + protected $pushContentsStack = []; + /** * The stack of in-progress sections. * * @var array */ protected $sectionStack = []; + /** + * The stack of in-progress push sections. + * + * @var array + */ + protected $pushStack = []; + /** * The number of active rendering operations. * @@ -636,6 +650,78 @@ public function yieldContent($section, $default = '') ); } + /** + * Start injecting content into a push section. + * + * @param string $section + * @param string $content + * @return void + */ + public function startPush($section, $content = '') + { + if ($content === '') { + if (ob_start()) { + $this->pushStack[] = $section; + } + } else { + $this->extendPush($section, $content); + } + } + + /** + * Stop injecting content into a push section. + * + * @return string + * @throws \InvalidArgumentException + */ + public function stopPush() + { + if (empty($this->pushStack)) { + throw new InvalidArgumentException('Cannot end a section without first starting one.'); + } + + $last = array_pop($this->pushStack); + + $this->extendPush($last, ob_get_clean()); + + return $last; + } + + /** + * Append content to a given push section. + * + * @param string $section + * @param string $content + * @return void + */ + protected function extendPush($section, $content) + { + if (! isset($this->pushContentsStack[$section])) { + $this->pushContentsStack[$section] = []; + } + if (! isset($this->pushContentsStack[$section][$this->renderCount])) { + $this->pushContentsStack[$section][$this->renderCount] = $content; + } else { + $this->pushContentsStack[$section][$this->renderCount] .= $content; + } + } + + /** + * Get the string contents of a push section. + * + * @param string $section + * @param string $default + * @return string + */ + public function yieldPushContent($section, $default = '') + { + if (! isset($this->pushContentsStack[$section])) { + return $default; + } + + return implode(array_reverse($this->pushContentsStack[$section])); + } + /** * Flush all of the section contents. *
true
Other
laravel
framework
f4fd485846df1e75435c8097499c2266ba356cd0.json
remove old method
src/Illuminate/Foundation/Application.php
@@ -1104,20 +1104,6 @@ public function flush() $this->loadedProviders = []; } - /** - * Get the used kernel object. - * - * @return \Illuminate\Contracts\Console\Kernel|\Illuminate\Contracts\Http\Kernel - */ - protected function getKernel() - { - $kernelContract = $this->runningInConsole() - ? 'Illuminate\Contracts\Console\Kernel' - : 'Illuminate\Contracts\Http\Kernel'; - - return $this->make($kernelContract); - } - /** * Get the application namespace. *
false
Other
laravel
framework
6a09db676e53f95f07c7ff252dd1842fea053fdc.json
add empty lines
src/Illuminate/Filesystem/Filesystem.php
@@ -38,6 +38,7 @@ public function get($path, $lock = false) if ($lock) { return $this->sharedGet($path, $lock); } + return file_get_contents($path); } @@ -62,6 +63,7 @@ public function sharedGet($path) } fclose($handle); } + return $contents; }
false
Other
laravel
framework
0b3bc1b6202c4baefd7c29f6a27948192a7cdbd3.json
Add shared locks to Filesystem and Cache/FileStore
src/Illuminate/Cache/FileStore.php
@@ -63,7 +63,7 @@ protected function getPayload($key) // just return null. Otherwise, we'll get the contents of the file and get // the expiration UNIX timestamps from the start of the file's contents. try { - $expire = substr($contents = $this->files->get($path), 0, 10); + $expire = substr($contents = $this->files->get($path, true), 0, 10); } catch (Exception $e) { return ['data' => null, 'time' => null]; } @@ -101,7 +101,7 @@ public function put($key, $value, $minutes) $this->createCacheDirectory($path = $this->path($key)); - $this->files->put($path, $value); + $this->files->put($path, $value, true); } /**
true
Other
laravel
framework
0b3bc1b6202c4baefd7c29f6a27948192a7cdbd3.json
Add shared locks to Filesystem and Cache/FileStore
src/Illuminate/Filesystem/Filesystem.php
@@ -27,19 +27,44 @@ public function exists($path) * Get the contents of a file. * * @param string $path + * @param bool $lock * @return string * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ - public function get($path) + public function get($path, $lock = false) { if ($this->isFile($path)) { + if ($lock) { + return $this->sharedGet($path, $lock); + } return file_get_contents($path); } throw new FileNotFoundException("File does not exist at path {$path}"); } + /** + * Get contents of a file with shared access + * + * @param string $path + * @return string + */ + public function sharedGet($path) + { + $contents = ''; + $handle = fopen($path, 'r'); + if ($handle) { + if (flock($handle, LOCK_SH)) { + while (!feof($handle)) { + $contents .= fread($handle, 1048576); + } + } + fclose($handle); + } + return $contents; + } + /** * Get the returned value of a file. *
true
Other
laravel
framework
0b3bc1b6202c4baefd7c29f6a27948192a7cdbd3.json
Add shared locks to Filesystem and Cache/FileStore
tests/Filesystem/FilesystemTest.php
@@ -289,4 +289,33 @@ public function testMakeDirectory() $this->assertFileExists(__DIR__.'/foo'); @rmdir(__DIR__.'/foo'); } + + public function testSharedGet() + { + $content = ''; + for ($i = 0; $i < 1000000; ++$i) { + $content .= $i; + } + $result = 1; + + for ($i = 1; $i <= 20; ++$i) { + $pid = pcntl_fork(); + + if (!$pid) { + $files = new Filesystem; + $files->put(__DIR__.'/file.txt', $content, true); + $read = $files->get(__DIR__.'/file.txt', true); + + exit(($read === $content) ? 1 : 0); + } + } + + while (pcntl_waitpid(0, $status) != -1) { + $status = pcntl_wexitstatus($status); + $result *= $status; + } + + $this->assertTrue($result === 1); + @unlink(__DIR__.'/file.txt'); + } }
true
Other
laravel
framework
638e32ab500150b36956bc9942c5c9719883071d.json
Add `failed()` on InteractsWithQueue. Allow to failed a job when using InteractsWithQueue instead of just deleting the job. Signed-off-by: crynobone <crynobone@gmail.com>
src/Illuminate/Queue/InteractsWithQueue.php
@@ -13,6 +13,16 @@ trait InteractsWithQueue */ protected $job; + /** + * Get the number of times the job has been attempted. + * + * @return int + */ + public function attempts() + { + return $this->job ? $this->job->attempts() : 1; + } + /** * Delete the job from the queue. * @@ -26,26 +36,28 @@ public function delete() } /** - * Release the job back into the queue. + * Fail the job from the queue. * - * @param int $delay * @return void */ - public function release($delay = 0) + public function failed() { if ($this->job) { - return $this->job->release($delay); + return $this->job->failed(); } } /** - * Get the number of times the job has been attempted. + * Release the job back into the queue. * - * @return int + * @param int $delay + * @return void */ - public function attempts() + public function release($delay = 0) { - return $this->job ? $this->job->attempts() : 1; + if ($this->job) { + return $this->job->release($delay); + } } /**
false
Other
laravel
framework
f3d8d99f585c2e9470974938afdbf47f9153d882.json
move method. formatting.
src/Illuminate/Support/Collection.php
@@ -542,6 +542,17 @@ public function merge($items) return new static(array_merge($this->items, $this->getArrayableItems($items))); } + /** + * Create a collection by using this collection for keys and another for its values. + * + * @param mixed $values + * @return static + */ + public function combine($values) + { + return new static(array_combine($this->all(), $this->getArrayableItems($values))); + } + /** * Get the min value of a given key. * @@ -1114,20 +1125,6 @@ public function offsetUnset($key) unset($this->items[$key]); } - /** - * Combines the collection as keys together with items as values. - * - * e.g. new Collection([1, 2, 3])->combine([4, 5, 6]); - * => [1=>4, 2=>5, 3=>6] - * - * @param mixed $items - * @return static - */ - public function combine($items) - { - return new static(array_combine($this->all(), $this->getArrayableItems($items))); - } - /** * Convert the collection to its string representation. *
false
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
src/Illuminate/Auth/SessionGuard.php
@@ -734,7 +734,7 @@ public function getLastAttempted() */ public function getName() { - return 'login_'.$this->name.'_'.sha1(get_class($this)); + return 'login_'.$this->name.'_'.sha1(static::class); } /** @@ -744,7 +744,7 @@ public function getName() */ public function getRecallerName() { - return 'remember_'.$this->name.'_'.sha1(get_class($this)); + return 'remember_'.$this->name.'_'.sha1(static::class); } /**
true
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
src/Illuminate/Database/Eloquent/Model.php
@@ -288,7 +288,7 @@ public function __construct(array $attributes = []) */ protected function bootIfNotBooted() { - $class = get_class($this); + $class = static::class; if (! isset(static::$booted[$class])) { static::$booted[$class] = true; @@ -318,9 +318,9 @@ protected static function boot() */ protected static function bootTraits() { - foreach (class_uses_recursive(get_called_class()) as $trait) { - if (method_exists(get_called_class(), $method = 'boot'.class_basename($trait))) { - forward_static_call([get_called_class(), $method]); + foreach (class_uses_recursive(static::class) as $trait) { + if (method_exists(static::class, $method = 'boot'.class_basename($trait))) { + forward_static_call([static::class, $method]); } } } @@ -348,15 +348,15 @@ public static function clearBootedModels() public static function addGlobalScope($scope, Closure $implementation = null) { if (is_string($scope) && $implementation !== null) { - return static::$globalScopes[get_called_class()][$scope] = $implementation; + return static::$globalScopes[static::class][$scope] = $implementation; } if ($scope instanceof Closure) { - return static::$globalScopes[get_called_class()][spl_object_hash($scope)] = $scope; + return static::$globalScopes[static::class][spl_object_hash($scope)] = $scope; } if ($scope instanceof Scope) { - return static::$globalScopes[get_called_class()][get_class($scope)] = $scope; + return static::$globalScopes[static::class][get_class($scope)] = $scope; } throw new InvalidArgumentException('Global scope must be an instance of Closure or Scope.'); @@ -381,7 +381,7 @@ public static function hasGlobalScope($scope) */ public static function getGlobalScope($scope) { - $modelScopes = Arr::get(static::$globalScopes, get_called_class(), []); + $modelScopes = Arr::get(static::$globalScopes, static::class, []); if (is_string($scope)) { return isset($modelScopes[$scope]) ? $modelScopes[$scope] : null; @@ -399,7 +399,7 @@ public static function getGlobalScope($scope) */ public function getGlobalScopes() { - return Arr::get(static::$globalScopes, get_class($this), []); + return Arr::get(static::$globalScopes, static::class, []); } /** @@ -1266,7 +1266,7 @@ public static function flushEventListeners() $instance = new static; foreach ($instance->getObservableEvents() as $event) { - static::$dispatcher->forget("eloquent.{$event}: ".get_called_class()); + static::$dispatcher->forget("eloquent.{$event}: ".static::class); } } @@ -1281,7 +1281,7 @@ public static function flushEventListeners() protected static function registerModelEvent($event, $callback, $priority = 0) { if (isset(static::$dispatcher)) { - $name = get_called_class(); + $name = static::class; static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback, $priority); } @@ -1672,7 +1672,7 @@ protected function fireModelEvent($event, $halt = true) // We will append the names of the class to the event to distinguish it from // other model events that are fired, allowing us to listen on each model // event set individually instead of catching event for all the models. - $event = "eloquent.{$event}: ".get_class($this); + $event = "eloquent.{$event}: ".static::class; $method = $halt ? 'until' : 'fire'; @@ -2038,7 +2038,7 @@ public function getMorphClass() { $morphMap = Relation::morphMap(); - $class = get_class($this); + $class = static::class; if (! empty($morphMap) && in_array($class, $morphMap)) { return array_search($class, $morphMap, true); @@ -3349,7 +3349,7 @@ public static function unsetEventDispatcher() */ public function getMutatedAttributes() { - $class = get_class($this); + $class = static::class; if (! isset(static::$mutatorCache[$class])) { static::cacheMutatedAttributes($class);
true
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
src/Illuminate/Database/Query/Builder.php
@@ -2156,7 +2156,7 @@ public function __call($method, $parameters) return $this->dynamicWhere($method, $parameters); } - $className = get_class($this); + $className = static::class; throw new BadMethodCallException("Call to undefined method {$className}::{$method}()"); }
true
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
@@ -206,7 +206,7 @@ public function loginUsername() protected function isUsingThrottlesLoginsTrait() { return in_array( - ThrottlesLogins::class, class_uses_recursive(get_class($this)) + ThrottlesLogins::class, class_uses_recursive(static::class) ); }
true
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
src/Illuminate/Foundation/Testing/TestCase.php
@@ -92,7 +92,7 @@ protected function refreshApplication() */ protected function setUpTraits() { - $uses = array_flip(class_uses_recursive(get_class($this))); + $uses = array_flip(class_uses_recursive(static::class)); if (isset($uses[DatabaseTransactions::class])) { $this->beginDatabaseTransaction();
true
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
src/Illuminate/Support/ServiceProvider.php
@@ -104,7 +104,7 @@ protected function loadTranslationsFrom($path, $namespace) */ protected function publishes(array $paths, $group = null) { - $class = get_class($this); + $class = static::class; if (! array_key_exists($class, static::$publishes)) { static::$publishes[$class] = [];
true
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
src/Illuminate/Support/Traits/Macroable.php
@@ -50,7 +50,7 @@ public static function __callStatic($method, $parameters) { if (static::hasMacro($method)) { if (static::$macros[$method] instanceof Closure) { - return call_user_func_array(Closure::bind(static::$macros[$method], null, get_called_class()), $parameters); + return call_user_func_array(Closure::bind(static::$macros[$method], null, static::class), $parameters); } else { return call_user_func_array(static::$macros[$method], $parameters); } @@ -72,7 +72,7 @@ public function __call($method, $parameters) { if (static::hasMacro($method)) { if (static::$macros[$method] instanceof Closure) { - return call_user_func_array(static::$macros[$method]->bindTo($this, get_class($this)), $parameters); + return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters); } else { return call_user_func_array(static::$macros[$method], $parameters); }
true
Other
laravel
framework
e8c0d702acf20f486fc973ddd4070c5da9a65a7c.json
Make use of static::class
tests/Database/DatabaseEloquentModelTest.php
@@ -1467,12 +1467,12 @@ class EloquentModelBootingTestStub extends Model { public static function unboot() { - unset(static::$booted[get_called_class()]); + unset(static::$booted[static::class]); } public static function isBooted() { - return array_key_exists(get_called_class(), static::$booted); + return array_key_exists(static::class, static::$booted); } }
true
Other
laravel
framework
1c88528b0a855b0ab4e7777aea4aa0ee838468c2.json
change method order
src/Illuminate/Foundation/Application.php
@@ -305,6 +305,16 @@ public function basePath() return $this->basePath; } + /** + * Get the path to the bootstrap directory. + * + * @return string + */ + public function bootstrapPath() + { + return $this->basePath.DIRECTORY_SEPARATOR.'bootstrap'; + } + /** * Get the path to the application configuration files. * @@ -385,16 +395,6 @@ public function useStoragePath($path) return $this; } - /** - * Get the path to the bootstrap directory. - * - * @return string - */ - public function bootstrapPath() - { - return $this->basePath.DIRECTORY_SEPARATOR.'bootstrap'; - } - /** * Get the path to the environment file directory. *
false
Other
laravel
framework
ddb937e78959e365e56c4cf5933f066511de0e83.json
Prefer dist installs instead of clones
.travis.yml
@@ -21,8 +21,8 @@ matrix: sudo: false install: - - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-source; fi - - if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-stable; fi - - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-lowest --prefer-stable; fi + - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist; fi + - if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable; fi + - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi script: vendor/bin/phpunit
false
Other
laravel
framework
af0523ee848d055a0c991ddb28bc4677b0b5f7fe.json
fix method order
src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php
@@ -295,6 +295,88 @@ protected function hasSource($text) return preg_match("/$pattern/i", $this->html()); } + /** + * Assert that an element is present on the page. + * + * @param string $selector + * @param array $attributes + * @return void + */ + public function seeElement($selector, array $attributes = []) + { + if (! $this->hasElement($selector, $attributes)) { + $element = "[$selector]".(empty($attributes) ? '' : ' with attributes '.json_encode($attributes)); + + $this->failPageInspection("Couldn't find $element on the page"); + } + } + + /** + * Assert that an element is not present on the page. + * + * @param string $selector + * @param array $attributes + * @return void + */ + public function dontSeeElement($selector, array $attributes = []) + { + if ($this->hasElement($selector, $attributes)) { + $element = "[$selector]".(empty($attributes) ? '' : ' with attributes '.json_encode($attributes)); + + $this->failPageInspection("$element was found on the page"); + } + } + + /** + * Determine if the given selector is present on the page. + * + * @param string $selector + * @param array $attributes + * @return bool + */ + protected function hasElement($selector, array $attributes = []) + { + $elements = $this->crawler()->filter($selector); + + if ($elements->count() == 0) { + return false; + } + + if (empty($attributes)) { + return true; + } + + $elements = $elements->reduce(function ($element) use ($attributes) { + return $this->hasAttributes($element, $attributes); + }); + + return $elements->count() > 0; + } + + /** + * Determines if the given element has the given attributes. + * + * @param Crawler $element + * @param array $attributes + * @return bool + */ + protected function hasAttributes(Crawler $element, array $attributes = []) + { + foreach ($attributes as $name => $value) { + if (is_numeric($name)) { + if ($element->attr($value) === null) { + return false; + } + } else { + if ($element->attr($name) != $value) { + return false; + } + } + } + + return true; + } + /** * Assert that a given string is seen on the current text. * @@ -727,86 +809,6 @@ protected function isChecked($selector) return $checkbox->attr('checked') !== null; } - /** - * Assert that an $element is present on the page. - * - * @param string $selector - * @param array $attributes - */ - public function seeElement($selector, array $attributes = []) - { - if (! $this->hasElement($selector, $attributes)) { - $element = "[$selector]".(empty($attributes) ? '' : ' with attributes '.json_encode($attributes)); - $this->failPageInspection("Couldn't find $element on the page"); - } - } - - /** - * Assert that an $element is not present on the page. - * - * @param string $selector - * @param array $attributes - */ - public function dontSeeElement($selector, array $attributes = []) - { - if ($this->hasElement($selector, $attributes)) { - $element = "[$selector]".(empty($attributes) ? '' : ' with attributes '.json_encode($attributes)); - $this->failPageInspection("$element was found on the page"); - } - } - - /** - * Return true if the element is present on the page, false otherwise. - * - * @param string $selector - * @param array $attributes - * @return bool - */ - protected function hasElement($selector, array $attributes = []) - { - $elements = $this->crawler()->filter($selector); - - if ($elements->count() == 0) { - return false; - } - - if (empty($attributes)) { - return true; - } - - $elements = $elements->reduce(function ($element) use ($attributes) { - return $this->hasAttributes($element, $attributes); - }); - - return $elements->count() > 0; - } - - /** - * Return true if the given element has the following attributes, false otherwise. - * This method can check if the attribute is present, and it also has the given - * value. Example: ['placeholder' => 'type here', 'required', 'value' => 1]. - * - * @param Crawler $element - * @param array $attributes - * @return bool - */ - protected function hasAttributes(Crawler $element, array $attributes = []) - { - foreach ($attributes as $name => $value) { - if (is_numeric($name)) { - if ($element->attr($value) === null) { - return false; - } - } else { - if ($element->attr($name) != $value) { - return false; - } - } - } - - return true; - } - /** * Click a link with the given body, name, or ID attribute. *
false
Other
laravel
framework
e226fed6ce59e7dc19ea334dff75107364ebda77.json
fix setting order.
src/Illuminate/Queue/Events/JobExceptionOccurred.php
@@ -45,7 +45,7 @@ public function __construct($connectionName, $job, $data, $exception) { $this->job = $job; $this->data = $data; - $this->connectionName = $connectionName; $this->exception = $exception; + $this->connectionName = $connectionName; } }
false
Other
laravel
framework
466e0e1cd026fa456b189d45975ae7c7adf3e53f.json
Use getters instead of hardcoded values
src/Illuminate/Foundation/Console/KeyGenerateCommand.php
@@ -37,7 +37,7 @@ public function fire() return $this->line('<comment>'.$key.'</comment>'); } - $path = base_path('.env'); + $path = $app->environmentPath().'/'.$app->environmentFile(); if (file_exists($path)) { $content = str_replace('APP_KEY='.$app['config']['app.key'], 'APP_KEY='.$key, file_get_contents($path));
false
Other
laravel
framework
17d6293ba52093ff71f464da7785206dde148158.json
Add isLocale method
src/Illuminate/Foundation/Application.php
@@ -1020,6 +1020,17 @@ public function setLocale($locale) $this['events']->fire('locale.changed', [$locale]); } + /** + * Determine if application locale equals the given locale. + * + * @param string $locale + * @return bool + */ + public function isLocale($locale) + { + return $this->getLocale() == $locale; + } + /** * Register the core class aliases in the container. *
false
Other
laravel
framework
efafba186a2787ad0642d4ff27cf618dc2191e10.json
Remove return since this is a void method.
src/Illuminate/Database/Schema/Blueprint.php
@@ -779,7 +779,7 @@ public function timestampTz($column) */ public function nullableTimestamps() { - return $this->timestamps(); + $this->timestamps(); } /**
false
Other
laravel
framework
f68ea56a3f8e44e37ea8740c3fb9bf691d12ff51.json
Add method Application::bootstrapPath()
src/Illuminate/Foundation/Application.php
@@ -282,6 +282,7 @@ protected function bindPathsInContainer() $this->instance('path.public', $this->publicPath()); $this->instance('path.storage', $this->storagePath()); $this->instance('path.database', $this->databasePath()); + $this->instance('path.bootstrap', $this->bootstrapPath()); } /** @@ -384,6 +385,16 @@ public function useStoragePath($path) return $this; } + /** + * Get the path to the bootstrap directory. + * + * @return string + */ + public function bootstrapPath() + { + return $this->basePath.DIRECTORY_SEPARATOR.'bootstrap'; + } + /** * Get the path to the environment file directory. * @@ -812,7 +823,7 @@ public function configurationIsCached() */ public function getCachedConfigPath() { - return $this->basePath().'/bootstrap/cache/config.php'; + return $this->bootstrapPath().'/cache/config.php'; } /** @@ -832,7 +843,7 @@ public function routesAreCached() */ public function getCachedRoutesPath() { - return $this->basePath().'/bootstrap/cache/routes.php'; + return $this->bootstrapPath().'/cache/routes.php'; } /** @@ -842,7 +853,7 @@ public function getCachedRoutesPath() */ public function getCachedCompilePath() { - return $this->basePath().'/bootstrap/cache/compiled.php'; + return $this->bootstrapPath().'/cache/compiled.php'; } /** @@ -852,7 +863,7 @@ public function getCachedCompilePath() */ public function getCachedServicesPath() { - return $this->basePath().'/bootstrap/cache/services.php'; + return $this->bootstrapPath().'/cache/services.php'; } /**
true
Other
laravel
framework
f68ea56a3f8e44e37ea8740c3fb9bf691d12ff51.json
Add method Application::bootstrapPath()
src/Illuminate/Foundation/Console/AppNameCommand.php
@@ -247,7 +247,7 @@ protected function replaceIn($path, $search, $replace) */ protected function getBootstrapPath() { - return $this->laravel->basePath().'/bootstrap/app.php'; + return $this->laravel->bootstrapPath().'/app.php'; } /**
true
Other
laravel
framework
f68ea56a3f8e44e37ea8740c3fb9bf691d12ff51.json
Add method Application::bootstrapPath()
src/Illuminate/Foundation/Console/ConfigCacheCommand.php
@@ -66,7 +66,7 @@ public function fire() */ protected function getFreshConfiguration() { - $app = require $this->laravel->basePath().'/bootstrap/app.php'; + $app = require $this->laravel->bootstrapPath().'/app.php'; $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
true
Other
laravel
framework
f68ea56a3f8e44e37ea8740c3fb9bf691d12ff51.json
Add method Application::bootstrapPath()
src/Illuminate/Foundation/Console/IlluminateCaster.php
@@ -30,6 +30,7 @@ class IlluminateCaster 'langPath', 'publicPath', 'storagePath', + 'bootstrapPath', ]; /**
true
Other
laravel
framework
f68ea56a3f8e44e37ea8740c3fb9bf691d12ff51.json
Add method Application::bootstrapPath()
src/Illuminate/Foundation/Console/RouteCacheCommand.php
@@ -75,7 +75,7 @@ public function fire() */ protected function getFreshApplicationRoutes() { - $app = require $this->laravel->basePath().'/bootstrap/app.php'; + $app = require $this->laravel->bootstrapPath().'/app.php'; $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
true
Other
laravel
framework
d3e81bdb525c3c1dc8f9683eb537ad85f0f6cc21.json
Correct docblock @return types
src/Illuminate/Foundation/Application.php
@@ -434,7 +434,7 @@ public function environmentFile() * Get or check the current application environment. * * @param mixed - * @return string + * @return string|bool */ public function environment() {
true
Other
laravel
framework
d3e81bdb525c3c1dc8f9683eb537ad85f0f6cc21.json
Correct docblock @return types
src/Illuminate/Queue/Queue.php
@@ -140,7 +140,7 @@ protected function prepareQueueableEntity($value) * * @param \Closure $job * @param mixed $data - * @return string + * @return array */ protected function createClosurePayload($job, $data) {
true
Other
laravel
framework
a82df4e4b88eb548e899bc73bd7270d4301c59d9.json
extract files from json data in test helper.
src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
@@ -7,6 +7,7 @@ use Illuminate\Http\Request; use Illuminate\Contracts\View\View; use PHPUnit_Framework_Assert as PHPUnit; +use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile; trait MakesHttpRequests { @@ -56,6 +57,16 @@ public function withoutMiddleware() */ public function json($method, $uri, array $data = [], array $headers = []) { + $files = []; + + foreach ($data as $key => $value) { + if ($value instanceof SymfonyUploadedFile) { + $files[$key] = $value; + + unset($data[$key]); + } + } + $content = json_encode($data); $headers = array_merge([ @@ -65,7 +76,7 @@ public function json($method, $uri, array $data = [], array $headers = []) ], $headers); $this->call( - $method, $uri, [], [], [], $this->transformHeadersToServerVars($headers), $content + $method, $uri, [], [], $files, $this->transformHeadersToServerVars($headers), $content ); return $this;
false
Other
laravel
framework
57787cbc3aa853701b42bf9a5d9017b4e13ac823.json
fix boolean check
src/Illuminate/Database/Connectors/SqlServerConnector.php
@@ -94,7 +94,7 @@ protected function getSqlSrvDsn(array $config) $arguments['ApplicationIntent'] = 'ReadOnly'; } - if (isset($config['pooling']) && $config['pooling'] == false) { + if (isset($config['pooling']) && $config['pooling'] === false) { $arguments['ConnectionPooling'] = '0'; }
false
Other
laravel
framework
73eddfa09c4a7d238e29d2e74692b8455fc1ceb7.json
Add tests for data_get with ArrayAccess object
tests/Support/SupportHelpersTest.php
@@ -356,6 +356,9 @@ public function testDataGetWithNestedArrays() $this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($array, '*.name')); $this->assertEquals(['taylorotwell@gmail.com', null, null], data_get($array, '*.email', 'irrelevant')); + $arrayAccess = new SupportTestArrayAccess($array); + $this->assertEquals([], data_get($arrayAccess, '*.name')); + $array = [ 'users' => [ ['first' => 'taylor', 'last' => 'otwell', 'email' => 'taylorotwell@gmail.com'], @@ -369,6 +372,9 @@ public function testDataGetWithNestedArrays() $this->assertEquals(['taylorotwell@gmail.com', null, null], data_get($array, 'users.*.email', 'irrelevant')); $this->assertEquals('not found', data_get($array, 'posts.*.date', 'not found')); $this->assertNull(data_get($array, 'posts.*.date')); + + $arrayAccess = new SupportTestArrayAccess($array); + $this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($arrayAccess, 'users.*.first')); } public function testDataGetWithDoubleNestedArraysCollapsesResult()
false
Other
laravel
framework
aceef36ebcc2e1e3bd9f10f628cf0f8ce4537d26.json
Add tests for data_get with null values
tests/Support/SupportHelpersTest.php
@@ -325,22 +325,24 @@ public function testDataGet() { $object = (object) ['users' => ['name' => ['Taylor', 'Otwell']]]; $array = [(object) ['users' => [(object) ['name' => 'Taylor']]]]; - $dottedArray = ['users' => ['first.name' => 'Taylor']]; - $arrayAccess = new SupportTestArrayAccess(['price' => 56, 'user' => new SupportTestArrayAccess(['name' => 'John'])]); + $dottedArray = ['users' => ['first.name' => 'Taylor', 'middle.name' => null]]; + $arrayAccess = new SupportTestArrayAccess(['price' => 56, 'user' => new SupportTestArrayAccess(['name' => 'John']), 'email' => null]); $this->assertEquals('Taylor', data_get($object, 'users.name.0')); $this->assertEquals('Taylor', data_get($array, '0.users.0.name')); $this->assertNull(data_get($array, '0.users.3')); $this->assertEquals('Not found', data_get($array, '0.users.3', 'Not found')); $this->assertEquals('Not found', data_get($array, '0.users.3', function () { return 'Not found'; })); $this->assertEquals('Taylor', data_get($dottedArray, ['users', 'first.name'])); + $this->assertNull(data_get($dottedArray, ['users', 'middle.name'])); $this->assertEquals('Not found', data_get($dottedArray, ['users', 'last.name'], 'Not found')); $this->assertEquals(56, data_get($arrayAccess, 'price')); $this->assertEquals('John', data_get($arrayAccess, 'user.name')); $this->assertEquals('void', data_get($arrayAccess, 'foo', 'void')); $this->assertEquals('void', data_get($arrayAccess, 'user.foo', 'void')); $this->assertNull(data_get($arrayAccess, 'foo')); $this->assertNull(data_get($arrayAccess, 'user.foo')); + $this->assertNull(data_get($arrayAccess, 'email', 'Not found')); } public function testDataGetWithNestedArrays() @@ -687,7 +689,7 @@ public function __construct($attributes = []) public function offsetExists($offset) { - return isset($this->attributes[$offset]); + return array_key_exists($offset, $this->attributes); } public function offsetGet($offset)
false
Other
laravel
framework
c6a84451d6771cea7d528e4303319c4c299105a7.json
Simplify code in data_get()
src/Illuminate/Support/helpers.php
@@ -421,17 +421,9 @@ function data_get($target, $key, $default = null) return in_array('*', $key) ? Arr::collapse($result) : $result; } - if (Arr::accessible($target)) { - if (! Arr::exists($target, $segment)) { - return value($default); - } - + if (Arr::accessible($target) && Arr::exists($target, $segment)) { $target = $target[$segment]; - } elseif (is_object($target)) { - if (! isset($target->{$segment})) { - return value($default); - } - + } elseif (is_object($target) && isset($target->{$segment})) { $target = $target->{$segment}; } else { return value($default);
false
Other
laravel
framework
cd2b514f818efedd32fb9f89bcd463e2ed8d4a46.json
Remove unneeded test in Arr::has This test changes nothing, so remove it for simplification and consistency with code of Arr::get
src/Illuminate/Support/Arr.php
@@ -288,7 +288,7 @@ public static function get($array, $key, $default = null) */ public static function has($array, $key) { - if (empty($array) || is_null($key)) { + if (is_null($key)) { return false; }
false
Other
laravel
framework
9b464ea677b583752b32ba52dada2a31db8522f6.json
Fix coding style
src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php
@@ -649,6 +649,7 @@ protected function getSelectedValue($selector) if ($element == 'input') { $value = $this->getCheckedValueFromRadioGroup($field); + return $value ? [$value] : []; }
false
Other
laravel
framework
41aec8abcc86e1bee4d72c3bb86173368458df11.json
Make use of Arr::exists in Arr::has/get Unify codebase and fixes minor discrepancies with "key.with.dots + null value"
src/Illuminate/Support/Arr.php
@@ -264,7 +264,7 @@ public static function get($array, $key, $default = null) return $array; } - if (isset($array[$key])) { + if (static::exists($array, $key)) { return $array[$key]; } @@ -292,7 +292,7 @@ public static function has($array, $key) return false; } - if (array_key_exists($key, $array)) { + if (static::exists($array, $key)) { return true; }
false
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/Database/Eloquent/Collection.php
@@ -20,7 +20,7 @@ public function find($key, $default = null) $key = $key->getKey(); } - return Arr::first($this->items, function ($itemKey, $model) use ($key) { + return Arr::first($this->items, function ($model) use ($key) { return $model->getKey() == $key; }, $default);
true
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/Database/Eloquent/Model.php
@@ -387,7 +387,7 @@ public static function getGlobalScope($scope) return isset($modelScopes[$scope]) ? $modelScopes[$scope] : null; } - return Arr::first($modelScopes, function ($key, $value) use ($scope) { + return Arr::first($modelScopes, function ($value) use ($scope) { return $scope instanceof $value; }); } @@ -1023,7 +1023,7 @@ protected function getBelongsToManyCaller() { $self = __FUNCTION__; - $caller = Arr::first(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), function ($key, $trace) use ($self) { + $caller = Arr::first(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), function ($trace) use ($self) { $caller = $trace['function']; return ! in_array($caller, Model::$manyMethods) && $caller != $self;
true
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/Foundation/Application.php
@@ -559,7 +559,7 @@ public function getProvider($provider) { $name = is_string($provider) ? $provider : get_class($provider); - return Arr::first($this->serviceProviders, function ($key, $value) use ($name) { + return Arr::first($this->serviceProviders, function ($value) use ($name) { return $value instanceof $name; }); }
true
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/Foundation/EnvironmentDetector.php
@@ -62,8 +62,8 @@ protected function detectConsoleEnvironment(Closure $callback, array $args) */ protected function getEnvironmentArgument(array $args) { - return Arr::first($args, function ($k, $v) { - return Str::startsWith($v, '--env'); + return Arr::first($args, function ($value) { + return Str::startsWith($value, '--env'); }); } }
true
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/Routing/Route.php
@@ -567,7 +567,7 @@ protected function parseAction($action) */ protected function findCallable(array $action) { - return Arr::first($action, function ($key, $value) { + return Arr::first($action, function ($value, $key) { return is_callable($value) && is_numeric($key); }); }
true
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/Routing/RouteCollection.php
@@ -229,7 +229,7 @@ protected function methodNotAllowed(array $others) */ protected function check(array $routes, $request, $includingMethod = true) { - return Arr::first($routes, function ($key, $value) use ($request, $includingMethod) { + return Arr::first($routes, function ($value) use ($request, $includingMethod) { return $value->matches($request, $includingMethod); }); }
true
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/Routing/RouteDependencyResolverTrait.php
@@ -95,7 +95,7 @@ protected function transformDependency(ReflectionParameter $parameter, $paramete */ protected function alreadyInParameters($class, array $parameters) { - return ! is_null(Arr::first($parameters, function ($key, $value) use ($class) { + return ! is_null(Arr::first($parameters, function ($value) use ($class) { return $value instanceof $class; })); }
true
Other
laravel
framework
41b4dd009463bd26c8322857340925692bb83301.json
Update all uses of first()
src/Illuminate/View/Factory.php
@@ -307,7 +307,7 @@ protected function getExtension($path) { $extensions = array_keys($this->extensions); - return Arr::first($extensions, function ($key, $value) use ($path) { + return Arr::first($extensions, function ($value) use ($path) { return Str::endsWith($path, $value); }); }
true
Other
laravel
framework
1349d70b659732c4592bef8901312a2840cef536.json
rename some methods.
src/Illuminate/Validation/Validator.php
@@ -1167,10 +1167,10 @@ protected function validateNotIn($attribute, $value, $parameters) */ protected function validateDistinct($attribute, $value, $parameters) { - $rawAttribute = $this->getRawAttribute($attribute); + $attributeName = $this->getPrimaryAttribute($attribute); - $data = Arr::where(Arr::dot($this->data), function ($key) use ($attribute, $rawAttribute) { - return $key != $attribute && Str::is($rawAttribute, $key); + $data = Arr::where(Arr::dot($this->data), function ($key) use ($attribute, $attributeName) { + return $key != $attribute && Str::is($attributeName, $key); }); return ! in_array($value, array_values($data)); @@ -1922,16 +1922,16 @@ protected function getAttributeList(array $values) */ protected function getAttribute($attribute) { - $rawAttribute = $this->getRawAttribute($attribute); + $attributeName = $this->getPrimaryAttribute($attribute); // The developer may dynamically specify the array of custom attributes // on this Validator instance. If the attribute exists in this array // it takes precedence over all other ways we can pull attributes. - if (isset($this->customAttributes[$rawAttribute])) { - return $this->customAttributes[$rawAttribute]; + if (isset($this->customAttributes[$attributeName])) { + return $this->customAttributes[$attributeName]; } - $key = "validation.attributes.{$rawAttribute}"; + $key = "validation.attributes.{$attributeName}"; // We allow for the developer to specify language lines for each of the // attributes allowing for more displayable counterparts of each of @@ -1947,23 +1947,22 @@ protected function getAttribute($attribute) } /** - * Get the raw attribute name. + * Get the primary attribute name. + * + * For example, if "name.0" is given, "name.*" will be returned. * * @param string $attribute * @return string|null */ - protected function getRawAttribute($attribute) + protected function getPrimaryAttribute($attribute) { - $rawAttribute = $attribute; - - foreach ($this->implicitAttributes as $raw => $dataAttributes) { - if (in_array($attribute, $dataAttributes)) { - $rawAttribute = $raw; - break; + foreach ($this->implicitAttributes as $unparsed => $parsed) { + if (in_array($attribute, $parsed)) { + return $unparsed; } } - return $rawAttribute; + return $attribute; } /**
false
Other
laravel
framework
7d7b73231bbb6c5c1916ff4263b207f18b9342c9.json
Preserve numeric keys in callback for Arr::last
src/Illuminate/Support/Arr.php
@@ -158,7 +158,7 @@ public static function last($array, callable $callback = null, $default = null) return empty($array) ? value($default) : end($array); } - return static::first(array_reverse($array), $callback, $default); + return static::first(array_reverse($array, true), $callback, $default); } /**
true
Other
laravel
framework
7d7b73231bbb6c5c1916ff4263b207f18b9342c9.json
Preserve numeric keys in callback for Arr::last
tests/Support/SupportArrTest.php
@@ -83,6 +83,9 @@ public function testLast() $last = Arr::last($array, function ($key, $value) { return $value < 250; }); $this->assertEquals(200, $last); + $last = Arr::last($array, function ($key, $value) { return $key < 2; }); + $this->assertEquals(200, $last); + $this->assertEquals(300, Arr::last($array)); }
true
Other
laravel
framework
7d7b73231bbb6c5c1916ff4263b207f18b9342c9.json
Preserve numeric keys in callback for Arr::last
tests/Support/SupportCollectionTest.php
@@ -25,6 +25,8 @@ public function testLastWithCallback() $data = new Collection([100, 200, 300]); $result = $data->last(function ($key, $value) { return $value < 250; }); $this->assertEquals(200, $result); + $result = $data->last(function ($key, $value) { return $key < 2; }); + $this->assertEquals(200, $result); } public function testLastWithCallbackAndDefault()
true
Other
laravel
framework
d3efa151cf1922b891134bffaf952533ad51e6a7.json
Replace attributes for arrays in validation
src/Illuminate/Validation/Validator.php
@@ -1932,8 +1932,8 @@ protected function getAttribute($attribute) // The developer may dynamically specify the array of custom attributes // on this Validator instance. If the attribute exists in this array // it takes precedence over all other ways we can pull attributes. - if (isset($this->customAttributes[$attribute])) { - return $this->customAttributes[$attribute]; + if ($customAttribute = $this->getCustomAttribute($attribute)) { + return $customAttribute; } $key = "validation.attributes.{$attribute}"; @@ -1951,6 +1951,19 @@ protected function getAttribute($attribute) return str_replace('_', ' ', Str::snake($attribute)); } + /** + * Get the value of a custom attribute. + * + * @param string $attribute + * @return string|null + */ + protected function getCustomAttribute($attribute) + { + return array_first($this->customAttributes, function ($custom) use ($attribute) { + return Str::is($custom, $attribute); + }); + } + /** * Get the displayable name of the value. *
true
Other
laravel
framework
d3efa151cf1922b891134bffaf952533ad51e6a7.json
Replace attributes for arrays in validation
tests/Validation/ValidationValidatorTest.php
@@ -180,6 +180,23 @@ public function testAttributeNamesAreReplaced() $this->assertEquals('NAME is required!', $v->messages()->first('name')); } + public function testAttributeNamesAreReplacedInArrays() + { + $trans = $this->getRealTranslator(); + $trans->addResource('array', ['validation.string' => ':attribute must be a string!'], 'en', 'messages'); + $v = new Validator($trans, ['name' => ['Jon', 2]], ['name.*' => 'string']); + $v->setAttributeNames(['name.*' => 'Any name']); + $this->assertFalse($v->passes()); + $v->messages()->setFormat(':message'); + $this->assertEquals('Any name must be a string!', $v->messages()->first('name.1')); + + $v = new Validator($trans, ['users' => [['name' => 'Jon'], ['name' => 2]]], ['users.*.name' => 'string']); + $v->setAttributeNames(['users.*.name' => 'Any name']); + $this->assertFalse($v->passes()); + $v->messages()->setFormat(':message'); + $this->assertEquals('Any name must be a string!', $v->messages()->first('users.1.name')); + } + public function testDisplayableValuesAreReplaced() { //required_if:foo,bar
true
Other
laravel
framework
6cf3819120fbc949ee2040c116f403f74562d9df.json
Improve test for mail Message class.
tests/Mail/MailMessageTest.php
@@ -1,6 +1,7 @@ <?php use Mockery as m; +use Illuminate\Mail\Message; class MailMessageTest extends PHPUnit_Framework_TestCase { @@ -9,6 +10,93 @@ public function tearDown() m::close(); } + public function testFromMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('setFrom')->once()->with('foo@bar.baz', 'Foo'); + $this->assertInstanceOf(Message::class, $message->from('foo@bar.baz', 'Foo')); + } + + public function testSenderMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('setSender')->once()->with('foo@bar.baz', 'Foo'); + $this->assertInstanceOf(Message::class, $message->sender('foo@bar.baz', 'Foo')); + } + + public function testReturnPathMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('setReturnPath')->once()->with('foo@bar.baz'); + $this->assertInstanceOf(Message::class, $message->returnPath('foo@bar.baz')); + } + + public function testToMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('addTo')->once()->with('foo@bar.baz', 'Foo'); + $this->assertInstanceOf(Message::class, $message->to('foo@bar.baz', 'Foo', false)); + } + + public function testToMethodWithOverride() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('setTo')->once()->with('foo@bar.baz', 'Foo'); + $this->assertInstanceOf(Message::class, $message->to('foo@bar.baz', 'Foo', true)); + } + + public function testCcMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('addCc')->once()->with('foo@bar.baz', 'Foo'); + $this->assertInstanceOf(Message::class, $message->cc('foo@bar.baz', 'Foo')); + } + + public function testBccMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('addBcc')->once()->with('foo@bar.baz', 'Foo'); + $this->assertInstanceOf(Message::class, $message->bcc('foo@bar.baz', 'Foo')); + } + + public function testReplyToMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('addReplyTo')->once()->with('foo@bar.baz', 'Foo'); + $this->assertInstanceOf(Message::class, $message->replyTo('foo@bar.baz', 'Foo')); + } + + public function testSubjectMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('setSubject')->once()->with('foo'); + $this->assertInstanceOf(Message::class, $message->subject('foo')); + } + + public function testPriorityMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $swift->shouldReceive('setPriority')->once()->with(1); + $this->assertInstanceOf(Message::class, $message->priority(1)); + } + + public function testGetSwiftMessageMethod() + { + $swift = m::mock(Swift_Mime_Message::class); + $message = new Message($swift); + $this->assertInstanceOf(Swift_Mime_Message::class, $message->getSwiftMessage()); + } + public function testBasicAttachment() { $swift = m::mock('StdClass');
false
Other
laravel
framework
b6c3743e606cd68eba55b4be8c1e1877630c9c51.json
change method order
src/Illuminate/Filesystem/Filesystem.php
@@ -170,36 +170,36 @@ public function name($path) } /** - * Extract the file extension from a file path. + * Extract the trailing name component from a file path. * * @param string $path * @return string */ - public function extension($path) + public function basename($path) { - return pathinfo($path, PATHINFO_EXTENSION); + return pathinfo($path, PATHINFO_BASENAME); } - + /** - * Extract the trailing name component from a file path. + * Extract the parent directory from a file path. * * @param string $path * @return string */ - public function basename($path) + public function dirname($path) { - return pathinfo($path, PATHINFO_BASENAME); + return pathinfo($path, PATHINFO_DIRNAME); } - + /** - * Extract the parent directory from a file path. + * Extract the file extension from a file path. * * @param string $path * @return string */ - public function dirname($path) + public function extension($path) { - return pathinfo($path, PATHINFO_DIRNAME); + return pathinfo($path, PATHINFO_EXTENSION); } /**
false
Other
laravel
framework
9be2b500eaa5833628046d096410f23948f454fe.json
Rewrite conditionals to be more intuitive
src/Illuminate/Support/Arr.php
@@ -269,12 +269,12 @@ public static function get($array, $key, $default = null) } foreach (explode('.', $key) as $segment) { - if ((! is_array($array) || ! array_key_exists($segment, $array)) && - (! $array instanceof ArrayAccess || ! $array->offsetExists($segment))) { + if ((is_array($array) && array_key_exists($segment, $array)) + || ($array instanceof ArrayAccess && $array->offsetExists($segment))) { + $array = $array[$segment]; + } else { return value($default); } - - $array = $array[$segment]; } return $array; @@ -298,12 +298,12 @@ public static function has($array, $key) } foreach (explode('.', $key) as $segment) { - if ((! is_array($array) || ! array_key_exists($segment, $array)) && - (! $array instanceof ArrayAccess || ! $array->offsetExists($segment))) { + if ((is_array($array) && array_key_exists($segment, $array)) + || ($array instanceof ArrayAccess && $array->offsetExists($segment))) { + $array = $array[$segment]; + } else { return false; } - - $array = $array[$segment]; } return true;
false
Other
laravel
framework
2f01353e7f72e1ac910f260af5a85e58e7946833.json
Add typehint for consistency
src/Illuminate/Support/helpers.php
@@ -195,7 +195,7 @@ function array_has($array, $key) * @param mixed $default * @return mixed */ - function array_last($array, $callback = null, $default = null) + function array_last($array, callable $callback = null, $default = null) { return Arr::last($array, $callback, $default); }
false
Other
laravel
framework
88a61f5fdb5a7c397b3fc06618f1f65992eb845d.json
Fix StyleCI issue
src/Illuminate/Support/Arr.php
@@ -154,7 +154,7 @@ public static function exists($array, $key) public static function first($array, callable $callback = null, $default = null) { if (is_null($callback)) { - return !empty($array) ? reset($array) : value($default); + return empty($array) ? value($default) : reset($array); } foreach ($array as $key => $value) { @@ -177,7 +177,7 @@ public static function first($array, callable $callback = null, $default = null) public static function last($array, callable $callback = null, $default = null) { if (is_null($callback)) { - return !empty($array) ? end($array) : value($default); + return empty($array) ? value($default) : end($array); } return static::first(array_reverse($array), $callback, $default);
false
Other
laravel
framework
f3a216471239bc112b91f3d5ae2ccce7b3e9b706.json
Fix Scheduling\Event tests on Windows
tests/Console/Scheduling/EventTest.php
@@ -6,31 +6,37 @@ class EventTest extends PHPUnit_Framework_TestCase { public function testBuildCommand() { + $quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'"; + $event = new Event('php -i'); $defaultOutput = (DIRECTORY_SEPARATOR == '\\') ? 'NUL' : '/dev/null'; - $this->assertSame("php -i > '{$defaultOutput}' 2>&1 &", $event->buildCommand()); + $this->assertSame("php -i > {$quote}{$defaultOutput}{$quote} 2>&1 &", $event->buildCommand()); } public function testBuildCommandSendOutputTo() { + $quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'"; + $event = new Event('php -i'); $event->sendOutputTo('/dev/null'); - $this->assertSame("php -i > '/dev/null' 2>&1 &", $event->buildCommand()); + $this->assertSame("php -i > {$quote}/dev/null{$quote} 2>&1 &", $event->buildCommand()); $event = new Event('php -i'); $event->sendOutputTo('/my folder/foo.log'); - $this->assertSame("php -i > '/my folder/foo.log' 2>&1 &", $event->buildCommand()); + $this->assertSame("php -i > {$quote}/my folder/foo.log{$quote} 2>&1 &", $event->buildCommand()); } public function testBuildCommandAppendOutput() { + $quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'"; + $event = new Event('php -i'); $event->appendOutputTo('/dev/null'); - $this->assertSame("php -i >> '/dev/null' 2>&1 &", $event->buildCommand()); + $this->assertSame("php -i >> {$quote}/dev/null{$quote} 2>&1 &", $event->buildCommand()); } /**
false
Other
laravel
framework
cd0af1093647b6447475f3b0c858cf10d3b9f48c.json
Make $callback optional for helper functions too
src/Illuminate/Support/helpers.php
@@ -123,7 +123,7 @@ function array_except($array, $keys) * @param mixed $default * @return mixed */ - function array_first($array, callable $callback, $default = null) + function array_first($array, callable $callback = null, $default = null) { return Arr::first($array, $callback, $default); } @@ -195,7 +195,7 @@ function array_has($array, $key) * @param mixed $default * @return mixed */ - function array_last($array, $callback, $default = null) + function array_last($array, $callback = null, $default = null) { return Arr::last($array, $callback, $default); }
false
Other
laravel
framework
00dbd7a24f4515aa502b4029b4eb54127bc95d8b.json
Make callback optional for first() and last()
src/Illuminate/Support/Arr.php
@@ -151,10 +151,10 @@ public static function exists($array, $key) * @param mixed $default * @return mixed */ - public static function first($array, callable $callback, $default = null) + public static function first($array, callable $callback = null, $default = null) { foreach ($array as $key => $value) { - if (call_user_func($callback, $key, $value)) { + if (is_null($callback) || call_user_func($callback, $key, $value)) { return $value; } } @@ -170,7 +170,7 @@ public static function first($array, callable $callback, $default = null) * @param mixed $default * @return mixed */ - public static function last($array, callable $callback, $default = null) + public static function last($array, callable $callback = null, $default = null) { return static::first(array_reverse($array), $callback, $default); }
false
Other
laravel
framework
d2efcaa2280399917ef6ad211feb85f30e796e8c.json
Use sprintf because it's easier to read
tests/View/ViewBladeCompilerTest.php
@@ -208,8 +208,8 @@ public function testCommentsAreCompiled() */ ?>'; $this->assertEquals($expected, $compiler->compileString($string)); - $string = '{{-- this is an ' . str_repeat('extremely ', 100) . 'long comment --}}'; - $expected = '<?php /* this is an ' . str_repeat('extremely ', 100) . 'long comment */ ?>'; + $string = sprintf('{{-- this is an %s long comment --}}', str_repeat('extremely ', 1000)); + $expected = sprintf('<?php /* this is an %s long comment */ ?>', str_repeat('extremely ', 1000)); $this->assertEquals($expected, $compiler->compileString($string)); }
false
Other
laravel
framework
64d71c1982ac866e80c2332fb4114d6d7ea054dc.json
Add tests for Str::is with stringable objects
tests/Support/SupportStrTest.php
@@ -93,6 +93,12 @@ public function testIs() $this->assertFalse(Str::is('/', '/a')); $this->assertTrue(Str::is('foo/*', 'foo/bar/baz')); $this->assertTrue(Str::is('*/foo', 'blah/baz/foo')); + + $valueObject = new StringableObjectStub('foo/bar/baz'); + $patternObject = new StringableObjectStub('foo/*'); + + $this->assertTrue(Str::is('foo/bar/baz', $valueObject)); + $this->assertTrue(Str::is($patternObject, $valueObject)); } public function testLower() @@ -182,3 +188,18 @@ public function testUcfirst() $this->assertEquals('Мама мыла раму', Str::ucfirst('мама мыла раму')); } } + +class StringableObjectStub +{ + private $value; + + public function __construct($value) + { + $this->value = $value; + } + + public function __toString() + { + return $this->value; + } +}
false
Other
laravel
framework
1178f619426b2ac689f3d8163db36d3c841fe163.json
Register swiftmailer before mailer Fix CS
src/Illuminate/Mail/MailServiceProvider.php
@@ -21,9 +21,9 @@ class MailServiceProvider extends ServiceProvider */ public function register() { - $this->app->singleton('mailer', function ($app) { - $this->registerSwiftMailer(); + $this->registerSwiftMailer(); + $this->app->singleton('mailer', function ($app) { // Once we have create the mailer instance, we will set a container instance // on the mailer. This allows us to resolve mailer classes via containers // for maximum testability on said classes instead of passing Closures.
false
Other
laravel
framework
169f9d414b256ae741bb5c69cf9ec6a9a298a3fb.json
Make the rule work without parameters
src/Illuminate/Validation/Validator.php
@@ -127,6 +127,13 @@ class Validator implements ValidatorContract */ protected $replacers = []; + /** + * The array of rules with asterisks. + * + * @var array + */ + protected $implicitAttributes = []; + /** * The size related validation rules. * @@ -290,6 +297,7 @@ public function each($attribute, $rules) if (Str::startsWith($key, $attribute) || (bool) preg_match('/^'.$pattern.'\z/', $key)) { foreach ((array) $rules as $ruleKey => $ruleValue) { if (! is_string($ruleKey) || Str::endsWith($key, $ruleKey)) { + $this->implicitAttributes[$attribute][] = $key; $this->mergeRules($key, $ruleValue); } } @@ -1139,10 +1147,19 @@ protected function validateNotIn($attribute, $value, $parameters) */ protected function validateNoDuplicates($attribute, $value, $parameters) { + $rawAttribute = ''; + + foreach ($this->implicitAttributes as $raw => $dataAttributes) { + if (in_array($attribute, $dataAttributes)) { + $rawAttribute = $raw; + break; + } + } + $data = []; foreach (Arr::dot($this->data) as $key => $val) { - if ($key != $attribute && Str::is($parameters[0], $key)) { + if ($key != $attribute && Str::is($rawAttribute, $key)) { $data[$key] = $val; } }
true
Other
laravel
framework
169f9d414b256ae741bb5c69cf9ec6a9a298a3fb.json
Make the rule work without parameters
tests/Validation/ValidationValidatorTest.php
@@ -1037,19 +1037,31 @@ public function testValidateNoDuplicates() { $trans = $this->getRealTranslator(); - $v = new Validator($trans, ['foo' => ['foo', 'foo']], ['foo.*' => 'no_duplicates:foo.*']); + $v = new Validator($trans, ['foo' => ['foo', 'foo']], ['foo.*' => 'no_duplicates']); $this->assertFalse($v->passes()); - $v = new Validator($trans, ['foo' => ['foo', 'bar']], ['foo.*' => 'no_duplicates:foo.*']); + $v = new Validator($trans, ['foo' => ['foo', 'bar']], ['foo.*' => 'no_duplicates']); $this->assertTrue($v->passes()); - $v = new Validator($trans, ['foo' => [['id' => 1], ['id' => 1]]], ['foo.*.id' => 'no_duplicates:foo.*.id']); + $v = new Validator($trans, ['foo' => ['bar' => ['id' => 1], 'baz' => ['id' => 1]]], ['foo.*.id' => 'no_duplicates']); $this->assertFalse($v->passes()); - $v = new Validator($trans, ['foo' => [['id' => 1], ['id' => 2]]], ['foo.*.id' => 'no_duplicates:foo.*.id']); + $v = new Validator($trans, ['foo' => ['bar' => ['id' => 1], 'baz' => ['id' => 2]]], ['foo.*.id' => 'no_duplicates']); $this->assertTrue($v->passes()); - $v = new Validator($trans, ['foo' => ['foo', 'foo']], ['foo.*' => 'no_duplicates:foo.*'], ['foo.*.no_duplicates' => 'There is a duplication!']); + $v = new Validator($trans, ['foo' => [['id' => 1], ['id' => 1]]], ['foo.*.id' => 'no_duplicates']); + $this->assertFalse($v->passes()); + + $v = new Validator($trans, ['foo' => [['id' => 1], ['id' => 2]]], ['foo.*.id' => 'no_duplicates']); + $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['cat' => [['prod' => [['id' => 1]]], ['prod' => [['id' => 1]]]]], ['cat.*.prod.*.id' => 'no_duplicates']); + $this->assertFalse($v->passes()); + + $v = new Validator($trans, ['cat' => [['prod' => [['id' => 1]]], ['prod' => [['id' => 2]]]]], ['cat.*.prod.*.id' => 'no_duplicates']); + $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['foo' => ['foo', 'foo']], ['foo.*' => 'no_duplicates'], ['foo.*.no_duplicates' => 'There is a duplication!']); $this->assertFalse($v->passes()); $v->messages()->setFormat(':message'); $this->assertEquals('There is a duplication!', $v->messages()->first('foo.0'));
true
Other
laravel
framework
5b057e4d840d63e265268112be40074ceec076b2.json
Add tests for Arr::get/has with null values
tests/Support/SupportArrayTest.php
@@ -137,6 +137,11 @@ public function testGet() $value = Arr::get($array, 'products.desk'); $this->assertEquals(['price' => 100], $value); + // Test null array values + $array = ['foo' => null, 'bar' => ['baz' => null]]; + $this->assertNull(Arr::get($array, 'foo', 'default')); + $this->assertNull(Arr::get($array, 'bar.baz', 'default')); + // Test direct ArrayAccess object $array = ['products' => ['desk' => ['price' => 100]]]; $arrayAccessObject = new ArrayObject($array); @@ -163,11 +168,16 @@ public function testGet() $value = Arr::get($array, 'parent.child.desk'); $this->assertNull($value); - // Test null ArrayAccess object field + // Test missing ArrayAccess object field $arrayAccessObject = new ArrayObject(['products' => ['desk' => null]]); $array = ['parent' => $arrayAccessObject]; $value = Arr::get($array, 'parent.products.desk.price'); $this->assertNull($value); + + // Test null ArrayAccess object fields + $array = new ArrayObject(['foo' => null, 'bar' => new ArrayObject(['baz' => null])]); + $this->assertNull(Arr::get($array, 'foo', 'default')); + $this->assertNull(Arr::get($array, 'bar.baz', 'default')); } public function testHas() @@ -177,6 +187,10 @@ public function testHas() $this->assertTrue(Arr::has($array, 'products.desk.price')); $this->assertFalse(Arr::has($array, 'products.foo')); $this->assertFalse(Arr::has($array, 'products.desk.foo')); + + $array = ['foo' => null, 'bar' => ['baz' => null]]; + $this->assertTrue(Arr::has($array, 'foo')); + $this->assertTrue(Arr::has($array, 'bar.baz')); } public function testIsAssoc()
false
Other
laravel
framework
ef90fbb6f5d0bfd5bc6cfcc469d0221112f361d6.json
Rewrite the check to work on PHP < 5.6.0 and hhvm
src/Illuminate/Validation/Validator.php
@@ -1127,9 +1127,13 @@ protected function validateNotIn($attribute, $value, $parameters) */ protected function validateNoDuplicates($attribute, $value, $parameters) { - $data = array_filter(Arr::dot($this->data), function ($key) use ($attribute, $parameters) { - return $key != $attribute && Str::is($parameters[0], $key); - }, ARRAY_FILTER_USE_KEY); + $data = []; + + foreach (Arr::dot($this->data) as $key => $val) { + if ($key != $attribute && Str::is($parameters[0], $key)) { + $data[$key] = $val; + } + } return ! in_array($value, array_values($data)); }
false
Other
laravel
framework
ad431e0267bb41eb97182bfdc33fe7853ef089a9.json
Add test for Request method() method.
tests/Http/HttpRequestTest.php
@@ -18,6 +18,30 @@ public function testInstanceMethod() $this->assertSame($request, $request->instance()); } + public function testMethodMethod() + { + $request = Request::create('', 'GET'); + $this->assertSame('GET', $request->method()); + + $request = Request::create('', 'HEAD'); + $this->assertSame('HEAD', $request->method()); + + $request = Request::create('', 'POST'); + $this->assertSame('POST', $request->method()); + + $request = Request::create('', 'PUT'); + $this->assertSame('PUT', $request->method()); + + $request = Request::create('', 'PATCH'); + $this->assertSame('PATCH', $request->method()); + + $request = Request::create('', 'DELETE'); + $this->assertSame('DELETE', $request->method()); + + $request = Request::create('', 'OPTIONS'); + $this->assertSame('OPTIONS', $request->method()); + } + public function testRootMethod() { $request = Request::create('http://example.com/foo/bar/script.php?test');
false
Other
laravel
framework
2f2f293ba232d69a8cb0b5ac81d78878b8d987af.json
Make whereIn defalut to loose comparison
src/Illuminate/Support/Collection.php
@@ -267,23 +267,23 @@ protected function operatorForWhere($key, $operator, $value) * @param bool $strict * @return static */ - public function whereIn($key, array $values, $strict = true) + public function whereIn($key, array $values, $strict = false) { return $this->filter(function ($item) use ($key, $values, $strict) { return in_array(data_get($item, $key), $values, $strict); }); } /** - * Filter items by the given key value pair using loose comparison. + * Filter items by the given key value pair using strict comparison. * * @param string $key * @param array $values * @return static */ - public function whereInLoose($key, array $values) + public function whereInStrict($key, array $values) { - return $this->whereIn($key, $values, false); + return $this->whereIn($key, $values, true); } /**
true
Other
laravel
framework
2f2f293ba232d69a8cb0b5ac81d78878b8d987af.json
Make whereIn defalut to loose comparison
tests/Support/SupportCollectionTest.php
@@ -330,13 +330,13 @@ public function testWhere() public function testWhereIn() { $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); - $this->assertEquals([['v' => 1], ['v' => 3]], $c->whereIn('v', [1, 3])->values()->all()); + $this->assertEquals([['v' => 1], ['v' => 3], ['v' => '3']], $c->whereIn('v', [1, 3])->values()->all()); } - public function testWhereInLoose() + public function testWhereInStrict() { $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); - $this->assertEquals([['v' => 1], ['v' => 3], ['v' => '3']], $c->whereInLoose('v', [1, 3])->values()->all()); + $this->assertEquals([['v' => 1], ['v' => 3]], $c->whereInStrict('v', [1, 3])->values()->all()); } public function testValues()
true
Other
laravel
framework
1f21898515f8a049b4f4529351fc427690795d8f.json
Reorganize operators in most-used order
src/Illuminate/Support/Collection.php
@@ -247,13 +247,13 @@ protected function operatorForWhere($key, $operator, $value) default: case '=': case '==': return $retrieved == $value; - case '===': return $retrieved === $value; - case '<=': return $retrieved <= $value; - case '>=': return $retrieved >= $value; + case '!=': + case '<>': return $retrieved != $value; case '<': return $retrieved < $value; case '>': return $retrieved > $value; - case '<>': - case '!=': return $retrieved != $value; + case '<=': return $retrieved <= $value; + case '>=': return $retrieved >= $value; + case '===': return $retrieved === $value; case '!==': return $retrieved !== $value; } };
false
Other
laravel
framework
8499b3a9774729bc1ebb3058f8c7c8a98d8e647d.json
Add DateTimeImmutable as valid date to Model.php DateTimeImmutable behaves just like the DateTime object, so it should be considered as a valid date object when returning a Carbon date object.
src/Illuminate/Database/Eloquent/Model.php
@@ -2934,6 +2934,12 @@ protected function asDateTime($value) if ($value instanceof DateTime) { return Carbon::instance($value); } + + // If the value is a DateTimeImmutable instance, also skip the rest of these + // checks. Just return the DateTimeImmutable right away. + if($value instanceof DateTimeImmutable) { + return new Carbon($value->format('Y-m-d H:i:s.u'), $value->getTimeZone()); + } // If this value is an integer, we will assume it is a UNIX timestamp's value // and format a Carbon object from this timestamp. This allows flexibility
false
Other
laravel
framework
83c3c56df9ec1ee764134021ce055db7bdc26038.json
Add operator support to collection@where
src/Illuminate/Support/Collection.php
@@ -215,16 +215,19 @@ public function filter(callable $callback = null) * Filter items by the given key value pair. * * @param string $key + * @param mixed $operator * @param mixed $value - * @param bool $strict * @return static */ - public function where($key, $value, $strict = true) + public function where($key, $operator, $value = null) { - return $this->filter(function ($item) use ($key, $value, $strict) { - return $strict ? data_get($item, $key) === $value - : data_get($item, $key) == $value; - }); + if (func_num_args() == 2) { + $value = $operator; + + $operator = '==='; + } + + return $this->filter($this->operatorChecker($key, $operator, $value)); } /** @@ -236,7 +239,7 @@ public function where($key, $value, $strict = true) */ public function whereLoose($key, $value) { - return $this->where($key, $value, false); + return $this->where($key, '=', $value); } /** @@ -984,6 +987,35 @@ public function zip($items) return new static(call_user_func_array('array_map', $params)); } + /** + * Get an operator checker callback. + * + * @param string $key + * @param string $operator + * @param mixed $value + * @return \Closure + */ + protected function operatorChecker($key, $operator, $value) + { + return function ($item) use ($key, $operator, $value) { + $retrieved = data_get($item, $key); + + switch ($operator) { + default: + case '=': + case '==': return $retrieved == $value; + case '===': return $retrieved === $value; + case '<=': return $retrieved <= $value; + case '>=': return $retrieved >= $value; + case '<': return $retrieved < $value; + case '>': return $retrieved > $value; + case '<>': + case '!=': return $retrieved != $value; + case '!==': return $retrieved !== $value; + } + }; + } + /** * Get the collection of items as a plain array. *
true
Other
laravel
framework
83c3c56df9ec1ee764134021ce055db7bdc26038.json
Add operator support to collection@where
tests/Support/SupportCollectionTest.php
@@ -275,7 +275,56 @@ public function testFilter() public function testWhere() { $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); - $this->assertEquals([['v' => 3]], $c->where('v', 3)->values()->all()); + + $this->assertEquals( + [['v' => 3]], + $c->where('v', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 3], ['v' => '3']], + $c->where('v', '=', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 3], ['v' => '3']], + $c->where('v', '==', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 3], ['v' => '3']], + $c->where('v', 'garbage', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 3]], + $c->where('v', '===', 3)->values()->all() + ); + + $this->assertEquals( + [['v' => 1], ['v' => 2], ['v' => 4]], + $c->where('v', '<>', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 1], ['v' => 2], ['v' => 4]], + $c->where('v', '!=', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 1], ['v' => 2], ['v' => '3'], ['v' => 4]], + $c->where('v', '!==', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3']], + $c->where('v', '<=', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 3], ['v' => '3'], ['v' => 4]], + $c->where('v', '>=', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 1], ['v' => 2]], + $c->where('v', '<', 3)->values()->all() + ); + $this->assertEquals( + [['v' => 4]], + $c->where('v', '>', 3)->values()->all() + ); } public function testWhereLoose()
true
Other
laravel
framework
8964f375093904b05a426a664255ecaf73bdfd02.json
Fix current URI used by Crawler in tests
src/Illuminate/Foundation/Testing/InteractsWithPages.php
@@ -64,7 +64,7 @@ protected function makeRequest($method, $uri, $parameters = [], $cookies = [], $ $this->currentUri = $this->app->make('request')->fullUrl(); - $this->crawler = new Crawler($this->response->getContent(), $uri); + $this->crawler = new Crawler($this->response->getContent(), $this->currentUri); return $this; }
false
Other
laravel
framework
d576bedd3f0f70c9df6dcecb2f44057ee92234fe.json
Change fresh() parameter type The $with parameter _always_ gets sent to Model::with() so it makes sense to mirror the type.
src/Illuminate/Database/Eloquent/Model.php
@@ -648,10 +648,10 @@ public static function all($columns = ['*']) /** * Reload a fresh model instance from the database. * - * @param array $with + * @param array|string $with * @return $this|null */ - public function fresh(array $with = []) + public function fresh($with = []) { if (! $this->exists) { return;
false
Other
laravel
framework
a7cf9a11a1f3a379af89856b84a156f8b25bb724.json
Allow array of validation rules on validateWith.
src/Illuminate/Foundation/Validation/ValidatesRequests.php
@@ -20,14 +20,18 @@ trait ValidatesRequests /** * Run the validation routine against the given validator. * - * @param \Illuminate\Contracts\Validation\Validator $validator + * @param \Illuminate\Contracts\Validation\Validator|array $validator * @param \Illuminate\Http\Request|null $request * @return void */ public function validateWith($validator, Request $request = null) { $request = $request ?: app('request'); + if (is_array($validator)) { + $validator = $this->getValidationFactory()->make($request->all(), $validator); + } + if ($validator->fails()) { $this->throwValidationException($request, $validator); }
false
Other
laravel
framework
0fe971b5dc41bb5afe51a530dcc17ed3d58ce19f.json
Add seeText and dontSeeText methods
src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php
@@ -208,7 +208,47 @@ protected function crawler() } /** - * Assert that a given string is seen on the page. + * Get the HTML from the current context or the full response. + * + * @return string + */ + protected function html() + { + return $this->crawler() + ? $this->crawler()->html() + : $this->response->getContent(); + } + + /** + * Get the plain text from the current context or the full response. + * + * @return string + */ + protected function text() + { + return $this->crawler() + ? $this->crawler()->text() + : strip_tags($this->response->getContent()); + } + + /** + * Get the escaped text pattern. + * + * @param string $text + * @return string + */ + protected function getEscapedPattern($text) + { + $rawPattern = preg_quote($text, '/'); + + $escapedPattern = preg_quote(e($text), '/'); + + return $rawPattern == $escapedPattern + ? $rawPattern : "({$rawPattern}|{$escapedPattern})"; + } + + /** + * Assert that a given string is seen on the current HTML. * * @param string $text * @param bool $negate @@ -218,31 +258,51 @@ protected function see($text, $negate = false) { $method = $negate ? 'assertNotRegExp' : 'assertRegExp'; - $rawPattern = preg_quote($text, '/'); + $pattern = $this->getEscapedPattern($text); - $escapedPattern = preg_quote(e($text), '/'); + $this->$method("/$pattern/i", $this->html()); - $pattern = $rawPattern == $escapedPattern - ? $rawPattern : "({$rawPattern}|{$escapedPattern})"; + return $this; + } + + /** + * Assert that a given string is not seen on the current HTML. + * + * @param string $text + * @return $this + */ + protected function dontSee($text) + { + return $this->see($text, true); + } + + /** + * Assert that a given string is seen on the current text. + * + * @param string $text + * @param bool $negate + * @return $this + */ + protected function seeText($text, $negate = false) + { + $method = $negate ? 'assertNotRegExp' : 'assertRegExp'; - $html = $this->crawler() - ? $this->crawler()->html() - : $this->response->getContent(); + $pattern = $this->getEscapedPattern($text); - $this->$method("/$pattern/i", $html); + $this->$method("/$pattern/i", $this->text()); return $this; } /** - * Assert that a given string is not seen on the page. + * Assert that a given string is not seen on the current text. * * @param string $text * @return $this */ - protected function dontSee($text) + protected function dontSeeText($text) { - return $this->see($text, true); + return $this->seeText($text, true); } /** @@ -295,12 +355,7 @@ protected function hasInElement($element, $text) { $elements = $this->crawler()->filter($element); - $rawPattern = preg_quote($text, '/'); - - $escapedPattern = preg_quote(e($text), '/'); - - $pattern = $rawPattern == $escapedPattern - ? $rawPattern : "({$rawPattern}|{$escapedPattern})"; + $pattern = $this->getEscapedPattern($text); foreach ($elements as $element) { $element = new Crawler($element);
true
Other
laravel
framework
0fe971b5dc41bb5afe51a530dcc17ed3d58ce19f.json
Add seeText and dontSeeText methods
tests/Foundation/FoundationInteractsWithPagesTest.php
@@ -52,6 +52,19 @@ public function testDontSee() $this->dontSee('Webmasters'); } + public function testSeeTextAndDontSeeText() + { + $this->setCrawler('<p>Laravel is a <strong>PHP Framework</strong>.'); + + // The methods see and dontSee compare against the HTML. + $this->see('strong'); + $this->dontSee('Laravel is a PHP Framework'); + + // seeText and dontSeeText strip the HTML and compare against the plain text. + $this->seeText('Laravel is a PHP Framework.'); + $this->dontSeeText('strong'); + } + public function testSeeInElement() { $this->setCrawler('<div>Laravel was created by <strong>Taylor Otwell</strong></div>');
true
Other
laravel
framework
6a4a91832775bcdeb0a387664eaa36c3189db196.json
add guestMiddleware method
src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
@@ -178,6 +178,16 @@ public function logout() return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/'); } + /** + * Get the guest middleware for the application. + */ + public function guestMiddleware() + { + $guard = $this->getGuard(); + + return $guard ? 'guest:'.$guard : 'guest'; + } + /** * Get the login username to be used by the controller. *
false
Other
laravel
framework
0c0654394c277576f20a8b45f5077f6800b47237.json
remove unneeded line
src/Illuminate/Auth/Console/MakeAuthCommand.php
@@ -55,8 +55,7 @@ public function fire() file_put_contents( app_path('Http/Controllers/HomeController.php'), - $this->compileControllerStub(), - FILE_TEXT + $this->compileControllerStub() ); $this->info('Updated Routes File.');
false
Other
laravel
framework
33c16b0c866b32911a1f6cc5cb6916d6d037e813.json
add default parameters to route (fixes #12185)
src/Illuminate/Routing/Route.php
@@ -551,7 +551,7 @@ public function bindParameters(Request $request) ); } - return $this->parameters = $this->replaceDefaults($params); + return $this->parameters = $this->fillDefaults($this->replaceDefaults($params)); } /** @@ -615,6 +615,23 @@ protected function replaceDefaults(array $parameters) return $parameters; } + /** + * Fill missing parameters with their defaults. + * + * @param array $parameters + * @return array + */ + protected function fillDefaults(array $parameters) + { + foreach ($this->defaults as $key => $value) { + if (! isset($parameters[$key])) { + $parameters[$key] = $value; + } + } + + return $parameters; + } + /** * Parse the route action into a standard array. *
false
Other
laravel
framework
a280ddbbb1de5a3fc676b03b19c8ee8b81ba1f0d.json
add failing unit test for #12185
tests/Routing/RoutingRouteTest.php
@@ -196,6 +196,16 @@ public function testNonGreedyMatches() $this->assertEquals('bar', $route->parameter('foo', 'bar')); } + public function testRouteParametersDefaultValue() + { + $router = $this->getRouter(); + $router->get('foo/{bar?}', ['uses' => 'RouteTestControllerWithParameterStub@returnParameter'])->defaults('bar', 'foo'); + $this->assertEquals('foo', $router->dispatch(Request::create('foo', 'GET'))->getContent()); + + $router->get('foo/{bar?}', function ($bar = '') { return $bar; })->defaults('bar', 'foo'); + $this->assertEquals('foo', $router->dispatch(Request::create('foo', 'GET'))->getContent()); + } + /** * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ @@ -952,6 +962,14 @@ public function index() } } +class RouteTestControllerWithParameterStub extends Illuminate\Routing\Controller +{ + public function returnParameter($bar = '') + { + return $bar; + } +} + class RouteTestControllerMiddleware { public function handle($request, $next)
false
Other
laravel
framework
3ef916aace74a4bbc7370bcabf47c7b5282e943f.json
Use newInstance in Builder
src/Illuminate/Database/Eloquent/Builder.php
@@ -142,7 +142,7 @@ public function findOrNew($id, $columns = ['*']) return $model; } - return $this->newModel(); + return $this->model->newInstance(); } /** @@ -157,7 +157,7 @@ public function firstOrNew(array $attributes) return $instance; } - return $this->newModel($attributes); + return $this->model->newInstance($attributes); } /** @@ -172,7 +172,7 @@ public function firstOrCreate(array $attributes) return $instance; } - $instance = $this->newModel($attributes); + $instance = $this->model->newInstance($attributes); $instance->save(); @@ -957,19 +957,6 @@ public function getModel() return $this->model; } - /** - * Get a fresh instance of a model instance being queried. - * - * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model - */ - public function newModel(array $attributes = []) - { - $class = get_class($this->model); - - return new $class($attributes); - } - /** * Set a model instance for the model being queried. *
false
Other
laravel
framework
6f3b61b5fd71c0d9632ac48d1473e3832ee019b8.json
Add windows support for withoutOverlapping
src/Illuminate/Console/Scheduling/Event.php
@@ -200,22 +200,36 @@ public function buildCommand() $redirect = $this->shouldAppendOutput ? ' >> ' : ' > '; if ($this->withoutOverlapping) { - $command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().')'.$redirect.$output.' 2>&1 &'; + if ($this->isWindowsEnvironment()){ + $command = '(echo \'\' > "'.$this->mutexPath().'" & '.$this->command.' & del "'.$this->mutexPath().'")'. $redirect.$output.' 2>&1 &'; + } else { + $command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().')'.$redirect.$output.' 2>&1 &'; + } } else { $command = $this->command.$redirect.$output.' 2>&1 &'; } return $this->user ? 'sudo -u '.$this->user.' '.$command : $command; } + /** + * Determine if the current enviroment is windows + * + * @return boolean + */ + protected function isWindowsEnvironment() + { + return (substr(strtoupper(php_uname('s')), 0, 3) === 'WIN'); + } + /** * Get the mutex path for the scheduled command. * * @return string */ protected function mutexPath() { - return storage_path('framework/schedule-'.sha1($this->expression.$this->command)); + return storage_path('framework'.DIRECTORY_SEPARATOR.'schedule-'.sha1($this->expression.$this->command)); } /**
false
Other
laravel
framework
2fdb5d13d05f771877dcdd9a44cb8e6d403cd8ac.json
add setCollection method to the Paginator
src/Illuminate/Pagination/AbstractPaginator.php
@@ -427,6 +427,19 @@ public function getCollection() return $this->items; } + /** + * Set the paginator's underlying collection. + * + * @param \Illuminate\Support\Collection $collection + * @return $this + */ + public function setCollection(\Illuminate\Support\Collection $collection) + { + $this->items = $collection; + + return $this; + } + /** * Determine if the given item exists. *
false
Other
laravel
framework
e84f0a4b5cb8ff976392a45b645397a7ba7db065.json
Add a validate method to the validation factory
src/Illuminate/Validation/Factory.php
@@ -111,6 +111,22 @@ public function make(array $data, array $rules, array $messages = [], array $cus return $validator; } + /** + * Validate the given data against the provided rules. + * + * @param array $data + * @param array $rules + * @param array $messages + * @param array $customAttributes + * @return void + * + * @throws \Illuminate\Validation\ValidationException + */ + public function validate(array $data, array $rules, array $messages = [], array $customAttributes = []) + { + $this->make($data, $rules, $messages, $customAttributes)->validate(); + } + /** * Add the extensions to a validator instance. *
false
Other
laravel
framework
8a73322ef2c56fa70d68d18a0fdc5265582539de.json
Add public validate method to the validator
src/Illuminate/Foundation/Exceptions/Handler.php
@@ -102,8 +102,8 @@ public function render($request, Exception $e) $e = new NotFoundHttpException($e->getMessage(), $e); } elseif ($e instanceof AuthorizationException) { $e = new HttpException(403, $e->getMessage()); - } elseif ($e instanceof ValidationException && $e->getResponse()) { - return $e->getResponse(); + } elseif ($e instanceof ValidationException) { + return $this->convertValidationExceptionToResponse($e, $request); } if ($this->isHttpException($e)) { @@ -158,6 +158,28 @@ protected function renderHttpException(HttpException $e) } } + /** + * Create a response object from the given validation exception. + * + * @param \Illuminate\Validation\ValidationException $e + * @param \Illuminate\Http\Request $request + * @return \Symfony\Component\HttpFoundation\Response + */ + protected function convertValidationExceptionToResponse(ValidationException $e, $request) + { + if ($e->response) { + return $e->response; + } + + $errors = $e->validator->errors()->getMessages(); + + if (($request->ajax() && ! $request->pjax()) || $request->wantsJson()) { + return response()->json($errors, 422); + } + + return redirect()->back()->withInput($request->input())->withErrors($errors); + } + /** * Create a Symfony response for the given exception. *
true
Other
laravel
framework
8a73322ef2c56fa70d68d18a0fdc5265582539de.json
Add public validate method to the validator
src/Illuminate/Validation/ValidationException.php
@@ -9,7 +9,7 @@ class ValidationException extends Exception /** * The validator instance. * - * @var \Illuminate\Validation\Validator + * @var \Illuminate\Contracts\Validation\Validator */ public $validator; @@ -23,7 +23,7 @@ class ValidationException extends Exception /** * Create a new exception instance. * - * @param \Illuminate\Validation\Validator $validator + * @param \Illuminate\Contracts\Validation\Validator $validator * @param \Illuminate\Http\Response $response * @return void */ @@ -38,7 +38,7 @@ public function __construct($validator, $response = null) /** * Get the underlying response instance. * - * @return \Symfony\Component\HttpFoundation\Response + * @return \Symfony\Component\HttpFoundation\Response|null */ public function getResponse() {
true
Other
laravel
framework
8a73322ef2c56fa70d68d18a0fdc5265582539de.json
Add public validate method to the validator
src/Illuminate/Validation/Validator.php
@@ -334,7 +334,7 @@ public function passes() // the other error messages, returning true if we don't have messages. foreach ($this->rules as $attribute => $rules) { foreach ($rules as $rule) { - $this->validate($attribute, $rule); + $this->validateAttribute($attribute, $rule); if ($this->shouldStopValidating($attribute)) { break; @@ -362,14 +362,28 @@ public function fails() return ! $this->passes(); } + /** + * Run the validator's rules against its data. + * + * @return void + * + * @throws \Illuminate\Validation\ValidationException + */ + public function validate() + { + if ($this->fails()) { + throw new ValidationException($this); + } + } + /** * Validate a given attribute against a rule. * * @param string $attribute * @param string $rule * @return void */ - protected function validate($attribute, $rule) + protected function validateAttribute($attribute, $rule) { list($rule, $parameters) = $this->parseRule($rule);
true
Other
laravel
framework
8665024c290a19c02e4ebf95059aed62f7351208.json
Create tests for validation validate method
tests/Validation/ValidationValidatorTest.php
@@ -50,6 +50,25 @@ public function testSometimesWorksOnArrays() $this->assertTrue($v->passes()); } + /** + * @expectedException \Illuminate\Validation\ValidationException + */ + public function testValidateThrowsOnFail() + { + $trans = $this->getRealTranslator(); + $v = new Validator($trans, ['foo' => 'bar'], ['baz' => 'required']); + + $v->validate(); + } + + public function testValidateDoesntThrowOnPass() + { + $trans = $this->getRealTranslator(); + $v = new Validator($trans, ['foo' => 'bar'], ['foo' => 'required']); + + $v->validate(); + } + public function testHasFailedValidationRules() { $trans = $this->getRealTranslator();
false
Other
laravel
framework
a96ea3c8c95657832f3d534d42db4b5efc7b8515.json
Add file() method to response factory.
src/Illuminate/Routing/ResponseFactory.php
@@ -137,6 +137,23 @@ public function download($file, $name = null, array $headers = [], $disposition return $response; } + /** + * Return the raw contents of a binary file. + * + * @param \SplFileInfo|string $file + * @param string $mime + * @param array $headers + * @return \Symfony\Component\HttpFoundation\BinaryFileResponse + */ + public function file($file, $mime, array $headers = []) + { + $headers['Content-Type'] = $mime; + + $response = new BinaryFileResponse($file, 200, $headers, true); + + return $response; + } + /** * Create a new redirect response to the given path. *
false
Other
laravel
framework
551cebeb143d43d23b57fe9c9dfaba4464243ac8.json
change whereDate method for Postgres
src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
@@ -44,7 +44,7 @@ protected function whereDate(Builder $query, $where) { $value = $this->parameter($where['value']); - return $this->wrap($where['column']).' '.$where['operator'].' '.$value.'::date'; + return $this->wrap($where['column']).'::date '.$where['operator'].' '.$value; } /**
true
Other
laravel
framework
551cebeb143d43d23b57fe9c9dfaba4464243ac8.json
change whereDate method for Postgres
tests/Database/DatabaseQueryBuilderTest.php
@@ -161,7 +161,7 @@ public function testWhereDatePostgres() { $builder = $this->getPostgresBuilder(); $builder->select('*')->from('users')->whereDate('created_at', '=', '2015-12-21'); - $this->assertEquals('select * from "users" where "created_at" = ?::date', $builder->toSql()); + $this->assertEquals('select * from "users" where "created_at"::date = ?', $builder->toSql()); $this->assertEquals([0 => '2015-12-21'], $builder->getBindings()); }
true