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
648bdae04bd15f4b32f76c5dfee0294e067e90b1.json
Apply fixes from StyleCI (#24794)
src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php
@@ -82,5 +82,4 @@ protected function inExceptArray($request) return false; } - }
false
Other
laravel
framework
2b3902a77f9f8193ab7ee157530e97d1b96cfa05.json
Allow tuple notation for actions (#24738)
src/Illuminate/Routing/UrlGenerator.php
@@ -392,7 +392,7 @@ protected function toRoute($route, $parameters, $absolute) /** * Get the URL to a controller action. * - * @param string $action + * @param string|array $action * @param mixed $parameters * @param bool $absolute * @return string @@ -411,11 +411,15 @@ public function action($action, $parameters = [], $absolute = true) /** * Format the given controller action. * - * @param string $action + * @param string|array $action * @return string */ protected function formatAction($action) { + if (is_array($action)) { + $action = implode('@', $action); + } + if ($this->rootNamespace && ! (strpos($action, '\\') === 0)) { return $this->rootNamespace.'\\'.$action; } else {
true
Other
laravel
framework
2b3902a77f9f8193ab7ee157530e97d1b96cfa05.json
Allow tuple notation for actions (#24738)
tests/Routing/RoutingUrlGeneratorTest.php
@@ -244,6 +244,7 @@ public function testBasicRouteGeneration() $this->assertEquals('/foo/bar/taylor/breeze/otwell?fly=wall', $url->route('bar', ['taylor', 'otwell', 'fly' => 'wall'], false)); $this->assertEquals('https://www.foo.com/foo/baz', $url->route('baz')); $this->assertEquals('http://www.foo.com/foo/bam', $url->action('foo@bar')); + $this->assertEquals('http://www.foo.com/foo/bam', $url->action(['foo', 'bar'])); $this->assertEquals('http://www.foo.com/foo/invoke', $url->action('InvokableActionStub')); $this->assertEquals('http://www.foo.com/foo/bar/taylor/breeze/otwell?wall&woz', $url->route('bar', ['wall', 'woz', 'boom' => 'otwell', 'baz' => 'taylor'])); $this->assertEquals('http://www.foo.com/foo/bar/taylor/breeze/otwell?wall&woz', $url->route('bar', ['taylor', 'otwell', 'wall', 'woz']));
true
Other
laravel
framework
e77160aa29370d76bb3b9440d7d141c0f21c226b.json
add missing docblock for RuntimeException (#24732)
src/Illuminate/Hashing/ArgonHasher.php
@@ -47,6 +47,8 @@ public function __construct(array $options = []) * @param string $value * @param array $options * @return string + * + * @throws \RuntimeException */ public function make($value, array $options = []) {
false
Other
laravel
framework
adec8f3b55a7d03305fb8a36b6865206f9a81a8b.json
add docblock for RuntimeException (#24686)
src/Illuminate/Foundation/Console/ViewClearCommand.php
@@ -46,6 +46,8 @@ public function __construct(Filesystem $files) * Execute the console command. * * @return void + * + * @throws \RuntimeException */ public function handle() {
false
Other
laravel
framework
3414dcfcbe27cf0f4deee0670f022983e8016392.json
add docblock for exception (#24673)
src/Illuminate/Console/Application.php
@@ -166,6 +166,8 @@ public static function forgetBootstrappers() * @param array $parameters * @param \Symfony\Component\Console\Output\OutputInterface|null $outputBuffer * @return int + * + * @throws \Symfony\Component\Console\Exception\CommandNotFoundException */ public function call($command, array $parameters = [], $outputBuffer = null) {
false
Other
laravel
framework
e227c3762b1b2216e3b98ab507a61d23450e1248.json
Add test for overwriting keys (#24676)
tests/Support/SupportCollectionTest.php
@@ -1586,6 +1586,25 @@ public function testNth() $this->assertEquals(['d'], $data->nth(4, 3)->all()); } + public function testMapWithKeysOverwritingKeys() + { + $data = new Collection([ + ['id' => 1, 'name' => 'A'], + ['id' => 2, 'name' => 'B'], + ['id' => 1, 'name' => 'C'], + ]); + $data = $data->mapWithKeys(function ($item) { + return [$item['id'] => $item['name']]; + }); + $this->assertSame( + [ + 1 => 'C', + 2 => 'B', + ], + $data->all() + ); + } + public function testTransform() { $data = new Collection(['first' => 'taylor', 'last' => 'otwell']);
false
Other
laravel
framework
314552e2a0fbdb26dc83077600685a598257839e.json
Apply fixes from StyleCI
src/Illuminate/Redis/Connectors/PhpRedisConnector.php
@@ -92,7 +92,7 @@ protected function createClient(array $config) */ protected function establishConnection($client, array $config) { - if($config['persistent'] ?? false) { + if ($config['persistent'] ?? false) { $this->establishPersistentConnection($client, $config); } else { $this->establishRegularConnection($client, $config); @@ -112,7 +112,7 @@ protected function establishPersistentConnection($client, array $config) $config['host'], $config['port'], Arr::get($config, 'timeout', 0.0), - Arr::get($config, 'persistent_id', NULL) + Arr::get($config, 'persistent_id', null) ); } @@ -129,7 +129,7 @@ protected function establishRegularConnection($client, array $config) $config['host'], $config['port'], Arr::get($config, 'timeout', 0.0), - Arr::get($config, 'reserved', NULL), + Arr::get($config, 'reserved', null), Arr::get($config, 'retry_interval', 0) ); }
true
Other
laravel
framework
314552e2a0fbdb26dc83077600685a598257839e.json
Apply fixes from StyleCI
tests/Redis/RedisConnectionTest.php
@@ -615,7 +615,7 @@ public function connections() 'options' => ['prefix' => 'laravel:'], 'timeout' => 0.5, 'persistent' => true, - 'persistent_id' => 'laravel' + 'persistent_id' => 'laravel', ], ]);
true
Other
laravel
framework
47f55ecc90c02493c50bab1c10985d063cca1267.json
Add a test case for Gate::has() (#24646)
tests/Auth/AuthAccessGateTest.php
@@ -373,6 +373,43 @@ public function test_every_ability_check_fails_if_none_pass() $this->assertFalse($gate->check(['edit', 'update'], new AccessGateTestDummy)); } + + /** + * @dataProvider hasAbilitiesTestDataProvider + * + * @param array $abilitiesToSet + * @param array|string $abilitiesToCheck + * @param bool $expectedHasValue + */ + public function test_has_abilities($abilitiesToSet, $abilitiesToCheck, $expectedHasValue) + { + $gate = $this->getBasicGate(); + + $gate->resource('test', AccessGateTestResource::class, $abilitiesToSet); + + $this->assertEquals($expectedHasValue, $gate->has($abilitiesToCheck)); + } + + public function hasAbilitiesTestDataProvider() + { + $abilities = ['foo' => 'foo', 'bar' => 'bar']; + $noAbilities = []; + + return [ + [$abilities, ['test.foo', 'test.bar'], true], + [$abilities, ['test.bar', 'test.foo'], true], + [$abilities, ['test.bar', 'test.foo', 'test.baz'], false], + [$abilities, ['test.bar'], true], + [$abilities, ['baz'], false], + [$abilities, [''], false], + [$abilities, [], true], + [$abilities, 'test.bar', true], + [$abilities, 'test.foo', true], + [$abilities, '', false], + [$noAbilities, '', false], + [$noAbilities, [], true], + ]; + } } class AccessGateTestClass
false
Other
laravel
framework
02591e21d6307d9ff34d406cf1857df13c15586c.json
Apply fixes from StyleCI (#24642)
tests/Database/DatabaseEloquentIntegrationTest.php
@@ -3,7 +3,6 @@ namespace Illuminate\Tests\Database; use Exception; -use ReflectionObject; use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model;
false
Other
laravel
framework
fdc1e61d901ec6f660b505630e34f292495497bb.json
Apply fixes from StyleCI (#24641)
src/Illuminate/Database/Eloquent/Relations/Relation.php
@@ -165,7 +165,7 @@ public function touch() if (! $model::isIgnoringTouch()) { $this->rawUpdate([ - $model->getUpdatedAtColumn() => $model->freshTimestampString() + $model->getUpdatedAtColumn() => $model->freshTimestampString(), ]); } }
false
Other
laravel
framework
14beafaebbd6fe0f1a48942389c57a67b69f23a2.json
Add missing import (#24614)
src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php
@@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Testing\Concerns; +use Exception; use Illuminate\Redis\RedisManager; trait InteractsWithRedis @@ -50,7 +51,7 @@ public function setUpRedis() try { $this->redis['predis']->connection()->flushdb(); - } catch (\Exception $e) { + } catch (Exception $e) { if ($host === '127.0.0.1' && $port === 6379 && getenv('REDIS_HOST') === false) { $this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__); static::$connectionFailedOnceWithDefaultsSkip = true;
false
Other
laravel
framework
5b5319ff627f0cd830ce52e8da2a70b48029284b.json
Use hSetNx with valid case (#24615)
src/Illuminate/Redis/Connections/PhpRedisConnection.php
@@ -140,7 +140,7 @@ public function hmset($key, ...$dictionary) */ public function hsetnx($hash, $key, $value) { - return (int) $this->client->hsetnx($hash, $key, $value); + return (int) $this->client->hSetNx($hash, $key, $value); } /**
false
Other
laravel
framework
8b289e9dd00ae34394f76e3615ecd8a30d7be8dd.json
Apply fixes from StyleCI (#24613)
src/Illuminate/Database/Migrations/Migrator.php
@@ -220,7 +220,7 @@ protected function getMigrationsForRollback(array $options) if (($steps = $options['step'] ?? 0) > 0) { return $this->repository->getMigrations($steps); } - + return $this->repository->getLast(); }
false
Other
laravel
framework
f05da7293b1921f40238a3e0f54c41656dfd941b.json
Remove unused import (#24587)
src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php
@@ -5,7 +5,6 @@ use Illuminate\Routing\Redirector; use Illuminate\Support\ServiceProvider; use Illuminate\Foundation\Http\FormRequest; -use Symfony\Component\HttpFoundation\Request; use Illuminate\Contracts\Validation\ValidatesWhenResolved; class FormRequestServiceProvider extends ServiceProvider
false
Other
laravel
framework
6197db7f3cfc8086d6beb486800b0d107cb9e2ce.json
check optional status on policies
src/Illuminate/Auth/Access/Gate.php
@@ -363,11 +363,25 @@ protected function allowsGuests($ability, $arguments) * @return bool */ protected function policyAllowsGuests($policy, $ability, $arguments) + { + return $this->methodAllowsGuests( + $policy, $this->formatAbilityToMethod($ability) + ); + } + + /** + * Determine if the given class method allows guests. + * + * @param string $class + * @param string $method + * @return bool + */ + protected function methodAllowsGuests($class, $method) { try { - $reflection = new ReflectionClass($policy); + $reflection = new ReflectionClass($class); - $method = $reflection->getMethod($this->formatAbilityToMethod($ability)); + $method = $reflection->getMethod($method); } catch (Exception $e) { return false; } @@ -390,7 +404,19 @@ protected function policyAllowsGuests($policy, $ability, $arguments) */ protected function abilityAllowsGuests($ability, $arguments) { - $parameters = (new ReflectionFunction($this->abilities[$ability]))->getParameters(); + return $this->callbackAllowsGuests($this->abilities[$ability]); + } + + /** + * Determine if the callback allows guests. + * + * @param callable $callback + * @param array $arguments + * @return bool + */ + protected function callbackAllowsGuests($callback) + { + $parameters = (new ReflectionFunction($callback))->getParameters(); return isset($parameters[0]) && $this->parameterAllowsGuests($parameters[0]); } @@ -435,6 +461,10 @@ protected function callBeforeCallbacks($user, $ability, array $arguments) $arguments = array_merge([$user, $ability], [$arguments]); foreach ($this->beforeCallbacks as $before) { + if (is_null($user) && ! $this->callbackAllowsGuests($before)) { + continue; + } + if (! is_null($result = $before(...$arguments))) { return $result; } @@ -455,6 +485,10 @@ protected function callAfterCallbacks($user, $ability, array $arguments, $result $arguments = array_merge([$user, $ability, $result], [$arguments]); foreach ($this->afterCallbacks as $after) { + if (is_null($user) && ! $this->callbackAllowsGuests($after)) { + continue; + } + $after(...$arguments); } } @@ -578,7 +612,8 @@ protected function resolvePolicyCallback($user, $ability, array $arguments, $pol */ protected function callPolicyBefore($policy, $user, $ability, $arguments) { - if (method_exists($policy, 'before')) { + if (method_exists($policy, 'before') && + (! is_null($user) || $this->methodAllowsGuests($policy, 'before'))) { return $policy->before($user, $ability, ...$arguments); } }
false
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Auth/Console/stubs/make/views/auth/login.stub
@@ -8,7 +8,7 @@ <div class="card-header">{{ __('Login') }}</div> <div class="card-body"> - <form method="POST" action="{{ route('login') }}"> + <form method="POST" action="{{ route('login') }}" aria-label="{{ __('Login') }}"> @csrf <div class="form-group row"> @@ -18,7 +18,7 @@ <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus> @if ($errors->has('email')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('email') }}</strong> </span> @endif @@ -32,7 +32,7 @@ <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required> @if ($errors->has('password')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('password') }}</strong> </span> @endif
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/email.stub
@@ -9,12 +9,12 @@ <div class="card-body"> @if (session('status')) - <div class="alert alert-success"> + <div class="alert alert-success" role="alert"> {{ session('status') }} </div> @endif - <form method="POST" action="{{ route('password.email') }}"> + <form method="POST" action="{{ route('password.email') }}" aria-label="{{ __('Reset Password') }}"> @csrf <div class="form-group row"> @@ -24,7 +24,7 @@ <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required> @if ($errors->has('email')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('email') }}</strong> </span> @endif
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/reset.stub
@@ -8,7 +8,7 @@ <div class="card-header">{{ __('Reset Password') }}</div> <div class="card-body"> - <form method="POST" action="{{ route('password.update') }}"> + <form method="POST" action="{{ route('password.update') }}" aria-label="{{ __('Reset Password') }}"> @csrf <input type="hidden" name="token" value="{{ $token }}"> @@ -20,7 +20,7 @@ <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ $email ?? old('email') }}" required autofocus> @if ($errors->has('email')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('email') }}</strong> </span> @endif @@ -34,7 +34,7 @@ <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required> @if ($errors->has('password')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('password') }}</strong> </span> @endif
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Auth/Console/stubs/make/views/auth/register.stub
@@ -8,7 +8,7 @@ <div class="card-header">{{ __('Register') }}</div> <div class="card-body"> - <form method="POST" action="{{ route('register') }}"> + <form method="POST" action="{{ route('register') }}" aria-label="{{ __('Register') }}"> @csrf <div class="form-group row"> @@ -18,7 +18,7 @@ <input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required autofocus> @if ($errors->has('name')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('name') }}</strong> </span> @endif @@ -32,7 +32,7 @@ <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required> @if ($errors->has('email')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('email') }}</strong> </span> @endif @@ -46,7 +46,7 @@ <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required> @if ($errors->has('password')) - <span class="invalid-feedback"> + <span class="invalid-feedback" role="alert"> <strong>{{ $errors->first('password') }}</strong> </span> @endif
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Auth/Console/stubs/make/views/home.stub
@@ -9,7 +9,7 @@ <div class="card-body"> @if (session('status')) - <div class="alert alert-success"> + <div class="alert alert-success" role="alert"> {{ session('status') }} </div> @endif
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub
@@ -27,7 +27,7 @@ <a class="navbar-brand" href="{{ url('/') }}"> {{ config('app.name', 'Laravel') }} </a> - <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> + <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}"> <span class="navbar-toggler-icon"></span> </button>
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Auth/GuardHelpers.php
@@ -40,6 +40,16 @@ public function authenticate() throw new AuthenticationException; } + /** + * Determine if the guard has a user instance. + * + * @return bool + */ + public function hasUser() + { + return ! is_null($this->user); + } + /** * Determine if the current user is authenticated. *
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Cache/ArrayStore.php
@@ -23,9 +23,7 @@ class ArrayStore extends TaggableStore implements Store */ public function get($key) { - if (array_key_exists($key, $this->storage)) { - return $this->storage[$key]; - } + return $this->storage[$key] ?? null; } /**
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Console/Scheduling/Event.php
@@ -145,7 +145,7 @@ class Event /** * Create a new event instance. * - * @param \Illuminate\Console\Scheduling\Mutex $mutex + * @param \Illuminate\Console\Scheduling\EventMutex $mutex * @param string $command * @return void */
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Console/Migrations/BaseCommand.php
@@ -25,7 +25,7 @@ protected function getMigrationPaths() } return array_merge( - [$this->getMigrationPath()], $this->migrator->paths() + $this->migrator->paths(), [$this->getMigrationPath()] ); }
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
@@ -535,7 +535,7 @@ protected function isCustomDateTimeCast($cast) * * @param string $key * @param mixed $value - * @return $this + * @return mixed */ public function setAttribute($key, $value) {
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
@@ -693,7 +693,7 @@ public function relationLoaded($key) } /** - * Set the specific relationship in the model. + * Set the given relationship on the model. * * @param string $relation * @param mixed $value @@ -706,6 +706,19 @@ public function setRelation($relation, $value) return $this; } + /** + * Unset a loaded relationship. + * + * @param string $relation + * @return $this + */ + public function unsetRelation($relation) + { + unset($this->relations[$relation]); + + return $this; + } + /** * Set the entire relations array on the model. *
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Eloquent/Relations/Relation.php
@@ -346,9 +346,7 @@ protected static function buildMorphMapFromModels(array $models = null) */ public static function getMorphedModel($alias) { - return array_key_exists($alias, self::$morphMap) - ? self::$morphMap[$alias] - : null; + return self::$morphMap[$alias] ?? null; } /**
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Grammar.php
@@ -2,10 +2,13 @@ namespace Illuminate\Database; +use Illuminate\Support\Traits\Macroable; use Illuminate\Database\Query\Expression; abstract class Grammar { + use Macroable; + /** * The grammar table prefix. *
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Query/Builder.php
@@ -1449,7 +1449,7 @@ public function whereJsonContains($column, $value, $boolean = 'and', $not = fals $this->wheres[] = compact('type', 'column', 'value', 'boolean', 'not'); if (! $value instanceof Expression) { - $this->addBinding(json_encode($value)); + $this->addBinding($this->grammar->prepareBindingForJsonContains($value)); } return $this;
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Query/Grammars/Grammar.php
@@ -523,6 +523,17 @@ protected function compileJsonContains($column, $value) throw new RuntimeException('This database engine does not support JSON contains operations.'); } + /** + * Prepare the binding for a "JSON contains" statement. + * + * @param mixed $binding + * @return string + */ + public function prepareBindingForJsonContains($binding) + { + return json_encode($binding); + } + /** * Compile the "group by" portions of the query. *
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
@@ -104,6 +104,33 @@ protected function whereDate(Builder $query, $where) return 'cast('.$this->wrap($where['column']).' as date) '.$where['operator'].' '.$value; } + /** + * Compile a "JSON contains" statement into SQL. + * + * @param string $column + * @param string $value + * @return string + */ + protected function compileJsonContains($column, $value) + { + $from = $column[0] == '[' + ? 'openjson('.$column.')' + : substr_replace($column, 'openjson', 0, strlen('json_value')); + + return $value.' in (select [value] from '.$from.')'; + } + + /** + * Prepare the binding for a "JSON contains" statement. + * + * @param mixed $binding + * @return string + */ + public function prepareBindingForJsonContains($binding) + { + return is_bool($binding) ? json_encode($binding) : $binding; + } + /** * Create a full ANSI offset clause for the query. *
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Filesystem/FilesystemManager.php
@@ -318,11 +318,13 @@ protected function adapt(FilesystemInterface $filesystem) * * @param string $name * @param mixed $disk - * @return void + * @return $this */ public function set($name, $disk) { $this->disks[$name] = $disk; + + return $this; } /**
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Foundation/Testing/TestResponse.php
@@ -64,6 +64,21 @@ public function assertSuccessful() return $this; } + /** + * Assert that the response has a 200 status code. + * + * @return $this + */ + public function assertOk() + { + PHPUnit::assertTrue( + $this->isOk(), + 'Response status code ['.$this->getStatusCode().'] does not match expected 200 status code.' + ); + + return $this; + } + /** * Assert that the response has a not found status code. *
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Foundation/helpers.php
@@ -779,7 +779,7 @@ function resource_path($path = '') /** * Return a new response from the application. * - * @param string $content + * @param string|array $content * @param int $status * @param array $headers * @return \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Routing\ResponseFactory
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Hashing/AbstractHasher.php
@@ -0,0 +1,34 @@ +<?php + +namespace Illuminate\Hashing; + +abstract class AbstractHasher +{ + /** + * Get information about the given hashed value. + * + * @param string $hashedValue + * @return array + */ + public function info($hashedValue) + { + return password_get_info($hashedValue); + } + + /** + * Check the given plain value against a hash. + * + * @param string $value + * @param string $hashedValue + * @param array $options + * @return bool + */ + public function check($value, $hashedValue, array $options = []) + { + if (strlen($hashedValue) === 0) { + return false; + } + + return password_verify($value, $hashedValue); + } +}
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Hashing/ArgonHasher.php
@@ -5,7 +5,7 @@ use RuntimeException; use Illuminate\Contracts\Hashing\Hasher as HasherContract; -class ArgonHasher implements HasherContract +class ArgonHasher extends AbstractHasher implements HasherContract { /** * The default memory cost factor. @@ -41,17 +41,6 @@ public function __construct(array $options = []) $this->threads = $options['threads'] ?? $this->threads; } - /** - * Get information about the given hashed value. - * - * @param string $hashedValue - * @return array - */ - public function info($hashedValue) - { - return password_get_info($hashedValue); - } - /** * Hash the given value. * @@ -83,20 +72,14 @@ public function make($value, array $options = []) * @param string $hashedValue * @param array $options * @return bool - * - * @throws \RuntimeException */ public function check($value, $hashedValue, array $options = []) { - if (strlen($hashedValue) === 0) { - return false; - } - if ($this->info($hashedValue)['algoName'] !== 'argon2i') { throw new RuntimeException('This password does not use the Argon algorithm.'); } - return password_verify($value, $hashedValue); + return parent::check($value, $hashedValue, $options); } /**
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Hashing/BcryptHasher.php
@@ -5,7 +5,7 @@ use RuntimeException; use Illuminate\Contracts\Hashing\Hasher as HasherContract; -class BcryptHasher implements HasherContract +class BcryptHasher extends AbstractHasher implements HasherContract { /** * The default cost factor. @@ -25,17 +25,6 @@ public function __construct(array $options = []) $this->rounds = $options['rounds'] ?? $this->rounds; } - /** - * Get information about the given hashed value. - * - * @param string $hashedValue - * @return array - */ - public function info($hashedValue) - { - return password_get_info($hashedValue); - } - /** * Hash the given value. * @@ -63,22 +52,16 @@ public function make($value, array $options = []) * * @param string $value * @param string $hashedValue - * @param array $options + * @param array $options * @return bool - * - * @throws \RuntimeException */ public function check($value, $hashedValue, array $options = []) { - if (strlen($hashedValue) === 0) { - return false; - } - if ($this->info($hashedValue)['algoName'] !== 'bcrypt') { throw new RuntimeException('This password does not use the Bcrypt algorithm.'); } - return password_verify($value, $hashedValue); + return parent::check($value, $hashedValue, $options); } /**
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Log/LogManager.php
@@ -336,8 +336,10 @@ protected function createMonologDriver(array $config) ); } + $with = array_merge($config['with'] ?? [], $config['handler_with'] ?? []); + return new Monolog($this->parseChannel($config), [$this->prepareHandler( - $this->app->make($config['handler'], $config['with'] ?? []), $config + $this->app->make($config['handler'], $with), $config )]); }
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Log/Logger.php
@@ -22,7 +22,7 @@ class Logger implements LoggerInterface /** * The event dispatcher instance. * - * @var \Illuminate\Contracts\Events\Dispatcher + * @var \Illuminate\Contracts\Events\Dispatcher|null */ protected $dispatcher;
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Routing/RouteAction.php
@@ -29,11 +29,10 @@ public static function parse($uri, $action) // as the "uses" property, because there is nothing else we need to do when // it is available. Otherwise we will need to find it in the action list. if (is_callable($action)) { - if (is_array($action)) { - $action = $action[0].'@'.$action[1]; - } - - return ['uses' => $action]; + return ! is_array($action) ? ['uses' => $action] : [ + 'uses' => $action[0].'@'.$action[1], + 'controller' => $action[0].'@'.$action[1], + ]; } // If no "uses" property has been set, we will dig through the array to find a
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Support/Facades/Auth.php
@@ -18,6 +18,11 @@ * @method static bool onceUsingId(mixed $id) * @method static bool viaRemember() * @method static void logout() + * @method static \Symfony\Component\HttpFoundation\Response|null onceBasic(string $field = 'email',array $extraConditions = []) + * @method static null|bool logoutOtherDevices(string $password, string $attribute = 'password') + * @method static \Illuminate\Contracts\Auth\UserProvider|null createUserProvider(string $provider = null) + * @method static \Illuminate\Auth\AuthManager extend(string $driver, \Closure $callback) + * @method static \Illuminate\Auth\AuthManager provider(string $name, \Closure $callback) * * @see \Illuminate\Auth\AuthManager * @see \Illuminate\Contracts\Auth\Factory
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Support/Facades/Broadcast.php
@@ -6,6 +6,8 @@ /** * @method static void connection($name = null); + * @method static \Illuminate\Broadcasting\Broadcasters\Broadcaster channel(string $channel, callable|string $callback) + * @method static mixed auth(\Illuminate\Http\Request $request) * * @see \Illuminate\Contracts\Broadcasting\Factory */
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Support/Facades/Lang.php
@@ -7,6 +7,7 @@ * @method static string transChoice(string $key, int | array | \Countable $number, array $replace = [], string $locale = null) * @method static string getLocale() * @method static void setLocale(string $locale) + * @method static string|array|null get(string $key, array $replace = [], string $locale = null, bool $fallback = true) * * @see \Illuminate\Translation\Translator */
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Support/Facades/Log.php
@@ -14,6 +14,8 @@ * @method static void info(string $message, array $context = []) * @method static void debug(string $message, array $context = []) * @method static void log($level, string $message, array $context = []) + * @method static mixed channel(string $channel = null) + * @method static \Psr\Log\LoggerInterface stack(array $channels, string $channel = null) * * @method static self channel(string $channel) * @method static self stack(array $channels)
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/Support/Facades/Route.php
@@ -14,6 +14,7 @@ * @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix) * @method static \Illuminate\Routing\PendingResourceRegistration resource(string $name, string $controller, array $options = []) * @method static \Illuminate\Routing\PendingResourceRegistration apiResource(string $name, string $controller, array $options = []) + * @method static void apiResources(array $resources) * @method static \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware) * @method static \Illuminate\Routing\Route substituteBindings(\Illuminate\Support\Facades\Route $route) * @method static void substituteImplicitBindings(\Illuminate\Support\Facades\Route $route)
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
src/Illuminate/View/Factory.php
@@ -148,7 +148,7 @@ public function make($view, $data = [], $mergeData = []) */ public function first(array $views, $data = [], $mergeData = []) { - $view = collect($views)->first(function ($view) { + $view = Arr::first($views, function ($view) { return $this->exists($view); });
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Auth/AuthGuardTest.php
@@ -178,6 +178,22 @@ public function testAuthenticateThrowsWhenUserIsNull() $guard->authenticate(); } + public function testHasUserReturnsTrueWhenUserIsNotNull() + { + $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); + $guard = $this->getGuard()->setUser($user); + + $this->assertTrue($guard->hasUser()); + } + + public function testHasUserReturnsFalseWhenUserIsNull() + { + $guard = $this->getGuard(); + $guard->getSession()->shouldNotReceive('get'); + + $this->assertFalse($guard->hasUser()); + } + public function testIsAuthedReturnsTrueWhenUserIsNotNull() { $user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Database/DatabaseEloquentRelationTest.php
@@ -25,6 +25,15 @@ public function testSetRelationFail() $this->assertArrayNotHasKey('foo', $parent->toArray()); } + public function testUnsetExistingRelation() + { + $parent = new EloquentRelationResetModelStub; + $relation = new EloquentRelationResetModelStub; + $parent->setRelation('foo', $relation); + $parent->unsetRelation('foo'); + $this->assertFalse($parent->relationLoaded('foo')); + } + public function testTouchMethodUpdatesRelatedTimestamps() { $builder = m::mock(Builder::class);
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Database/DatabaseMySqlSchemaGrammarTest.php
@@ -941,6 +941,18 @@ public function testDropAllTables() $this->assertEquals('drop table `alpha`,`beta`,`gamma`', $statement); } + public function testGrammarsAreMacroable() + { + // compileReplace macro. + $this->getGrammar()::macro('compileReplace', function () { + return true; + }); + + $c = $this->getGrammar()::compileReplace(); + + $this->assertTrue($c); + } + protected function getConnection() { return m::mock('Illuminate\Database\Connection');
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Database/DatabasePostgresSchemaGrammarTest.php
@@ -799,4 +799,16 @@ public function getGrammar() { return new \Illuminate\Database\Schema\Grammars\PostgresGrammar; } + + public function testGrammarsAreMacroable() + { + // compileReplace macro. + $this->getGrammar()::macro('compileReplace', function () { + return true; + }); + + $c = $this->getGrammar()::compileReplace(); + + $this->assertTrue($c); + } }
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Database/DatabaseQueryBuilderTest.php
@@ -2634,6 +2634,11 @@ public function testWhereRowValuesArityMismatch() public function testWhereJsonContainsMySql() { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereJsonContains('options', ['en']); + $this->assertEquals('select * from `users` where json_contains(`options`, ?)', $builder->toSql()); + $this->assertEquals(['["en"]'], $builder->getBindings()); + $builder = $this->getMySqlBuilder(); $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en']); $this->assertEquals('select * from `users` where json_contains(`options`->\'$."languages"\', ?)', $builder->toSql()); @@ -2647,6 +2652,11 @@ public function testWhereJsonContainsMySql() public function testWhereJsonContainsPostgres() { + $builder = $this->getPostgresBuilder(); + $builder->select('*')->from('users')->whereJsonContains('options', ['en']); + $this->assertEquals('select * from "users" where ("options")::jsonb @> ?', $builder->toSql()); + $this->assertEquals(['["en"]'], $builder->getBindings()); + $builder = $this->getPostgresBuilder(); $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en']); $this->assertEquals('select * from "users" where ("options"->\'languages\')::jsonb @> ?', $builder->toSql()); @@ -2667,13 +2677,22 @@ public function testWhereJsonContainsSqlite() $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en'])->toSql(); } - /** - * @expectedException \RuntimeException - */ public function testWhereJsonContainsSqlServer() { $builder = $this->getSqlServerBuilder(); - $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en'])->toSql(); + $builder->select('*')->from('users')->whereJsonContains('options', true); + $this->assertEquals('select * from [users] where ? in (select [value] from openjson([options]))', $builder->toSql()); + $this->assertEquals(['true'], $builder->getBindings()); + + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->whereJsonContains('options->languages', 'en'); + $this->assertEquals('select * from [users] where ? in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals(['en'], $builder->getBindings()); + + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->where('id', '=', 1)->orWhereJsonContains('options->languages', new Raw("'en'")); + $this->assertEquals('select * from [users] where [id] = ? or \'en\' in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals([1], $builder->getBindings()); } public function testWhereJsonDoesntContainMySql() @@ -2711,13 +2730,17 @@ public function testWhereJsonDoesntContainSqlite() $builder->select('*')->from('users')->whereJsonDoesntContain('options->languages', ['en'])->toSql(); } - /** - * @expectedException \RuntimeException - */ public function testWhereJsonDoesntContainSqlServer() { $builder = $this->getSqlServerBuilder(); - $builder->select('*')->from('users')->whereJsonDoesntContain('options->languages', ['en'])->toSql(); + $builder->select('*')->from('users')->whereJsonDoesntContain('options->languages', 'en'); + $this->assertEquals('select * from [users] where not ? in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals(['en'], $builder->getBindings()); + + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->where('id', '=', 1)->orWhereJsonDoesntContain('options->languages', new Raw("'en'")); + $this->assertEquals('select * from [users] where [id] = ? or not \'en\' in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals([1], $builder->getBindings()); } public function testFromSub()
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Database/DatabaseSQLiteSchemaGrammarTest.php
@@ -759,6 +759,18 @@ public function testAddingMultiPolygon() $this->assertEquals('alter table "geo" add column "coordinates" multipolygon not null', $statements[0]); } + public function testGrammarsAreMacroable() + { + // compileReplace macro. + $this->getGrammar()::macro('compileReplace', function () { + return true; + }); + + $c = $this->getGrammar()::compileReplace(); + + $this->assertTrue($c); + } + protected function getConnection() { return m::mock('Illuminate\Database\Connection');
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Database/DatabaseSqlServerSchemaGrammarTest.php
@@ -768,6 +768,18 @@ public function testAddingMultiPolygon() $this->assertEquals('alter table "geo" add "coordinates" geography not null', $statements[0]); } + public function testGrammarsAreMacroable() + { + // compileReplace macro. + $this->getGrammar()::macro('compileReplace', function () { + return true; + }); + + $c = $this->getGrammar()::compileReplace(); + + $this->assertTrue($c); + } + protected function getConnection() { return m::mock('Illuminate\Database\Connection');
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Hashing/HasherTest.php
@@ -31,7 +31,7 @@ public function testBasicArgonHashing() } /** - * @expectedException \Exception + * @expectedException \RuntimeException */ public function testBasicBcryptVerification() {
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Integration/Auth/AuthenticationTest.php
@@ -6,7 +6,7 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Schema; use Illuminate\Auth\EloquentUserProvider; -use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser; /** * @group integration @@ -206,25 +206,3 @@ public function auth_via_attempt_remembering() $this->assertNull($provider->retrieveByToken($user->id, $token)); } } - -class AuthenticationTestUser extends Authenticatable -{ - public $table = 'users'; - public $timestamps = false; - - /** - * The attributes that are mass assignable. - * - * @var array - */ - protected $guarded = ['id']; - - /** - * The attributes that should be hidden for arrays. - * - * @var array - */ - protected $hidden = [ - 'password', 'remember_token', - ]; -}
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Integration/Auth/Fixtures/AuthenticationTestUser.php
@@ -0,0 +1,27 @@ +<?php + +namespace Illuminate\Tests\Integration\Auth\Fixtures; + +use Illuminate\Foundation\Auth\User as Authenticatable; + +class AuthenticationTestUser extends Authenticatable +{ + public $table = 'users'; + public $timestamps = false; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $guarded = ['id']; + + /** + * The attributes that should be hidden for arrays. + * + * @var array + */ + protected $hidden = [ + 'password', 'remember_token', + ]; +}
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Integration/Routing/Fixtures/ApiResourceTaskController.php
@@ -0,0 +1,33 @@ +<?php + +namespace Illuminate\Tests\Integration\Routing\Fixtures; + +use Illuminate\Routing\Controller; + +class ApiResourceTaskController extends Controller +{ + public function index() + { + return 'I`m index tasks'; + } + + public function store() + { + return 'I`m store tasks'; + } + + public function show() + { + return 'I`m show tasks'; + } + + public function update() + { + return 'I`m update tasks'; + } + + public function destroy() + { + return 'I`m destroy tasks'; + } +}
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Integration/Routing/Fixtures/ApiResourceTestController.php
@@ -0,0 +1,33 @@ +<?php + +namespace Illuminate\Tests\Integration\Routing\Fixtures; + +use Illuminate\Routing\Controller; + +class ApiResourceTestController extends Controller +{ + public function index() + { + return 'I`m index'; + } + + public function store() + { + return 'I`m store'; + } + + public function show() + { + return 'I`m show'; + } + + public function update() + { + return 'I`m update'; + } + + public function destroy() + { + return 'I`m destroy'; + } +}
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Integration/Routing/RouteApiResourceTest.php
@@ -0,0 +1,115 @@ +<?php + +namespace Illuminate\Tests\Integration\Routing; + +use Orchestra\Testbench\TestCase; +use Illuminate\Support\Facades\Route; +use Illuminate\Tests\Integration\Routing\Fixtures\ApiResourceTaskController; +use Illuminate\Tests\Integration\Routing\Fixtures\ApiResourceTestController; + +/** + * @group integration + */ +class RouteApiResourceTest extends TestCase +{ + public function test_api_resource() + { + Route::apiResource('tests', ApiResourceTestController::class); + + $response = $this->get('/tests'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m index', $response->getContent()); + + $response = $this->post('/tests'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m store', $response->getContent()); + + $response = $this->get('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m show', $response->getContent()); + + $response = $this->put('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m update', $response->getContent()); + $response = $this->patch('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m update', $response->getContent()); + + $response = $this->delete('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m destroy', $response->getContent()); + } + + public function test_api_resource_with_only() + { + Route::apiResource('tests', ApiResourceTestController::class)->only(['index', 'store']); + + $response = $this->get('/tests'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m index', $response->getContent()); + + $response = $this->post('/tests'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m store', $response->getContent()); + + $this->assertEquals(404, $this->get('/tests/1')->getStatusCode()); + $this->assertEquals(404, $this->put('/tests/1')->getStatusCode()); + $this->assertEquals(404, $this->patch('/tests/1')->getStatusCode()); + $this->assertEquals(404, $this->delete('/tests/1')->getStatusCode()); + } + + public function test_api_resources() + { + Route::apiResources([ + 'tests' => ApiResourceTestController::class, + 'tasks' => ApiResourceTaskController::class, + ]); + + $response = $this->get('/tests'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m index', $response->getContent()); + + $response = $this->post('/tests'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m store', $response->getContent()); + + $response = $this->get('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m show', $response->getContent()); + + $response = $this->put('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m update', $response->getContent()); + $response = $this->patch('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m update', $response->getContent()); + + $response = $this->delete('/tests/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m destroy', $response->getContent()); + + ///////////////////// + $response = $this->get('/tasks'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m index tasks', $response->getContent()); + + $response = $this->post('/tasks'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m store tasks', $response->getContent()); + + $response = $this->get('/tasks/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m show tasks', $response->getContent()); + + $response = $this->put('/tasks/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m update tasks', $response->getContent()); + $response = $this->patch('/tasks/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m update tasks', $response->getContent()); + + $response = $this->delete('/tasks/1'); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('I`m destroy tasks', $response->getContent()); + } +}
true
Other
laravel
framework
25974ab05dabae76bd3c326598d9b694a1dc28d8.json
add back checks
tests/Routing/RoutingRouteTest.php
@@ -1326,6 +1326,8 @@ public function testControllerRoutingArrayCallable() $this->assertEquals(0, $_SERVER['route.test.controller.middleware.parameters.one']); $this->assertEquals(['foo', 'bar'], $_SERVER['route.test.controller.middleware.parameters.two']); $this->assertFalse(isset($_SERVER['route.test.controller.except.middleware'])); + $action = $router->getRoutes()->getRoutes()[0]->getAction()['controller']; + $this->assertEquals('Illuminate\Tests\Routing\RouteTestControllerStub@index', $action); } public function testCallableControllerRouting()
true
Other
laravel
framework
8dd376c3ffb1de29c0e421db1bda29a988768b0c.json
Fix JSON queries with table names on SQL Server
src/Illuminate/Database/Query/Grammars/Grammar.php
@@ -4,6 +4,7 @@ use RuntimeException; use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Grammar as BaseGrammar; @@ -37,6 +38,58 @@ class Grammar extends BaseGrammar 'lock', ]; + /** + * Wrap a value in keyword identifiers. + * + * @param \Illuminate\Database\Query\Expression|string $value + * @param bool $prefixAlias + * @return string + */ + public function wrap($value, $prefixAlias = false) + { + if ($this->isExpression($value)) { + return $this->getValue($value); + } + + // If the value being wrapped has a column alias we will need to separate out + // the pieces so we can wrap each of the segments of the expression on its + // own, and then join these both back together using the "as" connector. + if (strpos(strtolower($value), ' as ') !== false) { + return $this->wrapAliasedValue($value, $prefixAlias); + } + + // If the given value is a JSON selector we will wrap it differently than a + // traditional value. We will need to split this path and wrap each part + // wrapped, etc. Otherwise, we will simply wrap the value as a string. + if ($this->isJsonSelector($value)) { + return $this->wrapJsonSelector($value); + } + + return $this->wrapSegments(explode('.', $value)); + } + + /** + * Wrap the given JSON selector. + * + * @param string $value + * @return string + */ + protected function wrapJsonSelector($value) + { + throw new RuntimeException('This database engine does not support JSON operations.'); + } + + /** + * Determine if the given string is a JSON selector. + * + * @param string $value + * @return bool + */ + protected function isJsonSelector($value) + { + return Str::contains($value, '->'); + } + /** * Compile a select query into SQL. * @@ -506,7 +559,7 @@ protected function whereJsonContains(Builder $query, $where) $not = $where['not'] ? 'not ' : ''; return $not.$this->compileJsonContains( - $this->wrap($where['column']), $this->parameter($where['value']) + $where['column'], $this->parameter($where['value']) ); }
true
Other
laravel
framework
8dd376c3ffb1de29c0e421db1bda29a988768b0c.json
Fix JSON queries with table names on SQL Server
src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
@@ -3,7 +3,6 @@ namespace Illuminate\Database\Query\Grammars; use Illuminate\Support\Arr; -use Illuminate\Support\Str; use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\JsonExpression; @@ -61,7 +60,7 @@ public function compileSelect(Builder $query) */ protected function compileJsonContains($column, $value) { - return 'json_contains('.$column.', '.$value.')'; + return 'json_contains('.$this->wrap($column).', '.$value.')'; } /** @@ -291,18 +290,7 @@ protected function compileDeleteWithJoins($query, $table, $where) */ protected function wrapValue($value) { - if ($value === '*') { - return $value; - } - - // If the given value is a JSON selector we will wrap it differently than a - // traditional value. We will need to split this path and wrap each part - // wrapped, etc. Otherwise, we will simply wrap the value as a string. - if ($this->isJsonSelector($value)) { - return $this->wrapJsonSelector($value); - } - - return '`'.str_replace('`', '``', $value).'`'; + return $value === '*' ? $value : '`'.str_replace('`', '``', $value).'`'; } /** @@ -315,21 +303,10 @@ protected function wrapJsonSelector($value) { $path = explode('->', $value); - $field = $this->wrapValue(array_shift($path)); + $field = $this->wrapSegments(explode('.', array_shift($path))); return sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { return '"'.$part.'"'; })->implode('.')); } - - /** - * Determine if the given string is a JSON selector. - * - * @param string $value - * @return bool - */ - protected function isJsonSelector($value) - { - return Str::contains($value, '->'); - } }
true
Other
laravel
framework
8dd376c3ffb1de29c0e421db1bda29a988768b0c.json
Fix JSON queries with table names on SQL Server
src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
@@ -3,7 +3,6 @@ namespace Illuminate\Database\Query\Grammars; use Illuminate\Support\Arr; -use Illuminate\Support\Str; use Illuminate\Database\Query\Builder; class PostgresGrammar extends Grammar @@ -73,7 +72,7 @@ protected function dateBasedWhere($type, Builder $query, $where) */ protected function compileJsonContains($column, $value) { - $column = str_replace('->>', '->', $column); + $column = str_replace('->>', '->', $this->wrap($column)); return '('.$column.')::jsonb @> '.$value; } @@ -299,28 +298,6 @@ public function compileTruncate(Builder $query) return ['truncate '.$this->wrapTable($query->from).' restart identity' => []]; } - /** - * Wrap a single string in keyword identifiers. - * - * @param string $value - * @return string - */ - protected function wrapValue($value) - { - if ($value === '*') { - return $value; - } - - // If the given value is a JSON selector we will wrap it differently than a - // traditional value. We will need to split this path and wrap each part - // wrapped, etc. Otherwise, we will simply wrap the value as a string. - if (Str::contains($value, '->')) { - return $this->wrapJsonSelector($value); - } - - return '"'.str_replace('"', '""', $value).'"'; - } - /** * Wrap the given JSON selector. * @@ -331,7 +308,7 @@ protected function wrapJsonSelector($value) { $path = explode('->', $value); - $field = $this->wrapValue(array_shift($path)); + $field = $this->wrapSegments(explode('.', array_shift($path))); $wrappedPath = $this->wrapJsonPathAttributes($path);
true
Other
laravel
framework
8dd376c3ffb1de29c0e421db1bda29a988768b0c.json
Fix JSON queries with table names on SQL Server
src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
@@ -3,7 +3,6 @@ namespace Illuminate\Database\Query\Grammars; use Illuminate\Support\Arr; -use Illuminate\Support\Str; use Illuminate\Database\Query\Builder; class SqlServerGrammar extends Grammar @@ -113,11 +112,13 @@ protected function whereDate(Builder $query, $where) */ protected function compileJsonContains($column, $value) { - $from = $column[0] == '[' - ? 'openjson('.$column.')' - : substr_replace($column, 'openjson', 0, strlen('json_value')); + $parts = explode('->', $column, 2); - return $value.' in (select [value] from '.$from.')'; + $field = $this->wrap($parts[0]); + + $path = count($parts) > 1 ? ', '.$this->wrapJsonPath($parts[1]) : ''; + + return $value.' in (select [value] from openjson('.$field.$path.'))'; } /** @@ -439,18 +440,7 @@ public function getDateFormat() */ protected function wrapValue($value) { - if ($value === '*') { - return $value; - } - - // If the given value is a JSON selector we will wrap it differently than a - // traditional value. We will need to split this path and wrap each part - // wrapped, etc. Otherwise, we will simply wrap the value as a string. - if (Str::contains($value, '->')) { - return $this->wrapJsonSelector($value); - } - - return '['.str_replace(']', ']]', $value).']'; + return $value === '*' ? $value : '['.str_replace(']', ']]', $value).']'; } /** @@ -461,13 +451,22 @@ protected function wrapValue($value) */ protected function wrapJsonSelector($value) { - $path = explode('->', $value); + $parts = explode('->', $value, 2); + + $field = $this->wrapSegments(explode('.', array_shift($parts))); - $field = $this->wrapValue(array_shift($path)); + return 'json_value('.$field.', '.$this->wrapJsonPath($parts[0]).')'; + } - return sprintf('json_value(%s, \'$.%s\')', $field, collect($path)->map(function ($part) { - return '"'.$part.'"'; - })->implode('.')); + /** + * Wrap the given JSON path. + * + * @param string $value + * @return string + */ + protected function wrapJsonPath($value) + { + return '\'$."'.str_replace('->', '"."', $value).'"\''; } /**
true
Other
laravel
framework
8dd376c3ffb1de29c0e421db1bda29a988768b0c.json
Fix JSON queries with table names on SQL Server
tests/Database/DatabaseQueryBuilderTest.php
@@ -2024,8 +2024,8 @@ public function testMySqlWrappingJson() $this->assertEquals('select * from `users` where items->\'$."price"\' = 1', $builder->toSql()); $builder = $this->getMySqlBuilder(); - $builder->select('items->price')->from('users')->where('items->price', '=', 1)->orderBy('items->price'); - $this->assertEquals('select `items`->\'$."price"\' from `users` where `items`->\'$."price"\' = ? order by `items`->\'$."price"\' asc', $builder->toSql()); + $builder->select('items->price')->from('users')->where('users.items->price', '=', 1)->orderBy('items->price'); + $this->assertEquals('select `items`->\'$."price"\' from `users` where `users`.`items`->\'$."price"\' = ? order by `items`->\'$."price"\' asc', $builder->toSql()); $builder = $this->getMySqlBuilder(); $builder->select('*')->from('users')->where('items->price->in_usd', '=', 1); @@ -2039,8 +2039,8 @@ public function testMySqlWrappingJson() public function testPostgresWrappingJson() { $builder = $this->getPostgresBuilder(); - $builder->select('items->price')->from('users')->where('items->price', '=', 1)->orderBy('items->price'); - $this->assertEquals('select "items"->>\'price\' from "users" where "items"->>\'price\' = ? order by "items"->>\'price\' asc', $builder->toSql()); + $builder->select('items->price')->from('users')->where('users.items->price', '=', 1)->orderBy('items->price'); + $this->assertEquals('select "items"->>\'price\' from "users" where "users"."items"->>\'price\' = ? order by "items"->>\'price\' asc', $builder->toSql()); $builder = $this->getPostgresBuilder(); $builder->select('*')->from('users')->where('items->price->in_usd', '=', 1); @@ -2054,8 +2054,8 @@ public function testPostgresWrappingJson() public function testSqlServerWrappingJson() { $builder = $this->getSqlServerBuilder(); - $builder->select('items->price')->from('users')->where('items->price', '=', 1)->orderBy('items->price'); - $this->assertEquals('select json_value([items], \'$."price"\') from [users] where json_value([items], \'$."price"\') = ? order by json_value([items], \'$."price"\') asc', $builder->toSql()); + $builder->select('items->price')->from('users')->where('users.items->price', '=', 1)->orderBy('items->price'); + $this->assertEquals('select json_value([items], \'$."price"\') from [users] where json_value([users].[items], \'$."price"\') = ? order by json_value([items], \'$."price"\') asc', $builder->toSql()); $builder = $this->getSqlServerBuilder(); $builder->select('*')->from('users')->where('items->price->in_usd', '=', 1); @@ -2640,8 +2640,8 @@ public function testWhereJsonContainsMySql() $this->assertEquals(['["en"]'], $builder->getBindings()); $builder = $this->getMySqlBuilder(); - $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en']); - $this->assertEquals('select * from `users` where json_contains(`options`->\'$."languages"\', ?)', $builder->toSql()); + $builder->select('*')->from('users')->whereJsonContains('users.options->languages', ['en']); + $this->assertEquals('select * from `users` where json_contains(`users`.`options`->\'$."languages"\', ?)', $builder->toSql()); $this->assertEquals(['["en"]'], $builder->getBindings()); $builder = $this->getMySqlBuilder(); @@ -2658,8 +2658,8 @@ public function testWhereJsonContainsPostgres() $this->assertEquals(['["en"]'], $builder->getBindings()); $builder = $this->getPostgresBuilder(); - $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en']); - $this->assertEquals('select * from "users" where ("options"->\'languages\')::jsonb @> ?', $builder->toSql()); + $builder->select('*')->from('users')->whereJsonContains('users.options->languages', ['en']); + $this->assertEquals('select * from "users" where ("users"."options"->\'languages\')::jsonb @> ?', $builder->toSql()); $this->assertEquals(['["en"]'], $builder->getBindings()); $builder = $this->getPostgresBuilder(); @@ -2685,8 +2685,8 @@ public function testWhereJsonContainsSqlServer() $this->assertEquals(['true'], $builder->getBindings()); $builder = $this->getSqlServerBuilder(); - $builder->select('*')->from('users')->whereJsonContains('options->languages', 'en'); - $this->assertEquals('select * from [users] where ? in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $builder->select('*')->from('users')->whereJsonContains('users.options->languages', 'en'); + $this->assertEquals('select * from [users] where ? in (select [value] from openjson([users].[options], \'$."languages"\'))', $builder->toSql()); $this->assertEquals(['en'], $builder->getBindings()); $builder = $this->getSqlServerBuilder();
true
Other
laravel
framework
4f7b2760aefea06d4860af6ee2b0d52b2e93b78b.json
Apply fixes from StyleCI (#24540)
src/Illuminate/Foundation/Testing/TestResponse.php
@@ -73,7 +73,7 @@ public function assertOk() { PHPUnit::assertTrue( $this->isOk(), - 'Response status code [' . $this->getStatusCode() . '] does match expected 200 status code.' + 'Response status code ['.$this->getStatusCode().'] does match expected 200 status code.' ); return $this;
false
Other
laravel
framework
e2faaccc78b904bb0f0ec3258ee328be87458b28.json
Add missed 'static' in return type list (#24526)
src/Illuminate/Database/Eloquent/Builder.php
@@ -346,7 +346,7 @@ public function findMany($ids, $columns = ['*']) * * @param mixed $id * @param array $columns - * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection + * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ @@ -372,7 +372,7 @@ public function findOrFail($id, $columns = ['*']) * * @param mixed $id * @param array $columns - * @return \Illuminate\Database\Eloquent\Model + * @return \Illuminate\Database\Eloquent\Model|static */ public function findOrNew($id, $columns = ['*']) { @@ -388,7 +388,7 @@ public function findOrNew($id, $columns = ['*']) * * @param array $attributes * @param array $values - * @return \Illuminate\Database\Eloquent\Model + * @return \Illuminate\Database\Eloquent\Model|static */ public function firstOrNew(array $attributes, array $values = []) { @@ -404,7 +404,7 @@ public function firstOrNew(array $attributes, array $values = []) * * @param array $attributes * @param array $values - * @return \Illuminate\Database\Eloquent\Model + * @return \Illuminate\Database\Eloquent\Model|static */ public function firstOrCreate(array $attributes, array $values = []) { @@ -422,7 +422,7 @@ public function firstOrCreate(array $attributes, array $values = []) * * @param array $attributes * @param array $values - * @return \Illuminate\Database\Eloquent\Model + * @return \Illuminate\Database\Eloquent\Model|static */ public function updateOrCreate(array $attributes, array $values = []) { @@ -507,7 +507,7 @@ public function get($columns = ['*']) * Get the hydrated models without eager loading. * * @param array $columns - * @return \Illuminate\Database\Eloquent\Model[] + * @return \Illuminate\Database\Eloquent\Model[]|static[] */ public function getModels($columns = ['*']) { @@ -1093,7 +1093,7 @@ public function without($relations) * Create a new instance of the model being queried. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model + * @return \Illuminate\Database\Eloquent\Model|static */ public function newModelInstance($attributes = []) { @@ -1236,7 +1236,7 @@ public function setEagerLoads(array $eagerLoad) /** * Get the model instance being queried. * - * @return \Illuminate\Database\Eloquent\Model + * @return \Illuminate\Database\Eloquent\Model|static */ public function getModel() {
false
Other
laravel
framework
ffa3ef355ad015ecd87399a21214e1a7efbd9fb0.json
Apply fixes from StyleCI (#24503)
src/Illuminate/Filesystem/FilesystemManager.php
@@ -323,7 +323,7 @@ protected function adapt(FilesystemInterface $filesystem) public function set($name, $disk) { $this->disks[$name] = $disk; - + return $this; }
false
Other
laravel
framework
7efb6157741da04eedfa077abe283f9f39f89839.json
support other configuration option for consistency
src/Illuminate/Log/LogManager.php
@@ -336,8 +336,10 @@ protected function createMonologDriver(array $config) ); } + $with = array_merge($config['with'] ?? [], $config['handler_with'] ?? []); + return new Monolog($this->parseChannel($config), [$this->prepareHandler( - $this->app->make($config['handler'], $config['with'] ?? []), $config + $this->app->make($config['handler'], $with), $config )]); }
false
Other
laravel
framework
4b736f75f533e53f677dff52efd80fa5088a39b6.json
Apply fixes from StyleCI (#24481)
src/Illuminate/Routing/RouteAction.php
@@ -31,7 +31,7 @@ public static function parse($uri, $action) if (is_callable($action)) { return ! is_array($action) ? ['uses' => $action] : [ 'uses' => $action[0].'@'.$action[1], - 'controller' => $action[0].'@'.$action[1] + 'controller' => $action[0].'@'.$action[1], ]; }
false
Other
laravel
framework
ea3b5e5300be3824cee30dfa9608d27d8432addf.json
Add exit status to WorkStopping event. (#24476)
src/Illuminate/Queue/Events/WorkerStopping.php
@@ -4,5 +4,21 @@ class WorkerStopping { - // + /** + * The exit status. + * + * @var int + */ + public $status; + + /** + * Create a new event instance. + * + * @param int $status + * @return void + */ + public function __construct($status = 0) + { + $this->status = $status; + } }
true
Other
laravel
framework
ea3b5e5300be3824cee30dfa9608d27d8432addf.json
Add exit status to WorkStopping event. (#24476)
src/Illuminate/Queue/Worker.php
@@ -552,7 +552,7 @@ public function memoryExceeded($memoryLimit) */ public function stop($status = 0) { - $this->events->dispatch(new Events\WorkerStopping); + $this->events->dispatch(new Events\WorkerStopping($status)); exit($status); } @@ -565,7 +565,7 @@ public function stop($status = 0) */ public function kill($status = 0) { - $this->events->dispatch(new Events\WorkerStopping); + $this->events->dispatch(new Events\WorkerStopping($status)); if (extension_loaded('posix')) { posix_kill(getmypid(), SIGKILL);
true
Other
laravel
framework
8038c3d7eeb8d1cdbec8924bd0b4b41c3234f4d8.json
Add whereJsonContains() to SQL Server
src/Illuminate/Database/Query/Builder.php
@@ -1449,7 +1449,7 @@ public function whereJsonContains($column, $value, $boolean = 'and', $not = fals $this->wheres[] = compact('type', 'column', 'value', 'boolean', 'not'); if (! $value instanceof Expression) { - $this->addBinding(json_encode($value)); + $this->addBinding($this->grammar->prepareBindingForJsonContains($value)); } return $this;
true
Other
laravel
framework
8038c3d7eeb8d1cdbec8924bd0b4b41c3234f4d8.json
Add whereJsonContains() to SQL Server
src/Illuminate/Database/Query/Grammars/Grammar.php
@@ -523,6 +523,17 @@ protected function compileJsonContains($column, $value) throw new RuntimeException('This database engine does not support JSON contains operations.'); } + /** + * Prepare the binding for a "JSON contains" statement. + * + * @param mixed $binding + * @return string + */ + public function prepareBindingForJsonContains($binding) + { + return json_encode($binding); + } + /** * Compile the "group by" portions of the query. *
true
Other
laravel
framework
8038c3d7eeb8d1cdbec8924bd0b4b41c3234f4d8.json
Add whereJsonContains() to SQL Server
src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
@@ -104,6 +104,33 @@ protected function whereDate(Builder $query, $where) return 'cast('.$this->wrap($where['column']).' as date) '.$where['operator'].' '.$value; } + /** + * Compile a "JSON contains" statement into SQL. + * + * @param string $column + * @param string $value + * @return string + */ + protected function compileJsonContains($column, $value) + { + $from = $column[0] == '[' ? + 'openjson('.$column.')' : + substr_replace($column, 'openjson', 0, strlen('json_value')); + + return $value.' in (select [value] from '.$from.')'; + } + + /** + * Prepare the binding for a "JSON contains" statement. + * + * @param mixed $binding + * @return string + */ + public function prepareBindingForJsonContains($binding) + { + return is_bool($binding) ? json_encode($binding) : $binding; + } + /** * Create a full ANSI offset clause for the query. *
true
Other
laravel
framework
8038c3d7eeb8d1cdbec8924bd0b4b41c3234f4d8.json
Add whereJsonContains() to SQL Server
tests/Database/DatabaseQueryBuilderTest.php
@@ -2634,6 +2634,11 @@ public function testWhereRowValuesArityMismatch() public function testWhereJsonContainsMySql() { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereJsonContains('options', ['en']); + $this->assertEquals('select * from `users` where json_contains(`options`, ?)', $builder->toSql()); + $this->assertEquals(['["en"]'], $builder->getBindings()); + $builder = $this->getMySqlBuilder(); $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en']); $this->assertEquals('select * from `users` where json_contains(`options`->\'$."languages"\', ?)', $builder->toSql()); @@ -2647,6 +2652,11 @@ public function testWhereJsonContainsMySql() public function testWhereJsonContainsPostgres() { + $builder = $this->getPostgresBuilder(); + $builder->select('*')->from('users')->whereJsonContains('options', ['en']); + $this->assertEquals('select * from "users" where ("options")::jsonb @> ?', $builder->toSql()); + $this->assertEquals(['["en"]'], $builder->getBindings()); + $builder = $this->getPostgresBuilder(); $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en']); $this->assertEquals('select * from "users" where ("options"->\'languages\')::jsonb @> ?', $builder->toSql()); @@ -2667,13 +2677,22 @@ public function testWhereJsonContainsSqlite() $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en'])->toSql(); } - /** - * @expectedException \RuntimeException - */ public function testWhereJsonContainsSqlServer() { $builder = $this->getSqlServerBuilder(); - $builder->select('*')->from('users')->whereJsonContains('options->languages', ['en'])->toSql(); + $builder->select('*')->from('users')->whereJsonContains('options', true); + $this->assertEquals('select * from [users] where ? in (select [value] from openjson([options]))', $builder->toSql()); + $this->assertEquals(['true'], $builder->getBindings()); + + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->whereJsonContains('options->languages', 'en'); + $this->assertEquals('select * from [users] where ? in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals(['en'], $builder->getBindings()); + + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->where('id', '=', 1)->orWhereJsonContains('options->languages', new Raw("'en'")); + $this->assertEquals('select * from [users] where [id] = ? or \'en\' in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals([1], $builder->getBindings()); } public function testWhereJsonDoesntContainMySql() @@ -2711,13 +2730,17 @@ public function testWhereJsonDoesntContainSqlite() $builder->select('*')->from('users')->whereJsonDoesntContain('options->languages', ['en'])->toSql(); } - /** - * @expectedException \RuntimeException - */ public function testWhereJsonDoesntContainSqlServer() { $builder = $this->getSqlServerBuilder(); - $builder->select('*')->from('users')->whereJsonDoesntContain('options->languages', ['en'])->toSql(); + $builder->select('*')->from('users')->whereJsonDoesntContain('options->languages', 'en'); + $this->assertEquals('select * from [users] where not ? in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals(['en'], $builder->getBindings()); + + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->where('id', '=', 1)->orWhereJsonDoesntContain('options->languages', new Raw("'en'")); + $this->assertEquals('select * from [users] where [id] = ? or not \'en\' in (select [value] from openjson([options], \'$."languages"\'))', $builder->toSql()); + $this->assertEquals([1], $builder->getBindings()); } public function testFromSub()
true
Other
laravel
framework
c0afae9c56a0caabb03ac8e6d222c2b32a58a8bf.json
add assertTimesSent method to NotificationFake
src/Illuminate/Support/Testing/Fakes/NotificationFake.php
@@ -95,6 +95,29 @@ public function assertNothingSent() PHPUnit::assertEmpty($this->notifications, 'Notifications were sent unexpectedly.'); } + /** + * Assert the total amount of times a notification was sent. + * + * @param int $expectedCount + * @param string $notification + * + * @return void + */ + public function assertTimesSent(int $expectedCount, string $notification) + { + $actualCount = collect($this->notifications) + ->flatten(1) + ->reduce(function ($count, $sent) use ($notification) { + return $count + count($sent[$notification] ?? []); + }, 0); + + PHPUnit::assertSame( + $expectedCount, + $actualCount, + "[{$notification}] was not sent as many times as expected." + ); + } + /** * Get all of the notifications matching a truth-test callback. *
true
Other
laravel
framework
c0afae9c56a0caabb03ac8e6d222c2b32a58a8bf.json
add assertTimesSent method to NotificationFake
tests/Support/SupportTestingNotificationFakeTest.php
@@ -66,6 +66,19 @@ public function testResettingNotificationId() $this->assertNotNull($notification->id); $this->assertNotSame($id, $notification->id); } + + public function testAssertTimesSent() + { + $this->fake->assertTimesSent(0, NotificationStub::class); + + $this->fake->send($this->user, new NotificationStub); + + $this->fake->send($this->user, new NotificationStub); + + $this->fake->send(new UserStub, new NotificationStub); + + $this->fake->assertTimesSent(3, NotificationStub::class); + } } class NotificationStub extends Notification
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Database/DatabaseEloquentHasManyTest.php
@@ -231,10 +231,10 @@ public function testModelsAreProperlyMatchedToParents() $models = $relation->match([$model1, $model2, $model3], new Collection([$result1, $result2, $result3]), 'foo'); $this->assertEquals(1, $models[0]->foo[0]->foreign_key); - $this->assertEquals(1, count($models[0]->foo)); + $this->assertCount(1, $models[0]->foo); $this->assertEquals(2, $models[1]->foo[0]->foreign_key); $this->assertEquals(2, $models[1]->foo[1]->foreign_key); - $this->assertEquals(2, count($models[1]->foo)); + $this->assertCount(2, $models[1]->foo); $this->assertNull($models[2]->foo); }
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Database/DatabaseEloquentIntegrationTest.php
@@ -158,11 +158,11 @@ public function testBasicModelRetrieval() $collection = EloquentTestUser::find([]); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $collection); - $this->assertEquals(0, $collection->count()); + $this->assertCount(0, $collection); $collection = EloquentTestUser::find([1, 2, 3]); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $collection); - $this->assertEquals(2, $collection->count()); + $this->assertCount(2, $collection); $models = EloquentTestUser::where('id', 1)->cursor(); foreach ($models as $model) { @@ -187,7 +187,7 @@ public function testBasicModelCollectionRetrieval() $models = EloquentTestUser::oldest('id')->get(); - $this->assertEquals(2, $models->count()); + $this->assertCount(2, $models); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $models); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $models[0]); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $models[1]); @@ -206,7 +206,7 @@ public function testPaginatedModelCollectionRetrieval() }); $models = EloquentTestUser::oldest('id')->paginate(2); - $this->assertEquals(2, $models->count()); + $this->assertCount(2, $models); $this->assertInstanceOf('Illuminate\Pagination\LengthAwarePaginator', $models); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $models[0]); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $models[1]); @@ -218,7 +218,7 @@ public function testPaginatedModelCollectionRetrieval() }); $models = EloquentTestUser::oldest('id')->paginate(2); - $this->assertEquals(1, $models->count()); + $this->assertCount(1, $models); $this->assertInstanceOf('Illuminate\Pagination\LengthAwarePaginator', $models); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $models[0]); $this->assertEquals('foo@gmail.com', $models[0]->email); @@ -231,22 +231,22 @@ public function testPaginatedModelCollectionRetrievalWhenNoElements() }); $models = EloquentTestUser::oldest('id')->paginate(2); - $this->assertEquals(0, $models->count()); + $this->assertCount(0, $models); $this->assertInstanceOf('Illuminate\Pagination\LengthAwarePaginator', $models); Paginator::currentPageResolver(function () { return 2; }); $models = EloquentTestUser::oldest('id')->paginate(2); - $this->assertEquals(0, $models->count()); + $this->assertCount(0, $models); } public function testPaginatedModelCollectionRetrievalWhenNoElementsAndDefaultPerPage() { $models = EloquentTestUser::oldest('id')->paginate(); - $this->assertEquals(0, $models->count()); + $this->assertCount(0, $models); $this->assertInstanceOf('Illuminate\Pagination\LengthAwarePaginator', $models); } @@ -459,7 +459,7 @@ public function testOneToManyRelationship() $post2 = $user->posts()->where('name', 'Second Post')->first(); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $posts); - $this->assertEquals(2, $posts->count()); + $this->assertCount(2, $posts); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPost', $posts[0]); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPost', $posts[1]); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPost', $post2); @@ -484,7 +484,7 @@ public function testBasicModelHydration() $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $models[0]); $this->assertEquals('abigailotwell@gmail.com', $models[0]->email); $this->assertEquals('second_connection', $models[0]->getConnectionName()); - $this->assertEquals(1, $models->count()); + $this->assertCount(1, $models); } public function testHasOnSelfReferencingBelongsToManyRelationship() @@ -744,8 +744,8 @@ public function testBasicMorphManyRelationship() $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPhoto', $user->photos[0]); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $post->photos); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPhoto', $post->photos[0]); - $this->assertEquals(2, $user->photos->count()); - $this->assertEquals(2, $post->photos->count()); + $this->assertCount(2, $user->photos); + $this->assertCount(2, $post->photos); $this->assertEquals('Avatar 1', $user->photos[0]->name); $this->assertEquals('Avatar 2', $user->photos[1]->name); $this->assertEquals('Hero 1', $post->photos[0]->name); @@ -754,7 +754,7 @@ public function testBasicMorphManyRelationship() $photos = EloquentTestPhoto::orderBy('name')->get(); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $photos); - $this->assertEquals(4, $photos->count()); + $this->assertCount(4, $photos); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $photos[0]->imageable); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPost', $photos[2]->imageable); $this->assertEquals('taylorotwell@gmail.com', $photos[1]->imageable->email); @@ -779,8 +779,8 @@ public function testMorphMapIsUsedForCreatingAndFetchingThroughRelation() $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPhoto', $user->photos[0]); $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $post->photos); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestPhoto', $post->photos[0]); - $this->assertEquals(2, $user->photos->count()); - $this->assertEquals(2, $post->photos->count()); + $this->assertCount(2, $user->photos); + $this->assertCount(2, $post->photos); $this->assertEquals('Avatar 1', $user->photos[0]->name); $this->assertEquals('Avatar 2', $user->photos[1]->name); $this->assertEquals('Hero 1', $post->photos[0]->name);
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Database/DatabaseEloquentIntegrationWithTablePrefixTest.php
@@ -87,7 +87,7 @@ public function testBasicModelHydration() $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $models); $this->assertInstanceOf('Illuminate\Tests\Database\EloquentTestUser', $models[0]); $this->assertEquals('abigailotwell@gmail.com', $models[0]->email); - $this->assertEquals(1, $models->count()); + $this->assertCount(1, $models); } /**
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Database/DatabaseEloquentPolymorphicRelationsIntegrationTest.php
@@ -81,12 +81,12 @@ public function testCreation() $post->tags()->attach($tag2->id); $image->tags()->attach($tag->id); - $this->assertEquals(2, $post->tags->count()); - $this->assertEquals(1, $image->tags->count()); - $this->assertEquals(1, $tag->posts->count()); - $this->assertEquals(1, $tag->images->count()); - $this->assertEquals(1, $tag2->posts->count()); - $this->assertEquals(0, $tag2->images->count()); + $this->assertCount(2, $post->tags); + $this->assertCount(1, $image->tags); + $this->assertCount(1, $tag->posts); + $this->assertCount(1, $tag->images); + $this->assertCount(1, $tag2->posts); + $this->assertCount(0, $tag2->images); } public function testEagerLoading()
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Database/DatabaseMySqlSchemaGrammarTest.php
@@ -930,7 +930,7 @@ public function testAddingComment() $blueprint->string('foo')->comment("Escape ' when using words like it's"); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); - $this->assertEquals(1, count($statements)); + $this->assertCount(1, $statements); $this->assertEquals("alter table `users` add `foo` varchar(255) not null comment 'Escape \\' when using words like it\\'s'", $statements[0]); }
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Integration/Database/EloquentDeleteTest.php
@@ -58,10 +58,10 @@ public function testOnlyDeleteWhatGiven() } Post::latest('id')->limit(1)->delete(); - $this->assertEquals(9, Post::all()->count()); + $this->assertCount(9, Post::all()); Post::join('comments', 'comments.post_id', '=', 'posts.id')->where('posts.id', '>', 1)->orderBy('posts.id')->limit(1)->delete(); - $this->assertEquals(8, Post::all()->count()); + $this->assertCount(8, Post::all()); } public function testForceDeletedEventIsFired()
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Integration/Database/EloquentUpdateTest.php
@@ -53,7 +53,7 @@ public function testBasicUpdate() TestUpdateModel1::where('title', 'Ms.')->delete(); - $this->assertEquals(0, TestUpdateModel1::all()->count()); + $this->assertCount(0, TestUpdateModel1::all()); } public function testUpdateWithLimitsAndOrders() @@ -105,7 +105,7 @@ public function testSoftDeleteWithJoins() ->where('test_model1.title', '=', 'Mr.'); })->delete(); - $this->assertEquals(0, TestUpdateModel2::all()->count()); + $this->assertCount(0, TestUpdateModel2::all()); } }
true
Other
laravel
framework
520fb03d1fe8f019c79a4f49744ae36ab44bed51.json
Use assertCount(). (#24411)
tests/Support/SupportViewErrorBagTest.php
@@ -80,20 +80,20 @@ public function testCount() { $viewErrorBag = new ViewErrorBag(); $viewErrorBag->put('default', new MessageBag(['message', 'second'])); - $this->assertEquals(2, $viewErrorBag->count()); + $this->assertCount(2, $viewErrorBag); } public function testCountWithNoMessagesInMessageBag() { $viewErrorBag = new ViewErrorBag(); $viewErrorBag->put('default', new MessageBag()); - $this->assertEquals(0, $viewErrorBag->count()); + $this->assertCount(0, $viewErrorBag); } public function testCountWithNoMessageBags() { $viewErrorBag = new ViewErrorBag(); - $this->assertEquals(0, $viewErrorBag->count()); + $this->assertCount(0, $viewErrorBag); } public function testDynamicCallToDefaultMessageBag()
true
Other
laravel
framework
10c549f382c123264bfdd2aecd04124f3831aef1.json
fix mock data.
tests/Database/DatabaseSoftDeletingTraitTest.php
@@ -102,4 +102,8 @@ public function getUpdatedAtColumn() { return defined('static::UPDATED_AT') ? static::UPDATED_AT : 'updated_at'; } + + public function syncOriginal() + { + } }
false
Other
laravel
framework
d9d3c52d4ff380d901cca0c4d748bfed6e8ae9fe.json
Allow callable array syntax in route definition
src/Illuminate/Routing/RouteAction.php
@@ -29,6 +29,12 @@ public static function parse($uri, $action) // as the "uses" property, because there is nothing else we need to do when // it is available. Otherwise we will need to find it in the action list. if (is_callable($action)) { + + if (\is_array($action)) { + [$class, $method] = $action; + $action = $class . '@' . $method; + } + return ['uses' => $action]; }
true
Other
laravel
framework
d9d3c52d4ff380d901cca0c4d748bfed6e8ae9fe.json
Allow callable array syntax in route definition
tests/Routing/RoutingRouteTest.php
@@ -1289,6 +1289,26 @@ public function testControllerRouting() $this->assertFalse(isset($_SERVER['route.test.controller.except.middleware'])); } + public function testControllerRoutingArrayCallable() + { + unset( + $_SERVER['route.test.controller.middleware'], $_SERVER['route.test.controller.except.middleware'], + $_SERVER['route.test.controller.middleware.class'], + $_SERVER['route.test.controller.middleware.parameters.one'], $_SERVER['route.test.controller.middleware.parameters.two'] + ); + + $router = $this->getRouter(); + + $router->get('foo/bar', [RouteTestControllerStub::class, 'index']); + + $this->assertEquals('Hello World', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent()); + $this->assertTrue($_SERVER['route.test.controller.middleware']); + $this->assertEquals(\Illuminate\Http\Response::class, $_SERVER['route.test.controller.middleware.class']); + $this->assertEquals(0, $_SERVER['route.test.controller.middleware.parameters.one']); + $this->assertEquals(['foo', 'bar'], $_SERVER['route.test.controller.middleware.parameters.two']); + $this->assertFalse(isset($_SERVER['route.test.controller.except.middleware'])); + } + public function testCallableControllerRouting() { $router = $this->getRouter();
true
Other
laravel
framework
e2efbcbc609047f7342252fc12dfbaa4682f8b38.json
Prefer stricter negative comparisons with strings
src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
@@ -396,7 +396,7 @@ protected function transformHeadersToServerVars(array $headers) */ protected function formatServerHeaderKey($name) { - if (! Str::startsWith($name, 'HTTP_') && $name != 'CONTENT_TYPE' && $name != 'REMOTE_ADDR') { + if (! Str::startsWith($name, 'HTTP_') && $name !== 'CONTENT_TYPE' && $name !== 'REMOTE_ADDR') { return 'HTTP_'.$name; }
true
Other
laravel
framework
e2efbcbc609047f7342252fc12dfbaa4682f8b38.json
Prefer stricter negative comparisons with strings
src/Illuminate/Mail/Mailable.php
@@ -260,7 +260,7 @@ public function buildViewData() $data = $this->viewData; foreach ((new ReflectionClass($this))->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { - if ($property->getDeclaringClass()->getName() != self::class) { + if ($property->getDeclaringClass()->getName() !== self::class) { $data[$property->getName()] = $property->getValue($this); } }
true
Other
laravel
framework
a569df3cd814f891384ce73b3c8186f7b65521a0.json
remove unuse variable.
src/Illuminate/Foundation/Console/ObserverMakeCommand.php
@@ -81,13 +81,11 @@ protected function replaceModel($stub, $model) $model = class_basename(trim($model, '\\')); - $dummyModel = $model; - - $stub = str_replace('DocDummyModel', Str::snake($dummyModel, ' '), $stub); + $stub = str_replace('DocDummyModel', Str::snake($model, ' '), $stub); $stub = str_replace('DummyModel', $model, $stub); - return str_replace('dummyModel', Str::camel($dummyModel), $stub); + return str_replace('dummyModel', Str::camel($model), $stub); } /**
false
Other
laravel
framework
255b8fc30036c3fd05544d4d6bf9b57e3fd64592.json
Add model option to command.
src/Illuminate/Foundation/Console/ObserverMakeCommand.php
@@ -3,6 +3,8 @@ namespace Illuminate\Foundation\Console; use Illuminate\Console\GeneratorCommand; +use Illuminate\Support\Str; +use Symfony\Component\Console\Input\InputOption; class ObserverMakeCommand extends GeneratorCommand { @@ -27,14 +29,65 @@ class ObserverMakeCommand extends GeneratorCommand */ protected $type = 'Observer'; + /** + * Build the class with the given name. + * + * @param string $name + * @return string + */ + protected function buildClass($name) + { + $stub = parent::buildClass($name); + + $model = $this->option('model'); + + return $model ? $this->replaceModel($stub, $model) : $stub; + } + /** * Get the stub file for the generator. * * @return string */ protected function getStub() { - return __DIR__.'/stubs/observer.stub'; + return $this->option('model') + ? __DIR__.'/stubs/observer.stub' + : __DIR__.'/stubs/observer.plain.stub'; + } + + /** + * Replace the model for the given stub. + * + * @param string $stub + * @param string $model + * @return string + */ + protected function replaceModel($stub, $model) + { + $model = str_replace('/', '\\', $model); + + $namespaceModel = $this->laravel->getNamespace().$model; + + if (Str::startsWith($model, '\\')) { + $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub); + } else { + $stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub); + } + + $stub = str_replace( + "use {$namespaceModel};\nuse {$namespaceModel};", "use {$namespaceModel};", $stub + ); + + $model = class_basename(trim($model, '\\')); + + $dummyModel = $model; + + $stub = str_replace('DocDummyModel', Str::snake($dummyModel, ' '), $stub); + + $stub = str_replace('DummyModel', $model, $stub); + + return str_replace('dummyModel', Str::camel($dummyModel), $stub); } /** @@ -47,4 +100,16 @@ protected function getDefaultNamespace($rootNamespace) { return $rootNamespace.'\Observers'; } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getOptions() + { + return [ + ['model', 'm', InputOption::VALUE_OPTIONAL, 'The model that the observer applies to.'], + ]; + } }
false
Other
laravel
framework
30ef278148c447ee6f57e8651a3746ca0e42fd45.json
Create observer.plain stub. Update observer.stub file; added some functions.
src/Illuminate/Foundation/Console/stubs/observer.plain.stub
@@ -0,0 +1,8 @@ +<?php + +namespace DummyNamespace; + +class DummyClass +{ + // +}
true
Other
laravel
framework
30ef278148c447ee6f57e8651a3746ca0e42fd45.json
Create observer.plain stub. Update observer.stub file; added some functions.
src/Illuminate/Foundation/Console/stubs/observer.stub
@@ -2,7 +2,40 @@ namespace DummyNamespace; +use NamespacedDummyModel; + class DummyClass { - // + /** + * Listen to the DocDummyModel created event. + * + * @param \NamespacedDummyModel $dummyModel + * @return void + */ + public function created(DummyModel $dummyModel) + { + // + } + + /** + * Listen to the DocDummyModel updated event. + * + * @param \NamespacedDummyModel $dummyModel + * @return void + */ + public function updated(DummyModel $dummyModel) + { + // + } + + /** + * Listen to the DocDummyModel deleted event. + * + * @param \NamespacedDummyModel $dummyModel + * @return void + */ + public function deleted(DummyModel $dummyModel) + { + // + } }
true
Other
laravel
framework
f394191a95e69426e858928de8720fcf169bfc1b.json
Create observer stub
src/Illuminate/Foundation/Console/stubs/observer.stub
@@ -0,0 +1,8 @@ +<?php + +namespace DummyNamespace; + +class DummyClass +{ + // +}
false
Other
laravel
framework
7a78dab48ad00161206d992d6defc43d7159779a.json
Create ObserverMakeCommand file.
src/Illuminate/Foundation/Console/ObserverMakeCommand.php
@@ -0,0 +1,50 @@ +<?php + +namespace Illuminate\Foundation\Console; + +use Illuminate\Console\GeneratorCommand; + +class ObserverMakeCommand extends GeneratorCommand +{ + /** + * The console command name. + * + * @var string + */ + protected $name = 'make:observer'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Create a new observer class'; + + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Observer'; + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + return __DIR__.'/stubs/observer.stub'; + } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return $rootNamespace.'\Observers'; + } +}
false