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 | 74c9365845225459349b76e759ad64daba1ddf45.json | Remove empty constructor braces. (#36661) | tests/Support/SupportCollectionTest.php | @@ -3580,7 +3580,7 @@ public function testConcatWithCollection($collection)
*/
public function testDump($collection)
{
- $log = new Collection();
+ $log = new Collection;
VarDumper::setHandler(function ($value) use ($log) {
$log->add($value); | true |
Other | laravel | framework | 74c9365845225459349b76e759ad64daba1ddf45.json | Remove empty constructor braces. (#36661) | tests/Support/SupportReflectsClosuresTest.php | @@ -12,7 +12,7 @@ public function testReflectsClosures()
{
$this->assertParameterTypes([ExampleParameter::class], function (ExampleParameter $one) {
// assert the Closure isn't actually executed
- throw new RuntimeException();
+ throw new RuntimeException;
});
$this->assertParameterTypes([], function () { | true |
Other | laravel | framework | 74c9365845225459349b76e759ad64daba1ddf45.json | Remove empty constructor braces. (#36661) | tests/Testing/ParallelConsoleOutputTest.php | @@ -10,7 +10,7 @@ class ParallelConsoleOutputTest extends TestCase
{
public function testWrite()
{
- $original = new BufferedOutput();
+ $original = new BufferedOutput;
$output = new ParallelConsoleOutput($original);
$output->write('Running phpunit in 12 processes with laravel/laravel.'); | true |
Other | laravel | framework | 74c9365845225459349b76e759ad64daba1ddf45.json | Remove empty constructor braces. (#36661) | tests/Testing/TestResponseTest.php | @@ -1241,7 +1241,7 @@ public function testItCanBeTapped()
public function testAssertPlainCookie()
{
$response = TestResponse::fromBaseResponse(
- (new Response())->withCookie(new Cookie('cookie-name', 'cookie-value'))
+ (new Response)->withCookie(new Cookie('cookie-name', 'cookie-value'))
);
$response->assertPlainCookie('cookie-name', 'cookie-value');
@@ -1260,7 +1260,7 @@ public function testAssertCookie()
$encryptedValue = $encrypter->encrypt(CookieValuePrefix::create($cookieName, $encrypter->getKey()).$cookieValue, false);
$response = TestResponse::fromBaseResponse(
- (new Response())->withCookie(new Cookie($cookieName, $encryptedValue))
+ (new Response)->withCookie(new Cookie($cookieName, $encryptedValue))
);
$response->assertCookie($cookieName, $cookieValue);
@@ -1269,7 +1269,7 @@ public function testAssertCookie()
public function testAssertCookieExpired()
{
$response = TestResponse::fromBaseResponse(
- (new Response())->withCookie(new Cookie('cookie-name', 'cookie-value', time() - 5000))
+ (new Response)->withCookie(new Cookie('cookie-name', 'cookie-value', time() - 5000))
);
$response->assertCookieExpired('cookie-name');
@@ -1278,7 +1278,7 @@ public function testAssertCookieExpired()
public function testAssertSessionCookieExpiredDoesNotTriggerOnSessionCookies()
{
$response = TestResponse::fromBaseResponse(
- (new Response())->withCookie(new Cookie('cookie-name', 'cookie-value', 0))
+ (new Response)->withCookie(new Cookie('cookie-name', 'cookie-value', 0))
);
$this->expectException(ExpectationFailedException::class);
@@ -1289,7 +1289,7 @@ public function testAssertSessionCookieExpiredDoesNotTriggerOnSessionCookies()
public function testAssertCookieNotExpired()
{
$response = TestResponse::fromBaseResponse(
- (new Response())->withCookie(new Cookie('cookie-name', 'cookie-value', time() + 5000))
+ (new Response)->withCookie(new Cookie('cookie-name', 'cookie-value', time() + 5000))
);
$response->assertCookieNotExpired('cookie-name');
@@ -1298,15 +1298,15 @@ public function testAssertCookieNotExpired()
public function testAssertSessionCookieNotExpired()
{
$response = TestResponse::fromBaseResponse(
- (new Response())->withCookie(new Cookie('cookie-name', 'cookie-value', 0))
+ (new Response)->withCookie(new Cookie('cookie-name', 'cookie-value', 0))
);
$response->assertCookieNotExpired('cookie-name');
}
public function testAssertCookieMissing()
{
- $response = TestResponse::fromBaseResponse(new Response());
+ $response = TestResponse::fromBaseResponse(new Response);
$response->assertCookieMissing('cookie-name');
} | true |
Other | laravel | framework | 74c9365845225459349b76e759ad64daba1ddf45.json | Remove empty constructor braces. (#36661) | tests/Validation/ValidationValidatorTest.php | @@ -2634,7 +2634,7 @@ public function testValidateEmailWithFilterUnicodeCheck()
public function testValidateEmailWithCustomClassCheck()
{
$container = m::mock(Container::class);
- $container->shouldReceive('make')->with(NoRFCWarningsValidation::class)->andReturn(new NoRFCWarningsValidation());
+ $container->shouldReceive('make')->with(NoRFCWarningsValidation::class)->andReturn(new NoRFCWarningsValidation);
$v = new Validator($this->getIlluminateArrayTranslator(), ['x' => 'foo@bar '], ['x' => 'email:'.NoRFCWarningsValidation::class]);
$v->setContainer($container); | true |
Other | laravel | framework | 74c9365845225459349b76e759ad64daba1ddf45.json | Remove empty constructor braces. (#36661) | tests/View/ComponentTest.php | @@ -52,7 +52,7 @@ public function testInlineViewsGetCreated()
$this->viewFactory->shouldReceive('exists')->once()->andReturn(false);
$this->viewFactory->shouldReceive('addNamespace')->once()->with('__components', '/tmp');
- $component = new TestInlineViewComponent();
+ $component = new TestInlineViewComponent;
$this->assertSame('__components::c6327913fef3fca4518bcd7df1d0ff630758e241', $component->resolveView());
}
@@ -61,7 +61,7 @@ public function testRegularViewsGetReturned()
$view = m::mock(View::class);
$this->viewFactory->shouldReceive('make')->once()->with('alert', [], [])->andReturn($view);
- $component = new TestRegularViewComponent();
+ $component = new TestRegularViewComponent;
$this->assertSame($view, $component->resolveView());
}
@@ -71,14 +71,14 @@ public function testRegularViewNamesGetReturned()
$this->viewFactory->shouldReceive('exists')->once()->andReturn(true);
$this->viewFactory->shouldReceive('addNamespace')->never();
- $component = new TestRegularViewNameViewComponent();
+ $component = new TestRegularViewNameViewComponent;
$this->assertSame('alert', $component->resolveView());
}
public function testHtmlablesGetReturned()
{
- $component = new TestHtmlableReturningViewComponent();
+ $component = new TestHtmlableReturningViewComponent;
$view = $component->resolveView();
| true |
Other | laravel | framework | 74c9365845225459349b76e759ad64daba1ddf45.json | Remove empty constructor braces. (#36661) | tests/View/ViewComponentTest.php | @@ -62,7 +62,7 @@ public function testPublicMethodsWithNoArgsAreConvertedToStringableCallablesInvo
public function testItIgnoresExceptedMethodsAndProperties()
{
- $component = new TestExceptedViewComponent();
+ $component = new TestExceptedViewComponent;
$variables = $component->data();
// Ignored methods (with no args) are not invoked behind the scenes.
@@ -75,7 +75,7 @@ public function testItIgnoresExceptedMethodsAndProperties()
public function testMethodsOverridePropertyValues()
{
- $component = new TestHelloPropertyHelloMethodComponent();
+ $component = new TestHelloPropertyHelloMethodComponent;
$variables = $component->data();
$this->assertArrayHasKey('hello', $variables);
$this->assertSame('world', $variables['hello']()); | true |
Other | laravel | framework | 5390126e81d67368c543cbf2660b788e2faad731.json | Apply fixes from StyleCI (#36646) | src/Illuminate/Support/Str.php | @@ -2,7 +2,6 @@
namespace Illuminate\Support;
-use Illuminate\Support\Arr;
use Illuminate\Support\Traits\Macroable;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use Ramsey\Uuid\Codec\TimestampFirstCombCodec; | true |
Other | laravel | framework | 5390126e81d67368c543cbf2660b788e2faad731.json | Apply fixes from StyleCI (#36646) | tests/Support/SupportStrTest.php | @@ -367,16 +367,16 @@ public function testReplaceLast()
public function testRemove()
{
- $this->assertSame("Fbar", Str::remove('o', 'Foobar'));
- $this->assertSame("Foo", Str::remove('bar', 'Foobar'));
- $this->assertSame("oobar", Str::remove('F', 'Foobar'));
- $this->assertSame("Foobar", Str::remove('f', 'Foobar'));
- $this->assertSame("oobar", Str::remove('f', 'Foobar', false));
-
- $this->assertSame("Fbr", Str::remove(["o", "a"], 'Foobar'));
- $this->assertSame("Fooar", Str::remove(["f", "b"], 'Foobar'));
- $this->assertSame("ooar", Str::remove(["f", "b"], 'Foobar', false));
- $this->assertSame("Foobar", Str::remove(["f", "|"], 'Foo|bar'));
+ $this->assertSame('Fbar', Str::remove('o', 'Foobar'));
+ $this->assertSame('Foo', Str::remove('bar', 'Foobar'));
+ $this->assertSame('oobar', Str::remove('F', 'Foobar'));
+ $this->assertSame('Foobar', Str::remove('f', 'Foobar'));
+ $this->assertSame('oobar', Str::remove('f', 'Foobar', false));
+
+ $this->assertSame('Fbr', Str::remove(['o', 'a'], 'Foobar'));
+ $this->assertSame('Fooar', Str::remove(['f', 'b'], 'Foobar'));
+ $this->assertSame('ooar', Str::remove(['f', 'b'], 'Foobar', false));
+ $this->assertSame('Foobar', Str::remove(['f', '|'], 'Foo|bar'));
}
public function testSnake() | true |
Other | laravel | framework | 5390126e81d67368c543cbf2660b788e2faad731.json | Apply fixes from StyleCI (#36646) | tests/Support/SupportStringableTest.php | @@ -3,7 +3,6 @@
namespace Illuminate\Tests\Support;
use Illuminate\Support\Collection;
-use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
use PHPUnit\Framework\TestCase;
@@ -455,16 +454,16 @@ public function testReplaceLast()
public function testRemove()
{
- $this->assertSame("Fbar", (string) $this->stringable('Foobar')->remove('o'));
- $this->assertSame("Foo", (string) $this->stringable('Foobar')->remove('bar'));
- $this->assertSame("oobar", (string) $this->stringable('Foobar')->remove('F'));
- $this->assertSame("Foobar", (string) $this->stringable('Foobar')->remove('f'));
- $this->assertSame("oobar", (string) $this->stringable('Foobar')->remove('f', false));
+ $this->assertSame('Fbar', (string) $this->stringable('Foobar')->remove('o'));
+ $this->assertSame('Foo', (string) $this->stringable('Foobar')->remove('bar'));
+ $this->assertSame('oobar', (string) $this->stringable('Foobar')->remove('F'));
+ $this->assertSame('Foobar', (string) $this->stringable('Foobar')->remove('f'));
+ $this->assertSame('oobar', (string) $this->stringable('Foobar')->remove('f', false));
- $this->assertSame("Fbr", (string) $this->stringable('Foobar')->remove(["o", "a"]));
- $this->assertSame("Fooar", (string) $this->stringable('Foobar')->remove(["f", "b"]));
- $this->assertSame("ooar", (string) $this->stringable('Foobar')->remove(["f", "b"], false));
- $this->assertSame("Foobar", (string) $this->stringable('Foo|bar')->remove(["f", "|"]));
+ $this->assertSame('Fbr', (string) $this->stringable('Foobar')->remove(['o', 'a']));
+ $this->assertSame('Fooar', (string) $this->stringable('Foobar')->remove(['f', 'b']));
+ $this->assertSame('ooar', (string) $this->stringable('Foobar')->remove(['f', 'b'], false));
+ $this->assertSame('Foobar', (string) $this->stringable('Foo|bar')->remove(['f', '|']));
}
public function testSnake() | true |
Other | laravel | framework | 18b1b8946cc71cc074ea2733ff2054fb21d1dcb5.json | Adjust event facade comment for ide hint (#36641)
Co-authored-by: Nolin <nolin.chang@interpay.com.tw> | src/Illuminate/Support/Facades/Event.php | @@ -19,7 +19,7 @@
* @method static void flush(string $event)
* @method static void forget(string $event)
* @method static void forgetPushed()
- * @method static void listen(string|array $events, \Closure|string $listener = null)
+ * @method static void listen(\Closure|string|array $events, \Closure|string $listener = null)
* @method static void push(string $event, array $payload = [])
* @method static void subscribe(object|string $subscriber)
* | false |
Other | laravel | framework | fe48f2cff966e1193aab240ffb4c90072aed89e6.json | Fix description (#36642) | src/Illuminate/Queue/Middleware/ThrottlesExceptions.php | @@ -135,7 +135,7 @@ public function withPrefix(string $prefix)
}
/**
- * Specify the number of seconds a job should be delayed when it is released (before it has reached its max exceptions).
+ * Specify the number of minutes a job should be delayed when it is released (before it has reached its max exceptions).
*
* @param int $backoff
* @return $this | false |
Other | laravel | framework | 92b7bdeb4b8c40848fa276cfe1897c656302942f.json | add more quotes | src/Illuminate/Foundation/Inspiring.php | @@ -45,6 +45,11 @@ public static function quote()
'Waste no more time arguing what a good man should be, be one. - Marcus Aurelius',
'Well begun is half done. - Aristotle',
'When there is no desire, all things are at peace. - Laozi',
+ 'Walk as if you are kissing the Earth with your feet. - Thich Nhat Hanh',
+ 'Because you are alive, everything is possible. - Thich Nhat Hanh',
+ 'Breathing in, I calm body and mind. Breathing out, I smile. - Thich Nhat Hanh',
+ 'Life is available only in the present moment. - Thich Nhat Hanh',
+ 'The best way to take care of the future is to take care of the present moment. - Thich Nhat Hanh',
])->random();
}
} | false |
Other | laravel | framework | ebfa75fee5acef028a09f52a78a7069b1a09a723.json | Apply fixes from StyleCI (#36615) | src/Illuminate/Auth/SessionGuard.php | @@ -615,7 +615,7 @@ public function logoutOtherDevices($password, $attribute = 'password')
protected function rehashUserPassword($password, $attribute)
{
if (! Hash::check($password, $this->user()->{$attribute})) {
- throw new InvalidArgumentException("The given password does not match the current password.");
+ throw new InvalidArgumentException('The given password does not match the current password.');
}
return tap($this->user()->forceFill([ | false |
Other | laravel | framework | 7aabd8f0a8f8e0a3420359f807f42ceacb5c4140.json | Use FQN in docblock, remove description | src/Illuminate/Auth/SessionGuard.php | @@ -580,7 +580,7 @@ protected function cycleRememberToken(AuthenticatableContract $user)
* @param string $attribute
* @return bool|null
*
- * @throws AuthenticationException If the password is invalid.
+ * @throws \Illuminate\Auth\AuthenticationException
*/
protected function rehashUserPassword($password, $attribute)
{
@@ -602,7 +602,7 @@ protected function rehashUserPassword($password, $attribute)
* @param string $attribute
* @return bool|null
*
- * @throws AuthenticationException If the password is invalid.
+ * @throws \Illuminate\Auth\AuthenticationException
*/
public function logoutOtherDevices($password, $attribute = 'password')
{ | false |
Other | laravel | framework | ef4541d51a805eb711e14af897515aa7b2ed3569.json | Add @throws to logoutOtherDevices() | src/Illuminate/Auth/SessionGuard.php | @@ -601,6 +601,8 @@ protected function rehashUserPassword($password, $attribute)
* @param string $password
* @param string $attribute
* @return bool|null
+ *
+ * @throws AuthenticationException If the password is invalid.
*/
public function logoutOtherDevices($password, $attribute = 'password')
{ | false |
Other | laravel | framework | 580fb32724e9dfbeade884dcd91721f4f47b44b5.json | Require the correct password to rehash it | src/Illuminate/Auth/SessionGuard.php | @@ -573,6 +573,26 @@ protected function cycleRememberToken(AuthenticatableContract $user)
$this->provider->updateRememberToken($user, $token);
}
+ /**
+ * Rehash the user's password.
+ *
+ * @param string $password
+ * @param string $attribute
+ * @return bool|null
+ *
+ * @throws AuthenticationException If the password is invalid.
+ */
+ protected function rehashUserPassword($password, $attribute)
+ {
+ if (! Hash::check($password, $this->user()->$attribute)) {
+ throw new AuthenticationException('Password mismatch.');
+ }
+
+ return tap($this->user()->forceFill([
+ $attribute => Hash::make($password),
+ ]))->save();
+ }
+
/**
* Invalidate other sessions for the current user.
*
@@ -588,9 +608,7 @@ public function logoutOtherDevices($password, $attribute = 'password')
return;
}
- $result = tap($this->user()->forceFill([
- $attribute => Hash::make($password),
- ]))->save();
+ $result = $this->rehashUserPassword($password, $attribute);
if ($this->recaller() ||
$this->getCookieJar()->hasQueued($this->getRecallerName())) { | true |
Other | laravel | framework | 580fb32724e9dfbeade884dcd91721f4f47b44b5.json | Require the correct password to rehash it | tests/Integration/Auth/AuthenticationTest.php | @@ -2,6 +2,7 @@
namespace Illuminate\Tests\Integration\Auth;
+use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Auth\Events\Attempting;
use Illuminate\Auth\Events\Authenticated;
@@ -211,7 +212,7 @@ public function testLoggingOutOtherDevices()
$this->assertEquals(1, $user->id);
- $this->app['auth']->logoutOtherDevices('adifferentpassword');
+ $this->app['auth']->logoutOtherDevices('password');
$this->assertEquals(1, $user->id);
Event::assertDispatched(OtherDeviceLogout::class, function ($event) {
@@ -222,6 +223,20 @@ public function testLoggingOutOtherDevices()
});
}
+ public function testPasswordMustBeValidToLogOutOtherDevices()
+ {
+ $this->expectException(AuthenticationException::class);
+ $this->expectExceptionMessage('Password mismatch.');
+
+ $this->app['auth']->loginUsingId(1);
+
+ $user = $this->app['auth']->user();
+
+ $this->assertEquals(1, $user->id);
+
+ $this->app['auth']->logoutOtherDevices('adifferentpassword');
+ }
+
public function testLoggingInOutViaAttemptRemembering()
{
$this->assertTrue( | true |
Other | laravel | framework | c02e3250c3a933b08656ac4c84168353eba771a8.json | Apply fixes from StyleCI (#36603) | src/Illuminate/Log/LogManager.php | @@ -244,7 +244,7 @@ protected function createStackDriver(array $config)
$handlers = collect($config['channels'])->flatMap(function ($channel) {
return $this->channel($channel)->getHandlers();
})->all();
-
+
$processors = collect($config['channels'])->flatMap(function ($channel) {
return $this->channel($channel)->getProcessors();
})->all(); | false |
Other | laravel | framework | c67a685598de8e12e7fcf03095ac168f85122c4e.json | Update docblock (#36592) | src/Illuminate/Foundation/Console/stubs/view-component.stub | @@ -19,7 +19,7 @@ class DummyClass extends Component
/**
* Get the view / contents that represent the component.
*
- * @return \Illuminate\Contracts\View\View|string
+ * @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{ | false |
Other | laravel | framework | e0c638167c5e6911d6fc579bc4e04b66f6a94784.json | Remove null from return in phpdoc (#36593) | src/Illuminate/Support/Stringable.php | @@ -335,7 +335,7 @@ public function markdown(array $options = [])
* Get the string matching the given pattern.
*
* @param string $pattern
- * @return static|null
+ * @return static
*/
public function match($pattern)
{ | false |
Other | laravel | framework | e9e91b0d88115c7a968beadd8a12af5114216f51.json | Add Faker as dev dependency (#36586) | composer.json | @@ -80,6 +80,7 @@
"require-dev": {
"aws/aws-sdk-php": "^3.155",
"doctrine/dbal": "^2.12|^3.0",
+ "fakerphp/faker": "^1.9.2",
"filp/whoops": "^2.8",
"guzzlehttp/guzzle": "^7.2",
"league/flysystem-aws-s3-v3": "^2.0", | false |
Other | laravel | framework | 6d1da017689c004efece0bde8c3790202c359a31.json | Apply fixes from StyleCI (#36577) | tests/Routing/RouteRegistrarTest.php | @@ -338,7 +338,9 @@ public function testCanRegisterResourceWithMissingOption()
{
$this->router->middleware('resource-middleware')
->resource('users', RouteRegistrarControllerStub::class)
- ->missing(function () { return 'missing'; });
+ ->missing(function () {
+ return 'missing';
+ });
$this->assertIsCallable($this->router->getRoutes()->getByName('users.show')->getMissing());
$this->assertIsCallable($this->router->getRoutes()->getByName('users.edit')->getMissing()); | false |
Other | laravel | framework | c887875c23f393e3443b1fd2a8dd0c748e6f13ea.json | Add resource missing option | src/Illuminate/Routing/ResourceRegistrar.php | @@ -20,13 +20,6 @@ class ResourceRegistrar
*/
protected $resourceDefaults = ['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'];
- /**
- * Actions that use model binding.
- *
- * @var string[]
- */
- protected $modelBoundMethods = ['show', 'edit', 'update', 'destroy'];
-
/**
* The parameters set for this resource instance.
*
@@ -191,6 +184,8 @@ protected function addResourceIndex($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name);
+ unset($options['missing']);
+
$action = $this->getResourceAction($name, $controller, 'index', $options);
return $this->router->get($uri, $action);
@@ -209,6 +204,8 @@ protected function addResourceCreate($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name).'/'.static::$verbs['create'];
+ unset($options['missing']);
+
$action = $this->getResourceAction($name, $controller, 'create', $options);
return $this->router->get($uri, $action);
@@ -227,6 +224,8 @@ protected function addResourceStore($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name);
+ unset($options['missing']);
+
$action = $this->getResourceAction($name, $controller, 'store', $options);
return $this->router->post($uri, $action);
@@ -428,7 +427,7 @@ protected function getResourceAction($resource, $controller, $method, $options)
$action['where'] = $options['wheres'];
}
- if (isset($options['missing']) && in_array($method, $this->modelBoundMethods)) {
+ if (isset($options['missing'])) {
$action['missing'] = $options['missing'];
}
| false |
Other | laravel | framework | 62925b64310bb796dff479aea4acc55a1620d470.json | Add resource missing option | src/Illuminate/Routing/PendingResourceRegistration.php | @@ -195,6 +195,19 @@ public function shallow($shallow = true)
return $this;
}
+ /**
+ * Define the callable that should be invoked on a missing model exception.
+ *
+ * @param $callback
+ * @return $this
+ */
+ public function missing($callback)
+ {
+ $this->options['missing'] = $callback;
+
+ return $this;
+ }
+
/**
* Indicate that the resource routes should be scoped using the given binding fields.
* | true |
Other | laravel | framework | 62925b64310bb796dff479aea4acc55a1620d470.json | Add resource missing option | src/Illuminate/Routing/ResourceRegistrar.php | @@ -20,6 +20,13 @@ class ResourceRegistrar
*/
protected $resourceDefaults = ['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'];
+ /**
+ * Actions that use model binding.
+ *
+ * @var string[]
+ */
+ protected $modelBoundMethods = ['show', 'edit', 'update', 'destroy'];
+
/**
* The parameters set for this resource instance.
*
@@ -421,6 +428,10 @@ protected function getResourceAction($resource, $controller, $method, $options)
$action['where'] = $options['wheres'];
}
+ if (isset($options['missing']) && in_array($method, $this->modelBoundMethods)) {
+ $action['missing'] = $options['missing'];
+ }
+
return $action;
}
| true |
Other | laravel | framework | 62925b64310bb796dff479aea4acc55a1620d470.json | Add resource missing option | tests/Routing/RouteRegistrarTest.php | @@ -334,6 +334,22 @@ public function testCanRegisterResourcesWithoutOption()
}
}
+ public function testCanRegisterResourceWithMissingOption()
+ {
+ $this->router->middleware('resource-middleware')
+ ->resource('users', RouteRegistrarControllerStub::class)
+ ->missing(function () { return 'missing'; });
+
+ $this->assertIsCallable($this->router->getRoutes()->getByName('users.show')->getMissing());
+ $this->assertIsCallable($this->router->getRoutes()->getByName('users.edit')->getMissing());
+ $this->assertIsCallable($this->router->getRoutes()->getByName('users.update')->getMissing());
+ $this->assertIsCallable($this->router->getRoutes()->getByName('users.destroy')->getMissing());
+
+ $this->assertNull($this->router->getRoutes()->getByName('users.index')->getMissing());
+ $this->assertNull($this->router->getRoutes()->getByName('users.create')->getMissing());
+ $this->assertNull($this->router->getRoutes()->getByName('users.store')->getMissing());
+ }
+
public function testCanAccessRegisteredResourceRoutesAsRouteCollection()
{
$resource = $this->router->middleware('resource-middleware') | true |
Other | laravel | framework | 2d304d4e5dc49c5f80e0ee77cf44d08e8d94325d.json | Consolidate empty function bodies (#36560) | src/Illuminate/Events/NullDispatcher.php | @@ -37,6 +37,7 @@ public function __construct(DispatcherContract $dispatcher)
*/
public function dispatch($event, $payload = [], $halt = false)
{
+ //
}
/**
@@ -48,6 +49,7 @@ public function dispatch($event, $payload = [], $halt = false)
*/
public function push($event, $payload = [])
{
+ //
}
/**
@@ -59,6 +61,7 @@ public function push($event, $payload = [])
*/
public function until($event, $payload = [])
{
+ //
}
/** | true |
Other | laravel | framework | 2d304d4e5dc49c5f80e0ee77cf44d08e8d94325d.json | Consolidate empty function bodies (#36560) | src/Illuminate/Support/Testing/Fakes/BatchRepositoryFake.php | @@ -33,6 +33,7 @@ public function get($limit, $before)
*/
public function find(string $batchId)
{
+ //
}
/**
@@ -68,6 +69,7 @@ public function store(PendingBatch $batch)
*/
public function incrementTotalJobs(string $batchId, int $amount)
{
+ //
}
/**
@@ -102,6 +104,7 @@ public function incrementFailedJobs(string $batchId, string $jobId)
*/
public function markAsFinished(string $batchId)
{
+ //
}
/**
@@ -112,6 +115,7 @@ public function markAsFinished(string $batchId)
*/
public function cancel(string $batchId)
{
+ //
}
/**
@@ -122,6 +126,7 @@ public function cancel(string $batchId)
*/
public function delete(string $batchId)
{
+ //
}
/** | true |
Other | laravel | framework | 2d304d4e5dc49c5f80e0ee77cf44d08e8d94325d.json | Consolidate empty function bodies (#36560) | src/Illuminate/Support/Testing/Fakes/BusFake.php | @@ -517,6 +517,7 @@ public function chain($jobs)
*/
public function findBatch(string $batchId)
{
+ //
}
/** | true |
Other | laravel | framework | 2d304d4e5dc49c5f80e0ee77cf44d08e8d94325d.json | Consolidate empty function bodies (#36560) | tests/Container/ContainerTest.php | @@ -577,20 +577,23 @@ class CircularAStub
{
public function __construct(CircularBStub $b)
{
+ //
}
}
class CircularBStub
{
public function __construct(CircularCStub $c)
{
+ //
}
}
class CircularCStub
{
public function __construct(CircularAStub $a)
{
+ //
}
}
| true |
Other | laravel | framework | 2d304d4e5dc49c5f80e0ee77cf44d08e8d94325d.json | Consolidate empty function bodies (#36560) | tests/Integration/Queue/CustomPayloadTest.php | @@ -60,5 +60,6 @@ class MyJob implements ShouldQueue
public function handle()
{
+ //
}
} | true |
Other | laravel | framework | 2d304d4e5dc49c5f80e0ee77cf44d08e8d94325d.json | Consolidate empty function bodies (#36560) | tests/Support/SupportReflectorTest.php | @@ -81,6 +81,7 @@ class B extends A
{
public function f(parent $x)
{
+ //
}
}
@@ -92,6 +93,7 @@ class C
{
public function f(A|Model $x)
{
+ //
}
}'
);
@@ -101,12 +103,14 @@ class TestClassWithCall
{
public function __call($method, $parameters)
{
+ //
}
}
class TestClassWithCallStatic
{
public static function __callStatic($method, $parameters)
{
+ //
}
} | true |
Other | laravel | framework | d5cd4b3ee7e4db527c5a089af78183e6742afeb5.json | Add test for stack prepend (#36555) | tests/View/ViewFactoryTest.php | @@ -443,6 +443,27 @@ public function testMultipleStackPush()
$this->assertSame('hi, Hello!', $factory->yieldPushContent('foo'));
}
+ public function testSingleStackPrepend()
+ {
+ $factory = $this->getFactory();
+ $factory->startPrepend('foo');
+ echo 'hi';
+ $factory->stopPrepend();
+ $this->assertSame('hi', $factory->yieldPushContent('foo'));
+ }
+
+ public function testMultipleStackPrepend()
+ {
+ $factory = $this->getFactory();
+ $factory->startPrepend('foo');
+ echo ', Hello!';
+ $factory->stopPrepend();
+ $factory->startPrepend('foo');
+ echo 'hi';
+ $factory->stopPrepend();
+ $this->assertSame('hi, Hello!', $factory->yieldPushContent('foo'));
+ }
+
public function testSessionAppending()
{
$factory = $this->getFactory(); | false |
Other | laravel | framework | 71265318358ee150fe8b13f68a03cb9f869fb483.json | Apply fixes from StyleCI (#36553) | tests/Container/ContainerTest.php | @@ -564,29 +564,33 @@ public function testContainerCanResolveClasses()
$this->assertInstanceOf(ContainerConcreteStub::class, $class);
}
- public function testContainerCanCatchCircularDependency() {
+ public function testContainerCanCatchCircularDependency()
+ {
$this->expectException(CircularDependencyException::class);
$container = new Container;
$container->get(CircularAStub::class);
}
}
-class CircularAStub {
- public function __construct(CircularBStub $b) {
-
+class CircularAStub
+{
+ public function __construct(CircularBStub $b)
+ {
}
}
-class CircularBStub {
- public function __construct(CircularCStub $c) {
-
+class CircularBStub
+{
+ public function __construct(CircularCStub $c)
+ {
}
}
-class CircularCStub {
- public function __construct(CircularAStub $a) {
-
+class CircularCStub
+{
+ public function __construct(CircularAStub $a)
+ {
}
}
| false |
Other | laravel | framework | 0443f1c42c20f6a30d0d81050bc43e94c9c51145.json | Add class argument (#36513) | src/Illuminate/Database/Console/Seeds/SeedCommand.php | @@ -6,6 +6,7 @@
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Database\ConnectionResolverInterface as Resolver;
use Illuminate\Database\Eloquent\Model;
+use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class SeedCommand extends Command
@@ -81,7 +82,7 @@ public function handle()
*/
protected function getSeeder()
{
- $class = $this->input->getOption('class');
+ $class = $this->input->getArgument('class') ?? $this->input->getOption('class');
if (strpos($class, '\\') === false) {
$class = 'Database\\Seeders\\'.$class;
@@ -109,6 +110,18 @@ protected function getDatabase()
return $database ?: $this->laravel['config']['database.default'];
}
+ /**
+ * Get the console command arguments.
+ *
+ * @return array
+ */
+ protected function getArguments()
+ {
+ return [
+ ['class', InputArgument::OPTIONAL, 'The class name of the root seeder', null],
+ ];
+ }
+
/**
* Get the console command options.
* | false |
Other | laravel | framework | 35071ab6ec3c906c0f26d153e743770e8df86079.json | Add ThrottlesExceptionsWithRedis job middleware | src/Illuminate/Queue/Middleware/ThrottlesExceptionsWithRedis.php | @@ -0,0 +1,62 @@
+<?php
+
+namespace Illuminate\Queue\Middleware;
+
+use Illuminate\Container\Container;
+use Illuminate\Contracts\Redis\Factory as Redis;
+use Illuminate\Redis\Limiters\DurationLimiter;
+use Illuminate\Support\InteractsWithTime;
+use Throwable;
+
+class ThrottlesExceptionsWithRedis extends ThrottlesExceptions
+{
+ use InteractsWithTime;
+
+ /**
+ * The Redis factory implementation.
+ *
+ * @var \Illuminate\Contracts\Redis\Factory
+ */
+ protected $redis;
+
+ /**
+ * The rate limiter instance.
+ *
+ * @var \Illuminate\Redis\Limiters\DurationLimiter
+ */
+ protected $limiter;
+
+ /**
+ * Process the job.
+ *
+ * @param mixed $job
+ * @param callable $next
+ * @return mixed
+ */
+ public function handle($job, $next)
+ {
+ $this->redis = Container::getInstance()->make(Redis::class);
+
+ $this->limiter = new DurationLimiter(
+ $this->redis, $this->getKey($job), $this->maxAttempts, $this->decayMinutes * 60
+ );
+
+ if ($this->limiter->tooManyAttempts()) {
+ return $job->release($this->limiter->decaysAt - $this->currentTime());
+ }
+
+ try {
+ $next($job);
+
+ $this->limiter->clear();
+ } catch (Throwable $throwable) {
+ if ($this->whenCallback && ! call_user_func($this->whenCallback, $throwable)) {
+ throw $throwable;
+ }
+
+ $this->limiter->acquire();
+
+ return $job->release($this->retryAfterMinutes * 60);
+ }
+ }
+} | true |
Other | laravel | framework | 35071ab6ec3c906c0f26d153e743770e8df86079.json | Add ThrottlesExceptionsWithRedis job middleware | src/Illuminate/Redis/Limiters/DurationLimiter.php | @@ -111,6 +111,30 @@ public function acquire()
return (bool) $results[0];
}
+ /**
+ * Determine if the key has been "accessed" too many times.
+ *
+ * @return bool
+ */
+ public function tooManyAttempts()
+ {
+ [$this->decaysAt, $this->remaining] = $this->redis->eval(
+ $this->tooManyAttemptsScript(), 1, $this->name, microtime(true), time(), $this->decay, $this->maxLocks
+ );
+
+ return $this->remaining <= 0;
+ }
+
+ /**
+ * Clear the limiter.
+ *
+ * @return void
+ */
+ public function clear()
+ {
+ $this->redis->del($this->name);
+ }
+
/**
* Get the Lua script for acquiring a lock.
*
@@ -143,6 +167,36 @@ protected function luaScript()
end
return {reset(), ARGV[2] + ARGV[3], ARGV[4] - 1}
+LUA;
+ }
+
+ /**
+ * Get the Lua script to determine if the key has been "accessed" too many times.
+ *
+ * KEYS[1] - The limiter name
+ * ARGV[1] - Current time in microseconds
+ * ARGV[2] - Current time in seconds
+ * ARGV[3] - Duration of the bucket
+ * ARGV[4] - Allowed number of tasks
+ *
+ * @return string
+ */
+ protected function tooManyAttemptsScript()
+ {
+ return <<<'LUA'
+
+if redis.call('EXISTS', KEYS[1]) == 0 then
+ return {0, ARGV[2] + ARGV[3]}
+end
+
+if ARGV[1] >= redis.call('HGET', KEYS[1], 'start') and ARGV[1] <= redis.call('HGET', KEYS[1], 'end') then
+ return {
+ redis.call('HGET', KEYS[1], 'end'),
+ ARGV[4] - redis.call('HGET', KEYS[1], 'count')
+ }
+end
+
+return {0, ARGV[2] + ARGV[3]}
LUA;
}
} | true |
Other | laravel | framework | 35071ab6ec3c906c0f26d153e743770e8df86079.json | Add ThrottlesExceptionsWithRedis job middleware | tests/Integration/Queue/ThrottlesExceptionsWithRedisTest.php | @@ -0,0 +1,167 @@
+<?php
+
+namespace Illuminate\Tests\Integration\Queue;
+
+use Exception;
+use Illuminate\Bus\Dispatcher;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\Job;
+use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
+use Illuminate\Queue\CallQueuedHandler;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\Middleware\ThrottlesExceptionsWithRedis;
+use Illuminate\Support\Str;
+use Mockery as m;
+use Orchestra\Testbench\TestCase;
+
+/**
+ * @group integration
+ */
+class ThrottlesExceptionsWithRedisTest extends TestCase
+{
+ use InteractsWithRedis;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->setUpRedis();
+ }
+
+ protected function tearDown(): void
+ {
+ parent::tearDown();
+
+ $this->tearDownRedis();
+
+ m::close();
+ }
+
+ public function testCircuitIsOpenedForJobErrors()
+ {
+ $this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key = Str::random());
+ $this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key);
+ $this->assertJobWasReleasedWithDelay(CircuitBreakerWithRedisTestJob::class, $key);
+ }
+
+ public function testCircuitStaysClosedForSuccessfulJobs()
+ {
+ $this->assertJobRanSuccessfully(CircuitBreakerWithRedisSuccessfulJob::class, $key = Str::random());
+ $this->assertJobRanSuccessfully(CircuitBreakerWithRedisSuccessfulJob::class, $key);
+ $this->assertJobRanSuccessfully(CircuitBreakerWithRedisSuccessfulJob::class, $key);
+ }
+
+ public function testCircuitResetsAfterSuccess()
+ {
+ $this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key = Str::random());
+ $this->assertJobRanSuccessfully(CircuitBreakerWithRedisSuccessfulJob::class, $key);
+ $this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key);
+ $this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key);
+ $this->assertJobWasReleasedWithDelay(CircuitBreakerWithRedisTestJob::class, $key);
+ }
+
+ protected function assertJobWasReleasedImmediately($class, $key)
+ {
+ $class::$handled = false;
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
+
+ $job = m::mock(Job::class);
+
+ $job->shouldReceive('hasFailed')->once()->andReturn(false);
+ $job->shouldReceive('release')->with(0)->once();
+ $job->shouldReceive('isReleased')->andReturn(true);
+ $job->shouldReceive('isDeletedOrReleased')->once()->andReturn(true);
+
+ $instance->call($job, [
+ 'command' => serialize($command = new $class($key)),
+ ]);
+
+ $this->assertTrue($class::$handled);
+ }
+
+ protected function assertJobWasReleasedWithDelay($class, $key)
+ {
+ $class::$handled = false;
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
+
+ $job = m::mock(Job::class);
+
+ $job->shouldReceive('hasFailed')->once()->andReturn(false);
+ $job->shouldReceive('release')->withArgs(function ($delay) {
+ return $delay >= 600;
+ })->once();
+ $job->shouldReceive('isReleased')->andReturn(true);
+ $job->shouldReceive('isDeletedOrReleased')->once()->andReturn(true);
+
+ $instance->call($job, [
+ 'command' => serialize($command = new $class($key)),
+ ]);
+
+ $this->assertFalse($class::$handled);
+ }
+
+ protected function assertJobRanSuccessfully($class, $key)
+ {
+ $class::$handled = false;
+ $instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);
+
+ $job = m::mock(Job::class);
+
+ $job->shouldReceive('hasFailed')->once()->andReturn(false);
+ $job->shouldReceive('isReleased')->andReturn(false);
+ $job->shouldReceive('isDeletedOrReleased')->once()->andReturn(false);
+ $job->shouldReceive('delete')->once();
+
+ $instance->call($job, [
+ 'command' => serialize($command = new $class($key)),
+ ]);
+
+ $this->assertTrue($class::$handled);
+ }
+}
+
+class CircuitBreakerWithRedisTestJob
+{
+ use InteractsWithQueue, Queueable;
+
+ public static $handled = false;
+
+ public function __construct($key)
+ {
+ $this->key = $key;
+ }
+
+ public function handle()
+ {
+ static::$handled = true;
+
+ throw new Exception;
+ }
+
+ public function middleware()
+ {
+ return [new ThrottlesExceptionsWithRedis(2, 10, 0, $this->key)];
+ }
+}
+
+class CircuitBreakerWithRedisSuccessfulJob
+{
+ use InteractsWithQueue, Queueable;
+
+ public static $handled = false;
+
+ public function __construct($key)
+ {
+ $this->key = $key;
+ }
+
+ public function handle()
+ {
+ static::$handled = true;
+ }
+
+ public function middleware()
+ {
+ return [new ThrottlesExceptionsWithRedis(2, 10, 0, $this->key)];
+ }
+} | true |
Other | laravel | framework | 0798479b95fd241c829b0e36a1d6f8573a586738.json | Apply fixes from StyleCI (#36508) | src/Illuminate/Testing/TestResponse.php | @@ -14,9 +14,7 @@
use Illuminate\Support\Traits\Tappable;
use Illuminate\Testing\Assert as PHPUnit;
use Illuminate\Testing\Constraints\SeeInOrder;
-use Illuminate\Testing\Fluent\Assert as FluentAssert;
use Illuminate\Testing\Fluent\AssertableJson;
-use Illuminate\Testing\Fluent\FluentAssertableJson;
use LogicException;
use Symfony\Component\HttpFoundation\StreamedResponse;
| true |
Other | laravel | framework | 0798479b95fd241c829b0e36a1d6f8573a586738.json | Apply fixes from StyleCI (#36508) | tests/Testing/TestResponseTest.php | @@ -9,7 +9,6 @@
use Illuminate\Encryption\Encrypter;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Response;
-use Illuminate\Testing\Fluent\Assert;
use Illuminate\Testing\Fluent\AssertableJson;
use Illuminate\Testing\TestResponse;
use JsonSerializable; | true |
Other | laravel | framework | 883713b084fab51f972503395b14f662297cbab4.json | Use user defined url for AwsTemporaryUrl method | src/Illuminate/Filesystem/FilesystemAdapter.php | @@ -23,6 +23,7 @@
use League\Flysystem\Sftp\SftpAdapter as Sftp;
use PHPUnit\Framework\Assert as PHPUnit;
use Psr\Http\Message\StreamInterface;
+use Psr\Http\Message\UriInterface;
use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -593,9 +594,18 @@ public function getAwsTemporaryUrl($adapter, $path, $expiration, $options)
'Key' => $adapter->getPathPrefix().$path,
], $options));
- return (string) $client->createPresignedRequest(
+ $uri = $client->createPresignedRequest(
$command, $expiration
)->getUri();
+
+ // If an explicit base URL has been set on the disk configuration then we will use
+ // it as the base URL instead of the default path. This allows the developer to
+ // have full control over the base path for this filesystem's generated URLs.
+ if (! is_null($url = $this->driver->getConfig()->get('url'))) {
+ $uri = $this->replaceBaseUrl($uri, $url);
+ }
+
+ return (string) $uri;
}
/**
@@ -610,6 +620,20 @@ protected function concatPathToUrl($url, $path)
return rtrim($url, '/').'/'.ltrim($path, '/');
}
+ /**
+ * Replace base parts of UriInterface by values from URL.
+ *
+ * @param UriInterface $uri
+ * @param string $url
+ * @return UriInterface
+ */
+ protected function replaceBaseUrl($uri, $url)
+ {
+ $parsed_url = parse_url($url);
+
+ return $uri->withScheme($parsed_url['scheme'])->withHost($parsed_url['host']);
+ }
+
/**
* Get an array of all files in a directory.
* | false |
Other | laravel | framework | d7a4280423518939eeefce1f75f84b6e6bf03ad3.json | Apply fixes from StyleCI (#36477) | src/Illuminate/Cache/PhpRedisLock.php | @@ -46,7 +46,7 @@ protected function serializedAndCompressedOwner(): string
$owner = $client->_serialize($this->owner);
- // https://github.com/phpredis/phpredis/issues/1938
+ // https://github.com/phpredis/phpredis/issues/1938
if ($this->compressed()) {
if ($this->lzfCompressed()) {
$owner = \lzf_compress($owner); | false |
Other | laravel | framework | c5eadc4d9de5a2597dc0c4b64f0d009e287c25a6.json | Use FQN in DocBlocks | src/Illuminate/Testing/Fluent/Assert.php | @@ -75,7 +75,7 @@ protected function prop(string $key = null)
* Instantiate a new "scope" at the path of the given key.
*
* @param string $key
- * @param Closure $callback
+ * @param \Closure $callback
* @return $this
*/
protected function scope(string $key, Closure $callback): self
@@ -106,7 +106,7 @@ public static function fromArray(array $data): self
/**
* Create a new instance from a AssertableJsonString.
*
- * @param AssertableJsonString $json
+ * @param \Illuminate\Testing\AssertableJsonString $json
* @return static
*/
public static function fromAssertableJsonString(AssertableJsonString $json): self | true |
Other | laravel | framework | c5eadc4d9de5a2597dc0c4b64f0d009e287c25a6.json | Use FQN in DocBlocks | src/Illuminate/Testing/Fluent/Concerns/Has.php | @@ -31,7 +31,7 @@ protected function count(string $key, int $length): self
*
* @param string $key
* @param null $value
- * @param Closure|null $scope
+ * @param \Closure|null $scope
* @return $this
*/
public function has(string $key, $value = null, Closure $scope = null): self
@@ -151,7 +151,7 @@ abstract protected function prop(string $key = null);
* Instantiate a new "scope" at the path of the given key.
*
* @param string $key
- * @param Closure $callback
+ * @param \Closure $callback
* @return $this
*/
abstract protected function scope(string $key, Closure $callback); | true |
Other | laravel | framework | c5eadc4d9de5a2597dc0c4b64f0d009e287c25a6.json | Use FQN in DocBlocks | src/Illuminate/Testing/Fluent/Concerns/Matching.php | @@ -13,7 +13,7 @@ trait Matching
* Asserts that the property matches the expected value.
*
* @param string $key
- * @param mixed|callable $expected
+ * @param mixed|\Closure $expected
* @return $this
*/
public function where(string $key, $expected): self
@@ -94,7 +94,7 @@ abstract protected function dotPath(string $key): string;
*
* @param string $key
* @param null $value
- * @param Closure|null $scope
+ * @param \Closure|null $scope
* @return $this
*/
abstract public function has(string $key, $value = null, Closure $scope = null); | true |
Other | laravel | framework | 91bd93f92c26cc58c25849f1a1ac6d7ee6d55411.json | Add docblocks & minor cleanup | src/Illuminate/Testing/Fluent/Assert.php | @@ -19,19 +19,39 @@ class Assert implements Arrayable
Macroable,
Tappable;
- /** @var array */
+ /**
+ * The properties in the current scope.
+ *
+ * @var array
+ */
private $props;
- /** @var string */
+ /**
+ * The "dot" path to the current scope.
+ *
+ * @var string|null
+ */
private $path;
+ /**
+ * Create a new Assert instance.
+ *
+ * @param array $props
+ * @param string|null $path
+ */
protected function __construct(array $props, string $path = null)
{
$this->path = $path;
$this->props = $props;
}
- protected function dotPath($key): string
+ /**
+ * Compose the absolute "dot" path to the given key.
+ *
+ * @param string $key
+ * @return string
+ */
+ protected function dotPath(string $key): string
{
if (is_null($this->path)) {
return $key;
@@ -40,12 +60,25 @@ protected function dotPath($key): string
return implode('.', [$this->path, $key]);
}
+ /**
+ * Retrieve a prop within the current scope using "dot" notation.
+ *
+ * @param string|null $key
+ * @return mixed
+ */
protected function prop(string $key = null)
{
return Arr::get($this->props, $key);
}
- protected function scope($key, Closure $callback): self
+ /**
+ * Instantiate a new "scope" at the path of the given key.
+ *
+ * @param string $key
+ * @param Closure $callback
+ * @return $this
+ */
+ protected function scope(string $key, Closure $callback): self
{
$props = $this->prop($key);
$path = $this->dotPath($key);
@@ -59,16 +92,33 @@ protected function scope($key, Closure $callback): self
return $this;
}
+ /**
+ * Create a new instance from an array.
+ *
+ * @param array $data
+ * @return static
+ */
public static function fromArray(array $data): self
{
return new self($data);
}
+ /**
+ * Create a new instance from a AssertableJsonString.
+ *
+ * @param AssertableJsonString $json
+ * @return static
+ */
public static function fromAssertableJsonString(AssertableJsonString $json): self
{
return self::fromArray($json->json());
}
+ /**
+ * Get the instance as an array.
+ *
+ * @return array
+ */
public function toArray()
{
return $this->props; | true |
Other | laravel | framework | 91bd93f92c26cc58c25849f1a1ac6d7ee6d55411.json | Add docblocks & minor cleanup | src/Illuminate/Testing/Fluent/Concerns/Debugging.php | @@ -4,17 +4,35 @@
trait Debugging
{
+ /**
+ * Dumps the given props.
+ *
+ * @param string|null $prop
+ * @return $this
+ */
public function dump(string $prop = null): self
{
dump($this->prop($prop));
return $this;
}
+ /**
+ * Dumps the given props and exits.
+ *
+ * @param string|null $prop
+ * @return void
+ */
public function dd(string $prop = null): void
{
dd($this->prop($prop));
}
+ /**
+ * Retrieve a prop within the current scope using "dot" notation.
+ *
+ * @param string|null $key
+ * @return mixed
+ */
abstract protected function prop(string $key = null);
} | true |
Other | laravel | framework | 91bd93f92c26cc58c25849f1a1ac6d7ee6d55411.json | Add docblocks & minor cleanup | src/Illuminate/Testing/Fluent/Concerns/Has.php | @@ -8,7 +8,14 @@
trait Has
{
- protected function count(string $key, $length): self
+ /**
+ * Assert that the prop is of the expected size.
+ *
+ * @param string $key
+ * @param int $length
+ * @return $this
+ */
+ protected function count(string $key, int $length): self
{
PHPUnit::assertCount(
$length,
@@ -19,21 +26,14 @@ protected function count(string $key, $length): self
return $this;
}
- public function hasAll($key): self
- {
- $keys = is_array($key) ? $key : func_get_args();
-
- foreach ($keys as $prop => $count) {
- if (is_int($prop)) {
- $this->has($count);
- } else {
- $this->has($prop, $count);
- }
- }
-
- return $this;
- }
-
+ /**
+ * Ensure that the given prop exists.
+ *
+ * @param string $key
+ * @param null $value
+ * @param Closure|null $scope
+ * @return $this
+ */
public function has(string $key, $value = null, Closure $scope = null): self
{
$prop = $this->prop();
@@ -69,6 +69,33 @@ public function has(string $key, $value = null, Closure $scope = null): self
return $this;
}
+ /**
+ * Assert that all of the given props exist.
+ *
+ * @param array|string $key
+ * @return $this
+ */
+ public function hasAll($key): self
+ {
+ $keys = is_array($key) ? $key : func_get_args();
+
+ foreach ($keys as $prop => $count) {
+ if (is_int($prop)) {
+ $this->has($count);
+ } else {
+ $this->has($prop, $count);
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Assert that none of the given props exist.
+ *
+ * @param array|string $key
+ * @return $this
+ */
public function missingAll($key): self
{
$keys = is_array($key) ? $key : func_get_args();
@@ -80,6 +107,12 @@ public function missingAll($key): self
return $this;
}
+ /**
+ * Assert that the given prop does not exist.
+ *
+ * @param string $key
+ * @return $this
+ */
public function missing(string $key): self
{
PHPUnit::assertNotTrue(
@@ -90,11 +123,36 @@ public function missing(string $key): self
return $this;
}
- abstract protected function prop(string $key = null);
-
- abstract protected function dotPath($key): string;
-
+ /**
+ * Compose the absolute "dot" path to the given key.
+ *
+ * @param string $key
+ * @return string
+ */
+ abstract protected function dotPath(string $key): string;
+
+ /**
+ * Marks the property as interacted.
+ *
+ * @param string $key
+ * @return void
+ */
abstract protected function interactsWith(string $key): void;
- abstract protected function scope($key, Closure $callback);
+ /**
+ * Retrieve a prop within the current scope using "dot" notation.
+ *
+ * @param string|null $key
+ * @return mixed
+ */
+ abstract protected function prop(string $key = null);
+
+ /**
+ * Instantiate a new "scope" at the path of the given key.
+ *
+ * @param string $key
+ * @param Closure $callback
+ * @return $this
+ */
+ abstract protected function scope(string $key, Closure $callback);
} | true |
Other | laravel | framework | 91bd93f92c26cc58c25849f1a1ac6d7ee6d55411.json | Add docblocks & minor cleanup | src/Illuminate/Testing/Fluent/Concerns/Interaction.php | @@ -7,9 +7,19 @@
trait Interaction
{
- /** @var array */
+ /**
+ * The list of interacted properties.
+ *
+ * @var array
+ */
protected $interacted = [];
+ /**
+ * Marks the property as interacted.
+ *
+ * @param string $key
+ * @return void
+ */
protected function interactsWith(string $key): void
{
$prop = Str::before($key, '.');
@@ -19,6 +29,11 @@ protected function interactsWith(string $key): void
}
}
+ /**
+ * Asserts that all properties have been interacted with.
+ *
+ * @return void
+ */
public function interacted(): void
{
PHPUnit::assertSame(
@@ -30,12 +45,23 @@ public function interacted(): void
);
}
+ /**
+ * Disables the interaction check.
+ *
+ * @return $this
+ */
public function etc(): self
{
$this->interacted = array_keys($this->prop());
return $this;
}
+ /**
+ * Retrieve a prop within the current scope using "dot" notation.
+ *
+ * @param string|null $key
+ * @return mixed
+ */
abstract protected function prop(string $key = null);
} | true |
Other | laravel | framework | 91bd93f92c26cc58c25849f1a1ac6d7ee6d55411.json | Add docblocks & minor cleanup | src/Illuminate/Testing/Fluent/Concerns/Matching.php | @@ -9,16 +9,14 @@
trait Matching
{
- public function whereAll(array $bindings): self
- {
- foreach ($bindings as $key => $value) {
- $this->where($key, $value);
- }
-
- return $this;
- }
-
- public function where($key, $expected): self
+ /**
+ * Asserts that the property matches the expected value.
+ *
+ * @param string $key
+ * @param mixed|callable $expected
+ * @return $this
+ */
+ public function where(string $key, $expected): self
{
$this->has($key);
@@ -49,6 +47,27 @@ public function where($key, $expected): self
return $this;
}
+ /**
+ * Asserts that all properties match their expected values.
+ *
+ * @param array $bindings
+ * @return $this
+ */
+ public function whereAll(array $bindings): self
+ {
+ foreach ($bindings as $key => $value) {
+ $this->where($key, $value);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Ensures that all properties are sorted the same way, recursively.
+ *
+ * @param mixed $value
+ * @return void
+ */
protected function ensureSorted(&$value): void
{
if (! is_array($value)) {
@@ -62,9 +81,29 @@ protected function ensureSorted(&$value): void
ksort($value);
}
- abstract protected function dotPath($key): string;
+ /**
+ * Compose the absolute "dot" path to the given key.
+ *
+ * @param string $key
+ * @return string
+ */
+ abstract protected function dotPath(string $key): string;
+
+ /**
+ * Ensure that the given prop exists.
+ *
+ * @param string $key
+ * @param null $value
+ * @param Closure|null $scope
+ * @return $this
+ */
+ abstract public function has(string $key, $value = null, Closure $scope = null);
+ /**
+ * Retrieve a prop within the current scope using "dot" notation.
+ *
+ * @param string|null $key
+ * @return mixed
+ */
abstract protected function prop(string $key = null);
-
- abstract public function has(string $key, $value = null, Closure $scope = null);
} | true |
Other | laravel | framework | b1d76be077a96bc28321e5e289c4f0de324cd0ff.json | Add docblocks for dumping methods | src/Illuminate/Http/Client/Factory.php | @@ -32,6 +32,8 @@
* @method \Illuminate\Http\Client\PendingRequest withToken(string $token, string $type = 'Bearer')
* @method \Illuminate\Http\Client\PendingRequest withoutRedirecting()
* @method \Illuminate\Http\Client\PendingRequest withoutVerifying()
+ * @method \Illuminate\Http\Client\PendingRequest dump()
+ * @method \Illuminate\Http\Client\PendingRequest dd()
* @method \Illuminate\Http\Client\Response delete(string $url, array $data = [])
* @method \Illuminate\Http\Client\Response get(string $url, array $query = [])
* @method \Illuminate\Http\Client\Response head(string $url, array $query = []) | true |
Other | laravel | framework | b1d76be077a96bc28321e5e289c4f0de324cd0ff.json | Add docblocks for dumping methods | src/Illuminate/Support/Facades/Http.php | @@ -30,6 +30,8 @@
* @method static \Illuminate\Http\Client\PendingRequest withToken(string $token, string $type = 'Bearer')
* @method static \Illuminate\Http\Client\PendingRequest withoutRedirecting()
* @method static \Illuminate\Http\Client\PendingRequest withoutVerifying()
+ * @method static \Illuminate\Http\Client\PendingRequest dump()
+ * @method static \Illuminate\Http\Client\PendingRequest dd()
* @method static \Illuminate\Http\Client\Response delete(string $url, array $data = [])
* @method static \Illuminate\Http\Client\Response get(string $url, array $query = [])
* @method static \Illuminate\Http\Client\Response head(string $url, array $query = []) | true |
Other | laravel | framework | 6699a47565146cd318a22435f99104d54a90c2c1.json | Implement dump() and dd() methods | src/Illuminate/Http/Client/PendingRequest.php | @@ -9,6 +9,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
+use Symfony\Component\VarDumper\VarDumper;
class PendingRequest
{
@@ -452,6 +453,40 @@ public function beforeSending($callback)
});
}
+ /**
+ * Dump the request.
+ *
+ * @return $this
+ */
+ public function dump()
+ {
+ $values = func_get_args();
+
+ return $this->beforeSending(function (Request $request, array $options) use ($values) {
+ foreach (array_merge($values, [$request, $options]) as $value) {
+ VarDumper::dump($value);
+ }
+ });
+ }
+
+ /**
+ * Dump the request and end the script.
+ *
+ * @return $this
+ */
+ public function dd()
+ {
+ $values = func_get_args();
+
+ return $this->beforeSending(function (Request $request, array $options) use ($values) {
+ foreach (array_merge($values, [$request, $options]) as $value) {
+ VarDumper::dump($value);
+ }
+
+ exit(1);
+ });
+ }
+
/**
* Issue a GET request to the given URL.
* | false |
Other | laravel | framework | 5434332367c23230be01391b500005879bd6fa93.json | Add test for dumping requests | tests/Http/HttpClientTest.php | @@ -11,6 +11,7 @@
use Illuminate\Support\Str;
use OutOfBoundsException;
use PHPUnit\Framework\TestCase;
+use Symfony\Component\VarDumper\VarDumper;
class HttpClientTest extends TestCase
{
@@ -781,4 +782,23 @@ function (Request $request) {
$this->factory->assertSentInOrder($executionOrder);
}
+
+ public function testCanDump()
+ {
+ $dumped = [];
+
+ VarDumper::setHandler(function ($value) use (&$dumped) {
+ $dumped[] = $value;
+ });
+
+ $this->factory->fake()->dump(1, 2, 3)->withOptions(['delay' => 1000])->get('http://foo.com');
+
+ $this->assertSame(1, $dumped[0]);
+ $this->assertSame(2, $dumped[1]);
+ $this->assertSame(3, $dumped[2]);
+ $this->assertInstanceOf(Request::class, $dumped[3]);
+ $this->assertSame(1000, $dumped[4]['delay']);
+
+ VarDumper::setHandler(null);
+ }
} | false |
Other | laravel | framework | ddb0c5e68ec8037ed31738bbfed4ededa3cd39da.json | multiplatform newline check (#36464) | src/Illuminate/Foundation/Console/PolicyMakeCommand.php | @@ -131,8 +131,13 @@ protected function replaceModel($stub, $model)
array_keys($replace), array_values($replace), $stub
);
- return str_replace(
- "use {$namespacedModel};\nuse {$namespacedModel};", "use {$namespacedModel};", $stub
+ return preg_replace(
+ vsprintf('/use %s;[\r\n]+use %s;/', [
+ preg_quote($namespacedModel, '/'),
+ preg_quote($namespacedModel, '/'),
+ ]),
+ "use {$namespacedModel};",
+ $stub
);
}
| false |
Other | laravel | framework | cada3d21c7f127ba01bb949b2fa045b7faaedbca.json | Apply fixes from StyleCI (#36461) | src/Illuminate/View/Engines/CompilerEngine.php | @@ -3,8 +3,8 @@
namespace Illuminate\View\Engines;
use Illuminate\View\Compilers\CompilerInterface;
-use Throwable;
use Illuminate\View\ViewException;
+use Throwable;
class CompilerEngine extends PhpEngine
{ | false |
Other | laravel | framework | f31557f76ac5a790d66b717e074537031c48085e.json | Apply fixes from StyleCI | src/Illuminate/Testing/TestResponse.php | @@ -528,7 +528,6 @@ public function assertJson($value, $strict = false)
}
}
-
return $this;
}
| false |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | src/Illuminate/Testing/Fluent/Assert.php | @@ -0,0 +1,76 @@
+<?php
+
+namespace Illuminate\Testing\Fluent;
+
+use Closure;
+use Illuminate\Contracts\Support\Arrayable;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Traits\Macroable;
+use Illuminate\Support\Traits\Tappable;
+use Illuminate\Testing\AssertableJsonString;
+use PHPUnit\Framework\Assert as PHPUnit;
+
+class Assert implements Arrayable
+{
+ use Concerns\Has,
+ Concerns\Matching,
+ Concerns\Debugging,
+ Concerns\Interaction,
+ Macroable,
+ Tappable;
+
+ /** @var array */
+ private $props;
+
+ /** @var string */
+ private $path;
+
+ protected function __construct(array $props, string $path = null)
+ {
+ $this->path = $path;
+ $this->props = $props;
+ }
+
+ protected function dotPath($key): string
+ {
+ if (is_null($this->path)) {
+ return $key;
+ }
+
+ return implode('.', [$this->path, $key]);
+ }
+
+ protected function prop(string $key = null)
+ {
+ return Arr::get($this->props, $key);
+ }
+
+ protected function scope($key, Closure $callback): self
+ {
+ $props = $this->prop($key);
+ $path = $this->dotPath($key);
+
+ PHPUnit::assertIsArray($props, sprintf('Property [%s] is not scopeable.', $path));
+
+ $scope = new self($props, $path);
+ $callback($scope);
+ $scope->interacted();
+
+ return $this;
+ }
+
+ public static function fromArray(array $data): self
+ {
+ return new self($data);
+ }
+
+ public static function fromAssertableJsonString(AssertableJsonString $json): self
+ {
+ return self::fromArray($json->json());
+ }
+
+ public function toArray()
+ {
+ return $this->props;
+ }
+} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | src/Illuminate/Testing/Fluent/Concerns/Debugging.php | @@ -0,0 +1,20 @@
+<?php
+
+namespace Illuminate\Testing\Fluent\Concerns;
+
+trait Debugging
+{
+ public function dump(string $prop = null): self
+ {
+ dump($this->prop($prop));
+
+ return $this;
+ }
+
+ public function dd(string $prop = null): void
+ {
+ dd($this->prop($prop));
+ }
+
+ abstract protected function prop(string $key = null);
+} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | src/Illuminate/Testing/Fluent/Concerns/Has.php | @@ -0,0 +1,100 @@
+<?php
+
+namespace Illuminate\Testing\Fluent\Concerns;
+
+use Closure;
+use Illuminate\Support\Arr;
+use PHPUnit\Framework\Assert as PHPUnit;
+
+trait Has
+{
+ protected function count(string $key, $length): self
+ {
+ PHPUnit::assertCount(
+ $length,
+ $this->prop($key),
+ sprintf('Property [%s] does not have the expected size.', $this->dotPath($key))
+ );
+
+ return $this;
+ }
+
+ public function hasAll($key): self
+ {
+ $keys = is_array($key) ? $key : func_get_args();
+
+ foreach ($keys as $prop => $count) {
+ if (is_int($prop)) {
+ $this->has($count);
+ } else {
+ $this->has($prop, $count);
+ }
+ }
+
+ return $this;
+ }
+
+ public function has(string $key, $value = null, Closure $scope = null): self
+ {
+ $prop = $this->prop();
+
+ PHPUnit::assertTrue(
+ Arr::has($prop, $key),
+ sprintf('Property [%s] does not exist.', $this->dotPath($key))
+ );
+
+ $this->interactsWith($key);
+
+ // When all three arguments are provided, this indicates a short-hand
+ // expression that combines both a `count`-assertion, followed by
+ // directly creating a `scope` on the first element.
+ if (is_int($value) && ! is_null($scope)) {
+ $prop = $this->prop($key);
+ $path = $this->dotPath($key);
+
+ PHPUnit::assertTrue($value > 0, sprintf('Cannot scope directly onto the first entry of property [%s] when asserting that it has a size of 0.', $path));
+ PHPUnit::assertIsArray($prop, sprintf('Direct scoping is unsupported for non-array like properties such as [%s].', $path));
+
+ $this->count($key, $value);
+
+ return $this->scope($key.'.'.array_keys($prop)[0], $scope);
+ }
+
+ if (is_callable($value)) {
+ $this->scope($key, $value);
+ } elseif (! is_null($value)) {
+ $this->count($key, $value);
+ }
+
+ return $this;
+ }
+
+ public function missingAll($key): self
+ {
+ $keys = is_array($key) ? $key : func_get_args();
+
+ foreach ($keys as $prop) {
+ $this->missing($prop);
+ }
+
+ return $this;
+ }
+
+ public function missing(string $key): self
+ {
+ PHPUnit::assertNotTrue(
+ Arr::has($this->prop(), $key),
+ sprintf('Property [%s] was found while it was expected to be missing.', $this->dotPath($key))
+ );
+
+ return $this;
+ }
+
+ abstract protected function prop(string $key = null);
+
+ abstract protected function dotPath($key): string;
+
+ abstract protected function interactsWith(string $key): void;
+
+ abstract protected function scope($key, Closure $callback);
+} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | src/Illuminate/Testing/Fluent/Concerns/Interaction.php | @@ -0,0 +1,41 @@
+<?php
+
+namespace Illuminate\Testing\Fluent\Concerns;
+
+use Illuminate\Support\Str;
+use PHPUnit\Framework\Assert as PHPUnit;
+
+trait Interaction
+{
+ /** @var array */
+ protected $interacted = [];
+
+ protected function interactsWith(string $key): void
+ {
+ $prop = Str::before($key, '.');
+
+ if (! in_array($prop, $this->interacted, true)) {
+ $this->interacted[] = $prop;
+ }
+ }
+
+ public function interacted(): void
+ {
+ PHPUnit::assertSame(
+ [],
+ array_diff(array_keys($this->prop()), $this->interacted),
+ $this->path
+ ? sprintf('Unexpected properties were found in scope [%s].', $this->path)
+ : 'Unexpected properties were found on the root level.'
+ );
+ }
+
+ public function etc(): self
+ {
+ $this->interacted = array_keys($this->prop());
+
+ return $this;
+ }
+
+ abstract protected function prop(string $key = null);
+} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | src/Illuminate/Testing/Fluent/Concerns/Matching.php | @@ -0,0 +1,70 @@
+<?php
+
+namespace Illuminate\Testing\Fluent\Concerns;
+
+use Closure;
+use Illuminate\Contracts\Support\Arrayable;
+use Illuminate\Support\Collection;
+use PHPUnit\Framework\Assert as PHPUnit;
+
+trait Matching
+{
+ public function whereAll(array $bindings): self
+ {
+ foreach ($bindings as $key => $value) {
+ $this->where($key, $value);
+ }
+
+ return $this;
+ }
+
+ public function where($key, $expected): self
+ {
+ $this->has($key);
+
+ $actual = $this->prop($key);
+
+ if ($expected instanceof Closure) {
+ PHPUnit::assertTrue(
+ $expected(is_array($actual) ? Collection::make($actual) : $actual),
+ sprintf('Property [%s] was marked as invalid using a closure.', $this->dotPath($key))
+ );
+
+ return $this;
+ }
+
+ if ($expected instanceof Arrayable) {
+ $expected = $expected->toArray();
+ }
+
+ $this->ensureSorted($expected);
+ $this->ensureSorted($actual);
+
+ PHPUnit::assertSame(
+ $expected,
+ $actual,
+ sprintf('Property [%s] does not match the expected value.', $this->dotPath($key))
+ );
+
+ return $this;
+ }
+
+ protected function ensureSorted(&$value): void
+ {
+ if (! is_array($value)) {
+ return;
+ }
+
+ foreach ($value as &$arg) {
+ $this->ensureSorted($arg);
+ }
+
+ ksort($value);
+ }
+
+ abstract protected function dotPath($key): string;
+
+ abstract protected function prop(string $key = null);
+
+ abstract public function has(string $key, $value = null, Closure $scope = null);
+} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | src/Illuminate/Testing/TestResponse.php | @@ -14,6 +14,7 @@
use Illuminate\Support\Traits\Tappable;
use Illuminate\Testing\Assert as PHPUnit;
use Illuminate\Testing\Constraints\SeeInOrder;
+use Illuminate\Testing\Fluent\Assert as FluentAssert;
use LogicException;
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -507,13 +508,26 @@ public function assertDontSeeText($value, $escape = true)
/**
* Assert that the response is a superset of the given JSON.
*
- * @param array $data
+ * @param array|callable $value
* @param bool $strict
* @return $this
*/
- public function assertJson(array $data, $strict = false)
+ public function assertJson($value, $strict = false)
{
- $this->decodeResponseJson()->assertSubset($data, $strict);
+ $json = $this->decodeResponseJson();
+
+ if (is_array($value)) {
+ $json->assertSubset($value, $strict);
+ } else {
+ $assert = FluentAssert::fromAssertableJsonString($json);
+
+ $value($assert);
+
+ if ($strict) {
+ $assert->interacted();
+ }
+ }
+
return $this;
} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | tests/Testing/Fluent/AssertTest.php | @@ -0,0 +1,688 @@
+<?php
+
+namespace Illuminate\Tests\Testing\Fluent;
+
+use Illuminate\Support\Collection;
+use Illuminate\Testing\Fluent\Assert;
+use Illuminate\Tests\Testing\Stubs\ArrayableStubObject;
+use PHPUnit\Framework\AssertionFailedError;
+use PHPUnit\Framework\TestCase;
+use RuntimeException;
+use TypeError;
+
+class AssertTest extends TestCase
+{
+ public function testAssertHas()
+ {
+ $assert = Assert::fromArray([
+ 'prop' => 'value',
+ ]);
+
+ $assert->has('prop');
+ }
+
+ public function testAssertHasFailsWhenPropMissing()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'value',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [prop] does not exist.');
+
+ $assert->has('prop');
+ }
+
+ public function testAssertHasNestedProp()
+ {
+ $assert = Assert::fromArray([
+ 'example' => [
+ 'nested' => 'nested-value',
+ ],
+ ]);
+
+ $assert->has('example.nested');
+ }
+
+ public function testAssertHasFailsWhenNestedPropMissing()
+ {
+ $assert = Assert::fromArray([
+ 'example' => [
+ 'nested' => 'nested-value',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [example.another] does not exist.');
+
+ $assert->has('example.another');
+ }
+
+ public function testAssertCountItemsInProp()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $assert->has('bar', 2);
+ }
+
+ public function testAssertCountFailsWhenAmountOfItemsDoesNotMatch()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [bar] does not have the expected size.');
+
+ $assert->has('bar', 1);
+ }
+
+ public function testAssertCountFailsWhenPropMissing()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [baz] does not exist.');
+
+ $assert->has('baz', 1);
+ }
+
+ public function testAssertHasFailsWhenSecondArgumentUnsupportedType()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'baz',
+ ]);
+
+ $this->expectException(TypeError::class);
+
+ $assert->has('bar', 'invalid');
+ }
+
+ public function testAssertMissing()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => [
+ 'bar' => true,
+ ],
+ ]);
+
+ $assert->missing('foo.baz');
+ }
+
+ public function testAssertMissingFailsWhenPropExists()
+ {
+ $assert = Assert::fromArray([
+ 'prop' => 'value',
+ 'foo' => [
+ 'bar' => true,
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [foo.bar] was found while it was expected to be missing.');
+
+ $assert->missing('foo.bar');
+ }
+
+ public function testAssertMissingAll()
+ {
+ $assert = Assert::fromArray([
+ 'baz' => 'foo',
+ ]);
+
+ $assert->missingAll([
+ 'foo',
+ 'bar',
+ ]);
+ }
+
+ public function testAssertMissingAllFailsWhenAtLeastOnePropExists()
+ {
+ $assert = Assert::fromArray([
+ 'baz' => 'foo',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [baz] was found while it was expected to be missing.');
+
+ $assert->missingAll([
+ 'bar',
+ 'baz',
+ ]);
+ }
+
+ public function testAssertMissingAllAcceptsMultipleArgumentsInsteadOfArray()
+ {
+ $assert = Assert::fromArray([
+ 'baz' => 'foo',
+ ]);
+
+ $assert->missingAll('foo', 'bar');
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [baz] was found while it was expected to be missing.');
+
+ $assert->missingAll('bar', 'baz');
+ }
+
+ public function testAssertWhereMatchesValue()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'value',
+ ]);
+
+ $assert->where('bar', 'value');
+ }
+
+ public function testAssertWhereFailsWhenDoesNotMatchValue()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'value',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [bar] does not match the expected value.');
+
+ $assert->where('bar', 'invalid');
+ }
+
+ public function testAssertWhereFailsWhenMissing()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'value',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [baz] does not exist.');
+
+ $assert->where('baz', 'invalid');
+ }
+
+ public function testAssertWhereFailsWhenMachingLoosely()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 1,
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [bar] does not match the expected value.');
+
+ $assert->where('bar', true);
+ }
+
+ public function testAssertWhereUsingClosure()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'baz',
+ ]);
+
+ $assert->where('bar', function ($value) {
+ return $value === 'baz';
+ });
+ }
+
+ public function testAssertWhereFailsWhenDoesNotMatchValueUsingClosure()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'baz',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [bar] was marked as invalid using a closure.');
+
+ $assert->where('bar', function ($value) {
+ return $value === 'invalid';
+ });
+ }
+
+ public function testAssertWhereClosureArrayValuesAreAutomaticallyCastedToCollections()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'foo',
+ 'example' => 'value',
+ ],
+ ]);
+
+ $assert->where('bar', function ($value) {
+ $this->assertInstanceOf(Collection::class, $value);
+
+ return $value->count() === 2;
+ });
+ }
+
+ public function testAssertWhereMatchesValueUsingArrayable()
+ {
+ $stub = ArrayableStubObject::make(['foo' => 'bar']);
+
+ $assert = Assert::fromArray([
+ 'bar' => $stub->toArray(),
+ ]);
+
+ $assert->where('bar', $stub);
+ }
+
+ public function testAssertWhereMatchesValueUsingArrayableWhenSortedDifferently()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'foo',
+ 'example' => 'value',
+ ],
+ ]);
+
+ $assert->where('bar', function ($value) {
+ $this->assertInstanceOf(Collection::class, $value);
+
+ return $value->count() === 2;
+ });
+ }
+
+ public function testAssertWhereFailsWhenDoesNotMatchValueUsingArrayable()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => ['id' => 1, 'name' => 'Example'],
+ 'baz' => [
+ 'id' => 1,
+ 'name' => 'Taylor Otwell',
+ 'email' => 'taylor@laravel.com',
+ 'email_verified_at' => '2021-01-22T10:34:42.000000Z',
+ 'created_at' => '2021-01-22T10:34:42.000000Z',
+ 'updated_at' => '2021-01-22T10:34:42.000000Z',
+ ],
+ ]);
+
+ $assert
+ ->where('bar', ArrayableStubObject::make(['name' => 'Example', 'id' => 1]))
+ ->where('baz', [
+ 'name' => 'Taylor Otwell',
+ 'email' => 'taylor@laravel.com',
+ 'id' => 1,
+ 'email_verified_at' => '2021-01-22T10:34:42.000000Z',
+ 'updated_at' => '2021-01-22T10:34:42.000000Z',
+ 'created_at' => '2021-01-22T10:34:42.000000Z',
+ ]);
+ }
+
+ public function testAssertNestedWhereMatchesValue()
+ {
+ $assert = Assert::fromArray([
+ 'example' => [
+ 'nested' => 'nested-value',
+ ],
+ ]);
+
+ $assert->where('example.nested', 'nested-value');
+ }
+
+ public function testAssertNestedWhereFailsWhenDoesNotMatchValue()
+ {
+ $assert = Assert::fromArray([
+ 'example' => [
+ 'nested' => 'nested-value',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [example.nested] does not match the expected value.');
+
+ $assert->where('example.nested', 'another-value');
+ }
+
+ public function testScope()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $called = false;
+ $assert->has('bar', function (Assert $assert) use (&$called) {
+ $called = true;
+ $assert
+ ->where('baz', 'example')
+ ->where('prop', 'value');
+ });
+
+ $this->assertTrue($called, 'The scoped query was never actually called.');
+ }
+
+ public function testScopeFailsWhenPropMissing()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [baz] does not exist.');
+
+ $assert->has('baz', function (Assert $item) {
+ $item->where('baz', 'example');
+ });
+ }
+
+ public function testScopeFailsWhenPropSingleValue()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => 'value',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [bar] is not scopeable.');
+
+ $assert->has('bar', function (Assert $item) {
+ //
+ });
+ }
+
+ public function testScopeShorthand()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ ['key' => 'first'],
+ ['key' => 'second'],
+ ],
+ ]);
+
+ $called = false;
+ $assert->has('bar', 2, function (Assert $item) use (&$called) {
+ $item->where('key', 'first');
+ $called = true;
+ });
+
+ $this->assertTrue($called, 'The scoped query was never actually called.');
+ }
+
+ public function testScopeShorthandFailsWhenAssertingZeroItems()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ ['key' => 'first'],
+ ['key' => 'second'],
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Cannot scope directly onto the first entry of property [bar] when asserting that it has a size of 0.');
+
+ $assert->has('bar', 0, function (Assert $item) {
+ $item->where('key', 'first');
+ });
+ }
+
+ public function testScopeShorthandFailsWhenAmountOfItemsDoesNotMatch()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ ['key' => 'first'],
+ ['key' => 'second'],
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [bar] does not have the expected size.');
+
+ $assert->has('bar', 1, function (Assert $item) {
+ $item->where('key', 'first');
+ });
+ }
+
+ public function testFailsWhenNotInteractingWithAllPropsInScope()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Unexpected properties were found in scope [bar].');
+
+ $assert->has('bar', function (Assert $item) {
+ $item->where('baz', 'example');
+ });
+ }
+
+ public function testDisableInteractionCheckForCurrentScope()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $assert->has('bar', function (Assert $item) {
+ $item->etc();
+ });
+ }
+
+ public function testCannotDisableInteractionCheckForDifferentScopes()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => [
+ 'foo' => 'bar',
+ 'example' => 'value',
+ ],
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Unexpected properties were found in scope [bar.baz].');
+
+ $assert->has('bar', function (Assert $item) {
+ $item
+ ->etc()
+ ->has('baz', function (Assert $item) {
+ //
+ });
+ });
+ }
+
+ public function testTopLevelPropInteractionDisabledByDefault()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => 'bar',
+ 'bar' => 'baz',
+ ]);
+
+ $assert->has('foo');
+ }
+
+ public function testTopLevelInteractionEnabledWhenInteractedFlagSet()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => 'bar',
+ 'bar' => 'baz',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Unexpected properties were found on the root level.');
+
+ $assert
+ ->has('foo')
+ ->interacted();
+ }
+
+ public function testAssertWhereAllMatchesValues()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => [
+ 'bar' => 'value',
+ 'example' => ['hello' => 'world'],
+ ],
+ 'baz' => 'another',
+ ]);
+
+ $assert->whereAll([
+ 'foo.bar' => 'value',
+ 'foo.example' => ArrayableStubObject::make(['hello' => 'world']),
+ 'baz' => function ($value) {
+ return $value === 'another';
+ },
+ ]);
+ }
+
+ public function testAssertWhereAllFailsWhenAtLeastOnePropDoesNotMatchValue()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => 'bar',
+ 'baz' => 'example',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [baz] was marked as invalid using a closure.');
+
+ $assert->whereAll([
+ 'foo' => 'bar',
+ 'baz' => function ($value) {
+ return $value === 'foo';
+ },
+ ]);
+ }
+
+ public function testAssertHasAll()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => [
+ 'bar' => 'value',
+ 'example' => ['hello' => 'world'],
+ ],
+ 'baz' => 'another',
+ ]);
+
+ $assert->hasAll([
+ 'foo.bar',
+ 'foo.example',
+ 'baz',
+ ]);
+ }
+
+ public function testAssertHasAllFailsWhenAtLeastOnePropMissing()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => [
+ 'bar' => 'value',
+ 'example' => ['hello' => 'world'],
+ ],
+ 'baz' => 'another',
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [foo.baz] does not exist.');
+
+ $assert->hasAll([
+ 'foo.bar',
+ 'foo.baz',
+ 'baz',
+ ]);
+ }
+
+ public function testAssertHasAllAcceptsMultipleArgumentsInsteadOfArray()
+ {
+ $assert = Assert::fromArray([
+ 'foo' => [
+ 'bar' => 'value',
+ 'example' => ['hello' => 'world'],
+ ],
+ 'baz' => 'another',
+ ]);
+
+ $assert->hasAll('foo.bar', 'foo.example', 'baz');
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [foo.baz] does not exist.');
+
+ $assert->hasAll('foo.bar', 'foo.baz', 'baz');
+ }
+
+ public function testAssertCountMultipleProps()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'key' => 'value',
+ 'prop' => 'example',
+ ],
+ 'baz' => [
+ 'another' => 'value',
+ ],
+ ]);
+
+ $assert->hasAll([
+ 'bar' => 2,
+ 'baz' => 1,
+ ]);
+ }
+
+ public function testAssertCountMultiplePropsFailsWhenPropMissing()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'key' => 'value',
+ 'prop' => 'example',
+ ],
+ ]);
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Property [baz] does not exist.');
+
+ $assert->hasAll([
+ 'bar' => 2,
+ 'baz' => 1,
+ ]);
+ }
+
+ public function testMacroable()
+ {
+ Assert::macro('myCustomMacro', function () {
+ throw new RuntimeException('My Custom Macro was called!');
+ });
+
+ $this->expectException(RuntimeException::class);
+ $this->expectExceptionMessage('My Custom Macro was called!');
+
+ $assert = Assert::fromArray(['foo' => 'bar']);
+ $assert->myCustomMacro();
+ }
+
+ public function testTappable()
+ {
+ $assert = Assert::fromArray([
+ 'bar' => [
+ 'baz' => 'example',
+ 'prop' => 'value',
+ ],
+ ]);
+
+ $called = false;
+ $assert->has('bar', function (Assert $assert) use (&$called) {
+ $assert->etc();
+ $assert->tap(function (Assert $assert) use (&$called) {
+ $called = true;
+ });
+ });
+
+ $this->assertTrue($called, 'The scoped query was never actually called.');
+ }
+} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | tests/Testing/Stubs/ArrayableStubObject.php | @@ -0,0 +1,25 @@
+<?php
+
+namespace Illuminate\Tests\Testing\Stubs;
+
+use Illuminate\Contracts\Support\Arrayable;
+
+class ArrayableStubObject implements Arrayable
+{
+ protected $data;
+
+ public function __construct($data = [])
+ {
+ $this->data = $data;
+ }
+
+ public static function make($data = [])
+ {
+ return new self($data);
+ }
+
+ public function toArray()
+ {
+ return $this->data;
+ }
+} | true |
Other | laravel | framework | add249472cd192cabcb4f113ff7915f667394141.json | Implement Fluent JSON Assertions | tests/Testing/TestResponseTest.php | @@ -9,6 +9,7 @@
use Illuminate\Encryption\Encrypter;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Response;
+use Illuminate\Testing\Fluent\Assert;
use Illuminate\Testing\TestResponse;
use JsonSerializable;
use Mockery as m;
@@ -577,6 +578,27 @@ public function testAssertJsonWithNull()
$response->assertJson($resource->jsonSerialize());
}
+ public function testAssertJsonWithFluent()
+ {
+ $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub));
+
+ $response->assertJson(function (Assert $json) {
+ $json->where('0.foo', 'foo 0');
+ });
+ }
+
+ public function testAssertJsonWithFluentStrict()
+ {
+ $response = TestResponse::fromBaseResponse(new Response(new JsonSerializableSingleResourceStub));
+
+ $this->expectException(AssertionFailedError::class);
+ $this->expectExceptionMessage('Unexpected properties were found on the root level.');
+
+ $response->assertJson(function (Assert $json) {
+ $json->where('0.foo', 'foo 0');
+ }, true);
+ }
+
public function testAssertSimilarJsonWithMixed()
{
$response = TestResponse::fromBaseResponse(new Response(new JsonSerializableMixedResourcesStub)); | true |
Other | laravel | framework | b72178dbe9d8971c9f8bd1823cb1aa344bcb9637.json | Add Collection@isSingle method | src/Illuminate/Collections/Collection.php | @@ -553,6 +553,16 @@ public function isEmpty()
return empty($this->items);
}
+ /**
+ * Determine if the collection contains a single element.
+ *
+ * @return bool
+ */
+ public function isSingle()
+ {
+ return $this->count() === 1;
+ }
+
/**
* Join all items from the collection using a string. The final items can use a separate glue string.
* | true |
Other | laravel | framework | b72178dbe9d8971c9f8bd1823cb1aa344bcb9637.json | Add Collection@isSingle method | src/Illuminate/Collections/LazyCollection.php | @@ -556,6 +556,16 @@ public function isEmpty()
return ! $this->getIterator()->valid();
}
+ /**
+ * Determine if the collection contains a single element.
+ *
+ * @return bool
+ */
+ public function isSingle()
+ {
+ return $this->take(2)->count() === 1;
+ }
+
/**
* Join all items from the collection using a string. The final items can use a separate glue string.
* | true |
Other | laravel | framework | b72178dbe9d8971c9f8bd1823cb1aa344bcb9637.json | Add Collection@isSingle method | tests/Support/SupportCollectionTest.php | @@ -541,6 +541,16 @@ public function testCountableByWithCallback($collection)
})->all());
}
+ /**
+ * @dataProvider collectionClassProvider
+ */
+ public function testIsSingle($collection)
+ {
+ $this->assertFalse((new $collection([]))->isSingle());
+ $this->assertTrue((new $collection([1]))->isSingle());
+ $this->assertFalse((new $collection([1, 2]))->isSingle());
+ }
+
public function testIterable()
{
$c = new Collection(['foo']); | true |
Other | laravel | framework | b72178dbe9d8971c9f8bd1823cb1aa344bcb9637.json | Add Collection@isSingle method | tests/Support/SupportLazyCollectionIsLazyTest.php | @@ -484,6 +484,13 @@ public function testIsNotEmptyIsLazy()
});
}
+ public function testIsSingleIsLazy()
+ {
+ $this->assertEnumerates(2, function ($collection) {
+ $collection->isSingle();
+ });
+ }
+
public function testJoinIsLazy()
{
$this->assertEnumeratesOnce(function ($collection) { | true |
Other | laravel | framework | f330a094db465c5e07d8234a3ff1c10b2a1b4d99.json | Apply fixes from StyleCI (#36413) | src/Illuminate/Validation/Validator.php | @@ -381,8 +381,8 @@ public function passes()
}
if ($this->stopOnFirstFailure && $this->messages->isNotEmpty()) {
- break;
- }
+ break;
+ }
foreach ($rules as $rule) {
$this->validateAttribute($attribute, $rule); | false |
Other | laravel | framework | 8a1445396617408e98cdf306296bd9440f25e5be.json | Add Buffered Console Output (#36404)
* add buffered console output
* Apply fixes from StyleCI (#36403)
* change visibility | src/Illuminate/Console/Application.php | @@ -19,7 +19,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
-use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpExecutableFinder;
@@ -86,7 +85,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
$this->events->dispatch(
new CommandStarting(
- $commandName, $input, $output = $output ?: new ConsoleOutput
+ $commandName, $input, $output = $output ?: new BufferedConsoleOutput
)
);
| true |
Other | laravel | framework | 8a1445396617408e98cdf306296bd9440f25e5be.json | Add Buffered Console Output (#36404)
* add buffered console output
* Apply fixes from StyleCI (#36403)
* change visibility | src/Illuminate/Console/BufferedConsoleOutput.php | @@ -0,0 +1,41 @@
+<?php
+
+namespace Illuminate\Console;
+
+use Symfony\Component\Console\Output\ConsoleOutput;
+
+class BufferedConsoleOutput extends ConsoleOutput
+{
+ /**
+ * The current buffer.
+ *
+ * @var string
+ */
+ protected $buffer = '';
+
+ /**
+ * Empties the buffer and returns its content.
+ *
+ * @return string
+ */
+ public function fetch()
+ {
+ return tap($this->buffer, function () {
+ $this->buffer = '';
+ });
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doWrite(string $message, bool $newline)
+ {
+ $this->buffer .= $message;
+
+ if ($newline) {
+ $this->buffer .= \PHP_EOL;
+ }
+
+ return parent::doWrite($message, $newline);
+ }
+} | true |
Other | laravel | framework | aa19ecd0ceef93b6e8a96764cdb07d7c878871b0.json | add macroable trait to database factory (#36380) | src/Illuminate/Database/Eloquent/Factories/Factory.php | @@ -11,11 +11,14 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\ForwardsCalls;
+use Illuminate\Support\Traits\Macroable;
use Throwable;
abstract class Factory
{
- use ForwardsCalls;
+ use ForwardsCalls, Macroable {
+ __call as macroCall;
+ }
/**
* The name of the factory's corresponding model.
@@ -747,6 +750,10 @@ protected static function appNamespace()
*/
public function __call($method, $parameters)
{
+ if (static::hasMacro($method)) {
+ return $this->macroCall($method, $parameters);
+ }
+
if (! Str::startsWith($method, ['for', 'has'])) {
static::throwBadMethodCallException($method);
} | true |
Other | laravel | framework | aa19ecd0ceef93b6e8a96764cdb07d7c878871b0.json | add macroable trait to database factory (#36380) | tests/Database/DatabaseEloquentFactoryTest.php | @@ -473,6 +473,16 @@ public function test_dynamic_has_and_for_methods()
$this->assertCount(2, $post->comments);
}
+ public function test_can_be_macroable()
+ {
+ $factory = FactoryTestUserFactory::new();
+ $factory->macro('getFoo', function () {
+ return 'Hello World';
+ });
+
+ $this->assertEquals('Hello World', $factory->getFoo());
+ }
+
/**
* Get a database connection instance.
* | true |
Other | laravel | framework | 7f9441c1f990f513b40102bef5172b1d3c0eccf0.json | Update Http.php (#36366) | src/Illuminate/Support/Facades/Http.php | @@ -18,6 +18,7 @@
* @method static \Illuminate\Http\Client\PendingRequest bodyFormat(string $format)
* @method static \Illuminate\Http\Client\PendingRequest contentType(string $contentType)
* @method static \Illuminate\Http\Client\PendingRequest retry(int $times, int $sleep = 0)
+ * @method static \Illuminate\Http\Client\PendingRequest sink($to)
* @method static \Illuminate\Http\Client\PendingRequest stub(callable $callback)
* @method static \Illuminate\Http\Client\PendingRequest timeout(int $seconds)
* @method static \Illuminate\Http\Client\PendingRequest withBasicAuth(string $username, string $password) | false |
Other | laravel | framework | 75b1e9ea2d9157d65fc3d3d8cb20840aa2887c5b.json | Fix GateEvaluated event DocBlocks (#36347) | src/Illuminate/Auth/Access/Events/GateEvaluated.php | @@ -7,7 +7,7 @@ class GateEvaluated
/**
* The authenticatable model.
*
- * @var \Illuminate\Contracts\Auth\Authenticatable
+ * @var \Illuminate\Contracts\Auth\Authenticatable|null
*/
public $user;
@@ -35,7 +35,7 @@ class GateEvaluated
/**
* Create a new event instance.
*
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
+ * @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param string $ability
* @param bool|null $result
* @param array $arguments | true |
Other | laravel | framework | 75b1e9ea2d9157d65fc3d3d8cb20840aa2887c5b.json | Fix GateEvaluated event DocBlocks (#36347) | src/Illuminate/Auth/Access/Gate.php | @@ -87,7 +87,7 @@ class Gate implements GateContract
*/
public function __construct(Container $container, callable $userResolver, array $abilities = [],
array $policies = [], array $beforeCallbacks = [], array $afterCallbacks = [],
- callable $guessPolicyNamesUsingCallback = null)
+ callable $guessPolicyNamesUsingCallback = null)
{
$this->policies = $policies;
$this->container = $container;
@@ -525,10 +525,10 @@ protected function callAfterCallbacks($user, $ability, array $arguments, $result
/**
* Dispatch a gate evaluation event.
*
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
+ * @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param string $ability
* @param array $arguments
- * @param bool $result
+ * @param bool|null $result
* @return void
*/
protected function dispatchGateEvaluatedEvent($user, $ability, array $arguments, $result) | true |
Other | laravel | framework | ef3080d16cf8f9b2da33d8553d84786a5672202d.json | Fix retry command for encrypted jobs | src/Illuminate/Queue/Console/RetryCommand.php | @@ -4,7 +4,10 @@
use DateTimeInterface;
use Illuminate\Console\Command;
+use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Support\Arr;
+use Illuminate\Support\Str;
+use RuntimeException;
class RetryCommand extends Command
{
@@ -94,7 +97,8 @@ protected function getJobIdsByRanges(array $ranges)
protected function retryJob($job)
{
$this->laravel['queue']->connection($job->connection)->pushRaw(
- $this->refreshRetryUntil($this->resetAttempts($job->payload)), $job->queue
+ $this->refreshRetryUntil($this->resetAttempts($job->payload)),
+ $job->queue
);
}
@@ -131,7 +135,17 @@ protected function refreshRetryUntil($payload)
return json_encode($payload);
}
- $instance = unserialize($payload['data']['command']);
+ if (Str::startsWith($payload['data']['command'], 'O:')) {
+ $instance = unserialize($payload['data']['command']);
+ }
+
+ if (app()->bound(Encrypter::class)) {
+ $instance = unserialize(app()->make(Encrypter::class)->decrypt($payload['data']['command']));
+ }
+
+ if (! isset($instance)) {
+ throw new RuntimeException('Unable to extract job payload.');
+ }
if (is_object($instance) && method_exists($instance, 'retryUntil')) {
$retryUntil = $instance->retryUntil(); | false |
Other | laravel | framework | 3c66f6cda2ac4ee2844a67fc98e676cb170ff4b1.json | support closures in sequences | src/Illuminate/Database/Eloquent/Factories/Sequence.php | @@ -48,7 +48,7 @@ public function __invoke()
$this->index = 0;
}
- return tap($this->sequence[$this->index], function () {
+ return tap(value($this->sequence[$this->index]), function () {
$this->index = $this->index + 1;
});
} | false |
Other | laravel | framework | 3b515cea9cab30e2832ca7b7b9be7923d732cb5e.json | Use explicit flag as default sorting (#36261)
PHP 8.1 will no longer support passing `null` as `asort()` flag. | src/Illuminate/Collections/Collection.php | @@ -1086,7 +1086,7 @@ public function sort($callback = null)
$callback && is_callable($callback)
? uasort($items, $callback)
- : asort($items, $callback);
+ : asort($items, $callback ?? SORT_REGULAR);
return new static($items);
} | false |
Other | laravel | framework | eee817aa38de261ed1c205d9cf9315e4b563d57c.json | Handle directive $value as a string (#36260)
- As per PHPDoc `Str::startsWith` and `Str::endsWith` are not supposed to handle `null` values
- strncmp() will no longer accept `null` in PHP 8.1
- It needs a `string` in the end (`trim`) so it would be relevant to cast it first. | src/Illuminate/View/Compilers/BladeCompiler.php | @@ -449,6 +449,8 @@ protected function compileStatement($match)
*/
protected function callCustomDirective($name, $value)
{
+ $value = $value ?? '';
+
if (Str::startsWith($value, '(') && Str::endsWith($value, ')')) {
$value = Str::substr($value, 1, -1);
} | false |
Other | laravel | framework | d5ffd8efdd04b11a2b1199cc7f2148337418191f.json | Remove problem matchers (#36246) | .github/workflows/tests.yml | @@ -48,9 +48,6 @@ jobs:
tools: composer:v2
coverage: none
- - name: Setup problem matchers
- run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
-
- name: Set Minimum Guzzle Version
uses: nick-invision/retry@v1
with:
@@ -100,9 +97,6 @@ jobs:
tools: composer:v2
coverage: none
- - name: Setup problem matchers
- run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
-
- name: Set Minimum Guzzle Version
uses: nick-invision/retry@v1
with: | false |
Other | laravel | framework | 4880ca605b47608cc10906cd3ab9690c38006932.json | Update layout.blade.php (#36198)
The mail design in gmail app wasn't responsive, and I managed to solve the problem. | src/Illuminate/Mail/resources/views/html/layout.blade.php | @@ -5,8 +5,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="color-scheme" content="light">
<meta name="supported-color-schemes" content="light">
-</head>
-<body>
<style>
@media only screen and (max-width: 600px) {
.inner-body {
@@ -24,6 +22,8 @@
}
}
</style>
+</head>
+<body>
<table class="wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr> | false |
Other | laravel | framework | 87fe04daf668c4c1de9269a003760e677b575fcb.json | Apply fixes from StyleCI (#36139) | tests/Support/SupportPluralizerTest.php | @@ -77,7 +77,7 @@ public function testPluralNotAppliedForStringEndingWithNonAlphanumericCharacter(
$this->assertSame('Alien ', Str::plural('Alien '));
$this->assertSame('50%', Str::plural('50%'));
}
-
+
public function testPluralAppliedForStringEndingWithNumericCharacter()
{
$this->assertSame('User1s', Str::plural('User1')); | false |
Other | laravel | framework | 1884c4df4cc0d15b0721897153854c55c5e8ccbf.json | Fix incorrect PHPDoc (#36124) | src/Illuminate/Testing/Concerns/TestDatabases.php | @@ -100,7 +100,7 @@ protected function ensureSchemaIsUpToDate()
* Runs the given callable using the given database.
*
* @param string $database
- * @param callable $database
+ * @param callable $callable
* @return void
*/
protected function usingDatabase($database, $callable) | false |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Auth/GuardHelpers.php | @@ -25,7 +25,7 @@ trait GuardHelpers
protected $provider;
/**
- * Determine if current user is authenticated. If not, throw an exception.
+ * Determine if the current user is authenticated. If not, throw an exception.
*
* @return \Illuminate\Contracts\Auth\Authenticatable
* | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Broadcasting/Broadcasters/AblyBroadcaster.php | @@ -120,7 +120,7 @@ public function broadcast(array $channels, $event, array $payload = [])
}
/**
- * Return true if channel is protected by authentication.
+ * Return true if the channel is protected by authentication.
*
* @param string $channel
* @return bool | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Broadcasting/Broadcasters/UsePusherChannelConventions.php | @@ -7,7 +7,7 @@
trait UsePusherChannelConventions
{
/**
- * Return true if channel is protected by authentication.
+ * Return true if the channel is protected by authentication.
*
* @param string $channel
* @return bool | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Console/Scheduling/Event.php | @@ -87,7 +87,7 @@ class Event
public $expiresAt = 1440;
/**
- * Indicates if the command should run in background.
+ * Indicates if the command should run in the background.
*
* @var bool
*/
@@ -587,7 +587,7 @@ protected function pingCallback($url)
}
/**
- * State that the command should run in background.
+ * State that the command should run in the background.
*
* @return $this
*/ | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php | @@ -130,7 +130,7 @@ public static function reguard()
}
/**
- * Determine if current state is "unguarded".
+ * Determine if the current state is "unguarded".
*
* @return bool
*/ | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php | @@ -1525,7 +1525,7 @@ protected function hasChanges($changes, $attributes = null)
}
/**
- * Get the attributes that have been changed since last sync.
+ * Get the attributes that have been changed since the last sync.
*
* @return array
*/ | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Database/Eloquent/Model.php | @@ -1131,7 +1131,7 @@ public function delete()
/**
* Force a hard delete on a soft deleted model.
*
- * This method protects developers from running forceDelete when trait is missing.
+ * This method protects developers from running forceDelete when the trait is missing.
*
* @return bool|null
*/ | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | @@ -569,7 +569,7 @@ public function orderByPivot($column, $direction = 'asc')
}
/**
- * Find a related model by its primary key or return new instance of the related model.
+ * Find a related model by its primary key or return a new instance of the related model.
*
* @param mixed $id
* @param array $columns | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php | @@ -182,7 +182,7 @@ protected function buildDictionary(Collection $results)
}
/**
- * Find a model by its primary key or return new instance of the related model.
+ * Find a model by its primary key or return a new instance of the related model.
*
* @param mixed $id
* @param array $columns | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Database/Eloquent/Relations/Relation.php | @@ -49,7 +49,7 @@ abstract class Relation
protected static $constraints = true;
/**
- * An array to map class names to their morph names in database.
+ * An array to map class names to their morph names in the database.
*
* @var array
*/ | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Database/Migrations/MigrationRepositoryInterface.php | @@ -12,7 +12,7 @@ interface MigrationRepositoryInterface
public function getRan();
/**
- * Get list of migrations.
+ * Get the list of migrations.
*
* @param int $steps
* @return array | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Events/Dispatcher.php | @@ -286,7 +286,7 @@ protected function shouldBroadcast(array $payload)
}
/**
- * Check if event should be broadcasted by condition.
+ * Check if the event should be broadcasted by the condition.
*
* @param mixed $event
* @return bool | true |
Other | laravel | framework | 6319d94ccaf8169b103813a82139814573ddef09.json | Add missing articles (#36122) | src/Illuminate/Foundation/Application.php | @@ -560,7 +560,7 @@ public function environment(...$environments)
}
/**
- * Determine if application is in local environment.
+ * Determine if the application is in the local environment.
*
* @return bool
*/
@@ -570,7 +570,7 @@ public function isLocal()
}
/**
- * Determine if application is in production environment.
+ * Determine if the application is in the production environment.
*
* @return bool
*/
@@ -1260,7 +1260,7 @@ public function setFallbackLocale($fallbackLocale)
}
/**
- * Determine if application locale is the given locale.
+ * Determine if the application locale is the given locale.
*
* @param string $locale
* @return bool | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.