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
154b5ece01d524a303f1a7b17c936f60f747da43.json
Apply fixes from StyleCI (#33324)
tests/Foundation/FoundationExceptionsHandlerTest.php
@@ -16,8 +16,8 @@ use Illuminate\Support\MessageBag; use Illuminate\Validation\ValidationException; use Illuminate\Validation\Validator; -use Mockery as m; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; +use Mockery as m; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use RuntimeException;
false
Other
laravel
framework
1e1f5311f062d62468fe2d3cef1695b8fa338cfb.json
Add support for binary request
src/Illuminate/Http/Client/PendingRequest.php
@@ -41,6 +41,13 @@ class PendingRequest */ protected $pendingFiles = []; + /** + * The binary for the request. + * + * @var array + */ + protected $pendingBinary; + /** * The request cookies. * @@ -177,6 +184,34 @@ public function asMultipart() return $this->bodyFormat('multipart'); } + /** + * Attach a binary to the request. + * + * @param string $content + * @param string $contentType + * @return $this + */ + public function binary($content, $contentType) + { + $this->asBinary(); + + $this->pendingBinary = $content; + + $this->contentType($contentType); + + return $this; + } + + /** + * Indicate the request contains form parameters. + * + * @return $this + */ + public function asBinary() + { + return $this->bodyFormat('body'); + } + /** * Specify the body format of the request. * @@ -476,9 +511,15 @@ public function send(string $method, string $url, array $options = []) $options[$this->bodyFormat] = $this->parseMultipartBodyFormat($options[$this->bodyFormat]); } - $options[$this->bodyFormat] = array_merge( - $options[$this->bodyFormat], $this->pendingFiles - ); + if ($this->bodyFormat === 'body') { + $options[$this->bodyFormat] = $this->pendingBinary; + } + + if (is_array($options[$this->bodyFormat])) { + $options[$this->bodyFormat] = array_merge( + $options[$this->bodyFormat], $this->pendingFiles + ); + } } $this->pendingFiles = [];
false
Other
laravel
framework
e3c86b6bcecc0cfbcb5b9d5b735ad6bb3213b37d.json
Apply fixes from StyleCI (#33313)
tests/Integration/Database/DatabaseEloquentModelCustomCastingTest.php
@@ -107,9 +107,8 @@ public function testGetOriginalWithCastValueObjects() $this->assertEquals('110 Kingsbrook St.', $model->getOriginal('address')->lineOne); $this->assertEquals('117 Spencer St.', $model->address->lineOne); - $model = new TestEloquentModelWithCustomCast([ - 'address' => new Address('110 Kingsbrook St.', 'My Childhood House') + 'address' => new Address('110 Kingsbrook St.', 'My Childhood House'), ]); $model->syncOriginal(); @@ -120,7 +119,6 @@ public function testGetOriginalWithCastValueObjects() $this->assertEquals('110 Kingsbrook St.', $model->getOriginal()['address_line_one']); $this->assertEquals('117 Spencer St.', $model->address->lineOne); - $model = new TestEloquentModelWithCustomCast([ 'address' => new Address('110 Kingsbrook St.', 'My Childhood House'), ]);
false
Other
laravel
framework
d750abea34ea179e920294a462ec959decb29acc.json
Apply fixes from StyleCI (#33312)
tests/Integration/Database/DatabaseEloquentModelCustomCastingTest.php
@@ -96,7 +96,7 @@ public function testBasicCustomCasting() public function testGetOriginalWithCastValueObjects() { $model = new TestEloquentModelWithCustomCast([ - 'address' => new Address('110 Kingsbrook St.', 'My Childhood House') + 'address' => new Address('110 Kingsbrook St.', 'My Childhood House'), ]); $model->syncOriginal(); @@ -106,9 +106,8 @@ public function testGetOriginalWithCastValueObjects() $this->assertEquals('110 Kingsbrook St.', $model->getOriginal('address')->lineOne); $this->assertEquals('117 Spencer St.', $model->address->lineOne); - $model = new TestEloquentModelWithCustomCast([ - 'address' => new Address('110 Kingsbrook St.', 'My Childhood House') + 'address' => new Address('110 Kingsbrook St.', 'My Childhood House'), ]); $model->syncOriginal(); @@ -241,7 +240,7 @@ class AddressCaster implements CastsAttributes public function get($model, $key, $value, $attributes) { if (is_null($attributes['address_line_one'])) { - return null; + return; } return new Address($attributes['address_line_one'], $attributes['address_line_two']);
false
Other
laravel
framework
561d38887fd0848d1672d554dd1cd30f5044bb84.json
Apply fixes from StyleCI (#33280)
src/Illuminate/Console/Scheduling/ManagesFrequencies.php
@@ -350,7 +350,7 @@ public function twiceMonthly($first = 1, $second = 16, $time = '0:0') $days = $first.','.$second; $this->dailyAt($time); - + return $this->spliceIntoPosition(1, 0) ->spliceIntoPosition(2, 0) ->spliceIntoPosition(3, $days);
false
Other
laravel
framework
b4b72c77c003ffd9355abe815c22221a74422ecc.json
Apply fixes from StyleCI (#33269)
tests/Console/CommandTest.php
@@ -26,7 +26,6 @@ public function testCallingClassCommandResolveCommandViaApplicationResolution() $command = new class extends Command { public function handle() { - } };
true
Other
laravel
framework
b4b72c77c003ffd9355abe815c22221a74422ecc.json
Apply fixes from StyleCI (#33269)
tests/Events/EventsDispatcherTest.php
@@ -7,7 +7,6 @@ use Illuminate\Events\Dispatcher; use Mockery as m; use PHPUnit\Framework\TestCase; -use stdClass; class EventsDispatcherTest extends TestCase {
true
Other
laravel
framework
dd5e57940222878298423c6ba72f45160aca00ab.json
Add sort options to Arr::sortRecursive
src/Illuminate/Collections/Arr.php
@@ -609,20 +609,24 @@ public static function sort($array, $callback = null) * Recursively sort an array by keys and values. * * @param array $array + * @param int $options + * @param bool $descending * @return array */ - public static function sortRecursive($array) + public static function sortRecursive($array, $options = SORT_REGULAR, $descending = false) { foreach ($array as &$value) { if (is_array($value)) { - $value = static::sortRecursive($value); + $value = static::sortRecursive($value, $options, $descending); } } if (static::isAssoc($array)) { - ksort($array); + $descending ? krsort($array, $options) + : ksort($array, $options); } else { - sort($array); + $descending ? rsort($array, $options) + : sort($array, $options); } return $array;
false
Other
laravel
framework
1a312198b50bea27c7651ce2fe6a855910cd4c03.json
Add monthlyOnLastDay() to ManagesFrequencies
src/Illuminate/Console/Scheduling/ManagesFrequencies.php
@@ -337,6 +337,21 @@ public function monthlyOn($day = 1, $time = '0:0') return $this->spliceIntoPosition(3, $day); } + /** + * Schedule the event to run on the last day of the month + * + * @param string $time + * @return $this + */ + public function monthlyOnLastDay($time = '0:0') + { + $this->dailyAt($time); + + $lastDayOfMonth = now()->endOfMonth()->day; + + return $this->spliceIntoPosition(3, $lastDayOfMonth); + } + /** * Schedule the event to run twice monthly. *
false
Other
laravel
framework
16156447e4a0e47b4b46ade43731296f4b033f04.json
Apply fixes from StyleCI (#33219)
src/Illuminate/Foundation/Console/PolicyMakeCommand.php
@@ -3,7 +3,6 @@ namespace Illuminate\Foundation\Console; use Illuminate\Console\GeneratorCommand; -use Illuminate\Contracts\Auth\Access\Authorizable; use Illuminate\Support\Str; use Symfony\Component\Console\Input\InputOption; @@ -80,7 +79,7 @@ protected function userProviderModel() $guard = $this->option('guard') ?: $config->get('auth.defaults.guard'); return $config->get( - "auth.providers.".$config->get('auth.guards.'.$guard.'.provider').".model" + 'auth.providers.'.$config->get('auth.guards.'.$guard.'.provider').'.model' ); }
false
Other
laravel
framework
44879ecf372236f2446483da687f5eea7434c978.json
add theme to mailable properties (#33218) * add theme to mailable properties * Update Mailable.php Co-authored-by: Taylor Otwell <taylor@laravel.com>
src/Illuminate/Mail/Mailable.php
@@ -132,6 +132,13 @@ class Mailable implements MailableContract, Renderable */ public $callbacks = []; + /** + * The name of the theme that should be used when formatting the message. + * + * @var string|null + */ + public $theme; + /** * The name of the mailer that should send the message. *
false
Other
laravel
framework
b88df5d77d490bf76befe022b67423358b16de62.json
fix doc block
src/Illuminate/Events/Dispatcher.php
@@ -359,7 +359,7 @@ protected function addInterfaceListeners($eventName, array $listeners = []) /** * Register an event listener with the dispatcher. * - * @param \Closure|string $listener + * @param \Closure|string|array $listener * @param bool $wildcard * @return \Closure */
false
Other
laravel
framework
b80ddf458bd08de375d83b716a1309ed927197aa.json
handle array callbacks
src/Illuminate/Events/Dispatcher.php
@@ -365,7 +365,7 @@ protected function addInterfaceListeners($eventName, array $listeners = []) */ public function makeListener($listener, $wildcard = false) { - if (is_string($listener)) { + if (is_string($listener) || is_array($listener)) { return $this->createClassListener($listener, $wildcard); } @@ -381,7 +381,7 @@ public function makeListener($listener, $wildcard = false) /** * Create a class based listener using the IoC container. * - * @param string $listener + * @param string|array $listener * @param bool $wildcard * @return \Closure */ @@ -401,12 +401,12 @@ public function createClassListener($listener, $wildcard = false) /** * Create the class based event callable. * - * @param string $listener + * @param string|array $listener * @return callable */ protected function createClassCallable($listener) { - [$class, $method] = $this->parseClassCallable($listener); + [$class, $method] = is_array($listener) ? $listener : $this->parseClassCallable($listener); if ($this->handlerShouldBeQueued($class)) { return $this->createQueuedHandlerCallable($class, $method);
true
Other
laravel
framework
b80ddf458bd08de375d83b716a1309ed927197aa.json
handle array callbacks
tests/Events/EventsDispatcherTest.php
@@ -327,6 +327,16 @@ public function testClassesWork() $this->assertSame('baz', $_SERVER['__event.test']); } + public function testArrayCallbackListenersAreHandled() + { + unset($_SERVER['__event.ExampleListener']); + $d = new Dispatcher; + $d->listen(ExampleEvent::class, [ExampleListener::class, 'hear']); + $d->dispatch(new ExampleEvent); + + $this->assertTrue($_SERVER['__event.ExampleListener']); + } + public function testEventClassesArePayload() { unset($_SERVER['__event.test']); @@ -390,3 +400,11 @@ class AnotherEvent implements SomeEventInterface { // } + +class ExampleListener +{ + public function hear() + { + $_SERVER['__event.ExampleListener'] = true; + } +}
true
Other
laravel
framework
929d326d5a75facb66c56a208469793846da9935.json
improve event subscribers
src/Illuminate/Events/Dispatcher.php
@@ -161,7 +161,15 @@ public function subscribe($subscriber) { $subscriber = $this->resolveSubscriber($subscriber); - $subscriber->subscribe($this); + $events = $subscriber->subscribe($this); + + if (is_array($events)) { + foreach ($events as $event => $listeners) { + foreach (array_unique($listeners) as $listener) { + $this->listen($event, $listener); + } + } + } } /**
false
Other
laravel
framework
6cbf5c9e220a82fce5e1dc1740fdbcdb0ce47717.json
Improve static analyse (#33159)
src/Illuminate/Database/Query/Builder.php
@@ -242,7 +242,7 @@ public function select($columns = ['*']) /** * Add a subselect expression to the query. * - * @param \Closure|\Illuminate\Database\Query\Builder|string $query + * @param \Closure|$this|string $query * @param string $as * @return \Illuminate\Database\Query\Builder|static *
false
Other
laravel
framework
fefb64ec0de7bf49fb416ac4b022cc7ff901fdd9.json
Fix misleading docblocks (#33111)
src/Illuminate/Collections/EnumeratesValues.php
@@ -518,7 +518,7 @@ public function where($key, $operator = null, $value = null) } /** - * Filter items where the given key is not null. + * Filter items where the value for the given key is null. * * @param string|null $key * @return static @@ -529,7 +529,7 @@ public function whereNull($key = null) } /** - * Filter items where the given key is null. + * Filter items where the value for the given key is not null. * * @param string|null $key * @return static
false
Other
laravel
framework
49f542bbc10afa02fc947eb99d96b916776bb522.json
Fix indention for Blade component inline (#33102)
src/Illuminate/Foundation/Console/ComponentMakeCommand.php
@@ -80,7 +80,7 @@ protected function buildClass($name) if ($this->option('inline')) { return str_replace( 'DummyView', - "<<<'blade'\n<div>\n ".Inspiring::quote()."\n</div>\nblade", + "<<<'blade'\n <div>\n ".Inspiring::quote()."\n </div>\n blade", parent::buildClass($name) ); }
false
Other
laravel
framework
d3e486cc588ae4b30b3f3bfb49a5a455530849d6.json
Apply fixes from StyleCI (#33092)
tests/Mail/MailManagerTest.php
@@ -2,7 +2,6 @@ namespace Illuminate\Tests\Mail; -use Illuminate\Mail\MailManager; use Orchestra\Testbench\TestCase; class MailManagerTest extends TestCase
false
Other
laravel
framework
ac5ee4f4cacba0e79849c9d0de922f6e18b0725f.json
remove code that is in 8.x
src/Illuminate/Mail/MailManager.php
@@ -440,25 +440,6 @@ public function setDefaultDriver(string $name) $this->app['config']['mail.default'] = $name; } - /** - * Forget a mailer instance by name. - * - * @param array|string|null $name - * @return void - */ - public function forgetMailer($name = null) - { - $name = $name ?? $this->getDefaultDriver(); - - foreach ((array) $name as $mailerName) { - if (isset($this->mailers[$mailerName])) { - unset($this->mailers[$mailerName]); - } - } - - return $this; - } - /** * Register a custom transport creator Closure. *
true
Other
laravel
framework
ac5ee4f4cacba0e79849c9d0de922f6e18b0725f.json
remove code that is in 8.x
tests/Mail/MailManagerTest.php
@@ -33,30 +33,4 @@ public function emptyTransportConfigDataProvider() [null], [''], [' '], ]; } - - public function testForgetMailer() - { - $this->app['config']->set('mail.mailers.custom_smtp', [ - 'transport' => 'smtp', - 'host' => 'example.com', - 'port' => '25', - 'encryption' => 'tls', - 'username' => 'username', - 'password' => 'password', - 'timeout' => 10, - ]); - - /** @var MailManager $mailManager */ - $mailManager = $this->app['mail.manager']; - $mailManager->mailer('custom_smtp'); - - $mailersProperty = new \ReflectionProperty($mailManager, 'mailers'); - $mailersProperty->setAccessible(true); - - $this->assertArrayHasKey('custom_smtp', $mailersProperty->getValue($mailManager), 'Mailer must exist in the $mailers-property'); - - $mailManager->forgetMailer('custom_smtp'); - - $this->assertArrayNotHasKey('custom_smtp', $mailersProperty->getValue($mailManager), 'Mailer must not exist in the $mailers-property as it must have been removed with MailManager::forgetMailer()'); - } }
true
Other
laravel
framework
88c93eb59568d228736fa96b52bac51f1c2116cc.json
Apply fixes from StyleCI (#33091)
tests/Mail/MailManagerTest.php
@@ -37,26 +37,26 @@ public function emptyTransportConfigDataProvider() public function testForgetMailer() { $this->app['config']->set('mail.mailers.custom_smtp', [ - 'transport' => "smtp", - 'host' => "example.com", - 'port' => "25", - 'encryption' => "tls", - 'username' => "username", - 'password' => "password", + 'transport' => 'smtp', + 'host' => 'example.com', + 'port' => '25', + 'encryption' => 'tls', + 'username' => 'username', + 'password' => 'password', 'timeout' => 10, ]); /** @var MailManager $mailManager */ $mailManager = $this->app['mail.manager']; - $mailManager->mailer("custom_smtp"); + $mailManager->mailer('custom_smtp'); $mailersProperty = new \ReflectionProperty($mailManager, 'mailers'); $mailersProperty->setAccessible(true); - $this->assertArrayHasKey("custom_smtp", $mailersProperty->getValue($mailManager), "Mailer must exist in the \$mailers-property"); + $this->assertArrayHasKey('custom_smtp', $mailersProperty->getValue($mailManager), 'Mailer must exist in the $mailers-property'); - $mailManager->forgetMailer("custom_smtp"); + $mailManager->forgetMailer('custom_smtp'); - $this->assertArrayNotHasKey("custom_smtp", $mailersProperty->getValue($mailManager), "Mailer must not exist in the \$mailers-property as it must have been removed with MailManager::forgetMailer()"); + $this->assertArrayNotHasKey('custom_smtp', $mailersProperty->getValue($mailManager), 'Mailer must not exist in the $mailers-property as it must have been removed with MailManager::forgetMailer()'); } }
false
Other
laravel
framework
469b7719a8dca40841a74f59f2e9f30f01d3a106.json
Apply fixes from StyleCI (#33078)
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphPivot; use Illuminate\Support\Arr; class MorphToMany extends BelongsToMany
false
Other
laravel
framework
9e5226ecc28f960cba1bd38b6d1d82a52e072dc3.json
Apply fixes from StyleCI (#33077)
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -4,7 +4,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphPivot; use Illuminate\Support\Arr; class MorphToMany extends BelongsToMany
false
Other
laravel
framework
f9112ad06126d8e265df4b66560e92d924c823e8.json
Add test for withBearerToken method
tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php
@@ -14,6 +14,13 @@ public function testFromSetsHeaderAndSession() $this->assertSame('previous/url', $this->app['session']->previousUrl()); } + public function testBearerTokenSetsHeader() + { + $this->withBearerToken('foobar'); + + $this->assertSame('Bearer foobar', $this->defaultHeaders['Authorization']); + } + public function testWithoutAndWithMiddleware() { $this->assertFalse($this->app->has('middleware.disable'));
false
Other
laravel
framework
9897e3f77b33ee0546509ba73e48aeaa6f5a6c95.json
Add withBearerToken method
src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
@@ -92,6 +92,19 @@ public function flushHeaders() return $this; } + /** + * Add a bearer token to the request headers. + * + * @param string $value + * @return $this + */ + public function withBearerToken(string $value) + { + $this->defaultHeaders['Authorization'] = 'Bearer '.$value; + + return $this; + } + /** * Define a set of server variables to be sent with the requests. *
false
Other
laravel
framework
aa29193a2f60dd4af3d4824a7582d526dc8bd31a.json
Apply fixes from StyleCI (#33074)
tests/Integration/Support/AuthFacadeTest.php
@@ -3,8 +3,8 @@ namespace Illuminate\Tests\Integration\Support; use Illuminate\Support\Facades\Auth; -use RuntimeException; use Orchestra\Testbench\TestCase; +use RuntimeException; class AuthFacadeTest extends TestCase {
false
Other
laravel
framework
b0fb1ba07a248bc63a092b608746f681db4d54f2.json
Apply fixes from StyleCI (#33073)
tests/Integration/Support/AuthFacadeTest.php
@@ -3,8 +3,8 @@ namespace Illuminate\Tests\Integration\Support; use Illuminate\Support\Facades\Auth; -use RuntimeException; use Orchestra\Testbench\TestCase; +use RuntimeException; class AuthFacadeTest extends TestCase {
false
Other
laravel
framework
f54b58433d42a30754719895b653116d20c800f2.json
Replace deprecated class
src/Illuminate/Redis/Connections/PhpRedisConnection.php
@@ -3,8 +3,8 @@ namespace Illuminate\Redis\Connections; use Closure; +use Illuminate\Collections\Arr; use Illuminate\Contracts\Redis\Connection as ConnectionContract; -use Illuminate\Support\Arr; use Illuminate\Support\Str; use Redis; use RedisCluster;
false
Other
laravel
framework
941159162cdeb229e00e642a48d18d75ab8b1e56.json
Add stability to Composer Cache I'm not 100 sure on this one but I think the Cache dependencies key should include the stability (prefer-lowest or prefer-stable). Otherwise, some of the dependencies in the prefer-lowest build seem to be re-downloaded every time - unless the lowest version matches the stable one. If I'm correct this should increase the speed of every build.
.github/workflows/tests.yml
@@ -40,7 +40,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.composer/cache/files - key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + key: dependencies-php-${{ matrix.php }}-${{ matrix.stability }}-composer-${{ hashFiles('composer.json') }} - name: Setup PHP uses: shivammathur/setup-php@v2
false
Other
laravel
framework
8b33dcd1bbafed763c99bc3b8af4acf6b0ac08cf.json
make dependency optional
src/Illuminate/View/Engines/CompilerEngine.php
@@ -27,12 +27,12 @@ class CompilerEngine extends PhpEngine * Create a new compiler engine instance. * * @param \Illuminate\View\Compilers\CompilerInterface $compiler - * @param \Illuminate\Filesystem\Filesystem $files + * @param \Illuminate\Filesystem\Filesystem|null $files * @return void */ - public function __construct(CompilerInterface $compiler, Filesystem $files) + public function __construct(CompilerInterface $compiler, Filesystem $files = null) { - parent::__construct($files); + parent::__construct($files ?: new Filesystem); $this->compiler = $compiler; }
false
Other
laravel
framework
b7284daaa81d374fd4a4f6f23b0e3a2ad17797d2.json
Add putFile doc block to storage facade (#33036)
src/Illuminate/Support/Facades/Storage.php
@@ -10,6 +10,7 @@ * @method static string get(string $path) * @method static resource|null readStream(string $path) * @method static bool put(string $path, string|resource $contents, mixed $options = []) + * @method static string|false putFile(string $path, \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $file, mixed $options = []) * @method static bool writeStream(string $path, resource $resource, array $options = []) * @method static string getVisibility(string $path) * @method static bool setVisibility(string $path, string $visibility)
false
Other
laravel
framework
50efe099b59e75563298deb992017b4cabfb021d.json
add addIf method to message bag
src/Illuminate/Support/MessageBag.php
@@ -66,6 +66,19 @@ public function add($key, $message) return $this; } + /** + * Add a message to the message bag if the given conditional is "true". + * + * @param bool $boolean + * @param string $key + * @param string $message + * @return $this + */ + public function addIf($boolean, $key, $message) + { + return $boolean ? $this->add($key, $message) : $this; + } + /** * Determine if a key and message combination already exists. *
false
Other
laravel
framework
a904322413bcf3abf2f8945192157e42714d50ce.json
Call message method once only
src/Illuminate/Validation/Validator.php
@@ -697,7 +697,7 @@ protected function validateUsingCustomRule($attribute, $value, $rule) if (! $rule->passes($attribute, $value)) { $this->failedRules[$attribute][get_class($rule)] = []; - $messages = $rule->message() ? (array) $rule->message() : [get_class($rule)]; + $messages = ($messages = $rule->message()) ? (array) $messages : [get_class($rule)]; foreach ($messages as $message) { $this->messages->add($attribute, $this->makeReplacements(
false
Other
laravel
framework
656d0af4577d36770831db97df56305ffd65421b.json
Apply fixes from StyleCI (#33011)
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -123,7 +123,7 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, protected function getCurrentlyAttachedPivots() { return parent::getCurrentlyAttachedPivots()->map(function ($record) { - return $record->setMorphType($this->morphType) + return $record->setMorphType($this->morphType) ->setMorphClass($this->morphClass); }); }
false
Other
laravel
framework
6cb375d0d7a4090b68e53328bc481621035d232b.json
Apply fixes from StyleCI (#33010)
src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -123,7 +123,7 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, protected function getCurrentlyAttachedPivots() { return parent::getCurrentlyAttachedPivots()->map(function ($record) { - return $record->setMorphType($this->morphType) + return $record->setMorphType($this->morphType) ->setMorphClass($this->morphClass); }); }
false
Other
laravel
framework
00e9ed76483ea6ad1264676e7b1095b23e16a433.json
use array values first
src/Illuminate/Database/Eloquent/Collection.php
@@ -566,7 +566,7 @@ public function getQueueableRelations() if (count($relations) === 0 || $relations === [[]]) { return []; } elseif (count($relations) === 1) { - return $relations[0]; + return array_values($relations)[0]; } else { return array_intersect(...$relations); }
false
Other
laravel
framework
f66c103a9457328f0984a010c27afdf889b3c562.json
add dynamic component
src/Illuminate/View/DynamicComponent.php
@@ -0,0 +1,181 @@ +<?php + +namespace Illuminate\View; + +use Illuminate\Container\Container; +use Illuminate\Support\Str; +use Illuminate\View\Compilers\ComponentTagCompiler; + +class DynamicComponent extends Component +{ + /** + * The name of the component. + * + * @var string + */ + public $component; + + /** + * The component tag compiler instance. + * + * @var \Illuminate\View\Compilers\BladeTagCompiler + */ + protected static $compiler; + + /** + * The cached component classes. + * + * @var array + */ + protected static $componentClasses = []; + + /** + * The cached binding keys for component classes. + * + * @var array + */ + protected static $bindings = []; + + /** + * Create a new component instance. + * + * @return void + */ + public function __construct(string $component) + { + $this->component = $component; + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\View\View|string + */ + public function render() + { + $template = <<<'EOF' +<?php extract(collect($attributes->getAttributes())->mapWithKeys(function ($value, $key) { return [Illuminate\Support\Str::camel($key) => $value]; })->all(), EXTR_SKIP); ?> +{{ props }} +<x-{{ component }} {{ bindings }} {{ attributes }}> +{{ slots }} +{{ defaultSlot }} +</x-{{ component }}> +EOF; + + return function ($data) use ($template) { + $bindings = $this->bindings($class = $this->classForComponent()); + + return str_replace( + [ + '{{ component }}', + '{{ props }}', + '{{ bindings }}', + '{{ attributes }}', + '{{ slots }}', + '{{ defaultSlot }}', + ], + [ + $this->component, + $this->compileProps($bindings), + $this->compileBindings($bindings), + class_exists($class) ? '{{ $attributes }}' : '', + $this->compileSlots($data['__laravel_slots']), + '{{ $slot ?? "" }}', + ], + $template + ); + }; + } + + /** + * Compile the @props directive for the component. + * + * @param array $bindings + * @return string + */ + protected function compileProps(array $bindings) + { + if (empty($bindings)) { + return ''; + } + + return '@props('.'[\''.implode('\',\'', collect($bindings)->map(function ($dataKey) { + return Str::camel($dataKey); + })->all()).'\']'.')'; + } + + /** + * Compile the bindings for the component. + * + * @param array $bindings + * @return string + */ + protected function compileBindings(array $bindings) + { + return collect($bindings)->map(function ($key) { + return ':'.$key.'="$'.Str::camel($key).'"'; + })->implode(' '); + } + + /** + * Compile the slots for the component. + * + * @param array $slots + * @return string + */ + protected function compileSlots(array $slots) + { + return collect($slots)->map(function ($slot, $name) { + return $name === '__default' ? null : '<x-slot name="'.$name.'">{{ $'.$name.' }}</x-slot>'; + })->filter()->implode(PHP_EOL); + } + + /** + * Get the class for the current component. + * + * @return string + */ + protected function classForComponent() + { + if (isset(static::$componentClasses[$this->component])) { + return static::$componentClasses[$this->component]; + } + + return static::$componentClasses[$this->component] = + $this->compiler()->componentClass($this->component); + } + + /** + * Get the names of the variables that should be bound to the component. + * + * @param string $class + * @return array + */ + protected function bindings(string $class) + { + if (! isset(static::$bindings[$class])) { + [$data, $attributes] = $this->compiler()->partitionDataAndAttributes($class, $this->attributes->getAttributes()); + + static::$bindings[$class] = array_keys($data->all()); + } + + return static::$bindings[$class]; + } + + /** + * Get an instance of the Blade tag compiler. + * + * @return \Illuminate\View\Compilers\ComponentTagCompiler + */ + protected function compiler() + { + if (! static::$compiler) { + static::$compiler = new ComponentTagCompiler( + Container::getInstance()->make('blade.compiler')->getClassComponentAliases(), + Container::getInstance()->make('blade.compiler') + ); + } + + return static::$compiler; + } +}
true
Other
laravel
framework
f66c103a9457328f0984a010c27afdf889b3c562.json
add dynamic component
src/Illuminate/View/ViewServiceProvider.php
@@ -88,7 +88,9 @@ public function registerViewFinder() public function registerBladeCompiler() { $this->app->singleton('blade.compiler', function ($app) { - return new BladeCompiler($app['files'], $app['config']['view.compiled']); + return tap(new BladeCompiler($app['files'], $app['config']['view.compiled']), function ($blade) { + $blade->component('dynamic-component', DynamicComponent::class); + }); }); }
true
Other
laravel
framework
f66c103a9457328f0984a010c27afdf889b3c562.json
add dynamic component
tests/Integration/View/BladeTest.php
@@ -0,0 +1,42 @@ +<?php + +namespace Illuminate\Tests\Integration\View; + +use Illuminate\Support\Facades\View; +use Orchestra\Testbench\TestCase; + +/** + * @group integration + */ +class BladeTest extends TestCase +{ + public function test_basic_blade_rendering() + { + $view = View::make('hello', ['name' => 'Taylor'])->render(); + + $this->assertEquals('Hello Taylor', trim($view)); + } + + public function test_rendering_a_component() + { + $view = View::make('uses-panel', ['name' => 'Taylor'])->render(); + + $this->assertEquals('<div class="ml-2"> + Hello Taylor +</div>', trim($view)); + } + + public function test_rendering_a_dynamic_component() + { + $view = View::make('uses-panel-dynamically', ['name' => 'Taylor'])->render(); + + $this->assertEquals('<div class="ml-2"> + Hello Taylor +</div>', trim($view)); + } + + protected function getEnvironmentSetUp($app) + { + $app['config']->set('view.paths', [__DIR__.'/templates']); + } +}
true
Other
laravel
framework
f66c103a9457328f0984a010c27afdf889b3c562.json
add dynamic component
tests/Integration/View/templates/components/panel.blade.php
@@ -0,0 +1,5 @@ +@props(['name']) + +<div {{ $attributes }}> + Hello {{ $name }} +</div>
true
Other
laravel
framework
f66c103a9457328f0984a010c27afdf889b3c562.json
add dynamic component
tests/Integration/View/templates/hello.blade.php
@@ -0,0 +1 @@ +Hello {{ $name }}
true
Other
laravel
framework
f66c103a9457328f0984a010c27afdf889b3c562.json
add dynamic component
tests/Integration/View/templates/uses-panel-dynamically.blade.php
@@ -0,0 +1,3 @@ +<x-dynamic-component component="panel" class="ml-2" :name="$name"> + Panel contents +</x-dynamic-component>
true
Other
laravel
framework
f66c103a9457328f0984a010c27afdf889b3c562.json
add dynamic component
tests/Integration/View/templates/uses-panel.blade.php
@@ -0,0 +1,3 @@ +<x-panel class="ml-2" :name="$name"> + Panel contents +</x-panel>
true
Other
laravel
framework
2d52abc33865cc29b8e92a41ed7ad9a2b5383a11.json
fix custom class cast with dates
src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
@@ -231,6 +231,11 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt $attributes[$key] = $attributes[$key]->format(explode(':', $value, 2)[1]); } + if ($attributes[$key] && $attributes[$key] instanceof DateTimeInterface && + $this->isClassCastable($key)) { + $attributes[$key] = $this->serializeDate($attributes[$key]); + } + if ($attributes[$key] instanceof Arrayable) { $attributes[$key] = $attributes[$key]->toArray(); }
false
Other
laravel
framework
cfed25302fd0ed945541cbffa409785c8a1e2c85.json
Fix Filesystem tests failing in Windows (#32975) * testPutWithStreamInterface() leaves an fopen() stream resource that must be explicitly closed before temp directories can be deleted in Windows. * testReplaceStoresFiles() fails for multiple reasons under Windows. chmod() / umask() write permissions don't change and symlink() attempts fail in most Windows environments.
tests/Filesystem/FilesystemAdapterTest.php
@@ -236,8 +236,10 @@ public function testPutWithStreamInterface() $spy = m::spy($this->filesystem); $filesystemAdapter = new FilesystemAdapter($spy); - $stream = new Stream(fopen($this->tempDir.'/foo.txt', 'r')); - $filesystemAdapter->put('bar.txt', $stream); + $stream = fopen($this->tempDir.'/foo.txt', 'r'); + $guzzleStream = new Stream($stream); + $filesystemAdapter->put('bar.txt', $guzzleStream); + fclose($stream); $spy->shouldHaveReceived('putStream'); $this->assertEquals('some-data', $filesystemAdapter->get('bar.txt'));
true
Other
laravel
framework
cfed25302fd0ed945541cbffa409785c8a1e2c85.json
Fix Filesystem tests failing in Windows (#32975) * testPutWithStreamInterface() leaves an fopen() stream resource that must be explicitly closed before temp directories can be deleted in Windows. * testReplaceStoresFiles() fails for multiple reasons under Windows. chmod() / umask() write permissions don't change and symlink() attempts fail in most Windows environments.
tests/Filesystem/FilesystemTest.php
@@ -43,8 +43,22 @@ public function testPutStoresFiles() $this->assertStringEqualsFile($this->tempDir.'/file.txt', 'Hello World'); } - public function testReplaceStoresFiles() + public function testReplaceCreatesFile() { + $tempFile = "{$this->tempDir}/file.txt"; + + $filesystem = new Filesystem; + + $filesystem->replace($tempFile, 'Hello World'); + $this->assertStringEqualsFile($tempFile, 'Hello World'); + } + + public function testReplaceWhenUnixSymlinkExists() + { + if (windows_os()) { + $this->markTestSkipped('Skipping since operating system is Windows'); + } + $tempFile = "{$this->tempDir}/file.txt"; $symlinkDir = "{$this->tempDir}/symlink_dir"; $symlink = "{$symlinkDir}/symlink.txt";
true
Other
laravel
framework
c59cffa7825498e1d419d8c86cd8527520f718cb.json
fix behavior of oneachside = 1 with paginator
src/Illuminate/Pagination/UrlWindow.php
@@ -73,7 +73,7 @@ protected function getSmallSlider() */ protected function getUrlSlider($onEachSide) { - $window = $onEachSide * 2; + $window = $onEachSide + 4; if (! $this->hasPages()) { return ['first' => null, 'slider' => null, 'last' => null]; @@ -83,14 +83,14 @@ protected function getUrlSlider($onEachSide) // just render the beginning of the page range, followed by the last 2 of the // links in this list, since we will not have room to create a full slider. if ($this->currentPage() <= $window) { - return $this->getSliderTooCloseToBeginning($window); + return $this->getSliderTooCloseToBeginning($window, $onEachSide); } // If the current page is close to the ending of the page range we will just get // this first couple pages, followed by a larger window of these ending pages // since we're too close to the end of the list to create a full on slider. elseif ($this->currentPage() > ($this->lastPage() - $window)) { - return $this->getSliderTooCloseToEnding($window); + return $this->getSliderTooCloseToEnding($window, $onEachSide); } // If we have enough room on both sides of the current page to build a slider we @@ -103,12 +103,13 @@ protected function getUrlSlider($onEachSide) * Get the slider of URLs when too close to beginning of window. * * @param int $window + * @param int $onEachSide * @return array */ - protected function getSliderTooCloseToBeginning($window) + protected function getSliderTooCloseToBeginning($window, $onEachSide) { return [ - 'first' => $this->paginator->getUrlRange(1, $window + 2), + 'first' => $this->paginator->getUrlRange(1, $window + $onEachSide), 'slider' => null, 'last' => $this->getFinish(), ]; @@ -118,12 +119,13 @@ protected function getSliderTooCloseToBeginning($window) * Get the slider of URLs when too close to ending of window. * * @param int $window + * @param int $onEachSide * @return array */ - protected function getSliderTooCloseToEnding($window) + protected function getSliderTooCloseToEnding($window, $onEachSide) { $last = $this->paginator->getUrlRange( - $this->lastPage() - ($window + 2), + $this->lastPage() - ($window + ($onEachSide - 1)), $this->lastPage() );
true
Other
laravel
framework
c59cffa7825498e1d419d8c86cd8527520f718cb.json
fix behavior of oneachside = 1 with paginator
tests/Pagination/UrlWindowTest.php
@@ -25,28 +25,31 @@ public function testPresenterCanGetAUrlRangeForASmallNumberOfUrls() public function testPresenterCanGetAUrlRangeForAWindowOfLinks() { $array = []; - for ($i = 1; $i <= 13; $i++) { + for ($i = 1; $i <= 20; $i++) { $array[$i] = 'item'.$i; } - $p = new LengthAwarePaginator($array, count($array), 1, 7); + $p = new LengthAwarePaginator($array, count($array), 1, 12); $window = new UrlWindow($p); $slider = []; - for ($i = 4; $i <= 10; $i++) { + for ($i = 9; $i <= 15; $i++) { $slider[$i] = '/?page='.$i; } - $this->assertEquals(['first' => [1 => '/?page=1', 2 => '/?page=2'], 'slider' => $slider, 'last' => [12 => '/?page=12', 13 => '/?page=13']], $window->get()); + $this->assertEquals(['first' => [1 => '/?page=1', 2 => '/?page=2'], 'slider' => $slider, 'last' => [19 => '/?page=19', 20 => '/?page=20']], $window->get()); /* * Test Being Near The End Of The List */ - $p = new LengthAwarePaginator($array, count($array), 1, 8); + $array = []; + for ($i = 1; $i <= 13; $i++) { + $array[$i] = 'item'.$i; + } + $p = new LengthAwarePaginator($array, count($array), 1, 10); $window = new UrlWindow($p); $last = []; - for ($i = 5; $i <= 13; $i++) { + for ($i = 4; $i <= 13; $i++) { $last[$i] = '/?page='.$i; } - $this->assertEquals(['first' => [1 => '/?page=1', 2 => '/?page=2'], 'slider' => null, 'last' => $last], $window->get()); }
true
Other
laravel
framework
7ebd21193df520d78269d7abd740537a2fae889e.json
fix route list for excluded middleware
src/Illuminate/Foundation/Console/RouteListCommand.php
@@ -170,7 +170,7 @@ protected function displayRoutes(array $routes) */ protected function getMiddleware($route) { - return collect($route->gatherMiddleware())->map(function ($middleware) { + return collect($this->router->gatherRouteMiddleware($route))->map(function ($middleware) { return $middleware instanceof Closure ? 'Closure' : $middleware; })->implode(','); }
false
Other
laravel
framework
bf1eef400951dcee04839a9ab7c15da1a807f89c.json
add useTailwind method
src/Illuminate/Pagination/AbstractPaginator.php
@@ -552,6 +552,17 @@ public static function defaultSimpleView($view) static::$defaultSimpleView = $view; } + /** + * Indicate that Tailwind styling should be used for generated links. + * + * @return void + */ + public static function useTailwind() + { + static::defaultView('pagination::tailwind'); + static::defaultSimpleView('pagination::simple-tailwind'); + } + /** * Indicate that Bootstrap 3 styling should be used for generated links. *
false
Other
laravel
framework
4d66ce89c8865ecec0e079f41bb9ea98ce7f7255.json
Apply fixes from StyleCI (#32890)
src/Illuminate/Queue/WorkerOptions.php
@@ -73,7 +73,7 @@ class WorkerOptions * @param bool $stopWhenEmpty * @return void */ - public function __construct($name= 'default', $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false, $stopWhenEmpty = false) + public function __construct($name = 'default', $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false, $stopWhenEmpty = false) { $this->name = $name; $this->backoff = $backoff;
false
Other
laravel
framework
6ad92bf9a8552a7759a7757cf821b01969baf0b6.json
fix bug with request rebind and url defaults
src/Illuminate/Routing/UrlGenerator.php
@@ -699,7 +699,14 @@ public function setRequest(Request $request) $this->cachedRoot = null; $this->cachedScheme = null; - $this->routeGenerator = null; + + tap(optional($this->routeGenerator)->defaultParameters ?: [], function ($defaults) { + $this->routeGenerator = null; + + if (! empty($defaults)) { + $this->defaults($defaults); + } + }); } /**
false
Other
laravel
framework
b3453e8b18564610bcec44d2d9b458c6a1e8dcb2.json
fix doc block
src/Illuminate/Database/Console/Factories/stubs/factory.stub
@@ -18,7 +18,7 @@ class {{ model }}Factory extends Factory /** * Define the model's default state. * - * @return static + * @return array */ public function definition() {
false
Other
laravel
framework
73060db7c5541fadf5e4f2874a89d18621d705a3.json
fix wrong component generation
src/Illuminate/Foundation/Console/ComponentMakeCommand.php
@@ -99,7 +99,9 @@ protected function buildClass($name) */ protected function getView() { - return collect(explode('/', $this->argument('name'))) + $name = str_replace('\\', '/', $this->argument('name')); + + return collect(explode('/', $name)) ->map(function ($part) { return Str::kebab($part); })
false
Other
laravel
framework
fc779336bbf2559377d3409cf20f6b2db191d9fd.json
Fix eager capture + syntactic sugar (#32847)
src/Illuminate/Database/Schema/ForeignIdColumnDefinition.php
@@ -36,7 +36,7 @@ public function __construct(Blueprint $blueprint, $attributes = []) */ public function constrained($table = null, $column = 'id') { - return $this->references($column)->on($table ?: Str::plural(Str::before($this->name, '_'.$column))); + return $this->references($column)->on($table ?? Str::plural(Str::beforeLast($this->name, '_'.$column))); } /**
true
Other
laravel
framework
fc779336bbf2559377d3409cf20f6b2db191d9fd.json
Fix eager capture + syntactic sugar (#32847)
tests/Database/DatabaseMySqlSchemaGrammarTest.php
@@ -432,15 +432,17 @@ public function testAddingForeignID() $blueprint = new Blueprint('users'); $foreignId = $blueprint->foreignId('foo'); $blueprint->foreignId('company_id')->constrained(); + $blueprint->foreignId('laravel_idea_id')->constrained(); $blueprint->foreignId('team_id')->references('id')->on('teams'); $blueprint->foreignId('team_column_id')->constrained('teams'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertInstanceOf(ForeignIdColumnDefinition::class, $foreignId); $this->assertSame([ - 'alter table `users` add `foo` bigint unsigned not null, add `company_id` bigint unsigned not null, add `team_id` bigint unsigned not null, add `team_column_id` bigint unsigned not null', + 'alter table `users` add `foo` bigint unsigned not null, add `company_id` bigint unsigned not null, add `laravel_idea_id` bigint unsigned not null, add `team_id` bigint unsigned not null, add `team_column_id` bigint unsigned not null', 'alter table `users` add constraint `users_company_id_foreign` foreign key (`company_id`) references `companies` (`id`)', + 'alter table `users` add constraint `users_laravel_idea_id_foreign` foreign key (`laravel_idea_id`) references `laravel_ideas` (`id`)', 'alter table `users` add constraint `users_team_id_foreign` foreign key (`team_id`) references `teams` (`id`)', 'alter table `users` add constraint `users_team_column_id_foreign` foreign key (`team_column_id`) references `teams` (`id`)', ], $statements);
true
Other
laravel
framework
fc779336bbf2559377d3409cf20f6b2db191d9fd.json
Fix eager capture + syntactic sugar (#32847)
tests/Database/DatabasePostgresSchemaGrammarTest.php
@@ -330,15 +330,17 @@ public function testAddingForeignID() $blueprint = new Blueprint('users'); $foreignId = $blueprint->foreignId('foo'); $blueprint->foreignId('company_id')->constrained(); + $blueprint->foreignId('laravel_idea_id')->constrained(); $blueprint->foreignId('team_id')->references('id')->on('teams'); $blueprint->foreignId('team_column_id')->constrained('teams'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertInstanceOf(ForeignIdColumnDefinition::class, $foreignId); $this->assertSame([ - 'alter table "users" add column "foo" bigint not null, add column "company_id" bigint not null, add column "team_id" bigint not null, add column "team_column_id" bigint not null', + 'alter table "users" add column "foo" bigint not null, add column "company_id" bigint not null, add column "laravel_idea_id" bigint not null, add column "team_id" bigint not null, add column "team_column_id" bigint not null', 'alter table "users" add constraint "users_company_id_foreign" foreign key ("company_id") references "companies" ("id")', + 'alter table "users" add constraint "users_laravel_idea_id_foreign" foreign key ("laravel_idea_id") references "laravel_ideas" ("id")', 'alter table "users" add constraint "users_team_id_foreign" foreign key ("team_id") references "teams" ("id")', 'alter table "users" add constraint "users_team_column_id_foreign" foreign key ("team_column_id") references "teams" ("id")', ], $statements);
true
Other
laravel
framework
fc779336bbf2559377d3409cf20f6b2db191d9fd.json
Fix eager capture + syntactic sugar (#32847)
tests/Database/DatabaseSQLiteSchemaGrammarTest.php
@@ -314,6 +314,7 @@ public function testAddingForeignID() $blueprint = new Blueprint('users'); $foreignId = $blueprint->foreignId('foo'); $blueprint->foreignId('company_id')->constrained(); + $blueprint->foreignId('laravel_idea_id')->constrained(); $blueprint->foreignId('team_id')->references('id')->on('teams'); $blueprint->foreignId('team_column_id')->constrained('teams'); @@ -323,6 +324,7 @@ public function testAddingForeignID() $this->assertSame([ 'alter table "users" add column "foo" integer not null', 'alter table "users" add column "company_id" integer not null', + 'alter table "users" add column "laravel_idea_id" integer not null', 'alter table "users" add column "team_id" integer not null', 'alter table "users" add column "team_column_id" integer not null', ], $statements);
true
Other
laravel
framework
fc779336bbf2559377d3409cf20f6b2db191d9fd.json
Fix eager capture + syntactic sugar (#32847)
tests/Database/DatabaseSqlServerSchemaGrammarTest.php
@@ -339,15 +339,17 @@ public function testAddingForeignID() $blueprint = new Blueprint('users'); $foreignId = $blueprint->foreignId('foo'); $blueprint->foreignId('company_id')->constrained(); + $blueprint->foreignId('laravel_idea_id')->constrained(); $blueprint->foreignId('team_id')->references('id')->on('teams'); $blueprint->foreignId('team_column_id')->constrained('teams'); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertInstanceOf(ForeignIdColumnDefinition::class, $foreignId); $this->assertSame([ - 'alter table "users" add "foo" bigint not null, "company_id" bigint not null, "team_id" bigint not null, "team_column_id" bigint not null', + 'alter table "users" add "foo" bigint not null, "company_id" bigint not null, "laravel_idea_id" bigint not null, "team_id" bigint not null, "team_column_id" bigint not null', 'alter table "users" add constraint "users_company_id_foreign" foreign key ("company_id") references "companies" ("id")', + 'alter table "users" add constraint "users_laravel_idea_id_foreign" foreign key ("laravel_idea_id") references "laravel_ideas" ("id")', 'alter table "users" add constraint "users_team_id_foreign" foreign key ("team_id") references "teams" ("id")', 'alter table "users" add constraint "users_team_column_id_foreign" foreign key ("team_column_id") references "teams" ("id")', ], $statements);
true
Other
laravel
framework
aabd1a9edc36052fddb01931e9bfe09a0e260779.json
Add tests for file permissions
tests/Cache/CacheFileStoreTest.php
@@ -6,6 +6,7 @@ use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Carbon; +use Mockery as m; use PHPUnit\Framework\TestCase; class CacheFileStoreTest extends TestCase @@ -79,6 +80,27 @@ public function testStoreItemProperlyStoresValues() $this->assertTrue($result); } + public function testStoreItemProperlySetsPermissions() + { + $files = m::mock(Filesystem::class); + $files->shouldIgnoreMissing(); + $store = $this->getMockBuilder(FileStore::class)->setMethods(['expiration'])->setConstructorArgs([$files, __DIR__, 0644])->getMock(); + $hash = sha1('foo'); + $cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2); + $files->shouldReceive('put')->withArgs([__DIR__.'/'.$cache_dir.'/'.$hash, m::any(), m::any()])->andReturnUsing(function ($name, $value) { + return strlen($value); + }); + $files->shouldReceive('chmod')->withArgs([__DIR__.'/'.$cache_dir.'/'.$hash])->andReturnValues(["0600", "0644"])->times(3); + $files->shouldReceive('chmod')->withArgs([__DIR__.'/'.$cache_dir.'/'.$hash, 0644])->andReturn([true])->once(); + $result = $store->put('foo', 'foo', 10); + $this->assertTrue($result); + $result = $store->put('foo', 'bar', 10); + $this->assertTrue($result); + $result = $store->put('foo', 'baz', 10); + $this->assertTrue($result); + m::close(); + } + public function testForeversAreStoredWithHighTimestamp() { $files = $this->mockFilesystem();
false
Other
laravel
framework
f9165439ba826dab16b177680a14cf21f3ce462c.json
Fix ViewFacade reference
src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php
@@ -33,7 +33,7 @@ protected function blade(string $template, array $data = []) $tempDirectory = sys_get_temp_dir(); if (! in_array($tempDirectory, ViewFacade::getFinder()->getPaths())) { - View::addLocation(sys_get_temp_dir()); + ViewFacade::addLocation(sys_get_temp_dir()); } $tempFile = tempnam($tempDirectory, 'laravel-blade').'.blade.php';
false
Other
laravel
framework
36628971a86b680fcc73c2d78e671ca83ba2cee2.json
add regression test
tests/Integration/Database/DatabaseEloquentModelCustomCastingTest.php
@@ -31,6 +31,14 @@ public function testBasicCustomCasting() $model->uppercase = 'dries'; $this->assertEquals('TAYLOR', $model->getOriginal('uppercase')); + $model = new TestEloquentModelWithCustomCast; + $model->uppercase = 'taylor'; + $model->syncOriginal(); + $model->uppercase = 'dries'; + $model->getOriginal(); + + $this->assertEquals('DRIES', $model->uppercase); + $model = new TestEloquentModelWithCustomCast; $model->address = $address = new Address('110 Kingsbrook St.', 'My Childhood House');
false
Other
laravel
framework
68e7ad761cbe9ff73ebbecbdbc8fa3e0a97311f9.json
Apply fixes from StyleCI (#32791)
src/Illuminate/Database/Eloquent/Model.php
@@ -631,7 +631,7 @@ protected function incrementOrDecrement($column, $amount, $extra, $method) if ($this->fireModelEvent('updating') === false) { return false; - }; + } return tap($query->where( $this->getKeyName(), $this->getKey()
false
Other
laravel
framework
e37939e855fbcea5e78f00f3bf729a57b2d8a1c2.json
Apply fixes from StyleCI (#32781)
tests/Validation/ValidationValidatorTest.php
@@ -2323,7 +2323,7 @@ public function __toString() { return 'aslsdlks'; } - } + }, ], ['x' => 'Email']); $this->assertFalse($v->passes()); @@ -2333,7 +2333,7 @@ public function __toString() { return 'foo@gmail.com'; } - } + }, ], ['x' => 'Email']); $this->assertTrue($v->passes()); @@ -2943,7 +2943,7 @@ public function testValidateAlpha() $v = new Validator($trans, [ 'x' => 'aslsdlks 1 -1' +1', ], ['x' => 'Alpha']); $this->assertFalse($v->passes()); @@ -3601,7 +3601,7 @@ public function testCustomValidators() $v->addExtensions([ 'FooBar' => function () { return false; - } + }, ]); $v->setFallbackMessages(['foo_bar' => 'foo!']); $this->assertFalse($v->passes()); @@ -3780,23 +3780,23 @@ public function testValidateImplicitEachWithAsterisksForRequiredNonExistingKey() $data = [ 'people' => [ ['cars' => [['model' => 2005], []]], - ] + ], ]; $v = new Validator($trans, $data, ['people.*.cars.*.model' => 'required']); $this->assertFalse($v->passes()); $data = [ 'people' => [ ['name' => 'test', 'cars' => [['model' => 2005], ['name' => 'test2']]], - ] + ], ]; $v = new Validator($trans, $data, ['people.*.cars.*.model' => 'required']); $this->assertFalse($v->passes()); $data = [ 'people' => [ ['phones' => ['iphone', 'android'], 'cars' => [['model' => 2005], ['name' => 'test2']]], - ] + ], ]; $v = new Validator($trans, $data, ['people.*.cars.*.model' => 'required']); $this->assertFalse($v->passes()); @@ -3872,7 +3872,6 @@ public function testPassingSlashVulnerability() ]); $this->assertTrue($v->passes()); - $v = new Validator($trans, [ 'foo' => ['bar' => 'valid'], 'foo.bar' => 'invalid', 'foo->bar' => 'valid', ], [ @@ -3970,7 +3969,7 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'foo' => [ ['password' => 'foo0', 'password_confirmation' => 'foo0'], ['password' => 'foo1', 'password_confirmation' => 'foo1'], - ] + ], ], ['foo.*.password' => 'confirmed']); $this->assertTrue($v->passes()); @@ -3981,15 +3980,15 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'bar' => [ ['password' => 'bar0', 'password_confirmation' => 'bar0'], ['password' => 'bar1', 'password_confirmation' => 'bar1'], - ] + ], ], [ 'bar' => [ ['password' => 'bar2', 'password_confirmation' => 'bar2'], ['password' => 'bar3', 'password_confirmation' => 'bar3'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.password' => 'confirmed']); $this->assertTrue($v->passes()); @@ -3998,7 +3997,7 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'foo' => [ ['password' => 'foo0', 'password_confirmation' => 'bar0'], ['password' => 'foo1'], - ] + ], ], ['foo.*.password' => 'confirmed']); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.password')); @@ -4011,9 +4010,9 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'bar' => [ ['password' => 'bar0'], ['password' => 'bar1', 'password_confirmation' => 'bar2'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.password' => 'confirmed']); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.password')); @@ -4029,7 +4028,7 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'foo' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], ['foo.*.name' => ['different:foo.*.last']]); $this->assertTrue($v->passes()); @@ -4040,9 +4039,9 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'bar' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['different:foo.*.bar.*.last']]); $this->assertTrue($v->passes()); @@ -4051,7 +4050,7 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'foo' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['different:foo.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4064,9 +4063,9 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'bar' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['different:foo.*.bar.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4082,7 +4081,7 @@ public function testValidateImplicitEachWithAsterisksSame() 'foo' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['same:foo.*.last']]); $this->assertTrue($v->passes()); @@ -4093,9 +4092,9 @@ public function testValidateImplicitEachWithAsterisksSame() 'bar' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['same:foo.*.bar.*.last']]); $this->assertTrue($v->passes()); @@ -4104,7 +4103,7 @@ public function testValidateImplicitEachWithAsterisksSame() 'foo' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], ['foo.*.name' => ['same:foo.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4117,9 +4116,9 @@ public function testValidateImplicitEachWithAsterisksSame() 'bar' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['same:foo.*.bar.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4135,7 +4134,7 @@ public function testValidateImplicitEachWithAsterisksRequired() 'foo' => [ ['name' => 'first'], ['name' => 'second'], - ] + ], ], ['foo.*.name' => ['Required']]); $this->assertTrue($v->passes()); @@ -4144,7 +4143,7 @@ public function testValidateImplicitEachWithAsterisksRequired() 'foo' => [ ['name' => 'first'], ['name' => 'second'], - ] + ], ], ['foo.*.name' => ['Required']]); $this->assertTrue($v->passes()); @@ -4153,7 +4152,7 @@ public function testValidateImplicitEachWithAsterisksRequired() 'foo' => [ ['name' => null], ['name' => null, 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4166,9 +4165,9 @@ public function testValidateImplicitEachWithAsterisksRequired() 'bar' => [ ['name' => null], ['name' => null], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4184,7 +4183,7 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'foo' => [ ['name' => 'first', 'last' => 'foo'], ['last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_if:foo.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4193,7 +4192,7 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'foo' => [ ['name' => 'first', 'last' => 'foo'], ['last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_if:foo.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4202,7 +4201,7 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'foo' => [ ['name' => null, 'last' => 'foo'], ['name' => null, 'last' => 'foo'], - ] + ], ], ['foo.*.name' => ['Required_if:foo.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4215,9 +4214,9 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'bar' => [ ['name' => null, 'last' => 'foo'], ['name' => null, 'last' => 'foo'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_if:foo.*.bar.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4233,7 +4232,7 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'foo' => [ ['name' => null, 'last' => 'foo'], ['name' => 'second', 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_unless:foo.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4242,7 +4241,7 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'foo' => [ ['name' => null, 'last' => 'foo'], ['name' => 'second', 'last' => 'foo'], - ] + ], ], ['foo.*.bar.*.name' => ['Required_unless:foo.*.bar.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4251,7 +4250,7 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'foo' => [ ['name' => null, 'last' => 'baz'], ['name' => null, 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_unless:foo.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4264,9 +4263,9 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'bar' => [ ['name' => null, 'last' => 'bar'], ['name' => null, 'last' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_unless:foo.*.bar.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4282,7 +4281,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'foo' => [ ['name' => 'first', 'last' => 'last'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_with:foo.*.last']]); $this->assertTrue($v->passes()); @@ -4291,7 +4290,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'foo' => [ ['name' => 'first', 'last' => 'last'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_with:foo.*.last']]); $this->assertTrue($v->passes()); @@ -4300,7 +4299,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'foo' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_with:foo.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4310,7 +4309,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'fields' => [ 'fr' => ['name' => '', 'content' => 'ragnar'], 'es' => ['name' => '', 'content' => 'lagertha'], - ] + ], ], ['fields.*.name' => 'required_with:fields.*.content']); $this->assertFalse($v->passes()); @@ -4321,9 +4320,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'bar' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'last' => 'last'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_with:foo.*.bar.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4339,7 +4338,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'foo' => [ ['name' => 'first', 'last' => 'last', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last', 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_with_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4348,7 +4347,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'foo' => [ ['name' => 'first', 'last' => 'last', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last', 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_with_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4357,7 +4356,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'foo' => [ ['name' => null, 'last' => 'last', 'middle' => 'middle'], ['name' => null, 'last' => 'last', 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_with_all:foo.*.last,foo.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4370,9 +4369,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'bar' => [ ['name' => null, 'last' => 'last', 'middle' => 'middle'], ['name' => null, 'last' => 'last', 'middle' => 'middle'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_with_all:foo.*.bar.*.last,foo.*.bar.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4388,7 +4387,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'foo' => [ ['name' => 'first', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4397,7 +4396,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'foo' => [ ['name' => 'first', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4406,7 +4405,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'foo' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_without:foo.*.last,foo.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4419,9 +4418,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'bar' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'middle' => 'middle'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_without:foo.*.bar.*.last,foo.*.bar.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4438,7 +4437,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithoutAll() ['name' => 'first'], ['name' => null, 'middle' => 'middle'], ['name' => null, 'middle' => 'middle', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4449,15 +4448,15 @@ public function testValidateImplicitEachWithAsterisksRequiredWithoutAll() ['name' => 'first'], ['name' => null, 'middle' => 'middle'], ['name' => null, 'middle' => 'middle', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); $v = new Validator($trans, [ 'foo' => [ ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_without_all:foo.*.last,foo.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4470,9 +4469,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWithoutAll() 'bar' => [ ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_without_all:foo.*.bar.*.last,foo.*.bar.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4486,28 +4485,28 @@ public function testValidateImplicitEachWithAsterisksBeforeAndAfter() $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.start' => ['before:foo.*.end']]); $this->assertTrue($v->passes()); $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.end' => ['before:foo.*.start']]); $this->assertTrue($v->fails()); $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.end' => ['after:foo.*.start']]); $this->assertTrue($v->passes()); $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.start' => ['after:foo.*.end']]); $this->assertTrue($v->fails()); } @@ -4719,7 +4718,7 @@ public function message() { return ':attribute must be taylor'; } - } + }, ] ); @@ -4741,8 +4740,8 @@ public function message() { return ':attribute must be taylor'; } - } - ] + }, + ], ] ); @@ -4758,7 +4757,7 @@ public function message() if ($value !== 'taylor') { $fail(':attribute was '.$value.' instead of taylor'); } - } + }, ] ); @@ -4773,7 +4772,7 @@ public function message() if ($value !== 'taylor') { $fail(':attribute was '.$value.' instead of taylor'); } - } + }, ] ); @@ -4833,7 +4832,7 @@ public function message() { return [':attribute must be taylor', ':attribute must be a first name']; } - } + }, ] ); @@ -4857,8 +4856,8 @@ public function message() { return [':attribute must be taylor', ':attribute must be a first name']; } - }, 'string' - ] + }, 'string', + ], ] ); @@ -4889,7 +4888,7 @@ public function message() { return 'message'; } - } + }, ] ); @@ -5050,71 +5049,71 @@ public function providesPassingExcludeIfData() 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => false, - 'appointment_date' => 'should be excluded', - ], [ - 'has_appointment' => false, - ], + 'has_appointment' => false, + 'appointment_date' => 'should be excluded', + ], [ + 'has_appointment' => false, + ], ], [ [ 'cat' => ['required', 'string'], 'mouse' => ['exclude_if:cat,Tom', 'required', 'file'], ], [ - 'cat' => 'Tom', - 'mouse' => 'should be excluded', - ], [ - 'cat' => 'Tom', - ], + 'cat' => 'Tom', + 'mouse' => 'should be excluded', + ], [ + 'cat' => 'Tom', + ], ], [ [ 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => false, - ], [ - 'has_appointment' => false, - ], + 'has_appointment' => false, + ], [ + 'has_appointment' => false, + ], ], [ [ 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => true, - 'appointment_date' => '2019-12-13', - ], [ - 'has_appointment' => true, - 'appointment_date' => '2019-12-13', - ], + 'has_appointment' => true, + 'appointment_date' => '2019-12-13', + ], [ + 'has_appointment' => true, + 'appointment_date' => '2019-12-13', + ], ], [ [ 'has_no_appointments' => ['required', 'bool'], 'has_doctor_appointment' => ['exclude_if:has_no_appointments,true', 'required', 'bool'], 'doctor_appointment_date' => ['exclude_if:has_no_appointments,true', 'exclude_if:has_doctor_appointment,false', 'required', 'date'], ], [ - 'has_no_appointments' => true, - 'has_doctor_appointment' => true, - 'doctor_appointment_date' => '2019-12-13', - ], [ - 'has_no_appointments' => true, - ], + 'has_no_appointments' => true, + 'has_doctor_appointment' => true, + 'doctor_appointment_date' => '2019-12-13', + ], [ + 'has_no_appointments' => true, + ], ], [ [ 'has_no_appointments' => ['required', 'bool'], 'has_doctor_appointment' => ['exclude_if:has_no_appointments,true', 'required', 'bool'], 'doctor_appointment_date' => ['exclude_if:has_no_appointments,true', 'exclude_if:has_doctor_appointment,false', 'required', 'date'], ], [ - 'has_no_appointments' => false, - 'has_doctor_appointment' => false, - 'doctor_appointment_date' => 'should be excluded', - ], [ - 'has_no_appointments' => false, - 'has_doctor_appointment' => false, - ], + 'has_no_appointments' => false, + 'has_doctor_appointment' => false, + 'doctor_appointment_date' => 'should be excluded', + ], [ + 'has_no_appointments' => false, + 'has_doctor_appointment' => false, + ], ], 'nested-01' => [ [ @@ -5213,26 +5212,26 @@ public function providesPassingExcludeIfData() 'vehicles' => [ [ 'type' => 'car', 'wheels' => [ - ['color' => 'red', 'shape' => 'square'], - ['color' => 'blue', 'shape' => 'hexagon'], - ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], - ['color' => 'blue', 'shape' => 'triangle'], - ] + ['color' => 'red', 'shape' => 'square'], + ['color' => 'blue', 'shape' => 'hexagon'], + ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], + ['color' => 'blue', 'shape' => 'triangle'], + ], ], ['type' => 'boat'], ], ], [ 'vehicles' => [ [ 'type' => 'car', 'wheels' => [ - // The shape field for these blue wheels were correctly excluded (if they weren't, they would - // fail the validation). They still appear in the validated data. This behaviour is unrelated - // to the "exclude" type rules. - ['color' => 'red', 'shape' => 'square'], - ['color' => 'blue', 'shape' => 'hexagon'], - ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], - ['color' => 'blue', 'shape' => 'triangle'], - ] + // The shape field for these blue wheels were correctly excluded (if they weren't, they would + // fail the validation). They still appear in the validated data. This behaviour is unrelated + // to the "exclude" type rules. + ['color' => 'red', 'shape' => 'square'], + ['color' => 'blue', 'shape' => 'hexagon'], + ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], + ['color' => 'blue', 'shape' => 'triangle'], + ], ], ['type' => 'boat'], ], @@ -5275,21 +5274,21 @@ public function providesFailingExcludeIfData() 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => true, - ], [ - 'appointment_date' => ['validation.required'], - ], + 'has_appointment' => true, + ], [ + 'appointment_date' => ['validation.required'], + ], ], [ [ 'cat' => ['required', 'string'], 'mouse' => ['exclude_if:cat,Tom', 'required', 'file'], ], [ - 'cat' => 'Bob', - 'mouse' => 'not a file', - ], [ - 'mouse' => ['validation.file'], - ], + 'cat' => 'Bob', + 'mouse' => 'not a file', + ], [ + 'mouse' => ['validation.file'], + ], ], [ [ @@ -5298,36 +5297,36 @@ public function providesFailingExcludeIfData() 'appointments.*.date' => ['required', 'date'], 'appointments.*.name' => ['required', 'string'], ], [ - 'has_appointments' => true, - 'appointments' => [ - ['date' => 'invalid', 'name' => 'Bob'], - ['date' => '2019-05-15'], + 'has_appointments' => true, + 'appointments' => [ + ['date' => 'invalid', 'name' => 'Bob'], + ['date' => '2019-05-15'], + ], + ], [ + 'appointments.0.date' => ['validation.date'], + 'appointments.1.name' => ['validation.required'], ], - ], [ - 'appointments.0.date' => ['validation.date'], - 'appointments.1.name' => ['validation.required'], - ], ], [ [ 'vehicles.*.price' => 'required|numeric', 'vehicles.*.type' => 'required|in:car,boat', 'vehicles.*.wheels' => 'exclude_if:vehicles.*.type,boat|required|numeric', ], [ - 'vehicles' => [ - [ - 'price' => 100, - 'type' => 'car', - ], - [ - 'price' => 500, - 'type' => 'boat', + 'vehicles' => [ + [ + 'price' => 100, + 'type' => 'car', + ], + [ + 'price' => 500, + 'type' => 'boat', + ], ], + ], [ + 'vehicles.0.wheels' => ['validation.required'], + // vehicles.1.wheels is not required, because type is not "car" ], - ], [ - 'vehicles.0.wheels' => ['validation.required'], - // vehicles.1.wheels is not required, because type is not "car" - ], ], 'exclude-validation-error-01' => [ [ @@ -5340,11 +5339,11 @@ public function providesFailingExcludeIfData() 'vehicles' => [ [ 'type' => 'car', 'wheels' => [ - ['color' => 'red', 'shape' => 'square'], - ['color' => 'blue', 'shape' => 'hexagon'], - ['color' => 'red', 'shape' => 'hexagon'], - ['color' => 'blue', 'shape' => 'triangle'], - ] + ['color' => 'red', 'shape' => 'square'], + ['color' => 'blue', 'shape' => 'hexagon'], + ['color' => 'red', 'shape' => 'hexagon'], + ['color' => 'blue', 'shape' => 'triangle'], + ], ], ['type' => 'boat', 'wheels' => 'should be excluded'], ],
false
Other
laravel
framework
28b8111dac789b248c3c5f7887912c09ce37df0a.json
Apply fixes from StyleCI (#32780)
tests/Validation/ValidationValidatorTest.php
@@ -2284,7 +2284,7 @@ public function __toString() { return 'aslsdlks'; } - } + }, ], ['x' => 'Email']); $this->assertFalse($v->passes()); @@ -2294,7 +2294,7 @@ public function __toString() { return 'foo@gmail.com'; } - } + }, ], ['x' => 'Email']); $this->assertTrue($v->passes()); @@ -2878,7 +2878,7 @@ public function testValidateAlpha() $v = new Validator($trans, [ 'x' => 'aslsdlks 1 -1' +1', ], ['x' => 'Alpha']); $this->assertFalse($v->passes()); @@ -3530,7 +3530,7 @@ public function testCustomValidators() $v->addExtensions([ 'FooBar' => function () { return false; - } + }, ]); $v->setFallbackMessages(['foo_bar' => 'foo!']); $this->assertFalse($v->passes()); @@ -3709,23 +3709,23 @@ public function testValidateImplicitEachWithAsterisksForRequiredNonExistingKey() $data = [ 'people' => [ ['cars' => [['model' => 2005], []]], - ] + ], ]; $v = new Validator($trans, $data, ['people.*.cars.*.model' => 'required']); $this->assertFalse($v->passes()); $data = [ 'people' => [ ['name' => 'test', 'cars' => [['model' => 2005], ['name' => 'test2']]], - ] + ], ]; $v = new Validator($trans, $data, ['people.*.cars.*.model' => 'required']); $this->assertFalse($v->passes()); $data = [ 'people' => [ ['phones' => ['iphone', 'android'], 'cars' => [['model' => 2005], ['name' => 'test2']]], - ] + ], ]; $v = new Validator($trans, $data, ['people.*.cars.*.model' => 'required']); $this->assertFalse($v->passes()); @@ -3801,7 +3801,6 @@ public function testPassingSlashVulnerability() ]); $this->assertTrue($v->passes()); - $v = new Validator($trans, [ 'foo' => ['bar' => 'valid'], 'foo.bar' => 'invalid', 'foo->bar' => 'valid', ], [ @@ -3899,7 +3898,7 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'foo' => [ ['password' => 'foo0', 'password_confirmation' => 'foo0'], ['password' => 'foo1', 'password_confirmation' => 'foo1'], - ] + ], ], ['foo.*.password' => 'confirmed']); $this->assertTrue($v->passes()); @@ -3910,15 +3909,15 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'bar' => [ ['password' => 'bar0', 'password_confirmation' => 'bar0'], ['password' => 'bar1', 'password_confirmation' => 'bar1'], - ] + ], ], [ 'bar' => [ ['password' => 'bar2', 'password_confirmation' => 'bar2'], ['password' => 'bar3', 'password_confirmation' => 'bar3'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.password' => 'confirmed']); $this->assertTrue($v->passes()); @@ -3927,7 +3926,7 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'foo' => [ ['password' => 'foo0', 'password_confirmation' => 'bar0'], ['password' => 'foo1'], - ] + ], ], ['foo.*.password' => 'confirmed']); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.password')); @@ -3940,9 +3939,9 @@ public function testValidateImplicitEachWithAsterisksConfirmed() 'bar' => [ ['password' => 'bar0'], ['password' => 'bar1', 'password_confirmation' => 'bar2'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.password' => 'confirmed']); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.password')); @@ -3958,7 +3957,7 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'foo' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], ['foo.*.name' => ['different:foo.*.last']]); $this->assertTrue($v->passes()); @@ -3969,9 +3968,9 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'bar' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['different:foo.*.bar.*.last']]); $this->assertTrue($v->passes()); @@ -3980,7 +3979,7 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'foo' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['different:foo.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -3993,9 +3992,9 @@ public function testValidateImplicitEachWithAsterisksDifferent() 'bar' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['different:foo.*.bar.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4011,7 +4010,7 @@ public function testValidateImplicitEachWithAsterisksSame() 'foo' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['same:foo.*.last']]); $this->assertTrue($v->passes()); @@ -4022,9 +4021,9 @@ public function testValidateImplicitEachWithAsterisksSame() 'bar' => [ ['name' => 'foo', 'last' => 'foo'], ['name' => 'bar', 'last' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['same:foo.*.bar.*.last']]); $this->assertTrue($v->passes()); @@ -4033,7 +4032,7 @@ public function testValidateImplicitEachWithAsterisksSame() 'foo' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], ['foo.*.name' => ['same:foo.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4046,9 +4045,9 @@ public function testValidateImplicitEachWithAsterisksSame() 'bar' => [ ['name' => 'foo', 'last' => 'bar'], ['name' => 'bar', 'last' => 'foo'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['same:foo.*.bar.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4064,7 +4063,7 @@ public function testValidateImplicitEachWithAsterisksRequired() 'foo' => [ ['name' => 'first'], ['name' => 'second'], - ] + ], ], ['foo.*.name' => ['Required']]); $this->assertTrue($v->passes()); @@ -4073,7 +4072,7 @@ public function testValidateImplicitEachWithAsterisksRequired() 'foo' => [ ['name' => 'first'], ['name' => 'second'], - ] + ], ], ['foo.*.name' => ['Required']]); $this->assertTrue($v->passes()); @@ -4082,7 +4081,7 @@ public function testValidateImplicitEachWithAsterisksRequired() 'foo' => [ ['name' => null], ['name' => null, 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4095,9 +4094,9 @@ public function testValidateImplicitEachWithAsterisksRequired() 'bar' => [ ['name' => null], ['name' => null], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4113,7 +4112,7 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'foo' => [ ['name' => 'first', 'last' => 'foo'], ['last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_if:foo.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4122,7 +4121,7 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'foo' => [ ['name' => 'first', 'last' => 'foo'], ['last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_if:foo.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4131,7 +4130,7 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'foo' => [ ['name' => null, 'last' => 'foo'], ['name' => null, 'last' => 'foo'], - ] + ], ], ['foo.*.name' => ['Required_if:foo.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4144,9 +4143,9 @@ public function testValidateImplicitEachWithAsterisksRequiredIf() 'bar' => [ ['name' => null, 'last' => 'foo'], ['name' => null, 'last' => 'foo'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_if:foo.*.bar.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4162,7 +4161,7 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'foo' => [ ['name' => null, 'last' => 'foo'], ['name' => 'second', 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_unless:foo.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4171,7 +4170,7 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'foo' => [ ['name' => null, 'last' => 'foo'], ['name' => 'second', 'last' => 'foo'], - ] + ], ], ['foo.*.bar.*.name' => ['Required_unless:foo.*.bar.*.last,foo']]); $this->assertTrue($v->passes()); @@ -4180,7 +4179,7 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'foo' => [ ['name' => null, 'last' => 'baz'], ['name' => null, 'last' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_unless:foo.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4193,9 +4192,9 @@ public function testValidateImplicitEachWithAsterisksRequiredUnless() 'bar' => [ ['name' => null, 'last' => 'bar'], ['name' => null, 'last' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_unless:foo.*.bar.*.last,foo']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4211,7 +4210,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'foo' => [ ['name' => 'first', 'last' => 'last'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_with:foo.*.last']]); $this->assertTrue($v->passes()); @@ -4220,7 +4219,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'foo' => [ ['name' => 'first', 'last' => 'last'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_with:foo.*.last']]); $this->assertTrue($v->passes()); @@ -4229,7 +4228,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'foo' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_with:foo.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4239,7 +4238,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'fields' => [ 'fr' => ['name' => '', 'content' => 'ragnar'], 'es' => ['name' => '', 'content' => 'lagertha'], - ] + ], ], ['fields.*.name' => 'required_with:fields.*.content']); $this->assertFalse($v->passes()); @@ -4250,9 +4249,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWith() 'bar' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'last' => 'last'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_with:foo.*.bar.*.last']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4268,7 +4267,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'foo' => [ ['name' => 'first', 'last' => 'last', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last', 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_with_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4277,7 +4276,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'foo' => [ ['name' => 'first', 'last' => 'last', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last', 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_with_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4286,7 +4285,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'foo' => [ ['name' => null, 'last' => 'last', 'middle' => 'middle'], ['name' => null, 'last' => 'last', 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_with_all:foo.*.last,foo.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4299,9 +4298,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWithAll() 'bar' => [ ['name' => null, 'last' => 'last', 'middle' => 'middle'], ['name' => null, 'last' => 'last', 'middle' => 'middle'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_with_all:foo.*.bar.*.last,foo.*.bar.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4317,7 +4316,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'foo' => [ ['name' => 'first', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4326,7 +4325,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'foo' => [ ['name' => 'first', 'middle' => 'middle'], ['name' => 'second', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4335,7 +4334,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'foo' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'middle' => 'middle'], - ] + ], ], ['foo.*.name' => ['Required_without:foo.*.last,foo.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4348,9 +4347,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWithout() 'bar' => [ ['name' => null, 'last' => 'last'], ['name' => null, 'middle' => 'middle'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_without:foo.*.bar.*.last,foo.*.bar.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4367,7 +4366,7 @@ public function testValidateImplicitEachWithAsterisksRequiredWithoutAll() ['name' => 'first'], ['name' => null, 'middle' => 'middle'], ['name' => null, 'middle' => 'middle', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); @@ -4378,15 +4377,15 @@ public function testValidateImplicitEachWithAsterisksRequiredWithoutAll() ['name' => 'first'], ['name' => null, 'middle' => 'middle'], ['name' => null, 'middle' => 'middle', 'last' => 'last'], - ] + ], ], ['foo.*.name' => ['Required_without_all:foo.*.last,foo.*.middle']]); $this->assertTrue($v->passes()); $v = new Validator($trans, [ 'foo' => [ ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], - ] + ], ], ['foo.*.name' => ['Required_without_all:foo.*.last,foo.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.name')); @@ -4399,9 +4398,9 @@ public function testValidateImplicitEachWithAsterisksRequiredWithoutAll() 'bar' => [ ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], ['name' => null, 'foo' => 'foo', 'bar' => 'bar'], - ] + ], ], - ] + ], ], ['foo.*.bar.*.name' => ['Required_without_all:foo.*.bar.*.last,foo.*.bar.*.middle']]); $this->assertFalse($v->passes()); $this->assertTrue($v->messages()->has('foo.0.bar.0.name')); @@ -4415,28 +4414,28 @@ public function testValidateImplicitEachWithAsterisksBeforeAndAfter() $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.start' => ['before:foo.*.end']]); $this->assertTrue($v->passes()); $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.end' => ['before:foo.*.start']]); $this->assertTrue($v->fails()); $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.end' => ['after:foo.*.start']]); $this->assertTrue($v->passes()); $v = new Validator($trans, [ 'foo' => [ ['start' => '2016-04-19', 'end' => '2017-04-19'], - ] + ], ], ['foo.*.start' => ['after:foo.*.end']]); $this->assertTrue($v->fails()); } @@ -4648,7 +4647,7 @@ public function message() { return ':attribute must be taylor'; } - } + }, ] ); @@ -4670,8 +4669,8 @@ public function message() { return ':attribute must be taylor'; } - } - ] + }, + ], ] ); @@ -4687,7 +4686,7 @@ public function message() if ($value !== 'taylor') { $fail(':attribute was '.$value.' instead of taylor'); } - } + }, ] ); @@ -4702,7 +4701,7 @@ public function message() if ($value !== 'taylor') { $fail(':attribute was '.$value.' instead of taylor'); } - } + }, ] ); @@ -4762,7 +4761,7 @@ public function message() { return [':attribute must be taylor', ':attribute must be a first name']; } - } + }, ] ); @@ -4786,8 +4785,8 @@ public function message() { return [':attribute must be taylor', ':attribute must be a first name']; } - }, 'string' - ] + }, 'string', + ], ] ); @@ -4818,7 +4817,7 @@ public function message() { return 'message'; } - } + }, ] ); @@ -4979,71 +4978,71 @@ public function providesPassingExcludeIfData() 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => false, - 'appointment_date' => 'should be excluded', - ], [ - 'has_appointment' => false, - ], + 'has_appointment' => false, + 'appointment_date' => 'should be excluded', + ], [ + 'has_appointment' => false, + ], ], [ [ 'cat' => ['required', 'string'], 'mouse' => ['exclude_if:cat,Tom', 'required', 'file'], ], [ - 'cat' => 'Tom', - 'mouse' => 'should be excluded', - ], [ - 'cat' => 'Tom', - ], + 'cat' => 'Tom', + 'mouse' => 'should be excluded', + ], [ + 'cat' => 'Tom', + ], ], [ [ 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => false, - ], [ - 'has_appointment' => false, - ], + 'has_appointment' => false, + ], [ + 'has_appointment' => false, + ], ], [ [ 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => true, - 'appointment_date' => '2019-12-13', - ], [ - 'has_appointment' => true, - 'appointment_date' => '2019-12-13', - ], + 'has_appointment' => true, + 'appointment_date' => '2019-12-13', + ], [ + 'has_appointment' => true, + 'appointment_date' => '2019-12-13', + ], ], [ [ 'has_no_appointments' => ['required', 'bool'], 'has_doctor_appointment' => ['exclude_if:has_no_appointments,true', 'required', 'bool'], 'doctor_appointment_date' => ['exclude_if:has_no_appointments,true', 'exclude_if:has_doctor_appointment,false', 'required', 'date'], ], [ - 'has_no_appointments' => true, - 'has_doctor_appointment' => true, - 'doctor_appointment_date' => '2019-12-13', - ], [ - 'has_no_appointments' => true, - ], + 'has_no_appointments' => true, + 'has_doctor_appointment' => true, + 'doctor_appointment_date' => '2019-12-13', + ], [ + 'has_no_appointments' => true, + ], ], [ [ 'has_no_appointments' => ['required', 'bool'], 'has_doctor_appointment' => ['exclude_if:has_no_appointments,true', 'required', 'bool'], 'doctor_appointment_date' => ['exclude_if:has_no_appointments,true', 'exclude_if:has_doctor_appointment,false', 'required', 'date'], ], [ - 'has_no_appointments' => false, - 'has_doctor_appointment' => false, - 'doctor_appointment_date' => 'should be excluded', - ], [ - 'has_no_appointments' => false, - 'has_doctor_appointment' => false, - ], + 'has_no_appointments' => false, + 'has_doctor_appointment' => false, + 'doctor_appointment_date' => 'should be excluded', + ], [ + 'has_no_appointments' => false, + 'has_doctor_appointment' => false, + ], ], 'nested-01' => [ [ @@ -5142,26 +5141,26 @@ public function providesPassingExcludeIfData() 'vehicles' => [ [ 'type' => 'car', 'wheels' => [ - ['color' => 'red', 'shape' => 'square'], - ['color' => 'blue', 'shape' => 'hexagon'], - ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], - ['color' => 'blue', 'shape' => 'triangle'], - ] + ['color' => 'red', 'shape' => 'square'], + ['color' => 'blue', 'shape' => 'hexagon'], + ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], + ['color' => 'blue', 'shape' => 'triangle'], + ], ], ['type' => 'boat'], ], ], [ 'vehicles' => [ [ 'type' => 'car', 'wheels' => [ - // The shape field for these blue wheels were correctly excluded (if they weren't, they would - // fail the validation). They still appear in the validated data. This behaviour is unrelated - // to the "exclude" type rules. - ['color' => 'red', 'shape' => 'square'], - ['color' => 'blue', 'shape' => 'hexagon'], - ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], - ['color' => 'blue', 'shape' => 'triangle'], - ] + // The shape field for these blue wheels were correctly excluded (if they weren't, they would + // fail the validation). They still appear in the validated data. This behaviour is unrelated + // to the "exclude" type rules. + ['color' => 'red', 'shape' => 'square'], + ['color' => 'blue', 'shape' => 'hexagon'], + ['color' => 'red', 'shape' => 'round', 'junk' => 'no rule, still present'], + ['color' => 'blue', 'shape' => 'triangle'], + ], ], ['type' => 'boat'], ], @@ -5204,21 +5203,21 @@ public function providesFailingExcludeIfData() 'has_appointment' => ['required', 'bool'], 'appointment_date' => ['exclude_if:has_appointment,false', 'required', 'date'], ], [ - 'has_appointment' => true, - ], [ - 'appointment_date' => ['validation.required'], - ], + 'has_appointment' => true, + ], [ + 'appointment_date' => ['validation.required'], + ], ], [ [ 'cat' => ['required', 'string'], 'mouse' => ['exclude_if:cat,Tom', 'required', 'file'], ], [ - 'cat' => 'Bob', - 'mouse' => 'not a file', - ], [ - 'mouse' => ['validation.file'], - ], + 'cat' => 'Bob', + 'mouse' => 'not a file', + ], [ + 'mouse' => ['validation.file'], + ], ], [ [ @@ -5227,36 +5226,36 @@ public function providesFailingExcludeIfData() 'appointments.*.date' => ['required', 'date'], 'appointments.*.name' => ['required', 'string'], ], [ - 'has_appointments' => true, - 'appointments' => [ - ['date' => 'invalid', 'name' => 'Bob'], - ['date' => '2019-05-15'], + 'has_appointments' => true, + 'appointments' => [ + ['date' => 'invalid', 'name' => 'Bob'], + ['date' => '2019-05-15'], + ], + ], [ + 'appointments.0.date' => ['validation.date'], + 'appointments.1.name' => ['validation.required'], ], - ], [ - 'appointments.0.date' => ['validation.date'], - 'appointments.1.name' => ['validation.required'], - ], ], [ [ 'vehicles.*.price' => 'required|numeric', 'vehicles.*.type' => 'required|in:car,boat', 'vehicles.*.wheels' => 'exclude_if:vehicles.*.type,boat|required|numeric', ], [ - 'vehicles' => [ - [ - 'price' => 100, - 'type' => 'car', - ], - [ - 'price' => 500, - 'type' => 'boat', + 'vehicles' => [ + [ + 'price' => 100, + 'type' => 'car', + ], + [ + 'price' => 500, + 'type' => 'boat', + ], ], + ], [ + 'vehicles.0.wheels' => ['validation.required'], + // vehicles.1.wheels is not required, because type is not "car" ], - ], [ - 'vehicles.0.wheels' => ['validation.required'], - // vehicles.1.wheels is not required, because type is not "car" - ], ], 'exclude-validation-error-01' => [ [ @@ -5269,11 +5268,11 @@ public function providesFailingExcludeIfData() 'vehicles' => [ [ 'type' => 'car', 'wheels' => [ - ['color' => 'red', 'shape' => 'square'], - ['color' => 'blue', 'shape' => 'hexagon'], - ['color' => 'red', 'shape' => 'hexagon'], - ['color' => 'blue', 'shape' => 'triangle'], - ] + ['color' => 'red', 'shape' => 'square'], + ['color' => 'blue', 'shape' => 'hexagon'], + ['color' => 'red', 'shape' => 'hexagon'], + ['color' => 'blue', 'shape' => 'triangle'], + ], ], ['type' => 'boat', 'wheels' => 'should be excluded'], ],
false
Other
laravel
framework
cab1de36ad2e5e42a0111b1e5070d5c62e933f86.json
Apply fixes from StyleCI (#32762)
src/Illuminate/Queue/Jobs/Job.php
@@ -266,7 +266,7 @@ public function maxExceptions() } /** - * The number of seconds to wait before retrying a job that encountered an uncaught exception + * The number of seconds to wait before retrying a job that encountered an uncaught exception. * * @return int|null */
true
Other
laravel
framework
cab1de36ad2e5e42a0111b1e5070d5c62e933f86.json
Apply fixes from StyleCI (#32762)
src/Illuminate/Queue/WorkerOptions.php
@@ -5,7 +5,7 @@ class WorkerOptions { /** - * The number of seconds to wait before retrying a job that encountered an uncaught exception + * The number of seconds to wait before retrying a job that encountered an uncaught exception. * * @var int */
true
Other
laravel
framework
9b652406ab4ef2ef039ebcf972abffb9a4129291.json
Add usingConnection method to DatabaseManager
src/Illuminate/Database/DatabaseManager.php
@@ -245,6 +245,22 @@ public function reconnect($name = null) return $this->refreshPdoConnections($name); } + /** + * Set the database connection for the callback execution. + * + * @param string $name + * @param callable $callback + * @return void + */ + public function usingConnection(string $name, callable $callback) + { + $previousName = $this->getDefaultConnection(); + + $this->setDefaultConnection($name); + $callback(); + $this->setDefaultConnection($previousName); + } + /** * Refresh the PDO connections on a given connection. *
false
Other
laravel
framework
87bb1352e9e15c28700ffdd3656b429ceddf4e7d.json
Fix StyleCI lint
src/Illuminate/Support/Stringable.php
@@ -193,7 +193,7 @@ public function explode($delimiter, $limit = PHP_INT_MAX) { return collect(explode($delimiter, $this->value, $limit)); } - + /** * Split string by a regular expression. * @@ -206,7 +206,7 @@ public function split($pattern, $limit = -1, $flags = 0) { $keywords = preg_split($pattern, $this->value, $limit, $flags); - if(! $keywords) { + if (! $keywords) { return collect(); }
false
Other
laravel
framework
7490ed68d602f3d08a52109ef900428ee6cab49e.json
Add split() to Stringable class
src/Illuminate/Support/Stringable.php
@@ -193,6 +193,25 @@ public function explode($delimiter, $limit = PHP_INT_MAX) { return collect(explode($delimiter, $this->value, $limit)); } + + /** + * Split string by a regular expression. + * + * @param string $pattern + * @param int $limit + * @param int $flags + * @return \Illuminate\Support\Collection + */ + public function split($pattern, $limit = -1, $flags = 0) + { + $keywords = preg_split($pattern, $this->value, $limit, $flags); + + if(! $keywords) { + return collect(); + } + + return collect($keywords); + } /** * Cap a string with a single instance of a given value.
false
Other
laravel
framework
16164416f6dfb7e8c736b4cb4ff7409d22cc4e70.json
Add where pivot null methods
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -504,6 +504,55 @@ public function orWherePivotNotIn($column, $values) return $this->wherePivotNotIn($column, $values, 'or'); } + /** + * Set a "where null" clause for a pivot table column. + * + * @param string $column + * @param string $boolean + * @param bool $not + * @return $this + */ + public function wherePivotNull($column, $boolean = 'and', $not = false) + { + return $this->wherePivot($column, $not ? 'is not' : 'is', null, $boolean); + } + + /** + * Set a "where not null" clause for a pivot table column. + * + * @param string $column + * @param string $boolean + * @return $this + */ + public function wherePivotNotNull($column, $boolean = 'and') + { + return $this->wherePivotNull($column, $boolean, true); + } + + /** + * Set a "or where null" clause for a pivot table column. + * + * @param string $column + * @param bool $not + * @return $this + */ + public function orWherePivotNull($column, $not = false) + { + return $this->wherePivotNull($column, 'or', $not); + } + + /** + * Set a "or where not null" clause for a pivot table column. + * + * @param string $column + * @param bool $not + * @return $this + */ + public function orWherePivotNotNull($column) + { + return $this->orWherePivotNull($column, true); + } + /** * Find a related model by its primary key or return new instance of the related model. *
false
Other
laravel
framework
1b90dc48d4e9d020569d63eef142cbf14e0c824d.json
Improve parameter type of `destroy()` (#32694)
src/Illuminate/Database/Eloquent/Model.php
@@ -872,7 +872,7 @@ protected function insertAndSetId(Builder $query, $attributes) /** * Destroy the models for the given IDs. * - * @param \Illuminate\Support\Collection|array|int $ids + * @param \Illuminate\Support\Collection|array|int|string $ids * @return int */ public static function destroy($ids)
false
Other
laravel
framework
9ed157fbba83ff8925b01ee7de7c836ca97cd15c.json
add facade blocks
src/Illuminate/Support/Facades/Storage.php
@@ -27,6 +27,8 @@ * @method static array allDirectories(string|null $directory = null) * @method static bool makeDirectory(string $path) * @method static bool deleteDirectory(string $directory) + * @method static string url(string $path) + * @method static string temporaryUrl(string $path, \DateTimeInterface $expiration, array $options = []) * @method static \Illuminate\Contracts\Filesystem\Filesystem assertExists(string|array $path) * @method static \Illuminate\Contracts\Filesystem\Filesystem assertMissing(string|array $path) *
false
Other
laravel
framework
e802058d27c06748a0628c787d38f1618dbe4eaa.json
Add mergeFillable and mergeGuarded These new methods are to be inline with the `mergeCasts` method that was merged a few months ago. They're mostly useful in traits that add new attributes for example ``` trait HasActiveVisit { protected function initializeHasActiveVisit() { $this->mergeFillable([ 'is_indefinite', 'finished_at' ]); $this->mergeCasts([ 'is_indefinite' => 'bool', 'finished_at' => 'datetime' ]); } public function scopeActive(Builder $query) { $query->where('is_indefinite', false)->whereNull('finished_at'); } } ```
src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php
@@ -49,6 +49,32 @@ public function fillable(array $fillable) return $this; } + + /** + * Merge new fillable attributes with existing fillable attributes on the model. + * + * @param array $fillable + * @return $this + */ + public function mergeFillable(array $fillable) + { + $this->fillable = array_merge($this->fillable, $fillable); + + return $this; + } + + /** + * Merge new guarded attributes with existing guarded attributes on the model. + * + * @param array $guarded + * @return $this + */ + public function mergeGuarded(array $guarded) + { + $this->guarded = array_merge($this->guarded, $guarded); + + return $this; + } /** * Get the guarded attributes for the model.
false
Other
laravel
framework
f16d3256f93be71935ed86951e58f90b83912feb.json
support delete with limit on sqlsrv
src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
@@ -4,6 +4,7 @@ use Illuminate\Database\Query\Builder; use Illuminate\Support\Arr; +use Illuminate\Support\Str; class SqlServerGrammar extends Grammar { @@ -232,6 +233,23 @@ protected function compileRowConstraint($query) return ">= {$start}"; } + /** + * Compile a delete statement without joins into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param string $table + * @param string $where + * @return string + */ + protected function compileDeleteWithoutJoins(Builder $query, $table, $where) + { + $sql = parent::compileDeleteWithoutJoins($query, $table, $where); + + return ! is_null($query->limit) && $query->limit > 0 && $query->offset <= 0 + ? Str::replaceFirst('delete', 'delete top ('.$query->limit.')', $sql) + : $sql; + } + /** * Compile the random statement into SQL. *
true
Other
laravel
framework
f16d3256f93be71935ed86951e58f90b83912feb.json
support delete with limit on sqlsrv
tests/Database/DatabaseQueryBuilderTest.php
@@ -2355,6 +2355,11 @@ public function testDeleteMethod() $builder->getConnection()->shouldReceive('delete')->once()->with('delete from [users] where [email] = ?', ['foo'])->andReturn(1); $result = $builder->from('users')->where('email', '=', 'foo')->delete(); $this->assertEquals(1, $result); + + $builder = $this->getSqlServerBuilder(); + $builder->getConnection()->shouldReceive('delete')->once()->with('delete top (1) from [users] where [email] = ?', ['foo'])->andReturn(1); + $result = $builder->from('users')->where('email', '=', 'foo')->orderBy('id')->take(1)->delete(); + $this->assertEquals(1, $result); } public function testDeleteWithJoinMethod()
true
Other
laravel
framework
6d9a3523f47f7f73553ceee93495f960846cd41a.json
Apply fixes from StyleCI (#32671)
src/Illuminate/Session/Middleware/StartSession.php
@@ -3,7 +3,6 @@ namespace Illuminate\Session\Middleware; use Closure; -use Illuminate\Contracts\Cache\Factory as CacheFactory; use Illuminate\Contracts\Session\Session; use Illuminate\Http\Request; use Illuminate\Session\SessionManager;
false
Other
laravel
framework
b35afc7aa78f591aee364614660d406424d1e52e.json
defer resolution of cache factory
src/Illuminate/Session/Middleware/StartSession.php
@@ -21,17 +21,24 @@ class StartSession */ protected $manager; + /** + * The callback that can resolve an instance of the cache factory. + * + * @var callable + */ + protected $cacheFactoryResolver; + /** * Create a new session middleware. * * @param \Illuminate\Session\SessionManager $manager - * @param \Illuminate\Contracts\Cache\Factory $cache + * @param callable $cacheFactoryResolver * @return void */ - public function __construct(SessionManager $manager, CacheFactory $cache) + public function __construct(SessionManager $manager, callable $cacheFactoryResolver = null) { $this->manager = $manager; - $this->cache = $cache; + $this->cacheFactoryResolver = $cacheFactoryResolver; } /** @@ -71,7 +78,7 @@ protected function handleRequestWhileBlocking(Request $request, $session, Closur ? $request->route()->locksFor() : 10; - $lock = $this->cache->driver($this->manager->blockDriver()) + $lock = $this->cache($this->manager->blockDriver()) ->lock('session:'.$session->getId(), $lockFor) ->betweenBlockedAttemptsSleepFor(50); @@ -271,4 +278,15 @@ protected function sessionIsPersistent(array $config = null) return ! is_null($config['driver'] ?? null); } + + /** + * Resolve the given cache driver. + * + * @param string $cache + * @return \Illuminate\Cache\Store + */ + protected function cache($driver) + { + return call_user_func($this->cacheFactoryResolver)->driver($driver); + } }
true
Other
laravel
framework
b35afc7aa78f591aee364614660d406424d1e52e.json
defer resolution of cache factory
src/Illuminate/Session/SessionServiceProvider.php
@@ -2,6 +2,7 @@ namespace Illuminate\Session; +use Illuminate\Contracts\Cache\Factory as CacheFactory; use Illuminate\Session\Middleware\StartSession; use Illuminate\Support\ServiceProvider; @@ -18,7 +19,11 @@ public function register() $this->registerSessionDriver(); - $this->app->singleton(StartSession::class); + $this->app->singleton(StartSession::class, function () { + return new StartSession($this->app->make(SessionManager::class), function () { + return $this->app->make(CacheFactory::class); + }); + }); } /**
true
Other
laravel
framework
64d5af59b76fd8c33d8184c35f5f85933262e7f4.json
Apply fixes from StyleCI (#32661)
src/Illuminate/Support/Traits/ReflectsClosures.php
@@ -4,7 +4,6 @@ use Closure; use ReflectionFunction; -use ReflectionParameter; use RuntimeException; trait ReflectsClosures
false
Other
laravel
framework
7801e2a6dc5a6fb8be2a11fa7226e2ad868a8d02.json
Apply fixes from StyleCI (#32660)
src/Illuminate/Support/Traits/ReflectsClosures.php
@@ -4,7 +4,6 @@ use Closure; use ReflectionFunction; -use ReflectionParameter; use RuntimeException; trait ReflectsClosures
false
Other
laravel
framework
c9217c0b06a628c4c5188e080e062af8b0fa7ee7.json
Add exception for undefined cast
src/Illuminate/Database/Eloquent/CastNotFoundException.php
@@ -0,0 +1,50 @@ +<?php + +namespace Illuminate\Database\Eloquent; + +use RuntimeException; + +class CastNotFoundException extends RuntimeException +{ + /** + * The name of the affected Eloquent model. + * + * @var string + */ + public $model; + + /** + * The name of the column. + * + * @var string + */ + public $column; + + /** + * The name of the cast type. + * + * @var string + */ + public $castType; + + /** + * Create a new exception instance. + * + * @param mixed $model + * @param string $column + * @param string $castType + * @return static + */ + public static function make($model, $column, $castType) + { + $class = get_class($model); + + $instance = new static("Call to undefined cast [{$castType}] on column [{$column}] in model [{$class}]."); + + $instance->model = $model; + $instance->column = $column; + $instance->castType = $castType; + + return $instance; + } +}
true
Other
laravel
framework
c9217c0b06a628c4c5188e080e062af8b0fa7ee7.json
Add exception for undefined cast
src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
@@ -8,6 +8,7 @@ use Illuminate\Contracts\Database\Eloquent\Castable; use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Database\Eloquent\CastNotFoundException; use Illuminate\Database\Eloquent\JsonEncodingException; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Carbon; @@ -1050,9 +1051,21 @@ protected function isJsonCastable($key) */ protected function isClassCastable($key) { - return array_key_exists($key, $this->getCasts()) && - class_exists($class = $this->parseCasterClass($this->getCasts()[$key])) && - ! in_array($class, static::$primitiveCastTypes); + if (! array_key_exists($key, $this->getCasts())) { + return false; + } + + $castType = $this->parseCasterClass($this->getCasts()[$key]); + + if (in_array($castType, static::$primitiveCastTypes)) { + return false; + } + + if (class_exists($castType)) { + return true; + } + + throw CastNotFoundException::make($this->getModel(), $key, $castType); } /**
true
Other
laravel
framework
c9217c0b06a628c4c5188e080e062af8b0fa7ee7.json
Add exception for undefined cast
tests/Integration/Database/DatabaseEloquentModelCustomCastingTest.php
@@ -5,6 +5,7 @@ use Illuminate\Contracts\Database\Eloquent\Castable; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes; +use Illuminate\Database\Eloquent\CastNotFoundException; use Illuminate\Database\Eloquent\Model; /** @@ -141,6 +142,24 @@ public function testWithCastableInterface() $this->assertInstanceOf(ValueObject::class, $model->value_object_caster_with_caster_instance); } + + public function testGetFromUndefinedCast() + { + $this->expectException(CastNotFoundException::class); + + $model = new TestEloquentModelWithCustomCast; + $model->undefined_cast_column; + } + + public function testSetToUndefinedCast() + { + $this->expectException(CastNotFoundException::class); + + $model = new TestEloquentModelWithCustomCast; + $this->assertTrue($model->hasCast('undefined_cast_column')); + + $model->undefined_cast_column = 'Glāžšķūņu rūķīši'; + } } class TestEloquentModelWithCustomCast extends Model @@ -166,6 +185,7 @@ class TestEloquentModelWithCustomCast extends Model 'value_object_with_caster' => ValueObject::class, 'value_object_caster_with_argument' => ValueObject::class.':argument', 'value_object_caster_with_caster_instance' => ValueObjectWithCasterInstance::class, + 'undefined_cast_column' => UndefinedCast::class, ]; }
true
Other
laravel
framework
36e215dd39cd757a8ffc6b17794de60476b2289d.json
Fix console options parsing with scheduler Co-Authored-By: Mohamed Said <themsaid@gmail.com>
src/Illuminate/Console/Scheduling/Schedule.php
@@ -199,22 +199,44 @@ public function exec($command, array $parameters = []) protected function compileParameters(array $parameters) { return collect($parameters)->map(function ($value, $key) { - if (is_array($value) && Str::startsWith($key, '--')) { - return collect($value)->map(function ($value) use ($key) { - return $key.'='.ProcessUtils::escapeArgument($value); - })->implode(' '); - } elseif (is_array($value)) { - $value = collect($value)->map(function ($value) { - return ProcessUtils::escapeArgument($value); - })->implode(' '); - } elseif (! is_numeric($value) && ! preg_match('/^(-.$|--.*)/i', $value)) { + if (is_array($value)) { + return $this->compileArrayInput($key, $value); + } + + if (! is_numeric($value) && ! preg_match('/^(-.$|--.*)/i', $value)) { $value = ProcessUtils::escapeArgument($value); } return is_numeric($key) ? $value : "{$key}={$value}"; })->implode(' '); } + /** + * Compile array input for a command. + * + * @param string|int $key + * @param array $value + * @return string + */ + public function compileArrayInput($key, $value) + { + $value = collect($value)->map(function ($value) { + return ProcessUtils::escapeArgument($value); + }); + + if (Str::startsWith($key, '--')) { + $value = $value->map(function ($value) use ($key) { + return "{$key}={$value}"; + }); + } elseif (Str::startsWith($key, '-')) { + $value = $value->map(function ($value) use ($key) { + return "{$key} {$value}"; + }); + } + + return $value->implode(' '); + } + /** * Determine if the server is allowed to run this event. *
true
Other
laravel
framework
36e215dd39cd757a8ffc6b17794de60476b2289d.json
Fix console options parsing with scheduler Co-Authored-By: Mohamed Said <themsaid@gmail.com>
tests/Console/ConsoleEventSchedulerTest.php
@@ -59,6 +59,9 @@ public function testExecCreatesNewCommand() $schedule->exec('path/to/command', ['--title' => 'A "real" test']); $schedule->exec('path/to/command', [['one', 'two']]); $schedule->exec('path/to/command', ['-1 minute']); + $schedule->exec('path/to/command', ['foo' => ['bar', 'baz']]); + $schedule->exec('path/to/command', ['--foo' => ['bar', 'baz']]); + $schedule->exec('path/to/command', ['-F' => ['bar', 'baz']]); $events = $schedule->events(); $this->assertSame('path/to/command', $events[0]->command); @@ -69,6 +72,9 @@ public function testExecCreatesNewCommand() $this->assertSame("path/to/command --title={$escape}A {$escapeReal}real{$escapeReal} test{$escape}", $events[5]->command); $this->assertSame("path/to/command {$escape}one{$escape} {$escape}two{$escape}", $events[6]->command); $this->assertSame("path/to/command {$escape}-1 minute{$escape}", $events[7]->command); + $this->assertSame("path/to/command {$escape}bar{$escape} {$escape}baz{$escape}", $events[8]->command); + $this->assertSame("path/to/command --foo={$escape}bar{$escape} --foo={$escape}baz{$escape}", $events[9]->command); + $this->assertSame("path/to/command -F {$escape}bar{$escape} -F {$escape}baz{$escape}", $events[10]->command); } public function testExecCreatesNewCommandWithTimezone()
true
Other
laravel
framework
cfc3ac9c8b0a593d264ae722ab90601fa4882d0e.json
fix array options
src/Illuminate/Console/Scheduling/Schedule.php
@@ -11,6 +11,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\CallQueuedClosure; use Illuminate\Support\ProcessUtils; +use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use RuntimeException; @@ -198,7 +199,11 @@ public function exec($command, array $parameters = []) protected function compileParameters(array $parameters) { return collect($parameters)->map(function ($value, $key) { - if (is_array($value)) { + if (is_array($value) && Str::startsWith($key, '--')) { + return collect($value)->map(function ($value) use ($key) { + return $key.'='.ProcessUtils::escapeArgument($value); + })->implode(' '); + } elseif (is_array($value)) { $value = collect($value)->map(function ($value) { return ProcessUtils::escapeArgument($value); })->implode(' ');
false
Other
laravel
framework
8a0a8e430d33ea8c2f784f4443c1912f0a027013.json
Fix Closure namespace
src/Illuminate/Console/Scheduling/Event.php
@@ -501,7 +501,7 @@ protected function getEmailSubject() /** * Register a callback that uses the output after the job runs. * - * @param Closure $callback + * @param \Closure $callback * @param bool $onlyIfOutputExists * @return $this */ @@ -516,7 +516,7 @@ public function thenWithOutput(Closure $callback, $onlyIfOutputExists = false) * Register a callback that uses the output after the job runs if the given condition is true. * * @param bool $value - * @param Closure $callback + * @param \Closure $callback * @param bool $onlyIfOutputExists * @return $this */ @@ -530,7 +530,7 @@ public function thenIfWithOutput($value, Closure $callback, $onlyIfOutputExists /** * Register a callback that uses the output if the operation succeeds. * - * @param Closure $callback + * @param \Closure $callback * @param bool $onlyIfOutputExists * @return $this */ @@ -544,7 +544,7 @@ public function onSuccessWithOutput(Closure $callback, $onlyIfOutputExists = fal /** * Register a callback that uses the output if the operation fails. * - * @param Closure $callback + * @param \Closure $callback * @param bool $onlyIfOutputExists * @return $this */ @@ -558,9 +558,9 @@ public function onFailureWithOutput(Closure $callback, $onlyIfOutputExists = fal /** * Get the callback that provides output. * - * @param Closure $callback + * @param \Closure $callback * @param bool $onlyIfOutputExists - * @return Closure + * @return \Closure */ protected function withOutputCallback(Closure $callback, $onlyIfOutputExists = false) {
false
Other
laravel
framework
5d872d1fe07eee74fd7f28d138e31a4895c6aa53.json
Add withOutput callbacks
src/Illuminate/Console/Scheduling/Event.php
@@ -498,6 +498,83 @@ protected function getEmailSubject() return "Scheduled Job Output For [{$this->command}]"; } + /** + * Register a callback that uses the output after the job runs. + * + * @param Closure $callback + * @param bool $onlyIfOutputExists + * @return $this + */ + public function thenWithOutput(Closure $callback, $onlyIfOutputExists = false) + { + $this->ensureOutputIsBeingCaptured(); + + return $this->then($this->withOutputCallback($callback, $onlyIfOutputExists)); + } + + /** + * Register a callback that uses the output after the job runs if the given condition is true. + * + * @param bool $value + * @param Closure $callback + * @param bool $onlyIfOutputExists + * @return $this + */ + public function thenIfWithOutput($value, Closure $callback, $onlyIfOutputExists = false) + { + $this->ensureOutputIsBeingCaptured(); + + return $value ? $this->then($this->withOutputCallback($callback, $onlyIfOutputExists)) : $this; + } + + /** + * Register a callback that uses the output if the operation succeeds. + * + * @param Closure $callback + * @param bool $onlyIfOutputExists + * @return $this + */ + public function onSuccessWithOutput(Closure $callback, $onlyIfOutputExists = false) + { + $this->ensureOutputIsBeingCaptured(); + + return $this->onSuccess($this->withOutputCallback($callback, $onlyIfOutputExists)); + } + + /** + * Register a callback that uses the output if the operation fails. + * + * @param Closure $callback + * @param bool $onlyIfOutputExists + * @return $this + */ + public function onFailureWithOutput(Closure $callback, $onlyIfOutputExists = false) + { + $this->ensureOutputIsBeingCaptured(); + + return $this->onFailure($this->withOutputCallback($callback, $onlyIfOutputExists)); + } + + /** + * Get the callback that provides output. + * + * @param Closure $callback + * @param bool $onlyIfOutputExists + * @return Closure + */ + protected function withOutputCallback(Closure $callback, $onlyIfOutputExists = false) + { + return function () use ($callback, $onlyIfOutputExists) { + $text = file_exists($this->output) ? file_get_contents($this->output) : ''; + + if ($onlyIfOutputExists && empty($text)) { + return; + } + + return $callback($text); + }; + } + /** * Register a callback to ping a given URL before the job runs. *
false
Other
laravel
framework
386e7d7ada0985dfb5408d2f4d5cdbf30846f9af.json
Implement call named scope
src/Illuminate/Database/Eloquent/Builder.php
@@ -922,10 +922,7 @@ public function scopes($scopes) // Next we'll pass the scope callback to the callScope method which will take // care of grouping the "wheres" properly so the logical order doesn't get // messed up when adding scopes. Then we'll return back out the builder. - $builder = $builder->callScope( - [$this->model, 'scope'.ucfirst($scope)], - (array) $parameters - ); + $builder = $builder->callNamedScope($scope, (array) $parameters); } return $builder; @@ -976,7 +973,7 @@ public function applyScopes() * @param array $parameters * @return mixed */ - protected function callScope(callable $scope, $parameters = []) + protected function callScope(callable $scope, array $parameters = []) { array_unshift($parameters, $this); @@ -997,6 +994,20 @@ protected function callScope(callable $scope, $parameters = []) return $result; } + /** + * Apply the given named scope on the current builder instance. + * + * @param string $scope + * @param array $parameters + * @return mixed + */ + protected function callNamedScope($scope, array $parameters = []) + { + return $this->callScope(function () use ($scope, $parameters) { + return $this->model->callNamedScope($scope, $parameters); + }); + } + /** * Nest where conditions by slicing them at the given where count. * @@ -1385,7 +1396,7 @@ public function __call($method, $parameters) } if ($this->hasScope($method)) { - return $this->callScope([$this->model, 'scope'.ucfirst($method)], $parameters); + return $this->callNamedScope($method, $parameters); } if (in_array($method, $this->passthru)) {
true
Other
laravel
framework
386e7d7ada0985dfb5408d2f4d5cdbf30846f9af.json
Implement call named scope
src/Illuminate/Database/Eloquent/Model.php
@@ -1111,12 +1111,24 @@ public function newPivot(self $parent, array $attributes, $table, $exists, $usin /** * Determine if the model has a given scope. * - * @param string $method + * @param string $scope * @return bool */ - public function hasScope($method) + public function hasScope($scope) + { + return method_exists($this, 'scope'.ucfirst($scope)); + } + + /** + * Apply the given named scope if possible. + * + * @param string $scope + * @param array $parameters + * @return mixed + */ + public function callNamedScope($scope, array $parameters = []) { - return method_exists($this, 'scope'.ucfirst($method)); + return $this->{'scope'.ucfirst($scope)}(...$parameters); } /**
true
Other
laravel
framework
9922c87369962939af7c620472fe3a82dd0f4019.json
allow only a closure in Event::fake() assertions
src/Illuminate/Support/Testing/Fakes/EventFake.php
@@ -5,10 +5,13 @@ use Closure; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Arr; +use Illuminate\Support\Traits\ReflectsClosures; use PHPUnit\Framework\Assert as PHPUnit; class EventFake implements Dispatcher { + use ReflectsClosures; + /** * The original event dispatcher. * @@ -53,6 +56,10 @@ public function __construct(Dispatcher $dispatcher, $eventsToFake = []) */ public function assertDispatched($event, $callback = null) { + if ($event instanceof Closure) { + [$event, $callback] = [$this->firstParameterType($event), $event]; + } + if (is_int($callback)) { return $this->assertDispatchedTimes($event, $callback); } @@ -89,6 +96,10 @@ public function assertDispatchedTimes($event, $times = 1) */ public function assertNotDispatched($event, $callback = null) { + if ($event instanceof Closure) { + [$event, $callback] = [$this->firstParameterType($event), $event]; + } + PHPUnit::assertCount( 0, $this->dispatched($event, $callback), "The unexpected [{$event}] event was dispatched."
true
Other
laravel
framework
9922c87369962939af7c620472fe3a82dd0f4019.json
allow only a closure in Event::fake() assertions
tests/Support/SupportTestingEventFakeTest.php
@@ -31,6 +31,15 @@ public function testAssertDispatched() $this->fake->assertDispatched(EventStub::class); } + public function testAssertDispatchedWithClosure() + { + $this->fake->dispatch(new EventStub); + + $this->fake->assertDispatched(function (EventStub $event) { + return true; + }); + } + public function testAssertDispatchedWithCallbackInt() { $this->fake->dispatch(EventStub::class); @@ -75,6 +84,20 @@ public function testAssertNotDispatched() } } + public function testAssertNotDispatchedWithClosure() + { + $this->fake->dispatch(new EventStub); + + try { + $this->fake->assertNotDispatched(function (EventStub $event) { + return true; + }); + $this->fail(); + } catch (ExpectationFailedException $e) { + $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\EventStub] event was dispatched.')); + } + } + public function testAssertDispatchedWithIgnore() { $dispatcher = m::mock(Dispatcher::class);
true
Other
laravel
framework
5783f4a741a537aaee9845fb725e9eb9941ce376.json
allow only a closure in Queue::fake() assertions
src/Illuminate/Support/Testing/Fakes/QueueFake.php
@@ -3,12 +3,16 @@ namespace Illuminate\Support\Testing\Fakes; use BadMethodCallException; +use Closure; use Illuminate\Contracts\Queue\Queue; use Illuminate\Queue\QueueManager; +use Illuminate\Support\Traits\ReflectsClosures; use PHPUnit\Framework\Assert as PHPUnit; class QueueFake extends QueueManager implements Queue { + use ReflectsClosures; + /** * All of the jobs that have been pushed. * @@ -25,6 +29,10 @@ class QueueFake extends QueueManager implements Queue */ public function assertPushed($job, $callback = null) { + if ($job instanceof Closure) { + [$job, $callback] = [$this->firstParameterType($job), $job]; + } + if (is_numeric($callback)) { return $this->assertPushedTimes($job, $callback); } @@ -62,6 +70,10 @@ protected function assertPushedTimes($job, $times = 1) */ public function assertPushedOn($queue, $job, $callback = null) { + if ($job instanceof Closure) { + [$job, $callback] = [$this->firstParameterType($job), $job]; + } + return $this->assertPushed($job, function ($job, $pushedQueue) use ($callback, $queue) { if ($pushedQueue !== $queue) { return false; @@ -180,6 +192,10 @@ protected function isChainOfObjects($chain) */ public function assertNotPushed($job, $callback = null) { + if ($job instanceof Closure) { + [$job, $callback] = [$this->firstParameterType($job), $job]; + } + PHPUnit::assertCount( 0, $this->pushed($job, $callback), "The unexpected [{$job}] job was pushed."
true
Other
laravel
framework
5783f4a741a537aaee9845fb725e9eb9941ce376.json
allow only a closure in Queue::fake() assertions
tests/Support/SupportTestingQueueFakeTest.php
@@ -43,6 +43,15 @@ public function testAssertPushed() $this->fake->assertPushed(JobStub::class); } + public function testAssertPushedWithClosure() + { + $this->fake->push($this->job); + + $this->fake->assertPushed(function (JobStub $job) { + return true; + }); + } + public function testQueueSize() { $this->assertEquals(0, $this->fake->size()); @@ -53,13 +62,27 @@ public function testQueueSize() } public function testAssertNotPushed() + { + $this->fake->push($this->job); + + try { + $this->fake->assertNotPushed(JobStub::class); + $this->fail(); + } catch (ExpectationFailedException $e) { + $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\JobStub] job was pushed.')); + } + } + + public function testAssertNotPushedWithClosure() { $this->fake->assertNotPushed(JobStub::class); $this->fake->push($this->job); try { - $this->fake->assertNotPushed(JobStub::class); + $this->fake->assertNotPushed(function (JobStub $job) { + return true; + }); $this->fail(); } catch (ExpectationFailedException $e) { $this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\JobStub] job was pushed.')); @@ -80,6 +103,24 @@ public function testAssertPushedOn() $this->fake->assertPushedOn('foo', JobStub::class); } + public function testAssertPushedOnWithClosure() + { + $this->fake->push($this->job, '', 'foo'); + + try { + $this->fake->assertPushedOn('bar', function (JobStub $job) { + return true; + }); + $this->fail(); + } catch (ExpectationFailedException $e) { + $this->assertThat($e, new ExceptionMessage('The expected [Illuminate\Tests\Support\JobStub] job was not pushed.')); + } + + $this->fake->assertPushedOn('foo', function (JobStub $job) { + return true; + }); + } + public function testAssertPushedTimes() { $this->fake->push($this->job);
true
Other
laravel
framework
6cb43b99eceff801ab7f660e23d8b57fa5c3559f.json
add ReflectsClosures trait
src/Illuminate/Support/Traits/ReflectsClosures.php
@@ -0,0 +1,31 @@ +<?php + +namespace Illuminate\Support\Traits; + +use Closure; +use ReflectionFunction; +use ReflectionParameter; + +trait ReflectsClosures +{ + /** + * Get the class types of the parameters of the given closure. + * + * @param Closure $closure + * @return array + * + * @throws \ReflectionException + */ + protected function closureParameterTypes(Closure $closure) + { + $reflection = new ReflectionFunction($closure); + + return array_map(function (ReflectionParameter $parameter) { + if ($parameter->isVariadic()) { + return null; + } + + return $parameter->getClass()->name ?? null; + }, $reflection->getParameters()); + } +}
true
Other
laravel
framework
6cb43b99eceff801ab7f660e23d8b57fa5c3559f.json
add ReflectsClosures trait
tests/Support/SupportReflectsClosuresTest.php
@@ -0,0 +1,61 @@ +<?php + +namespace Illuminate\Tests\Support; + +use Illuminate\Support\Traits\ReflectsClosures; +use PHPUnit\Framework\TestCase; +use RuntimeException; + +class SupportReflectsClosuresTest extends TestCase +{ + public function testReflectsClosures() + { + $this->assertParameterTypes([ExampleParameter::class], function (ExampleParameter $one) { + // assert the Closure isn't actually executed + throw new RunTimeException(); + }); + + $this->assertParameterTypes([], function () { + // + }); + + $this->assertParameterTypes([null], function ($one) { + // + }); + + $this->assertParameterTypes([null, ExampleParameter::class], function ($one, ExampleParameter $two = null) { + // + }); + + $this->assertParameterTypes([null, ExampleParameter::class], function (string $one, ?ExampleParameter $two) { + // + }); + + // Because the parameter is variadic, the closure will always receive an array. + $this->assertParameterTypes([null], function (ExampleParameter ...$vars) { + // + }); + } + + private function assertParameterTypes($expected, $closure) + { + $types = ReflectsClosuresClass::reflect($closure); + + $this->assertSame($expected, $types); + } +} + +class ReflectsClosuresClass +{ + use ReflectsClosures; + + public static function reflect($closure) + { + return (new static)->closureParameterTypes($closure); + } +} + +class ExampleParameter +{ + // +}
true
Other
laravel
framework
358827f3b0e44eeb166e6ef70d720213b5b5d3a7.json
Fix duplicate model name
tests/Integration/Database/EloquentModelScopeTest.php
@@ -11,20 +11,20 @@ class EloquentModelScopeTest extends DatabaseTestCase { public function testModelHasScope() { - $model = new TestModel1; + $model = new TestScopeModel1; $this->assertTrue($model->hasScope("exists")); } public function testModelDoesNotHaveScope() { - $model = new TestModel1; + $model = new TestScopeModel1; $this->assertFalse($model->hasScope("doesNotExist")); } } -class TestModel1 extends Model +class TestScopeModel1 extends Model { public function scopeExists() {
false
Other
laravel
framework
d370eb18092210adadcbdd857f97d4c1dc2784c3.json
Add hasScope to the builder
src/Illuminate/Database/Eloquent/Builder.php
@@ -1327,6 +1327,17 @@ public static function hasGlobalMacro($name) return isset(static::$macros[$name]); } + /** + * Determine if the given model has a scope. + * + * @param string $method + * @return bool + */ + public function hasScope(string $name) + { + return $this->model->hasScope($name); + } + /** * Dynamically access builder proxies. * @@ -1373,7 +1384,7 @@ public function __call($method, $parameters) return call_user_func_array(static::$macros[$method], $parameters); } - if ($this->model->hasScope($method)) { + if ($this->hasScope($method)) { return $this->callScope([$this->model, 'scope' . ucfirst($method)], $parameters); }
false