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
2e9d90bad11dbaf33e4a7cedcdcbb60419f85a25.json
fix srid mysql schema (#31852)
tests/Database/DatabaseMySqlSchemaGrammarTest.php
@@ -898,6 +898,26 @@ public function testAddingPoint() $this->assertSame('alter table `geo` add `coordinates` point not null', $statements[0]); } + public function testAddingPointWithSrid() + { + $blueprint = new Blueprint('geo'); + $blueprint->point('coordinates', 4326); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertCount(1, $statements); + $this->assertSame('alter table `geo` add `coordinates` point not null srid 4326', $statements[0]); + } + + public function testAddingPointWithSridColumn() + { + $blueprint = new Blueprint('geo'); + $blueprint->point('coordinates', 4326)->after('id'); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + + $this->assertCount(1, $statements); + $this->assertSame('alter table `geo` add `coordinates` point not null srid 4326 after `id`', $statements[0]); + } + public function testAddingLineString() { $blueprint = new Blueprint('geo');
true
Other
laravel
framework
2ce99051636e8dee09ef405edb90a483f72b7f40.json
Use local variable (#31849)
src/Illuminate/View/Component.php
@@ -61,9 +61,9 @@ public function resolveView() $factory = Container::getInstance()->make('view'); - return $factory->exists($this->render()) - ? $this->render() - : $this->createBladeViewFromString($factory, $this->render()); + return $factory->exists($view) + ? $view + : $this->createBladeViewFromString($factory, $view); } /**
false
Other
laravel
framework
35f81ffd8ae93823a62b5e7b5386704d8b7fc212.json
add another test case
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -5,6 +5,7 @@ use Illuminate\Container\Container; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; @@ -133,7 +134,7 @@ public function match(Request $request) if (! $dynamicRoute->isFallback) { $route = $dynamicRoute; } - } catch (NotFoundHttpException $e) { + } catch (NotFoundHttpException | MethodNotAllowedHttpException $e) { // } }
true
Other
laravel
framework
35f81ffd8ae93823a62b5e7b5386704d8b7fc212.json
add another test case
tests/Integration/Routing/CompiledRouteCollectionTest.php
@@ -388,6 +388,17 @@ public function testMatchingCachedFallbackTakesPrecedenceOverDynamicFallback() $this->assertEquals('fallback', $routes->match(Request::create('/baz/1', 'GET'))->getName()); } + public function testMatchingCachedFallbackTakesPrecedenceOverDynamicRouteWithWrongMethod() + { + $this->routeCollection->add($this->fallbackRoute(['uses' => 'FooController@index', 'as' => 'fallback'])); + + $routes = $this->collection(); + + $routes->add($this->newRoute('POST', '/bar/{id}', ['uses' => 'FooController@index', 'as' => 'bar'])); + + $this->assertEquals('fallback', $routes->match(Request::create('/bar/1', 'GET'))->getName()); + } + public function testSlashPrefixIsProperlyHandled() { $this->routeCollection->add($this->newRoute('GET', 'foo/bar', ['uses' => 'FooController@index', 'prefix' => '/']));
true
Other
laravel
framework
9a805d3dac8208b7450b22717a0bfc6e16e030d0.json
remove redundant condition
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -130,7 +130,7 @@ public function match(Request $request) try { $dynamicRoute = $this->routes->match($request); - if (! $dynamicRoute->isFallback || ! $route->isFallback) { + if (! $dynamicRoute->isFallback) { $route = $dynamicRoute; } } catch (NotFoundHttpException $e) {
false
Other
laravel
framework
5c8255b2a4b10593fa86013737a55560b96c8341.json
Apply fixes from StyleCI (#31833)
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -2,7 +2,6 @@ namespace Illuminate\Routing; -use Exception; use Illuminate\Container\Container; use Illuminate\Http\Request; use Illuminate\Support\Collection;
false
Other
laravel
framework
83ef6a7eae193ef11e03c400364f2a39fd92acb3.json
Add tests and refactor
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -115,33 +115,22 @@ public function match(Request $request) $route = null; - $checkedDynamicRoutes = false; - $matchedCachedRouteIsFallback = false; - try { if ($result = $matcher->matchRequest($request)) { $route = $this->getByName($result['_route']); } - - $matchedCachedRouteIsFallback = $route->isFallback; } catch (ResourceNotFoundException | MethodNotAllowedException $e) { - $checkedDynamicRoutes = true; - try { return $this->routes->match($request); } catch (NotFoundHttpException $e) { // } } - if ($matchedCachedRouteIsFallback && ! $checkedDynamicRoutes) { + if ($route && $route->isFallback) { try { - $dynamicRoute = $this->routes->match($request); - - if (! $dynamicRoute->isFallback) { - $route = $dynamicRoute; - } - } catch (Exception $e) { + return $this->routes->match($request); + } catch (NotFoundHttpException $e) { // } }
true
Other
laravel
framework
83ef6a7eae193ef11e03c400364f2a39fd92acb3.json
Add tests and refactor
tests/Integration/Routing/CompiledRouteCollectionTest.php
@@ -295,7 +295,7 @@ public function testMatchingThrowsMethodNotAllowedHttpExceptionWhenMethodIsNotAl $this->collection()->match(Request::create('/foo', 'POST')); } - public function testMatchingThrowsMethodNotAllowedHttpExceptionWhenMethodIsNotAllowedWhileSameRouteIsAddedDynamically() + public function testMatchingThrowsExceptionWhenMethodIsNotAllowedWhileSameRouteIsAddedDynamically() { $this->routeCollection->add($this->newRoute('GET', '/', ['uses' => 'FooController@index'])); @@ -349,7 +349,35 @@ public function testMatchingWildcardFromCompiledRoutesAlwaysTakesPrecedent() $this->assertSame('foo', $routes->match(Request::create('/foo', 'GET'))->getName()); } - public function testSlashPrefixIsProperly() + public function testMatchingDynamicallyAddedRoutesTakePrecedenceOverFallbackRoutes() + { + $this->routeCollection->add($this->fallbackRoute(['uses' => 'FooController@index'])); + $this->routeCollection->add( + $this->newRoute('GET', '/foo/{id}', ['uses' => 'FooController@index', 'as' => 'foo']) + ); + + $routes = $this->collection(); + + $routes->add($this->newRoute('GET', '/bar/{id}', ['uses' => 'FooController@index', 'as' => 'bar'])); + + $this->assertEquals('bar', $routes->match(Request::create('/bar/1', 'GET'))->getName()); + } + + public function testMatchingFallbackRouteCatchesAll() + { + $this->routeCollection->add($this->fallbackRoute(['uses' => 'FooController@index', 'as' => 'fallback'])); + $this->routeCollection->add( + $this->newRoute('GET', '/foo/{id}', ['uses' => 'FooController@index', 'as' => 'foo']) + ); + + $routes = $this->collection(); + + $routes->add($this->newRoute('GET', '/bar/{id}', ['uses' => 'FooController@index', 'as' => 'bar'])); + + $this->assertEquals('fallback', $routes->match(Request::create('/baz/1', 'GET'))->getName()); + } + + public function testSlashPrefixIsProperlyHandled() { $this->routeCollection->add($this->newRoute('GET', 'foo/bar', ['uses' => 'FooController@index', 'prefix' => '/'])); @@ -386,4 +414,19 @@ protected function newRoute($methods, $uri, $action) ->setRouter($this->router) ->setContainer($this->app); } + + /** + * Create a new fallback Route object. + * + * @param mixed $action + * @return \Illuminate\Routing\Route + */ + protected function fallbackRoute($action) + { + $placeholder = 'fallbackPlaceholder'; + + return $this->newRoute( + 'GET', "{{$placeholder}}", $action + )->where($placeholder, '.*')->fallback(); + } }
true
Other
laravel
framework
20f5605b6cf0d0b3e0aee6bebd007ac24a9ae96c.json
Apply fixes from StyleCI (#31832)
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -146,7 +146,6 @@ public function match(Request $request) } } - return $this->handleMatchedRoute($request, $route); }
false
Other
laravel
framework
577c88532f1ef11db487b63e589cdd20d58028e9.json
handle fallback priority
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -2,6 +2,7 @@ namespace Illuminate\Routing; +use Exception; use Illuminate\Container\Container; use Illuminate\Http\Request; use Illuminate\Support\Collection; @@ -114,18 +115,38 @@ public function match(Request $request) $route = null; + $checkedDynamicRoutes = false; + $matchedCachedRouteIsFallback = false; + try { if ($result = $matcher->matchRequest($request)) { $route = $this->getByName($result['_route']); } + + $matchedCachedRouteIsFallback = $route->isFallback; } catch (ResourceNotFoundException | MethodNotAllowedException $e) { + $checkedDynamicRoutes = true; + try { return $this->routes->match($request); } catch (NotFoundHttpException $e) { // } } + if ($matchedCachedRouteIsFallback && ! $checkedDynamicRoutes) { + try { + $dynamicRoute = $this->routes->match($request); + + if (! $dynamicRoute->isFallback) { + $route = $dynamicRoute; + } + } catch (Exception $e) { + // + } + } + + return $this->handleMatchedRoute($request, $route); }
false
Other
laravel
framework
eca35179ed82a32ba90532ae21a08178581a461b.json
Add tests for new route caching (#31827)
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -185,7 +185,11 @@ public function getByName($name) public function getByAction($action) { $attributes = collect($this->attributes)->first(function (array $attributes) use ($action) { - return $attributes['action']['controller'] === $action; + if (isset($attributes['action']['controller'])) { + return $attributes['action']['controller'] === $action; + } + + return $attributes['action']['uses'] === $action; }); return $attributes ? $this->newRoute($attributes) : null;
true
Other
laravel
framework
eca35179ed82a32ba90532ae21a08178581a461b.json
Add tests for new route caching (#31827)
tests/Integration/Routing/CompiledRouteCollectionTest.php
@@ -3,9 +3,13 @@ namespace Illuminate\Tests\Routing; use ArrayIterator; +use Illuminate\Http\Request; use Illuminate\Routing\CompiledRouteCollection; use Illuminate\Routing\Route; +use Illuminate\Support\Arr; use Illuminate\Tests\Integration\IntegrationTest; +use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class CompiledRouteCollectionTest extends IntegrationTest { @@ -73,10 +77,12 @@ public function testRouteCollectionCanRetrieveByAction() { $this->routeCollection->add($routeIndex = $this->newRoute('GET', 'foo/index', $action = [ 'uses' => 'FooController@index', - 'as' => 'route_name', ])); - $this->assertSame($action, $routeIndex->getAction()); + $route = $this->routeCollection->getByAction('FooController@index'); + + $this->assertSame($action, Arr::except($routeIndex->getAction(), 'as')); + $this->assertSame($action, Arr::except($route->getAction(), 'as')); } public function testRouteCollectionCanGetIterator() @@ -238,6 +244,47 @@ public function testRouteCollectionCleansUpOverwrittenRoutes() $this->assertEquals($routeB, $this->routeCollection->getByAction('OverwrittenView@view')); } + public function testMatchingThrowsNotFoundExceptionWhenRouteIsNotFound() + { + $this->routeCollection->add($this->newRoute('GET', '/', ['uses' => 'FooController@index'])); + + $this->expectException(NotFoundHttpException::class); + + $this->routeCollection->match(Request::create('/foo')); + } + + public function testMatchingThrowsMethodNotAllowedHttpExceptionWhenMethodIsNotAllowed() + { + $this->routeCollection->add($this->newRoute('POST', '/foo', ['uses' => 'FooController@index'])); + + $this->expectException(MethodNotAllowedHttpException::class); + + $this->routeCollection->match(Request::create('/foo')); + } + + public function testSlashPrefixIsProperly() + { + $this->routeCollection->add($this->newRoute('GET', 'foo/bar', ['uses' => 'FooController@index', 'prefix' => '/'])); + + $route = $this->routeCollection->getByAction('FooController@index'); + + $this->assertEquals('foo/bar', $route->uri()); + } + + public function testRouteBindingsAreProperlySaved() + { + $this->routeCollection->add($this->newRoute('GET', 'posts/{post:slug}/show', [ + 'uses' => 'FooController@index', + 'prefix' => 'profile/{user:username}', + 'as' => 'foo', + ])); + + $route = $this->routeCollection->getByName('foo'); + + $this->assertEquals('profile/{user}/posts/{post}/show', $route->uri()); + $this->assertSame(['user' => 'username', 'post' => 'slug'], $route->bindingFields()); + } + /** * Create a new Route object. *
true
Other
laravel
framework
eca35179ed82a32ba90532ae21a08178581a461b.json
Add tests for new route caching (#31827)
tests/Routing/RouteCollectionTest.php
@@ -5,6 +5,7 @@ use ArrayIterator; use Illuminate\Routing\Route; use Illuminate\Routing\RouteCollection; +use LogicException; use PHPUnit\Framework\TestCase; class RouteCollectionTest extends TestCase @@ -247,4 +248,18 @@ public function testRouteCollectionCleansUpOverwrittenRoutes() $this->assertEquals($routeB, $this->routeCollection->getByName('overwrittenRouteA')); $this->assertEquals($routeB, $this->routeCollection->getByAction('OverwrittenView@view')); } + + public function testCannotCacheDuplicateRouteNames() + { + $this->routeCollection->add( + new Route('GET', 'users', ['uses' => 'UsersController@index', 'as' => 'users']) + ); + $this->routeCollection->add( + new Route('GET', 'users/{user}', ['uses' => 'UsersController@show', 'as' => 'users']) + ); + + $this->expectException(LogicException::class); + + $this->routeCollection->compile(); + } }
true
Other
laravel
framework
eca35179ed82a32ba90532ae21a08178581a461b.json
Add tests for new route caching (#31827)
tests/Routing/RoutingRouteTest.php
@@ -1144,6 +1144,18 @@ public function testRoutePrefixing() $routes = $routes->getRoutes(); $routes[0]->prefix('prefix'); $this->assertSame('prefix', $routes[0]->uri()); + + /* + * Prefix homepage with empty prefix + */ + $router = $this->getRouter(); + $router->get('/', function () { + return 'hello'; + }); + $routes = $router->getRoutes(); + $routes = $routes->getRoutes(); + $routes[0]->prefix('/'); + $this->assertSame('/', $routes[0]->uri()); } public function testRoutePreservingOriginalParametersState()
true
Other
laravel
framework
d3ba921e5844a31e639f92188900e7b49424ec9e.json
add test for queued listener (#31818)
tests/Events/EventsDispatcherTest.php
@@ -10,6 +10,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Events\CallQueuedListener; use Illuminate\Events\Dispatcher; +use Illuminate\Support\Testing\Fakes\QueueFake; use Mockery as m; use PHPUnit\Framework\TestCase; @@ -336,6 +337,22 @@ public function testQueuedEventHandlersAreQueued() $d->dispatch('some.event', ['foo', 'bar']); } + public function testCustomizedQueuedEventHandlersAreQueued() + { + $d = new Dispatcher; + + $fakeQueue = new QueueFake(new Container()); + + $d->setQueueResolver(function () use ($fakeQueue) { + return $fakeQueue; + }); + + $d->listen('some.event', TestDispatcherConnectionQueuedHandler::class.'@handle'); + $d->dispatch('some.event', ['foo', 'bar']); + + $fakeQueue->assertPushedOn('my_queue', CallQueuedListener::class); + } + public function testClassesWork() { unset($_SERVER['__event.test']); @@ -473,6 +490,20 @@ public function handle() } } +class TestDispatcherConnectionQueuedHandler implements ShouldQueue +{ + public $connection = 'redis'; + + public $delay = 10; + + public $queue = 'my_queue'; + + public function handle() + { + // + } +} + class TestDispatcherQueuedHandlerCustomQueue implements ShouldQueue { public function handle()
false
Other
laravel
framework
bb60a457f6c3692ea4f14355bddd8ee74cff91d7.json
add missing test cases for arr first (#31820)
tests/Support/SupportArrTest.php
@@ -143,12 +143,37 @@ public function testFirst() { $array = [100, 200, 300]; + //Callback is null and array is empty + $this->assertNull(Arr::first([], null)); + $this->assertSame('foo', Arr::first([], null, 'foo')); + $this->assertSame('bar', Arr::first([], null, function () { + return 'bar'; + })); + + //Callback is null and array is not empty + $this->assertEquals(100, Arr::first($array)); + + //Callback is not null and array is not empty $value = Arr::first($array, function ($value) { return $value >= 150; }); - $this->assertEquals(200, $value); - $this->assertEquals(100, Arr::first($array)); + + //Callback is not null, array is not empty but no satisfied item + $value2 = Arr::first($array, function ($value) { + return $value > 300; + }); + $value3 = Arr::first($array, function ($value) { + return $value > 300; + }, 'bar'); + $value4 = Arr::first($array, function ($value) { + return $value > 300; + }, function () { + return 'baz'; + }); + $this->assertNull($value2); + $this->assertSame('bar', $value3); + $this->assertSame('baz', $value4); } public function testLast()
false
Other
laravel
framework
e4f477c42d3e24f6cdf44a45801c0db476ad2b91.json
add missing public methods to interface
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -78,6 +78,30 @@ public function add(Route $route) return $route; } + /** + * Refresh the name look-up table. + * + * This is done in case any names are fluently defined or if routes are overwritten. + * + * @return void + */ + public function refreshNameLookups() + { + // + } + + /** + * Refresh the action look-up table. + * + * This is done in case any actions are overwritten with new controllers. + * + * @return void + */ + public function refreshActionLookups() + { + // + } + /** * Find the first route matching a given request. *
true
Other
laravel
framework
e4f477c42d3e24f6cdf44a45801c0db476ad2b91.json
add missing public methods to interface
src/Illuminate/Routing/RouteCollectionInterface.php
@@ -14,6 +14,24 @@ interface RouteCollectionInterface */ public function add(Route $route); + /** + * Refresh the name look-up table. + * + * This is done in case any names are fluently defined or if routes are overwritten. + * + * @return void + */ + public function refreshNameLookups(); + + /** + * Refresh the action look-up table. + * + * This is done in case any actions are overwritten with new controllers. + * + * @return void + */ + public function refreshActionLookups(); + /** * Find the first route matching a given request. *
true
Other
laravel
framework
af806851931700e8dd8de0ac0333efd853b19f3d.json
fix model binding when cached
src/Illuminate/Routing/AbstractRouteCollection.php
@@ -146,6 +146,7 @@ public function compile() 'fallback' => $route->isFallback, 'defaults' => $route->defaults, 'wheres' => $route->wheres, + 'bindingFields' => $route->bindingFields(), ]; }
true
Other
laravel
framework
af806851931700e8dd8de0ac0333efd853b19f3d.json
fix model binding when cached
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -70,6 +70,7 @@ public function add(Route $route) 'fallback' => $route->isFallback, 'defaults' => $route->defaults, 'wheres' => $route->wheres, + 'bindingFields' => $route->bindingFields(), ]; $this->compiled = []; @@ -244,6 +245,7 @@ protected function newRoute(array $attributes) ->setFallback($attributes['fallback']) ->setDefaults($attributes['defaults']) ->setWheres($attributes['wheres']) + ->setBindingFields($attributes['bindingFields']) ->setRouter($this->router) ->setContainer($this->container); }
true
Other
laravel
framework
af806851931700e8dd8de0ac0333efd853b19f3d.json
fix model binding when cached
src/Illuminate/Routing/Route.php
@@ -488,6 +488,29 @@ public function bindingFieldFor($parameter) return $this->bindingFields[$parameter] ?? null; } + /** + * Get the binding fields for the route. + * + * @return array + */ + public function bindingFields() + { + return $this->bindingFields ?? []; + } + + /** + * Set the binding fields for the route. + * + * @param array $bindingFields + * @return $this + */ + public function setBindingFields(array $bindingFields) + { + $this->bindingFields = $bindingFields; + + return $this; + } + /** * Get the parent parameter of the given parameter. *
true
Other
laravel
framework
9c1c8390de66a27de7f41e3c599e5642103b6c73.json
Fix typehints (#31806)
src/Illuminate/Foundation/Application.php
@@ -901,7 +901,7 @@ protected function fireAppCallbacks(array $callbacks) /** * {@inheritdoc} */ - public function handle(SymfonyRequest $request, $type = self::MASTER_REQUEST, $catch = true) + public function handle(SymfonyRequest $request, int $type = self::MASTER_REQUEST, bool $catch = true) { return $this[HttpKernelContract::class]->handle(Request::createFromBase($request)); }
false
Other
laravel
framework
64c9c13734dd9468ee014d01e95fc81ed127182c.json
Remove useless Closure comment (#31783)
src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php
@@ -261,7 +261,7 @@ protected function binder() * Normalize the given callback into a callable. * * @param mixed $callback - * @return \Closure|callable + * @return callable */ protected function normalizeChannelHandlerToCallable($callback) {
true
Other
laravel
framework
64c9c13734dd9468ee014d01e95fc81ed127182c.json
Remove useless Closure comment (#31783)
src/Illuminate/Contracts/Routing/Registrar.php
@@ -8,7 +8,7 @@ interface Registrar * Register a new GET route with the router. * * @param string $uri - * @param \Closure|array|string|callable $action + * @param array|string|callable $action * @return \Illuminate\Routing\Route */ public function get($uri, $action); @@ -17,7 +17,7 @@ public function get($uri, $action); * Register a new POST route with the router. * * @param string $uri - * @param \Closure|array|string|callable $action + * @param array|string|callable $action * @return \Illuminate\Routing\Route */ public function post($uri, $action); @@ -26,7 +26,7 @@ public function post($uri, $action); * Register a new PUT route with the router. * * @param string $uri - * @param \Closure|array|string|callable $action + * @param array|string|callable $action * @return \Illuminate\Routing\Route */ public function put($uri, $action); @@ -35,7 +35,7 @@ public function put($uri, $action); * Register a new DELETE route with the router. * * @param string $uri - * @param \Closure|array|string|callable $action + * @param array|string|callable $action * @return \Illuminate\Routing\Route */ public function delete($uri, $action); @@ -44,7 +44,7 @@ public function delete($uri, $action); * Register a new PATCH route with the router. * * @param string $uri - * @param \Closure|array|string|callable $action + * @param array|string|callable $action * @return \Illuminate\Routing\Route */ public function patch($uri, $action); @@ -53,7 +53,7 @@ public function patch($uri, $action); * Register a new OPTIONS route with the router. * * @param string $uri - * @param \Closure|array|string|callable $action + * @param array|string|callable $action * @return \Illuminate\Routing\Route */ public function options($uri, $action); @@ -63,7 +63,7 @@ public function options($uri, $action); * * @param array|string $methods * @param string $uri - * @param \Closure|array|string|callable $action + * @param array|string|callable $action * @return \Illuminate\Routing\Route */ public function match($methods, $uri, $action);
true
Other
laravel
framework
64c9c13734dd9468ee014d01e95fc81ed127182c.json
Remove useless Closure comment (#31783)
src/Illuminate/Routing/Router.php
@@ -137,7 +137,7 @@ public function __construct(Dispatcher $events, Container $container = null) * Register a new GET route with the router. * * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function get($uri, $action = null) @@ -149,7 +149,7 @@ public function get($uri, $action = null) * Register a new POST route with the router. * * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function post($uri, $action = null) @@ -161,7 +161,7 @@ public function post($uri, $action = null) * Register a new PUT route with the router. * * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function put($uri, $action = null) @@ -173,7 +173,7 @@ public function put($uri, $action = null) * Register a new PATCH route with the router. * * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function patch($uri, $action = null) @@ -185,7 +185,7 @@ public function patch($uri, $action = null) * Register a new DELETE route with the router. * * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function delete($uri, $action = null) @@ -197,7 +197,7 @@ public function delete($uri, $action = null) * Register a new OPTIONS route with the router. * * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function options($uri, $action = null) @@ -209,7 +209,7 @@ public function options($uri, $action = null) * Register a new route responding to all verbs. * * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function any($uri, $action = null) @@ -220,7 +220,7 @@ public function any($uri, $action = null) /** * Register a new Fallback route with the router. * - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function fallback($action) @@ -279,7 +279,7 @@ public function view($uri, $view, $data = []) * * @param array|string $methods * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function match($methods, $uri, $action = null) @@ -438,7 +438,7 @@ public function getLastGroupPrefix() * * @param array|string $methods * @param string $uri - * @param \Closure|array|string|callable|null $action + * @param array|string|callable|null $action * @return \Illuminate\Routing\Route */ public function addRoute($methods, $uri, $action)
true
Other
laravel
framework
64c9c13734dd9468ee014d01e95fc81ed127182c.json
Remove useless Closure comment (#31783)
src/Illuminate/Support/Facades/Route.php
@@ -3,15 +3,15 @@ namespace Illuminate\Support\Facades; /** - * @method static \Illuminate\Routing\Route fallback(\Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route get(string $uri, \Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route post(string $uri, \Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route put(string $uri, \Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route delete(string $uri, \Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route patch(string $uri, \Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route options(string $uri, \Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route any(string $uri, \Closure|array|string|callable|null $action = null) - * @method static \Illuminate\Routing\Route match(array|string $methods, string $uri, \Closure|array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route fallback(array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route get(string $uri, array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route post(string $uri, array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route put(string $uri, array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route delete(string $uri, array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route patch(string $uri, array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route options(string $uri, array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route any(string $uri, array|string|callable|null $action = null) + * @method static \Illuminate\Routing\Route match(array|string $methods, string $uri, array|string|callable|null $action = null) * @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix) * @method static \Illuminate\Routing\RouteRegistrar where(array $where) * @method static \Illuminate\Routing\PendingResourceRegistration resource(string $name, string $controller, array $options = [])
true
Other
laravel
framework
c087ffe606bfb96f2689a2b9908e5158ff6efb7b.json
Fix a bug with slash prefix
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -229,10 +229,12 @@ protected function newRoute(array $attributes) if (empty($attributes['action']['prefix'] ?? '')) { $baseUri = $attributes['uri']; } else { + $prefixParts = trim($attributes['action']['prefix'], '/'); + $baseUri = trim(implode( '/', array_slice( explode('/', trim($attributes['uri'], '/')), - count(explode('/', trim($attributes['action']['prefix'], '/'))) + count($prefixParts !== '' ? explode('/', $prefixParts) : []) ) ), '/'); }
false
Other
laravel
framework
bea4f7629ab7d74d901204e29a5a5ef14fc4b10b.json
add a containter test (#31751)
tests/Container/ContainerTest.php
@@ -198,6 +198,15 @@ public function testBindingAnInstanceReturnsTheInstance() $this->assertSame($bound, $resolved); } + public function testBindingAnInstanceAsShared() + { + $container = new Container; + $bound = new stdClass; + $container->instance('foo', $bound); + $object = $container->make('foo'); + $this->assertSame($bound, $object); + } + public function testResolutionOfDefaultParameters() { $container = new Container;
false
Other
laravel
framework
672761ca3828220dee3279a8f630784ae68c9f2d.json
Update doc block (#31741)
src/Illuminate/Support/Facades/Cache.php
@@ -8,8 +8,8 @@ * @method static bool missing(string $key) * @method static mixed get(string $key, mixed $default = null) * @method static mixed pull(string $key, mixed $default = null) - * @method static bool put(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl) - * @method static bool add(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl) + * @method static bool put(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl = null) + * @method static bool add(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl = null) * @method static int|bool increment(string $key, $value = 1) * @method static int|bool decrement(string $key, $value = 1) * @method static bool forever(string $key, $value)
false
Other
laravel
framework
7ab5b4bbd5e7a662395f5cec0ece7497cec16806.json
Catch Symfony exception (#31738)
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -5,6 +5,7 @@ use Illuminate\Container\Container; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Matcher\CompiledUrlMatcher; use Symfony\Component\Routing\RequestContext; @@ -95,8 +96,12 @@ public function match(Request $request) $this->compiled, (new RequestContext)->fromRequest($request) ); - if ($result = $matcher->matchRequest($request)) { - $route = $this->getByName($result['_route']); + try { + if ($result = $matcher->matchRequest($request)) { + $route = $this->getByName($result['_route']); + } + } catch (ResourceNotFoundException $e) { + // } return $this->handleMatchedRoute($request, $route);
false
Other
laravel
framework
5cf7fecc7d656de950ab93d80c3a4a3a4c68fc7d.json
Fix doc @return class (#31737)
src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php
@@ -35,7 +35,7 @@ trait InteractsWithConsole * * @param string $command * @param array $parameters - * @return \Illuminate\Foundation\Testing\PendingCommand|int + * @return \Illuminate\Testing\PendingCommand|int */ public function artisan($command, $parameters = []) {
false
Other
laravel
framework
1f0b7763a4cfce873a52e14fa0405e18c8b344fb.json
Apply fixes from StyleCI (#31735)
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -5,7 +5,6 @@ use Illuminate\Container\Container; use Illuminate\Http\Request; use Illuminate\Support\Collection; -use Illuminate\Support\Str; use Symfony\Component\Routing\Matcher\CompiledUrlMatcher; use Symfony\Component\Routing\RequestContext;
false
Other
laravel
framework
90b0167d97e61eb06fce9cfc58527f4e09cd2a5e.json
fix route caching attempt
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -222,11 +222,15 @@ public function mapAttributesToRoutes() */ protected function newRoute(array $attributes) { - $baseUri = ltrim(Str::replaceFirst( - ltrim($attributes['action']['prefix'] ?? '', '/'), - '', - $attributes['uri'] - ), '/'); + if (! empty($attributes['action']['prefix'] ?? '')) { + $prefixSegments = explode('/', trim($attributes['action']['prefix'], '/')); + + $baseUri = trim(implode( + '/', array_slice(explode('/', trim($attributes['uri'], '/')), count($prefixSegments)) + ), '/'); + } else { + $baseUri = $attributes['uri']; + } return (new Route($attributes['methods'], $baseUri == '' ? '/' : $baseUri, $attributes['action'])) ->setFallback($attributes['fallback'])
false
Other
laravel
framework
ee71973398875afffad81c2c601d6aacf4723cf0.json
add missing docblock
src/Illuminate/Support/Traits/EnumeratesValues.php
@@ -30,6 +30,7 @@ * @property-read HigherOrderCollectionProxy $min * @property-read HigherOrderCollectionProxy $partition * @property-read HigherOrderCollectionProxy $reject + * @property-read HigherOrderCollectionProxy $some * @property-read HigherOrderCollectionProxy $sortBy * @property-read HigherOrderCollectionProxy $sortByDesc * @property-read HigherOrderCollectionProxy $sum
false
Other
laravel
framework
ce0355c72bf4defb93ae80c7bf7812bd6532031a.json
trim prefix off
src/Illuminate/Routing/CompiledRouteCollection.php
@@ -5,6 +5,7 @@ use Illuminate\Container\Container; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use Symfony\Component\Routing\Matcher\CompiledUrlMatcher; use Symfony\Component\Routing\RequestContext; @@ -221,7 +222,9 @@ public function mapAttributesToRoutes() */ protected function newRoute(array $attributes) { - return (new Route($attributes['methods'], $attributes['uri'], $attributes['action'])) + $baseUri = ltrim(Str::replaceFirst(ltrim($attributes['action']['prefix'] ?? '', '/'), '', $attributes['uri']), '/'); + + return (new Route($attributes['methods'], $baseUri, $attributes['action'])) ->setFallback($attributes['fallback']) ->setDefaults($attributes['defaults']) ->setWheres($attributes['wheres'])
false
Other
laravel
framework
2964d2dfd3cc50f7a709effee0af671c86587915.json
remove comments before compiling components
src/Illuminate/View/Compilers/BladeCompiler.php
@@ -65,7 +65,7 @@ class BladeCompiler extends Compiler implements CompilerInterface * @var array */ protected $compilers = [ - 'Comments', + // 'Comments', 'Extensions', 'Statements', 'Echos', @@ -219,7 +219,7 @@ public function compileString($value) // step which compiles the component Blade tags into @component directives // that may be used by Blade. Then we should call any other precompilers. $value = $this->compileComponentTags( - $this->storeUncompiledBlocks($value) + $this->compileComments($this->storeUncompiledBlocks($value)) ); foreach ($this->precompilers as $precompiler) {
false
Other
laravel
framework
39f1da2756de9e5b6cf6e486d0000cf53ac3357a.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/Factory.php
@@ -3,9 +3,11 @@ namespace Illuminate\Http\Client; use Closure; +use GuzzleHttp\Psr7\Response as Psr7Response; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use PHPUnit\Framework\Assert as PHPUnit; +use function GuzzleHttp\Promise\promise_for; class Factory { @@ -16,7 +18,7 @@ class Factory /** * The stub callables that will handle requests. * - * @var \Illuminate\Support\Collection|null + * @var \Illuminate\Support\Collection */ protected $stubCallbacks; @@ -34,6 +36,13 @@ class Factory */ protected $responseSequences = []; + /** + * The record array. + * + * @var array + */ + protected $recorded; + /** * Create a new factory instance. * @@ -60,7 +69,7 @@ public static function response($body = null, $status = 200, $headers = []) $headers['Content-Type'] = 'application/json'; } - return \GuzzleHttp\Promise\promise_for(new \GuzzleHttp\Psr7\Response($status, $headers, $body)); + return promise_for(new Psr7Response($status, $headers, $body)); } /** @@ -95,7 +104,7 @@ public function fake($callback = null) $this->stubUrl($url, $callable); } - return; + return $this; } $this->stubCallbacks = $this->stubCallbacks->merge(collect([
true
Other
laravel
framework
39f1da2756de9e5b6cf6e486d0000cf53ac3357a.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/Request.php
@@ -36,7 +36,7 @@ public function __construct($request) /** * Get the request method. * - * @return strign + * @return string */ public function method() { @@ -70,6 +70,7 @@ public function hasHeader($key, $value = null) /** * Get the values for the header with the given name. * + * @param string $key * @return array */ public function header($key)
true
Other
laravel
framework
39f1da2756de9e5b6cf6e486d0000cf53ac3357a.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/Response.php
@@ -64,6 +64,7 @@ public function json() /** * Get a header from the response. * + * @param string $header * @return string */ public function header(string $header) @@ -134,7 +135,7 @@ public function redirect() } /** - * Detemine if the response indicates a client error occurred. + * Determine if the response indicates a client error occurred. * * @return bool */ @@ -144,7 +145,7 @@ public function clientError() } /** - * Detemine if the response indicates a server error occurred. + * Determine if the response indicates a server error occurred. * * @return bool */ @@ -177,6 +178,8 @@ public function toPsrResponse() * Throw an exception if a server or client error occurred. * * @return $this + * + * @throws \Illuminate\Http\Client\RequestException */ public function throw() {
true
Other
laravel
framework
39f1da2756de9e5b6cf6e486d0000cf53ac3357a.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/ResponseSequence.php
@@ -21,7 +21,7 @@ class ResponseSequence protected $failWhenEmpty = true; /** - * The repsonse that should be returned when the sequence is empty. + * The response that should be returned when the sequence is empty. * * @var \GuzzleHttp\Promise\PromiseInterface */ @@ -48,11 +48,7 @@ public function __construct(array $responses) */ public function push($body = '', int $status = 200, array $headers = []) { - if (is_array($body)) { - return $this->pushResponse( - Factory::response(json_encode($body), $status, $headers) - ); - } + $body = is_array($body) ? json_encode($body) : $body; return $this->pushResponse( Factory::response($body, $status, $headers)
true
Other
laravel
framework
4fe16c2997cfee9b46dea810dc04016c93002625.json
fix typo in docblock (#31699)
src/Illuminate/View/Component.php
@@ -26,7 +26,7 @@ abstract class Component protected static $methodCache = []; /** - * That properties / methods that should not be exposed to the component. + * The properties / methods that should not be exposed to the component. * * @var array */
false
Other
laravel
framework
380d8c692b1448c6b701cc3c94abf98c81715e54.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/Factory.php
@@ -3,9 +3,11 @@ namespace Illuminate\Http\Client; use Closure; +use GuzzleHttp\Psr7\Response as Psr7Response; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use PHPUnit\Framework\Assert as PHPUnit; +use function GuzzleHttp\Promise\promise_for; class Factory { @@ -16,7 +18,7 @@ class Factory /** * The stub callables that will handle requests. * - * @var \Illuminate\Support\Collection|null + * @var \Illuminate\Support\Collection */ protected $stubCallbacks; @@ -34,6 +36,13 @@ class Factory */ protected $responseSequences = []; + /** + * The record array. + * + * @var array + */ + protected $recorded; + /** * Create a new factory instance. * @@ -60,7 +69,7 @@ public static function response($body = null, $status = 200, $headers = []) $headers['Content-Type'] = 'application/json'; } - return \GuzzleHttp\Promise\promise_for(new \GuzzleHttp\Psr7\Response($status, $headers, $body)); + return promise_for(new Psr7Response($status, $headers, $body)); } /** @@ -95,7 +104,7 @@ public function fake($callback = null) $this->stubUrl($url, $callable); } - return; + return $this; } $this->stubCallbacks = $this->stubCallbacks->merge(collect([
true
Other
laravel
framework
380d8c692b1448c6b701cc3c94abf98c81715e54.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/Request.php
@@ -36,7 +36,7 @@ public function __construct($request) /** * Get the request method. * - * @return strign + * @return string */ public function method() { @@ -70,6 +70,7 @@ public function hasHeader($key, $value = null) /** * Get the values for the header with the given name. * + * @param string $key * @return array */ public function header($key)
true
Other
laravel
framework
380d8c692b1448c6b701cc3c94abf98c81715e54.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/Response.php
@@ -64,6 +64,7 @@ public function json() /** * Get a header from the response. * + * @param string $header * @return string */ public function header(string $header) @@ -134,7 +135,7 @@ public function redirect() } /** - * Detemine if the response indicates a client error occurred. + * Determine if the response indicates a client error occurred. * * @return bool */ @@ -144,7 +145,7 @@ public function clientError() } /** - * Detemine if the response indicates a server error occurred. + * Determine if the response indicates a server error occurred. * * @return bool */ @@ -177,6 +178,8 @@ public function toPsrResponse() * Throw an exception if a server or client error occurred. * * @return $this + * + * @throws \Illuminate\Http\Client\RequestException */ public function throw() {
true
Other
laravel
framework
380d8c692b1448c6b701cc3c94abf98c81715e54.json
Add minor changes to HTTP client.
src/Illuminate/Http/Client/ResponseSequence.php
@@ -21,7 +21,7 @@ class ResponseSequence protected $failWhenEmpty = true; /** - * The repsonse that should be returned when the sequence is empty. + * The response that should be returned when the sequence is empty. * * @var \GuzzleHttp\Promise\PromiseInterface */ @@ -48,11 +48,7 @@ public function __construct(array $responses) */ public function push($body = '', int $status = 200, array $headers = []) { - if (is_array($body)) { - return $this->pushResponse( - Factory::response(json_encode($body), $status, $headers) - ); - } + $body = is_array($body) ? json_encode($body) : $body; return $this->pushResponse( Factory::response($body, $status, $headers)
true
Other
laravel
framework
fe8c7e17e765c99f35c0c44448258e94409f405f.json
Fix a docblock. (#31689)
src/Illuminate/Support/Stringable.php
@@ -299,7 +299,7 @@ public function match($pattern) * Get the string matching the given pattern. * * @param string $pattern - * @return static|null + * @return \Illuminate\Support\Collection */ public function matchAll($pattern) {
false
Other
laravel
framework
792da8415cdef8eaf41a955248592c2a23f00478.json
Remove unused properties. (#31688)
src/Illuminate/Support/Stringable.php
@@ -27,34 +27,6 @@ public function __construct($value = '') $this->value = (string) $value; } - /** - * The cache of snake-cased words. - * - * @var array - */ - protected static $snakeCache = []; - - /** - * The cache of camel-cased words. - * - * @var array - */ - protected static $camelCache = []; - - /** - * The cache of studly-cased words. - * - * @var array - */ - protected static $studlyCache = []; - - /** - * The callback that should be used to generate UUIDs. - * - * @var callable - */ - protected static $uuidFactory; - /** * Return the remainder of a string after the first occurrence of a given value. *
false
Other
laravel
framework
dd878c067ed2ef2ba3adf710e2f4e73effbb256f.json
Add retry to Http facade annotations
src/Illuminate/Support/Facades/Http.php
@@ -13,6 +13,7 @@ * @method static \Illuminate\Http\Client\PendingRequest contentType(string $contentType) * @method static \Illuminate\Http\Client\PendingRequest acceptJson() * @method static \Illuminate\Http\Client\PendingRequest accept(string $contentType) + * @method static \Illuminate\Http\Client\PendingRequest retry(int $times, int $sleep = 0) * @method static \Illuminate\Http\Client\PendingRequest withHeaders(array $headers) * @method static \Illuminate\Http\Client\PendingRequest withBasicAuth(string $username, string $password) * @method static \Illuminate\Http\Client\PendingRequest withDigestAuth(string $username, string $password)
false
Other
laravel
framework
33461dcbb77702d444ec0e04a55c2e7ff97521b1.json
add test for view component class (#31665)
tests/View/ViewComponentTest.php
@@ -17,6 +17,34 @@ public function testDataExposure() $this->assertEquals('world', $variables['hello']()); $this->assertEquals('taylor', $variables['hello']('taylor')); } + + public function testPublicMethodsWithNoArgsAreEagerlyInvokedAndNotCached() + { + $component = new TestSampleViewComponent; + + $this->assertEquals(0, $component->counter); + $variables = $component->data(); + $this->assertEquals(1, $component->counter); + + $this->assertEquals('noArgs val', $variables['noArgs']); + $this->assertEquals(0, $variables['counter']); + + // make sure non-public members are not invoked nor counted. + $this->assertEquals(1, $component->counter); + $this->assertArrayHasKey('publicHello', $variables); + $this->assertArrayNotHasKey('protectedHello', $variables); + $this->assertArrayNotHasKey('privateHello', $variables); + + $this->assertArrayNotHasKey('protectedCounter', $variables); + $this->assertArrayNotHasKey('privateCounter', $variables); + + // test each time we invoke data(), the non-argument methods are invoked + $this->assertEquals(1, $component->counter); + $component->data(); + $this->assertEquals(2, $component->counter); + $component->data(); + $this->assertEquals(3, $component->counter); + } } class TestViewComponent extends Component @@ -33,3 +61,41 @@ public function hello($string = 'world') return $string; } } + +class TestSampleViewComponent extends Component +{ + public $counter = 0; + + protected $protectedCounter = 0; + + private $privateCounter = 0; + + public function render() + { + return 'test'; + } + + public function publicHello($string = 'world') + { + $this->counter = 100; + + return $string; + } + + public function noArgs() + { + $this->counter++; + + return 'noArgs val'; + } + + protected function protectedHello() + { + $this->counter++; + } + + private function privateHello() + { + $this->counter++; + } +}
false
Other
laravel
framework
a1b0a996ab9ab04702a407169c29a34a17173c97.json
add missing return datatype (#31654)
src/Illuminate/Queue/Console/ListFailedCommand.php
@@ -92,7 +92,7 @@ private function extractJobName($payload) * Match the job name from the payload. * * @param array $payload - * @return string + * @return string|null */ protected function matchJobName($payload) {
true
Other
laravel
framework
a1b0a996ab9ab04702a407169c29a34a17173c97.json
add missing return datatype (#31654)
src/Illuminate/Queue/Jobs/RedisJob.php
@@ -110,7 +110,7 @@ public function attempts() /** * Get the job identifier. * - * @return string + * @return string|null */ public function getJobId() {
true
Other
laravel
framework
a1b0a996ab9ab04702a407169c29a34a17173c97.json
add missing return datatype (#31654)
src/Illuminate/Routing/Route.php
@@ -686,7 +686,7 @@ public function getDomain() /** * Get the prefix of the route instance. * - * @return string + * @return string|null */ public function getPrefix() { @@ -734,7 +734,7 @@ public function setUri($uri) /** * Get the name of the route instance. * - * @return string + * @return string|null */ public function getName() {
true
Other
laravel
framework
1a383120a5b39c501cef9cab2a835ea076cc0eb6.json
allow base url
src/Illuminate/Http/Client/PendingRequest.php
@@ -15,6 +15,13 @@ class PendingRequest */ protected $factory; + /** + * The base URL for the request. + * + * @var string + */ + protected $baseUrl = ''; + /** * The request body format. * @@ -99,6 +106,19 @@ public function __construct(Factory $factory = null) }]); } + /** + * Set the base URL for the pending request. + * + * @param string $url + * @return $this + */ + public function baseUrl(string $url) + { + $this->baseUrl = $url; + + return $this; + } + /** * Indicate the request contains JSON. * @@ -435,6 +455,8 @@ public function delete($url, $data = []) */ public function send(string $method, string $url, array $options = []) { + $url = ltrim(rtrim($this->baseUrl, '/').'/'.ltrim($url, '/'), '/'); + if (isset($options[$this->bodyFormat])) { $options[$this->bodyFormat] = array_merge( $options[$this->bodyFormat], $this->pendingFiles
false
Other
laravel
framework
ceba11ef3ce9775b04f8169b30c9aab60d0b6810.json
Add withQueryString method to paginator
src/Illuminate/Pagination/AbstractPaginator.php
@@ -3,10 +3,10 @@ namespace Illuminate\Pagination; use Closure; -use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\Arr; -use Illuminate\Support\Collection; use Illuminate\Support\Str; +use Illuminate\Support\Collection; +use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\Traits\ForwardsCalls; /** @@ -100,6 +100,13 @@ abstract class AbstractPaginator implements Htmlable */ protected static $viewFactoryResolver; + /** + * The with query string resolver callback. + * + * @var \Closure + */ + protected static $queryStringResolver; + /** * The default pagination view. * @@ -215,6 +222,20 @@ public function appends($key, $value = null) return $this->addQuery($key, $value); } + /** + * Add a set of query string values to the paginator. + * + * @return $this + */ + public function withQueryString() + { + if (isset(static::$queryStringResolver)) { + return $this->appends(call_user_func(static::$queryStringResolver)); + } + + return $this; + } + /** * Add an array of query string values. * @@ -484,6 +505,17 @@ public static function viewFactoryResolver(Closure $resolver) static::$viewFactoryResolver = $resolver; } + /** + * Set with query string resolver callback. + * + * @param \Closure $resolver + * @return void + */ + public static function withQueryStringResolver(Closure $resolver) + { + static::$queryStringResolver = $resolver; + } + /** * Set the default pagination view. *
true
Other
laravel
framework
ceba11ef3ce9775b04f8169b30c9aab60d0b6810.json
Add withQueryString method to paginator
src/Illuminate/Pagination/PaginationServiceProvider.php
@@ -46,5 +46,9 @@ public function register() return 1; }); + + Paginator::withQueryStringResolver(function () { + return $this->app['request']->query(); + }); } }
true
Other
laravel
framework
e9f3c95d35c51f486fa4d608be4f6611bd259f72.json
Fix flakey memcached tests (#31646)
tests/Integration/Cache/MemcachedTaggedCacheTest.php
@@ -13,8 +13,8 @@ public function testMemcachedCanStoreAndRetrieveTaggedCacheItems() { $store = Cache::store('memcached'); - $store->tags(['people', 'artists'])->put('John', 'foo', 1); - $store->tags(['people', 'authors'])->put('Anne', 'bar', 1); + $store->tags(['people', 'artists'])->put('John', 'foo', 2); + $store->tags(['people', 'authors'])->put('Anne', 'bar', 2); $this->assertSame('foo', $store->tags(['people', 'artists'])->get('John')); $this->assertSame('bar', $store->tags(['people', 'authors'])->get('Anne')); @@ -36,7 +36,7 @@ public function testMemcachedCanStoreManyTaggedCacheItems() { $store = Cache::store('memcached'); - $store->tags(['people', 'artists'])->putMany(['John' => 'foo', 'Jane' => 'bar'], 1); + $store->tags(['people', 'artists'])->putMany(['John' => 'foo', 'Jane' => 'bar'], 2); $this->assertSame('foo', $store->tags(['people', 'artists'])->get('John')); $this->assertSame('bar', $store->tags(['people', 'artists'])->get('Jane'));
false
Other
laravel
framework
ec30b5ecf94071058ac19e88c93126d7c0275bdf.json
add more tests
tests/Support/SupportStrTest.php
@@ -129,7 +129,15 @@ public function testStrBeforeLast() public function testStrBetween() { + $this->assertSame('abc', Str::between('abc', '', 'c')); + $this->assertSame('abc', Str::between('abc', 'a', '')); + $this->assertSame('abc', Str::between('abc', '', '')); + $this->assertSame('b', Str::between('abc', 'a', 'c')); + $this->assertSame('b', Str::between('dddabc', 'a', 'c')); + $this->assertSame('b', Str::between('abcddd', 'a', 'c')); + $this->assertSame('b', Str::between('dddabcddd', 'a', 'c')); $this->assertSame('nn', Str::between('hannah', 'ha', 'ah')); + $this->assertSame('a]ab[b', Str::between('[a]ab[b]', '[', ']')); $this->assertSame('foo', Str::between('foofoobar', 'foo', 'bar')); $this->assertSame('bar', Str::between('foobarbar', 'foo', 'bar')); }
false
Other
laravel
framework
2488eba6f85092af7cb4d3b8271d8024d3978379.json
add stringable method
src/Illuminate/Support/Stringable.php
@@ -132,6 +132,18 @@ public function beforeLast($search) return new static(Str::beforeLast($this->value, $search)); } + /** + * Get the portion of a string between a given values. + * + * @param string $before + * @param string $after + * @return static + */ + public function between($before, $after) + { + return new static(Str::between($this->value, $before, $after)); + } + /** * Convert a value to camel case. *
false
Other
laravel
framework
0d16818a7c1114b1d9b12975bcac820a21c35bcc.json
Apply fixes from StyleCI (#31626)
src/Illuminate/Http/Client/ResponseSequence.php
@@ -2,7 +2,6 @@ namespace Illuminate\Http\Client; -use Closure; use OutOfBoundsException; class ResponseSequence
false
Other
laravel
framework
c354a691669005381c824331f29e184e31f7c583.json
Add Str::between method
src/Illuminate/Support/Str.php
@@ -132,6 +132,25 @@ public static function beforeLast($subject, $search) return static::substr($subject, 0, $pos); } + /** + * Get the portion of a string between a given values. + * + * @param string $subject + * @param string $before + * @param string $after + * @return string + */ + public static function between($subject, $before, $after) + { + if ($before === '' || $after === '') { + return $subject; + } + + $rightCropped = static::after($subject, $before); + + return static::beforeLast($rightCropped, $after); + } + /** * Convert a value to camel case. *
true
Other
laravel
framework
c354a691669005381c824331f29e184e31f7c583.json
Add Str::between method
tests/Support/SupportStrTest.php
@@ -127,6 +127,13 @@ public function testStrBeforeLast() $this->assertSame('yv2et', Str::beforeLast('yv2et2te', 2)); } + public function testStrBetween() + { + $this->assertSame('nn', Str::between('hannah', 'ha', 'ah')); + $this->assertSame('foo', Str::between('foofoobar', 'foo', 'bar')); + $this->assertSame('bar', Str::between('foobarbar', 'foo', 'bar')); + } + public function testStrAfter() { $this->assertSame('nah', Str::after('hannah', 'han'));
true
Other
laravel
framework
9495b284bb2177f6d84993442bb822ab2bb358de.json
add retry support
src/Illuminate/Http/Client/PendingRequest.php
@@ -50,6 +50,20 @@ class PendingRequest */ protected $options = []; + /** + * The number of times to try the request. + * + * @var int + */ + protected $tries = 1; + + /** + * The number of milliseconds to wait between retries. + * + * @var int + */ + protected $retryDelay = 100; + /** * The callbacks that should execute before the request is sent. * @@ -300,6 +314,21 @@ public function timeout(int $seconds) }); } + /** + * Specify the number of times the request should be attempted. + * + * @param int $times + * @param int $sleep + * @return $this + */ + public function retry(int $times, int $sleep = 0) + { + $this->tries = $times; + $this->retryDelay = $sleep; + + return $this; + } + /** * Merge new options into the client. * @@ -414,20 +443,26 @@ public function send(string $method, string $url, array $options = []) $this->pendingFiles = []; - try { - return tap(new Response($this->buildClient()->request($method, $url, $this->mergeOptions([ - 'laravel_data' => $options[$this->bodyFormat] ?? [], - 'query' => $this->parseQueryParams($url), - 'on_stats' => function ($transferStats) { - $this->transferStats = $transferStats; - }, - ], $options))), function ($response) { - $response->cookies = $this->cookies; - $response->transferStats = $this->transferStats; - }); - } catch (\GuzzleHttp\Exception\ConnectException $e) { - throw new ConnectionException($e->getMessage(), 0, $e); - } + return retry($this->tries ?? 1, function () use ($method, $url, $options) { + try { + return tap(new Response($this->buildClient()->request($method, $url, $this->mergeOptions([ + 'laravel_data' => $options[$this->bodyFormat] ?? [], + 'query' => $this->parseQueryParams($url), + 'on_stats' => function ($transferStats) { + $this->transferStats = $transferStats; + }, + ], $options))), function ($response) { + $response->cookies = $this->cookies; + $response->transferStats = $this->transferStats; + + if ($this->tries > 1 && ! $response->successful()) { + $response->throw(); + } + }); + } catch (\GuzzleHttp\Exception\ConnectException $e) { + throw new ConnectionException($e->getMessage(), 0, $e); + } + }, $this->retryDelay ?? 100); } /**
false
Other
laravel
framework
61c887fddd6706208be16da5e3e7f3a2ddf95953.json
Clarify invalid connection message (#31584)
src/Illuminate/Database/DatabaseManager.php
@@ -149,7 +149,7 @@ protected function configuration($name) $connections = $this->app['config']['database.connections']; if (is_null($config = Arr::get($connections, $name))) { - throw new InvalidArgumentException("Database [{$name}] not configured."); + throw new InvalidArgumentException("Database connection [{$name}] not configured."); } return (new ConfigurationUrlParser)
false
Other
laravel
framework
192e6caf53f8d4592c6fd1fbf70d60bed58bf9a8.json
Apply fixes from StyleCI (#31570)
src/Illuminate/Support/Facades/URL.php
@@ -16,7 +16,7 @@ * @method static string temporarySignedRoute(string $name, \DateTimeInterface|\DateInterval|int $expiration, array $parameters = [], bool $absolute = true) * @method static bool hasValidSignature(\Illuminate\Http\Request $request, bool $absolute = true) * @method static void defaults(array $defaults) - * @method static void forceScheme(string $scheme) + * @method static void forceScheme(string $scheme) * * @see \Illuminate\Routing\UrlGenerator */
false
Other
laravel
framework
8934a9189f62907adc9e896c59262a51c06efe1d.json
change doc block
src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
@@ -39,7 +39,7 @@ trait HasAttributes protected $changes = []; /** - * The attributes that should be cast to native types. + * The attributes that should be cast. * * @var array */
false
Other
laravel
framework
0f693c992d0df1ee34716cdfc4d9c5a5bf9872b9.json
fix bug in isClassCastable
src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
@@ -1049,7 +1049,7 @@ protected function isJsonCastable($key) protected function isClassCastable($key) { return array_key_exists($key, $this->getCasts()) && - class_exists($class = $this->getCasts()[$key]) && + class_exists($class = $this->parseCasterClass($this->getCasts()[$key])) && ! in_array($class, static::$primitiveCastTypes); } @@ -1070,6 +1070,19 @@ protected function resolveCasterClass($key) return new $segments[0](...explode(',', $segments[1])); } + /** + * Parse the given caster class, removing any arguments. + * + * @param string $class + * @return string + */ + protected function parseCasterClass($class) + { + return strpos($class, ':') === false + ? $class + : explode(':', $class, 2)[0]; + } + /** * Merge the cast class attributes back into the model. *
false
Other
laravel
framework
fd66e088ec53026667f261e0dae2799bbf37d811.json
improve container tests (#31547)
tests/Container/ContainerTest.php
@@ -68,41 +68,40 @@ public function testBindIfDoesRegisterIfServiceNotRegisteredYet() public function testSingletonIfDoesntRegisterIfBindingAlreadyRegistered() { $container = new Container; - $class = new stdClass; - $container->singleton('class', function () use ($class) { - return $class; + $container->singleton('class', function () { + return new stdClass; }); - $otherClass = new stdClass; - $container->singletonIf('class', function () use ($otherClass) { - return $otherClass; + $firstInstantiation = $container->make('class'); + $container->singletonIf('class', function () { + return new ContainerConcreteStub; }); - - $this->assertSame($class, $container->make('class')); + $secondInstantiation = $container->make('class'); + $this->assertSame($firstInstantiation, $secondInstantiation); } public function testSingletonIfDoesRegisterIfBindingNotRegisteredYet() { $container = new Container; - $class = new stdClass; - $container->singleton('class', function () use ($class) { - return $class; + $container->singleton('class', function () { + return new stdClass; }); - $otherClass = new stdClass; - $container->singletonIf('otherClass', function () use ($otherClass) { - return $otherClass; + $container->singletonIf('otherClass', function () { + return new ContainerConcreteStub; }); - - $this->assertSame($otherClass, $container->make('otherClass')); + $firstInstantiation = $container->make('otherClass'); + $secondInstantiation = $container->make('otherClass'); + $this->assertSame($firstInstantiation, $secondInstantiation); } public function testSharedClosureResolution() { $container = new Container; - $class = new stdClass; - $container->singleton('class', function () use ($class) { - return $class; + $container->singleton('class', function () { + return new stdClass; }); - $this->assertSame($class, $container->make('class')); + $firstInstantiation = $container->make('class'); + $secondInstantiation = $container->make('class'); + $this->assertSame($firstInstantiation, $secondInstantiation); } public function testAutoConcreteResolution()
false
Other
laravel
framework
7848377efcc2e09cfab3239c7a93f85beeece11f.json
fix null return
src/Illuminate/Http/Client/PendingRequest.php
@@ -510,7 +510,7 @@ public function buildStubHandler() ->first(); if (is_null($response)) { - return Factory::response(); + return $handler($request, $options); } elseif (is_array($response)) { return Factory::response($response); }
false
Other
laravel
framework
d138e4cc950edc2685750dbfa22b4f01bc6b25e1.json
add replace method
src/Illuminate/Support/Stringable.php
@@ -372,6 +372,18 @@ public function prepend(...$values) return new static(implode('', $values).$this->value); } + /** + * Replace the given value in the given string. + * + * @param string $search + * @param string $replace + * @return static + */ + public function replace($search, $replace) + { + return new static(str_replace($search, $replace, $this->value)); + } + /** * Replace a given value in the string sequentially with an array. *
false
Other
laravel
framework
14a9515b48b50979ce90994b0f136d1c96e93fb5.json
Use testbench-core 6
composer.json
@@ -85,7 +85,7 @@ "league/flysystem-cached-adapter": "^1.0", "mockery/mockery": "^1.3.1", "moontoast/math": "^1.1", - "orchestra/testbench-core": "^5.0", + "orchestra/testbench-core": "^6.0", "pda/pheanstalk": "^4.0", "phpunit/phpunit": "^8.4|^9.0", "predis/predis": "^1.1.1",
false
Other
laravel
framework
37d03d6002c6218e6147c4ee85187673fc7b61f2.json
fail a response sequence when out of responses
src/Illuminate/Http/Client/ResponseSequence.php
@@ -2,6 +2,8 @@ namespace Illuminate\Http\Client; +use OutOfBoundsException; + class ResponseSequence { /** @@ -11,6 +13,13 @@ class ResponseSequence */ protected $responses; + /** + * Indicates that invoking this sequence when it is empty should throw an exception. + * + * @var bool + */ + protected $failWhenEmpty = true; + /** * Create a new response sequence. * @@ -87,13 +96,29 @@ public function pushResponse($response) return $this; } + /** + * Make the sequence return a default response when it is empty. + * + * @return $this + */ + public function dontFailWhenEmpty() + { + $this->failWhenEmpty = false; + + return $this; + } + /** * Get the next response in the sequence. * * @return mixed */ public function __invoke() { + if ($this->failWhenEmpty && count($this->responses) === 0) { + throw new OutOfBoundsException('A request was made, but the response sequence is empty.'); + } + return array_shift($this->responses); } }
true
Other
laravel
framework
37d03d6002c6218e6147c4ee85187673fc7b61f2.json
fail a response sequence when out of responses
tests/Http/HttpClientTest.php
@@ -5,6 +5,7 @@ use Illuminate\Http\Client\Factory; use Illuminate\Http\Client\PendingRequest; use Illuminate\Support\Str; +use OutOfBoundsException; use PHPUnit\Framework\TestCase; class HttpClientTest extends TestCase @@ -148,5 +149,28 @@ public function testSequenceBuilder() $response = $factory->get('https://example.com'); $this->assertSame('', $response->body()); $this->assertSame(403, $response->status()); + + $this->expectException(OutOfBoundsException::class); + + // The sequence is empty, it should throw an exception. + $factory->get('https://example.com'); + } + + public function testSequenceBuilderCanKeepGoingWhenEmpty() + { + $factory = new Factory; + + $factory->fake([ + '*' => Factory::sequence() + ->dontFailWhenEmpty() + ->push('Ok'), + ]); + + /** @var PendingRequest $factory */ + $response = $factory->get('https://example.com'); + $this->assertSame('Ok', $response->body()); + + // The sequence is empty, but it should not fail. + $factory->get('https://example.com'); } }
true
Other
laravel
framework
38f8a4933543ef9390cfd0e0963359a6ad650e9c.json
Use ViewErrorBag instead of MessageBag
src/Illuminate/View/View.php
@@ -13,6 +13,7 @@ use Illuminate\Support\MessageBag; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; +use Illuminate\Support\ViewErrorBag; use Throwable; class View implements ArrayAccess, Htmlable, ViewContract @@ -207,23 +208,30 @@ public function nest($key, $view, array $data = []) * @param \Illuminate\Contracts\Support\MessageProvider|array $provider * @return $this */ - public function withErrors($provider) + public function withErrors($provider, $key = 'default') { - $this->with('errors', $this->formatErrors($provider)); + $value = $this->parseErrors($provider); + + $errors = new ViewErrorBag; + + $this->with('errors', $errors->put($key, $value)); return $this; } /** - * Format the given message provider into a MessageBag. + * Parse the given errors into an appropriate value. * - * @param \Illuminate\Contracts\Support\MessageProvider|array $provider + * @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider * @return \Illuminate\Support\MessageBag */ - protected function formatErrors($provider) + protected function parseErrors($provider) { - return $provider instanceof MessageProvider - ? $provider->getMessageBag() : new MessageBag((array) $provider); + if ($provider instanceof MessageProvider) { + return $provider->getMessageBag(); + } + + return new MessageBag((array) $provider); } /**
true
Other
laravel
framework
38f8a4933543ef9390cfd0e0963359a6ad650e9c.json
Use ViewErrorBag instead of MessageBag
tests/View/ViewTest.php
@@ -9,6 +9,7 @@ use Illuminate\Contracts\Support\Renderable; use Illuminate\Contracts\View\Engine; use Illuminate\Support\MessageBag; +use Illuminate\Support\ViewErrorBag; use Illuminate\View\Factory; use Illuminate\View\View; use Mockery as m; @@ -216,7 +217,7 @@ public function testWithErrors() $view = $this->getView(); $errors = ['foo' => 'bar', 'qu' => 'ux']; $this->assertSame($view, $view->withErrors($errors)); - $this->assertInstanceOf(MessageBag::class, $view->errors); + $this->assertInstanceOf(ViewErrorBag::class, $view->errors); $foo = $view->errors->get('foo'); $this->assertEquals($foo[0], 'bar'); $qu = $view->errors->get('qu'); @@ -225,6 +226,11 @@ public function testWithErrors() $this->assertSame($view, $view->withErrors(new MessageBag($data))); $foo = $view->errors->get('foo'); $this->assertEquals($foo[0], 'baz'); + $foo = $view->errors->getBag('default')->get('foo'); + $this->assertEquals($foo[0], 'baz'); + $this->assertSame($view, $view->withErrors(new MessageBag($data), 'login')); + $foo = $view->errors->getBag('login')->get('foo'); + $this->assertEquals($foo[0], 'baz'); } protected function getView($data = [])
true
Other
laravel
framework
391a1ad63ac4577a5d7730c67ccad3bd9dcf50e0.json
add a sequence builder to the new http client
src/Illuminate/Http/Client/Factory.php
@@ -62,7 +62,7 @@ public static function response($body = null, $status = 200, $headers = []) * @param array $responses * @return \Illuminate\Http\Client\ResponseSequence */ - public static function sequence(array $responses) + public static function sequence(array $responses = []) { return new ResponseSequence($responses); }
true
Other
laravel
framework
391a1ad63ac4577a5d7730c67ccad3bd9dcf50e0.json
add a sequence builder to the new http client
src/Illuminate/Http/Client/ResponseSequence.php
@@ -22,6 +22,80 @@ public function __construct(array $responses) $this->responses = $responses; } + /** + * Push a response to the sequence. + * + * @param mixed $response + * @return $this + */ + public function pushResponse($response) + { + $this->responses[] = $response; + + return $this; + } + + /** + * Push an empty response to the sequence. + * + * @param int $status + * @param array $headers + * @return $this + */ + public function pushEmptyResponse($status = 200, $headers = []) + { + return $this->pushResponse( + Factory::response('', $status, $headers) + ); + } + + /** + * Push response with a string body to the sequence. + * + * @param string $string + * @param int $status + * @param array $headers + * @return $this + */ + public function pushString($string, $status = 200, $headers = []) + { + return $this->pushResponse( + Factory::response($string, $status, $headers) + ); + } + + /** + * Push response with a json body to the sequence. + * + * @param array $data + * @param int $status + * @param array $headers + * @return $this + */ + public function pushJson(array $data, $status = 200, $headers = []) + { + return $this->pushResponse( + Factory::response(json_encode($data), $status, $headers) + ); + } + + /** + * Push response with the contents of a file as the body to the sequence. + * + * @param string $filePath + * @param int $status + * @param array $headers + * @return $this + */ + public function pushFile($filePath, $status = 200, $headers = []) + { + $string = file_get_contents($filePath); + + return $this->pushResponse( + Factory::response($string, $status, $headers) + ); + } + /** * Get the next response in the sequence. *
true
Other
laravel
framework
391a1ad63ac4577a5d7730c67ccad3bd9dcf50e0.json
add a sequence builder to the new http client
tests/Http/HttpClientTest.php
@@ -3,6 +3,7 @@ namespace Illuminate\Tests\Http; use Illuminate\Http\Client\Factory; +use Illuminate\Http\Client\PendingRequest; use Illuminate\Support\Str; use PHPUnit\Framework\TestCase; @@ -118,4 +119,34 @@ public function testFilesCanBeAttached() $request->hasFile('foo', 'data', 'file.txt'); }); } + + public function testSequenceBuilder() + { + $factory = new Factory; + + $factory->fake([ + '*' => Factory::sequence() + ->pushString('Ok', 201) + ->pushJson(['fact' => 'Cats are great!']) + ->pushFile(__DIR__.'/fixtures/test.txt') + ->pushEmptyResponse(403), + ]); + + /** @var PendingRequest $factory */ + $response = $factory->get('https://example.com'); + $this->assertSame('Ok', $response->body()); + $this->assertSame(201, $response->status()); + + $response = $factory->get('https://example.com'); + $this->assertSame(['fact' => 'Cats are great!'], $response->json()); + $this->assertSame(200, $response->status()); + + $response = $factory->get('https://example.com'); + $this->assertSame("This is a story about something that happened long ago when your grandfather was a child.\n", $response->body()); + $this->assertSame(200, $response->status()); + + $response = $factory->get('https://example.com'); + $this->assertSame("", $response->body()); + $this->assertSame(403, $response->status()); + } }
true
Other
laravel
framework
8e10370c9c27290d40df12e90cc2f84b6235060b.json
add tests for broadcasted events (#31515)
tests/Events/EventsDispatcherTest.php
@@ -4,6 +4,7 @@ use Exception; use Illuminate\Container\Container; +use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Queue\Queue; use Illuminate\Contracts\Queue\ShouldQueue; @@ -404,6 +405,27 @@ public function testShouldBroadcastSuccess() $event = new BroadcastEvent; $this->assertTrue($d->shouldBroadcast([$event])); + + $event = new AlwaysBroadcastEvent; + + $this->assertTrue($d->shouldBroadcast([$event])); + } + + public function testShouldBroadcastAsQueuedAndCallNormalListeners() + { + unset($_SERVER['__event.test']); + $d = new Dispatcher($container = m::mock(Container::class)); + $broadcast = m::mock(BroadcastFactory::class); + $broadcast->shouldReceive('queue')->once(); + $container->shouldReceive('make')->once()->with(BroadcastFactory::class)->andReturn($broadcast); + + $d->listen(AlwaysBroadcastEvent::class, function ($payload) { + $_SERVER['__event.test'] = $payload; + }); + + $d->dispatch($e = new AlwaysBroadcastEvent); + + $this->assertSame($e, $_SERVER['__event.test']); } public function testShouldBroadcastFail() @@ -415,6 +437,10 @@ public function testShouldBroadcastFail() $event = new BroadcastFalseCondition; $this->assertFalse($d->shouldBroadcast([$event])); + + $event = new ExampleEvent; + + $this->assertFalse($d->shouldBroadcast([$event])); } public function testEventSubscribers() @@ -496,6 +522,14 @@ public function broadcastWhen() } } +class AlwaysBroadcastEvent implements ShouldBroadcast +{ + public function broadcastOn() + { + return ['test-channel']; + } +} + class BroadcastFalseCondition extends BroadcastEvent { public function broadcastWhen()
false
Other
laravel
framework
0a670b4db8d4e3c49bcc062833eb21413527d040.json
Add test for event subscribers (#31496)
tests/Events/EventsDispatcherTest.php
@@ -416,6 +416,27 @@ public function testShouldBroadcastFail() $this->assertFalse($d->shouldBroadcast([$event])); } + + public function testEventSubscribers() + { + $d = new Dispatcher($container = m::mock(Container::class)); + $subs = m::mock(ExampleSubscriber::class); + $subs->shouldReceive('subscribe')->once()->with($d); + $container->shouldReceive('make')->once()->with(ExampleSubscriber::class)->andReturn($subs); + + $d->subscribe(ExampleSubscriber::class); + $this->assertTrue(true); + } + + public function testEventSubscribeCanAcceptObject() + { + $d = new Dispatcher(); + $subs = m::mock(ExampleSubscriber::class); + $subs->shouldReceive('subscribe')->once()->with($d); + + $d->subscribe($subs); + $this->assertTrue(true); + } } class TestDispatcherQueuedHandler implements ShouldQueue @@ -444,6 +465,14 @@ class ExampleEvent // } +class ExampleSubscriber +{ + public function subscribe($e) + { + // + } +} + interface SomeEventInterface { //
false
Other
laravel
framework
cfd068e09b2983c20b310435d48a1c16b01a238a.json
use camelCase for data
src/Illuminate/View/Compilers/ComponentTagCompiler.php
@@ -155,6 +155,10 @@ protected function componentString(string $component, array $attributes) [$data, $attributes] = $this->partitionDataAndAttributes($class, $attributes); + $data = $data->mapWithKeys(function ($value, $key) { + return [Str::camel($key) => $value]; + }); + // If the component doesn't exists as a class we'll assume it's a class-less // component and pass the component as a view parameter to the data so it // can be accessed within the component and we can render out the view. @@ -241,7 +245,7 @@ protected function partitionDataAndAttributes($class, array $attributes) : []; return collect($attributes)->partition(function ($value, $key) use ($parameterNames) { - return in_array($key, $parameterNames); + return in_array(Str::camel($key), $parameterNames); }); }
true
Other
laravel
framework
cfd068e09b2983c20b310435d48a1c16b01a238a.json
use camelCase for data
src/Illuminate/View/Compilers/Concerns/CompilesComponents.php
@@ -147,7 +147,7 @@ protected function compileEndComponentFirst() */ protected function compileProps($expression) { - return "<?php \$attributes = \$attributes->except{$expression}; ?> + return "<?php \$attributes = \$attributes->exceptProps{$expression}; ?> <?php \$__defined_vars = get_defined_vars(); ?> <?php foreach (\$attributes as \$key => \$value) { if (array_key_exists(\$key, \$__defined_vars)) unset(\$\$key);
true
Other
laravel
framework
cfd068e09b2983c20b310435d48a1c16b01a238a.json
use camelCase for data
src/Illuminate/View/ComponentAttributeBag.php
@@ -7,6 +7,7 @@ use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\Arr; use Illuminate\Support\HtmlString; +use Illuminate\Support\Str; use IteratorAggregate; class ComponentAttributeBag implements ArrayAccess, Htmlable, IteratorAggregate @@ -79,6 +80,24 @@ public function except($keys) return new static($values); } + /** + * Exclude the given attribute from the attribute array. + * + * @param mixed|array $keys + * @return static + */ + public function exceptProps($keys) + { + $props = []; + + foreach ($keys as $key) { + $props[] = $key; + $props[] = Str::kebab($key); + } + + return $this->except($props); + } + /** * Merge additional attributes / values into the attribute bag. *
true
Other
laravel
framework
cfd068e09b2983c20b310435d48a1c16b01a238a.json
use camelCase for data
tests/View/Blade/BladeComponentTagCompilerTest.php
@@ -35,6 +35,14 @@ public function testBasicComponentParsing() @endcomponentClass</div>", trim($result)); } + public function testDataCamelCasing() + { + $result = (new ComponentTagCompiler(['profile' => TestProfileComponent::class]))->compileTags('<x-profile user-id="1"></x-profile>'); + + $this->assertEquals("@component('Illuminate\Tests\View\Blade\TestProfileComponent', ['userId' => '1']) +<?php \$component->withAttributes([]); ?>@endcomponentClass", trim($result)); + } + public function testColonNestedComponentParsing() { $result = (new ComponentTagCompiler(['foo:alert' => TestAlertComponent::class]))->compileTags('<x-foo:alert></x-foo:alert>'); @@ -146,7 +154,7 @@ class TestAlertComponent extends Component { public $title; - public function __construct($title = 'foo') + public function __construct($title = 'foo', $userId = 1) { $this->title = $title; } @@ -156,3 +164,18 @@ public function render() return 'alert'; } } + +class TestProfileComponent extends Component +{ + public $userId; + + public function __construct($userId = 'foo') + { + $this->userId = $userId; + } + + public function render() + { + return 'profile'; + } +}
true
Other
laravel
framework
4288dbb7df86f95687d514a4d7b33b93c8200fc8.json
Apply fixes from StyleCI (#31480)
src/Illuminate/Console/Concerns/InteractsWithIO.php
@@ -8,7 +8,6 @@ use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question;
false
Other
laravel
framework
8ec8628dc3cc0fbed0d75dd28f6207d16ef75c2c.json
Apply fixes from StyleCI (#31479)
src/Illuminate/Console/Concerns/InteractsWithIO.php
@@ -8,7 +8,6 @@ use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question;
false
Other
laravel
framework
4be35a5023050c27680336bb256e54a331fefc71.json
add test for event payload of type object (#31477)
tests/Events/EventsDispatcherTest.php
@@ -347,6 +347,18 @@ public function testClassesWork() $this->assertSame('baz', $_SERVER['__event.test']); } + public function testEventClassesArePayload() + { + unset($_SERVER['__event.test']); + $d = new Dispatcher; + $d->listen(ExampleEvent::class, function ($payload) { + $_SERVER['__event.test'] = $payload; + }); + $d->dispatch($e = new ExampleEvent, ['foo']); + + $this->assertSame($e, $_SERVER['__event.test']); + } + public function testInterfacesWork() { unset($_SERVER['__event.test']); @@ -362,17 +374,25 @@ public function testInterfacesWork() public function testBothClassesAndInterfacesWork() { unset($_SERVER['__event.test']); + $_SERVER['__event.test'] = []; $d = new Dispatcher; - $d->listen(AnotherEvent::class, function () { + $d->listen(AnotherEvent::class, function ($p) { + $_SERVER['__event.test'][] = $p; $_SERVER['__event.test1'] = 'fooo'; }); - $d->listen(SomeEventInterface::class, function () { + $d->listen(SomeEventInterface::class, function ($p) { + $_SERVER['__event.test'][] = $p; $_SERVER['__event.test2'] = 'baar'; }); - $d->dispatch(new AnotherEvent); + $d->dispatch($e = new AnotherEvent, ['foo']); + $this->assertSame($e, $_SERVER['__event.test'][0]); + $this->assertSame($e, $_SERVER['__event.test'][1]); $this->assertSame('fooo', $_SERVER['__event.test1']); $this->assertSame('baar', $_SERVER['__event.test2']); + + unset($_SERVER['__event.test1']); + unset($_SERVER['__event.test2']); } public function testShouldBroadcastSuccess()
false
Other
laravel
framework
ddc6883f4c62821ec48d9670037019175864bf93.json
Apply fixes from StyleCI (#31474)
src/Illuminate/Database/Query/Builder.php
@@ -656,8 +656,8 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' } // If the column is a Closure instance and there is an operator value, we will - // assume the developer wants to run a subquery and then compare the result - // of that subquery with the given value that was provided to the method. + // assume the developer wants to run a subquery and then compare the result + // of that subquery with the given value that was provided to the method. if ($this->isQueryable($column) && ! is_null($operator)) { [$sub, $bindings] = $this->createSub($column);
false
Other
laravel
framework
4436662a1ee19fc5e9eb76a0651d0de1aedb3ee2.json
fix password check
src/Illuminate/Auth/EloquentUserProvider.php
@@ -107,7 +107,7 @@ public function retrieveByCredentials(array $credentials) { if (empty($credentials) || (count($credentials) === 1 && - array_key_exists('password', $credentials))) { + Str::contains($this->firstCredentialKey($credentials), 'password'))) { return; } @@ -131,6 +131,19 @@ public function retrieveByCredentials(array $credentials) return $query->first(); } + /** + * Get the first key from the credential array. + * + * @param array $credentials + * @return string|null + */ + protected function firstCredentialKey(array $credentials) + { + foreach ($credentials as $key => $value) { + return $key; + } + } + /** * Validate a user against the given credentials. *
false
Other
laravel
framework
339928401af2b22c4bcec562d4669176b237020f.json
Throw exception on empty collection (#31471)
src/Illuminate/Support/Testing/Fakes/NotificationFake.php
@@ -2,6 +2,7 @@ namespace Illuminate\Support\Testing\Fakes; +use Exception; use Illuminate\Contracts\Notifications\Dispatcher as NotificationDispatcher; use Illuminate\Contracts\Notifications\Factory as NotificationFactory; use Illuminate\Contracts\Translation\HasLocalePreference; @@ -35,10 +36,16 @@ class NotificationFake implements NotificationDispatcher, NotificationFactory * @param string $notification * @param callable|null $callback * @return void + * + * @throws \Exception */ public function assertSentTo($notifiable, $notification, $callback = null) { if (is_array($notifiable) || $notifiable instanceof Collection) { + if (count($notifiable) === 0) { + throw new Exception('No notifiable given.'); + } + foreach ($notifiable as $singleNotifiable) { $this->assertSentTo($singleNotifiable, $notification, $callback); } @@ -79,10 +86,16 @@ public function assertSentToTimes($notifiable, $notification, $times = 1) * @param string $notification * @param callable|null $callback * @return void + * + * @throws \Exception */ public function assertNotSentTo($notifiable, $notification, $callback = null) { if (is_array($notifiable) || $notifiable instanceof Collection) { + if (count($notifiable) === 0) { + throw new Exception('No notifiable given.'); + } + foreach ($notifiable as $singleNotifiable) { $this->assertNotSentTo($singleNotifiable, $notification, $callback); }
true
Other
laravel
framework
339928401af2b22c4bcec562d4669176b237020f.json
Throw exception on empty collection (#31471)
tests/Support/SupportTestingNotificationFakeTest.php
@@ -2,9 +2,11 @@ namespace Illuminate\Tests\Support; +use Exception; use Illuminate\Contracts\Translation\HasLocalePreference; use Illuminate\Foundation\Auth\User; use Illuminate\Notifications\Notification; +use Illuminate\Support\Collection; use Illuminate\Support\Testing\Fakes\NotificationFake; use PHPUnit\Framework\Constraint\ExceptionMessage; use PHPUnit\Framework\ExpectationFailedException; @@ -63,6 +65,20 @@ public function testAssertNotSentTo() } } + public function testAssertSentToFailsForEmptyArray() + { + $this->expectException(Exception::class); + + $this->fake->assertSentTo([], NotificationStub::class); + } + + public function testAssertSentToFailsForEmptyCollection() + { + $this->expectException(Exception::class); + + $this->fake->assertSentTo(new Collection, NotificationStub::class); + } + public function testResettingNotificationId() { $this->fake->send($this->user, $this->notification);
true
Other
laravel
framework
a284f906193c22e0e0a5d827da9fc5f8916e081b.json
Remove addHidden method (#31463)
src/Illuminate/Database/Eloquent/Concerns/HidesAttributes.php
@@ -41,19 +41,6 @@ public function setHidden(array $hidden) return $this; } - /** - * Add hidden attributes for the model. - * - * @param array|string|null $attributes - * @return void - */ - public function addHidden($attributes = null) - { - $this->hidden = array_merge( - $this->hidden, is_array($attributes) ? $attributes : func_get_args() - ); - } - /** * Get the visible attributes for the model. *
false
Other
laravel
framework
4123c8d18807a0b31c8d82a446a46b611875ba28.json
allow afterResponse chain
src/Illuminate/Foundation/Bus/PendingDispatch.php
@@ -13,6 +13,13 @@ class PendingDispatch */ protected $job; + /** + * Indicates if the job should be dispatched immediately after sending the response. + * + * @var bool + */ + protected $afterResponse = false; + /** * Create a new pending job dispatch. * @@ -102,13 +109,29 @@ public function chain($chain) return $this; } + /** + * Indicate that the job should be dispatched after the response is sent to the browser. + * + * @return $this + */ + public function afterResponse() + { + $this->afterResponse = true; + + return $this; + } + /** * Handle the object's destruction. * * @return void */ public function __destruct() { - app(Dispatcher::class)->dispatch($this->job); + if ($this->afterResponse) { + app(Dispatcher::class)->dispatchAfterResponse($this->job); + } else { + app(Dispatcher::class)->dispatch($this->job); + } } }
false
Other
laravel
framework
64804d58f7ce957a0236c834ac6d68c2deb7c13e.json
Remove unused use-statement
tests/Integration/Database/QueryBuilderTest.php
@@ -7,7 +7,6 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; -use Illuminate\Tests\Integration\Database\DatabaseTestCase; /** * @group integration
false
Other
laravel
framework
582c5337b06cd476432e4295356f147174454f13.json
Extract database specific verifier method
src/Illuminate/Validation/Concerns/ValidatesAttributes.php
@@ -671,7 +671,7 @@ public function validateExists($attribute, $value, $parameters) */ protected function getExistCount($connection, $table, $column, $value, $parameters) { - $verifier = $this->getPresenceVerifierFor($connection); + $verifier = $this->getPresenceVerifier($connection); $extra = $this->getExtraConditions( array_values(array_slice($parameters, 2)) @@ -720,7 +720,7 @@ public function validateUnique($attribute, $value, $parameters) // The presence verifier is responsible for counting rows within this store // mechanism which might be a relational database or any other permanent // data store like Redis, etc. We will use it to determine uniqueness. - $verifier = $this->getPresenceVerifierFor($connection); + $verifier = $this->getPresenceVerifier($connection); $extra = $this->getUniqueExtra($parameters);
true
Other
laravel
framework
582c5337b06cd476432e4295356f147174454f13.json
Extract database specific verifier method
src/Illuminate/Validation/DatabasePresenceVerifier.php
@@ -6,7 +6,7 @@ use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Support\Str; -class DatabasePresenceVerifier implements PresenceVerifierInterface +class DatabasePresenceVerifier implements DatabasePresenceVerifierInterface { /** * The database connection instance.
true
Other
laravel
framework
582c5337b06cd476432e4295356f147174454f13.json
Extract database specific verifier method
src/Illuminate/Validation/DatabasePresenceVerifierInterface.php
@@ -0,0 +1,14 @@ +<?php + +namespace Illuminate\Validation; + +interface DatabasePresenceVerifierInterface extends PresenceVerifierInterface +{ + /** + * Set the connection to be used. + * + * @param string $connection + * @return void + */ + public function setConnection($connection); +}
true
Other
laravel
framework
582c5337b06cd476432e4295356f147174454f13.json
Extract database specific verifier method
src/Illuminate/Validation/Validator.php
@@ -1074,34 +1074,24 @@ public function setFallbackMessages(array $messages) /** * Get the Presence Verifier implementation. * + * @param string | NULL $connection * @return \Illuminate\Validation\PresenceVerifierInterface * * @throws \RuntimeException */ - public function getPresenceVerifier() + public function getPresenceVerifier($connection = NULL) { if (! isset($this->presenceVerifier)) { throw new RuntimeException('Presence verifier has not been set.'); } - + + if (! is_null($connection) && !$this->presenceVerifier instanceOf DatabasePresenceVerifierInterface) { + throw new RuntimeException('PresenceVerifier does not support connections'); + } + return $this->presenceVerifier; } - /** - * Get the Presence Verifier implementation. - * - * @param string $connection - * @return \Illuminate\Validation\PresenceVerifierInterface - * - * @throws \RuntimeException - */ - public function getPresenceVerifierFor($connection) - { - return tap($this->getPresenceVerifier(), function ($verifier) use ($connection) { - $verifier->setConnection($connection); - }); - } - /** * Set the Presence Verifier implementation. *
true
Other
laravel
framework
b4df9393bf0185929aa864529798caae740da99a.json
Fix PresenceVerifier contract
src/Illuminate/Validation/DatabasePresenceVerifier.php
@@ -3,8 +3,8 @@ namespace Illuminate\Validation; use Closure; -use Illuminate\Support\Str; use Illuminate\Database\ConnectionResolverInterface; +use Illuminate\Support\Str; class DatabasePresenceVerifier implements PresenceVerifierInterface { @@ -120,7 +120,7 @@ protected function addWhere($query, $key, $extraValue) * @param string $table * @return \Illuminate\Database\Query\Builder */ - public function table($table) + protected function table($table) { return $this->db->connection($this->connection)->table($table)->useWritePdo(); }
true
Other
laravel
framework
b4df9393bf0185929aa864529798caae740da99a.json
Fix PresenceVerifier contract
src/Illuminate/Validation/PresenceVerifierInterface.php
@@ -27,4 +27,12 @@ public function getCount($collection, $column, $value, $excludeId = null, $idCol * @return int */ public function getMultiCount($collection, $column, array $values, array $extra = []); + + /** + * Set the connection to be used. + * + * @param string $connection + * @return void + */ + public function setConnection($connection); }
true
Other
laravel
framework
53f3a817ea90964688948ed144e8bdb686a3662f.json
Fix postgres grammar for nested json arrays.
src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
@@ -380,6 +380,10 @@ protected function wrapJsonBooleanValue($value) protected function wrapJsonPathAttributes($path) { return array_map(function ($attribute) { + if (\strval(\intval($attribute)) === $attribute) { + return $attribute; + } + return "'$attribute'"; }, $path); }
true