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
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Support/SupportTestingMailFakeTest.php
@@ -23,7 +23,7 @@ class SupportTestingMailFakeTest extends TestCase */ private $mailable; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->fake = new MailFake;
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Support/SupportTestingNotificationFakeTest.php
@@ -27,7 +27,7 @@ class SupportTestingNotificationFakeTest extends TestCase */ private $user; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->fake = new NotificationFake;
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Support/SupportTestingQueueFakeTest.php
@@ -21,7 +21,7 @@ class SupportTestingQueueFakeTest extends TestCase */ private $job; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->fake = new QueueFake(new Application);
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Translation/TranslationFileLoaderTest.php
@@ -9,7 +9,7 @@ class TranslationFileLoaderTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Translation/TranslationTranslatorTest.php
@@ -11,7 +11,7 @@ class TranslationTranslatorTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Validation/ValidationDatabasePresenceVerifierTest.php
@@ -11,7 +11,7 @@ class ValidationDatabasePresenceVerifierTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Validation/ValidationExistsRuleTest.php
@@ -18,7 +18,7 @@ class ValidationExistsRuleTest extends TestCase * * @return void */ - public function setUp() + public function setUp(): void { $db = new DB; @@ -159,7 +159,7 @@ protected function getConnectionResolver() * * @return void */ - public function tearDown() + public function tearDown(): void { $this->schema('default')->drop('users'); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Validation/ValidationFactoryTest.php
@@ -11,7 +11,7 @@ class ValidationFactoryTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/Validation/ValidationValidatorTest.php
@@ -24,7 +24,7 @@ class ValidationValidatorTest extends TestCase { - public function tearDown() + public function tearDown(): void { Carbon::setTestNow(); m::close();
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/Blade/AbstractBladeTestCase.php
@@ -11,13 +11,13 @@ abstract class AbstractBladeTestCase extends TestCase { protected $compiler; - public function setUp() + public function setUp(): void { $this->compiler = new BladeCompiler(m::mock(Filesystem::class), __DIR__); parent::setUp(); } - public function tearDown() + public function tearDown(): void { m::close();
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/Blade/BladeElseAuthStatementsTest.php
@@ -9,7 +9,7 @@ class BladeElseAuthStatementsTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/Blade/BladeElseGuestStatementsTest.php
@@ -9,7 +9,7 @@ class BladeElseGuestStatementsTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/Blade/BladeIfAuthStatementsTest.php
@@ -9,7 +9,7 @@ class BladeIfAuthStatementsTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/Blade/BladeIfGuestStatementsTest.php
@@ -9,7 +9,7 @@ class BladeIfGuestStatementsTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/ViewBladeCompilerTest.php
@@ -9,7 +9,7 @@ class ViewBladeCompilerTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/ViewCompilerEngineTest.php
@@ -9,7 +9,7 @@ class ViewCompilerEngineTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/ViewFactoryTest.php
@@ -22,7 +22,7 @@ class ViewFactoryTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/ViewFileViewFinderTest.php
@@ -9,7 +9,7 @@ class ViewFileViewFinderTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/ViewPhpEngineTest.php
@@ -8,7 +8,7 @@ class ViewPhpEngineTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
8fc3a75b413267a30e41464d358c1d0714a6a186.json
Add void return type to setUp and tearDown methods
tests/View/ViewTest.php
@@ -15,7 +15,7 @@ class ViewTest extends TestCase { - public function tearDown() + public function tearDown(): void { m::close(); }
true
Other
laravel
framework
afd4da5a782f02b9b82427b50a4fcc292bf787a2.json
Allow install of PHPUnit 8
composer.json
@@ -85,7 +85,7 @@ "moontoast/math": "^1.1", "orchestra/testbench-core": "3.8.*", "pda/pheanstalk": "^3.0", - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^7.5|^8.0", "predis/predis": "^1.1.1", "symfony/css-selector": "^4.2", "symfony/dom-crawler": "^4.2",
false
Other
laravel
framework
a309e88344add6f47d8e2dac84feaff1a0deddcb.json
Make ENV variable uppercase in Travis config It's a convention to make ENV variables uppercase so let's also do this here.
.travis.yml
@@ -3,20 +3,20 @@ language: php env: global: - - setup=stable + - SETUP=stable matrix: fast_finish: true include: - php: 7.1 - php: 7.1 - env: setup=lowest + env: SETUP=lowest - php: 7.2 - php: 7.2 - env: setup=lowest + env: SETUP=lowest - php: 7.3 - php: 7.3 - env: setup=lowest + env: SETUP=lowest cache: directories: @@ -35,7 +35,7 @@ before_install: - mysql -e 'CREATE DATABASE forge;' install: - - if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi - - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi + - if [[ $SETUP = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi + - if [[ $SETUP = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi script: vendor/bin/phpunit
false
Other
laravel
framework
8cb5ae73b8ecb649abd38f2548362f0145dc1da5.json
Indicate defer property removal This property was deprecated by an alternative implementation in https://github.com/laravel/framework/pull/27067 and should be removed in the next major release.
src/Illuminate/Support/ServiceProvider.php
@@ -17,7 +17,7 @@ abstract class ServiceProvider /** * Indicates if loading of the provider is deferred. * - * @deprecated 5.8 Implement the \Illuminate\Contracts\Support\DeferrableProvider interface instead. + * @deprecated Implement the \Illuminate\Contracts\Support\DeferrableProvider interface instead. Will be removed in Laravel 5.9. * * @var bool */
false
Other
laravel
framework
44cccf2b27350ad41e93496ba435d1e255b9b8d6.json
Fix event fake dispatch method not returning
src/Illuminate/Support/Testing/Fakes/EventFake.php
@@ -211,7 +211,7 @@ public function dispatch($event, $payload = [], $halt = false) if ($this->shouldFakeEvent($name, $payload)) { $this->events[$name][] = func_get_args(); } else { - $this->dispatcher->dispatch($event, $payload, $halt); + return $this->dispatcher->dispatch($event, $payload, $halt); } }
true
Other
laravel
framework
44cccf2b27350ad41e93496ba435d1e255b9b8d6.json
Fix event fake dispatch method not returning
tests/Integration/Events/EventFakeTest.php
@@ -73,6 +73,24 @@ public function testNonFakedEventGetsProperlyDispatched() Event::assertNotDispatched(NonImportantEvent::class); } + + public function testNonFakedHaltedEventGetsProperlyDispatchedAndReturnsResponse() + { + Event::fake(NonImportantEvent::class); + Event::listen('test', function () { + // one + }); + Event::listen('test', function () { + return 'two'; + }); + Event::listen('test', function () { + $this->fail('should not be called'); + }); + + $this->assertEquals('two', Event::until('test')); + + Event::assertNotDispatched(NonImportantEvent::class); + } } class Post extends Model
true
Other
laravel
framework
d261f9fc75e888fd15895f1354b7ac338638dc47.json
add thenReturn helper method to Pipeline
src/Illuminate/Pipeline/Pipeline.php
@@ -104,6 +104,18 @@ public function then(Closure $destination) return $pipeline($this->passable); } + /** + * Run the pipeline and return the result. + * + * @return mixed + */ + public function thenReturn() + { + return $this->then(function ($passable) { + return $passable; + }); + } + /** * Get the final piece of the Closure onion. *
true
Other
laravel
framework
d261f9fc75e888fd15895f1354b7ac338638dc47.json
add thenReturn helper method to Pipeline
tests/Pipeline/PipelineTest.php
@@ -162,6 +162,19 @@ public function testPipelineThrowsExceptionOnResolveWithoutContainer() return $piped; }); } + + public function testPipelineThenReturnMethodRunsPipelineThenReturnsPassable() + { + $result = (new Pipeline(new Container)) + ->send('foo') + ->through([PipelineTestPipeOne::class]) + ->thenReturn(); + + $this->assertEquals('foo', $result); + $this->assertEquals('foo', $_SERVER['__test.pipe.one']); + + unset($_SERVER['__test.pipe.one']); + } } class PipelineTestPipeOne
true
Other
laravel
framework
e9952e5a07d4cbd664fdac743ede25f10b7abb1c.json
Remove forgotten echo statement
src/Illuminate/Foundation/Console/ServeCommand.php
@@ -51,8 +51,6 @@ public function handle() return $this->handle(); } - echo $status; - return $status; }
false
Other
laravel
framework
a10c50239a6f57e15100e88ed2441f2a1d1911a8.json
Apply fixes from StyleCI (#27423)
src/Illuminate/Foundation/Console/ServeCommand.php
@@ -92,7 +92,7 @@ protected function port() } /** - * Check if command has reached its max amount of port tries + * Check if command has reached its max amount of port tries. * * @return bool */
false
Other
laravel
framework
04b751f3f274d7ae454cb703482ca38911947f81.json
Remove unnecessary temporary variable
src/Illuminate/Database/Eloquent/Concerns/HasEvents.php
@@ -365,13 +365,11 @@ public static function withoutEventDispatcher(callable $callback) static::unsetEventDispatcher(); try { - $result = $callback(); + return $callback(); } finally { if ($dispatcher) { static::setEventDispatcher($dispatcher); } } - - return $result; } }
false
Other
laravel
framework
3c907066923823ff8e3f6079f8f49bf4eb9a6c26.json
Fix style violation
tests/Database/DatabaseEloquentModelTest.php
@@ -1338,6 +1338,7 @@ public function testWithoutEventDispatcher() $model = EloquentModelSaveStub::withoutEventDispatcher(function () { $model = new EloquentModelSaveStub; $model->save(); + return $model; });
false
Other
laravel
framework
645e622a519f5bc8a52ddabf1cd6507fd5d57d39.json
Add Model::withoutEventDispatcher() method It is sometimes desirable to bypass model events temporarily. For example, when seeding. While it is already possible to do this, the code is verbose. This aims to simplify that by creating an intuitively named helper method to execute a callback with the event dispatcher temporarily disabled, returning the result of the callback.
src/Illuminate/Database/Eloquent/Concerns/HasEvents.php
@@ -351,4 +351,27 @@ public static function unsetEventDispatcher() { static::$dispatcher = null; } + + /** + * Execute a callback without the event dispatcher. + * + * @param callable $callback + * @return mixed + */ + public static function withoutEventDispatcher(callable $callback) + { + $dispatcher = static::getEventDispatcher(); + + static::unsetEventDispatcher(); + + try { + $result = $callback(); + } finally { + if ($dispatcher) { + static::setEventDispatcher($dispatcher); + } + } + + return $result; + } }
true
Other
laravel
framework
645e622a519f5bc8a52ddabf1cd6507fd5d57d39.json
Add Model::withoutEventDispatcher() method It is sometimes desirable to bypass model events temporarily. For example, when seeding. While it is already possible to do this, the code is verbose. This aims to simplify that by creating an intuitively named helper method to execute a callback with the event dispatcher temporarily disabled, returning the result of the callback.
tests/Database/DatabaseEloquentModelTest.php
@@ -1325,6 +1325,30 @@ public function testModelObserversCanBeAttachedToModelsThroughCallingObserveMeth EloquentModelStub::flushEventListeners(); } + public function testWithoutEventDispatcher() + { + EloquentModelSaveStub::setEventDispatcher($events = m::mock(Dispatcher::class)); + $events->shouldReceive('listen')->once()->with('eloquent.creating: Illuminate\Tests\Database\EloquentModelSaveStub', EloquentTestObserverStub::class.'@creating'); + $events->shouldReceive('listen')->once()->with('eloquent.saved: Illuminate\Tests\Database\EloquentModelSaveStub', EloquentTestObserverStub::class.'@saved'); + $events->shouldNotReceive('until'); + $events->shouldNotReceive('dispatch'); + $events->shouldReceive('forget'); + EloquentModelSaveStub::observe(EloquentTestObserverStub::class); + + $model = EloquentModelSaveStub::withoutEventDispatcher(function () { + $model = new EloquentModelSaveStub; + $model->save(); + return $model; + }); + + $model->withoutEventDispatcher(function () use ($model) { + $model->name = 'Taylor'; + $model->save(); + }); + + EloquentModelSaveStub::flushEventListeners(); + } + public function testSetObservableEvents() { $class = new EloquentModelStub; @@ -1976,7 +2000,13 @@ class EloquentModelSaveStub extends Model public function save(array $options = []) { + if ($this->fireModelEvent('saving') === false) { + return false; + } + $_SERVER['__eloquent.saved'] = true; + + $this->fireModelEvent('saved', false); } public function setIncrementing($value)
true
Other
laravel
framework
7376daca412c5ff99d9807e7d27159221ef959d8.json
Add 2 test cases for negative pad size
tests/Support/SupportCollectionTest.php
@@ -2157,6 +2157,14 @@ public function testPadPadsArrayWithValue() $c = new Collection([1, 2, 3, 4, 5]); $c = $c->pad(4, 0); $this->assertEquals([1, 2, 3, 4, 5], $c->all()); + + $c = new Collection([1, 2, 3]); + $c = $c->pad(-4, 0); + $this->assertEquals([0, 1, 2, 3], $c->all()); + + $c = new Collection([1, 2, 3, 4, 5]); + $c = $c->pad(-4, 0); + $this->assertEquals([1, 2, 3, 4, 5], $c->all()); } public function testGettingMaxItemsFromCollection()
false
Other
laravel
framework
a464b5c70cdb12b1eaab5fb84be1d24b71bec804.json
Add test for change
src/Illuminate/Foundation/Application.php
@@ -970,7 +970,7 @@ public function abort($code, $message = '', array $headers = []) /** * Register a terminating callback with the application. * - * @param mixed $callback + * @param callable|string $callback * @return $this */ public function terminating($callback)
true
Other
laravel
framework
a464b5c70cdb12b1eaab5fb84be1d24b71bec804.json
Add test for change
tests/Foundation/FoundationApplicationTest.php
@@ -218,6 +218,16 @@ public function testAfterBootstrappingAddsClosure() $app->afterBootstrapping(RegisterFacades::class, $closure); $this->assertArrayHasKey(0, $app['events']->getListeners('bootstrapped: Illuminate\Foundation\Bootstrap\RegisterFacades')); } + + public function testTerminationCallbacksCanAcceptAtNotation() + { + $app = new Application; + $app->terminating(ConcreteTerminator::class.'@terminate'); + + $app->terminate(); + + $this->assertEquals(1, ConcreteTerminator::$counter); + } } class ApplicationBasicServiceProviderStub extends ServiceProvider @@ -307,3 +317,13 @@ class ConcreteClass extends AbstractClass { // } + +class ConcreteTerminator +{ + public static $counter = 0; + + public function terminate() + { + return self::$counter++; + } +}
true
Other
laravel
framework
6c2892f04dcbbd0c294cf60f2b82e4351d3231cc.json
remove the type hint from the signature
src/Illuminate/Foundation/Application.php
@@ -970,10 +970,10 @@ public function abort($code, $message = '', array $headers = []) /** * Register a terminating callback with the application. * - * @param \Closure $callback + * @param mixed $callback * @return $this */ - public function terminating(Closure $callback) + public function terminating($callback) { $this->terminatingCallbacks[] = $callback;
false
Other
laravel
framework
5b2bc35ecd271eaf7d4dc8f37f1399811edd2a37.json
Add missing tests
tests/Foundation/FoundationApplicationTest.php
@@ -209,6 +209,32 @@ public function testBeforeBootstrappingAddsClosure() $this->assertArrayHasKey(0, $app['events']->getListeners('bootstrapping: Illuminate\Foundation\Bootstrap\RegisterFacades')); } + public function testTerminationTests() + { + $app = new Application; + + $counter = 0; + $callback1 = function () use (&$counter) { + $counter++; + }; + + $callback2 = function () use (&$counter) { + $counter++; + }; + + $callback3 = function () use (&$counter) { + $counter++; + }; + + $app->terminating($callback1); + $app->terminating($callback2); + $app->terminating($callback3); + + $app->terminate(); + + $this->assertEquals(3, $counter); + } + public function testAfterBootstrappingAddsClosure() { $app = new Application;
false
Other
laravel
framework
c1984c9715e980e7f545fe70db0f997c87a70bd7.json
apply suggestions from @staudenmeir
src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php
@@ -79,14 +79,13 @@ protected function removeMissingValues($data) $value->resource instanceof PotentiallyMissing && $value->isMissing())) { unset($data[$key]); + } else { + $numericKeys = $numericKeys && is_numeric($key); } - $numericKeys = $numericKeys && is_numeric($key); } if (property_exists($this, 'preserveKeys') && $this->preserveKeys === true) { - $values = array_values($data); - - return $values === $data ? $values : $data; + return $data; } return $numericKeys ? array_values($data) : $data;
true
Other
laravel
framework
c1984c9715e980e7f545fe70db0f997c87a70bd7.json
apply suggestions from @staudenmeir
tests/Integration/Http/ResourceTest.php
@@ -878,6 +878,27 @@ public function test_the_resource_can_be_an_array() ]); } + public function test_it_will_return_as_an_array_when_string_keys_are_stripped() + { + $this->assertJsonResourceResponse([ + 1 => 'John', + 2 => 'Hank', + 'foo' => new MissingValue, + ], ['data' => ['John', 'Hank']]); + + $this->assertJsonResourceResponse([ + 1 => 'John', + 'foo' => new MissingValue, + 3 => 'Hank', + ], ['data' => ['John', 'Hank']]); + + $this->assertJsonResourceResponse([ + 'foo' => new MissingValue, + 2 => 'John', + 3 => 'Hank', + ], ['data' => ['John', 'Hank']]); + } + public function test_it_strips_numeric_keys() { $this->assertJsonResourceResponse([
true
Other
laravel
framework
e689ae9869bf264b9fcc8aac4b006a256798f693.json
Add missing type to param in docblock
src/Illuminate/Http/Resources/MergeValue.php
@@ -17,7 +17,7 @@ class MergeValue /** * Create new merge value instance. * - * @param \Illuminate\Support\Collection|array $data + * @param \Illuminate\Support\Collection|JsonSerializable|array $data * @return void */ public function __construct($data)
false
Other
laravel
framework
b02b368a732aefbcdc2a739800880334ed247d11.json
fix unauthenticated return docblock
src/Illuminate/Foundation/Exceptions/Handler.php
@@ -212,7 +212,7 @@ protected function prepareException(Exception $e) * * @param \Illuminate\Http\Request $request * @param \Illuminate\Auth\AuthenticationException $exception - * @return \Illuminate\Http\Response + * @return \Symfony\Component\HttpFoundation\Response */ protected function unauthenticated($request, AuthenticationException $exception) {
false
Other
laravel
framework
1d7fafc50ec24e4506054abfcb9b384fb2aa7382.json
Add period to end of sentence
tests/Integration/Queue/ModelSerializationTest.php
@@ -187,7 +187,7 @@ public function test_it_reloads_nested_relationships() } /** - * Regression test for https://github.com/laravel/framework/issues/23068 + * Regression test for https://github.com/laravel/framework/issues/23068. */ public function test_it_can_unserialize_nested_relationships_without_pivot() {
false
Other
laravel
framework
5138a5ccce405751988934eacc627bb4f3cc7bed.json
Add tests for SQL Server computed support
tests/Database/DatabaseSqlServerSchemaGrammarTest.php
@@ -770,6 +770,17 @@ public function testAddingMultiPolygon() $this->assertEquals('alter table "geo" add "coordinates" geography not null', $statements[0]); } + public function testAddingGeneratedColumn() + { + $blueprint = new Blueprint('products'); + $blueprint->integer('price'); + $blueprint->virtual('discounted_virtual', 'price - 5'); + $blueprint->virtual('discounted_stored', 'price - 5')->persisted(); + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); + $this->assertCount(1, $statements); + $this->assertEquals('alter table "products" add "price" int not null, add "discounted_virtual" as (price - 5), add "discounted_stored" as (price - 5) persisted', $statements[0]); + } + public function testGrammarsAreMacroable() { // compileReplace macro.
false
Other
laravel
framework
0fc4965f052b19fbd572afa69c0882bbcc0f9dc2.json
Add computed support to SQL Server schema grammar [SQL Server also supports computed columns (Azure & 2016+)](https://docs.microsoft.com/en-us/sql/relational-databases/tables/specify-computed-columns-in-a-table), but as a type; not a modifier. Add virtual column type Document persisted (SQL Server) column modifier
src/Illuminate/Database/Schema/Blueprint.php
@@ -822,6 +822,18 @@ public function unsignedDecimal($column, $total = 8, $places = 2) ]); } + /** + * Create a new generated virtual column on the table. + * + * @param string $column + * @param string $formula + * @return \Illuminate\Database\Schema\ColumnDefinition + */ + public function virtual($column, $formula) + { + return $this->addColumn('virtual', $column, compact('formula')); + } + /** * Create a new boolean column on the table. *
true
Other
laravel
framework
0fc4965f052b19fbd572afa69c0882bbcc0f9dc2.json
Add computed support to SQL Server schema grammar [SQL Server also supports computed columns (Azure & 2016+)](https://docs.microsoft.com/en-us/sql/relational-databases/tables/specify-computed-columns-in-a-table), but as a type; not a modifier. Add virtual column type Document persisted (SQL Server) column modifier
src/Illuminate/Database/Schema/ColumnDefinition.php
@@ -24,6 +24,7 @@ * @method ColumnDefinition unsigned() Set the INTEGER column as UNSIGNED (MySQL) * @method ColumnDefinition useCurrent() Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value * @method ColumnDefinition virtualAs(string $expression) Create a virtual generated column (MySQL) + * @method ColumnDefinition persisted() Mark the virtual generated column as persistent (SQL Server) */ class ColumnDefinition extends Fluent {
true
Other
laravel
framework
0fc4965f052b19fbd572afa69c0882bbcc0f9dc2.json
Add computed support to SQL Server schema grammar [SQL Server also supports computed columns (Azure & 2016+)](https://docs.microsoft.com/en-us/sql/relational-databases/tables/specify-computed-columns-in-a-table), but as a type; not a modifier. Add virtual column type Document persisted (SQL Server) column modifier
src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
@@ -19,7 +19,7 @@ class SqlServerGrammar extends Grammar * * @var array */ - protected $modifiers = ['Increment', 'Collate', 'Nullable', 'Default']; + protected $modifiers = ['Increment', 'Collate', 'Nullable', 'Default', 'Persisted']; /** * The columns available as serials. @@ -733,6 +733,18 @@ public function typeMultiPolygon(Fluent $column) return 'geography'; } + + /** + * Create the column definition for a generated virtual column type. + * + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function typeVirtual(Fluent $column) + { + return " as ({$column->formula})"; + } + /** * Get the SQL for a collation column modifier. * @@ -756,7 +768,9 @@ protected function modifyCollate(Blueprint $blueprint, Fluent $column) */ protected function modifyNullable(Blueprint $blueprint, Fluent $column) { - return $column->nullable ? ' null' : ' not null'; + if($column->type !== 'virtual') { + return $column->nullable ? ' null' : ' not null'; + } } /** @@ -787,6 +801,20 @@ protected function modifyIncrement(Blueprint $blueprint, Fluent $column) } } + /** + * Get the SQL for a generated stored column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyPersisted(Blueprint $blueprint, Fluent $column) + { + if ($column->persisted) { + return ' persisted'; + } + } + /** * Wrap a table in keyword identifiers. *
true
Other
laravel
framework
8999f5eebadee2433c8ad1ef8837a90de111fcc9.json
Allow lenient log stacks
src/Illuminate/Log/LogManager.php
@@ -15,6 +15,7 @@ use Monolog\Handler\HandlerInterface; use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\SlackWebhookHandler; +use Monolog\Handler\WhatFailureGroupHandler; class LogManager implements LoggerInterface { @@ -216,6 +217,10 @@ protected function createStackDriver(array $config) return $this->channel($channel)->getHandlers(); })->all(); + if ($config['lenient'] ?? false) { + $handlers = [new WhatFailureGroupHandler($handlers)]; + } + return new Monolog($this->parseChannel($config), $handlers); }
false
Other
laravel
framework
1730fa0ea30c83a7ee5e85ef616d7b5bf0de498e.json
Add Azure SQL Server "connection lost" message
src/Illuminate/Database/DetectsLostConnections.php
@@ -38,6 +38,7 @@ protected function causedByLostConnection(Throwable $e) 'ORA-03114', 'Packets out of order. Expected', 'Adaptive Server connection failed', + 'Communication link failure', ]); } }
false
Other
laravel
framework
4c6849dbab40e585097db3124eae6fa01cd9e322.json
Apply fixes from StyleCI (#27294)
src/Illuminate/Database/Eloquent/HigherOrderBuilderProxy.php
@@ -2,8 +2,6 @@ namespace Illuminate\Database\Eloquent; -use Illuminate\Database\Eloquent\Builder; - /** * @mixin \Illuminate\Database\Eloquent\Builder */
false
Other
laravel
framework
d9ea96e554abc6db534b0454a77dc063123256aa.json
Apply fixes from StyleCI (#27293)
src/Illuminate/Database/Eloquent/HigherOrderBuilderProxy.php
@@ -2,8 +2,6 @@ namespace Illuminate\Database\Eloquent; -use Illuminate\Database\Eloquent\Builder; - /** * @mixin \Illuminate\Database\Eloquent\Builder */
false
Other
laravel
framework
6fc5d25e2314a24c02ce1bdf6fa11b6cf7bddb2d.json
Add file method to ResponseFactory contract
src/Illuminate/Contracts/Routing/ResponseFactory.php
@@ -89,6 +89,15 @@ public function streamDownload($callback, $name = null, array $headers = [], $di */ public function download($file, $name = null, array $headers = [], $disposition = 'attachment'); + /** + * Return the raw contents of a binary file. + * + * @param \SplFileInfo|string $file + * @param array $headers + * @return \Symfony\Component\HttpFoundation\BinaryFileResponse + */ + public function file($file, array $headers = []); + /** * Create a new redirect response to the given path. *
false
Other
laravel
framework
f2cba5f6af47f7a220eb39195752b5be37a16e7f.json
Add comments to the Lua scripts
src/Illuminate/Queue/LuaScripts.php
@@ -95,6 +95,7 @@ public static function migrateExpiredJobs() for i = 1, #val, 100 do redis.call('rpush', KEYS[2], unpack(val, i, math.min(i+99, #val))) + -- Push a notification for every job that was migrated... if KEYS[3] ~= nil then for j = 1, math.min(i+99, #val) do redis.call('rpush', KEYS[3], 1) @@ -119,7 +120,9 @@ public static function migrateExpiredJobs() public static function push() { return <<<'LUA' +-- Push the job onto the queue... redis.call('rpush', KEYS[1], ARGV[1]) +-- Push a notification onto the "notify" queue... if KEYS[2] ~= nil then redis.call('rpush', KEYS[2], 1) end
false
Other
laravel
framework
d3cd5d9b75a11cc4172929e7585635d8360a592f.json
Remove unused bootstrap class This class isn't available in Bootstrap 4.
src/Illuminate/Foundation/Console/Presets/vue-stubs/ExampleComponent.vue
@@ -2,7 +2,7 @@ <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> - <div class="card card-default"> + <div class="card"> <div class="card-header">Example Component</div> <div class="card-body">
false
Other
laravel
framework
c537be971fb0c2da051d4c35438dca327ab9efca.json
Update components with new cache TTL
src/Illuminate/Console/Scheduling/CacheEventMutex.php
@@ -40,7 +40,7 @@ public function __construct(Cache $cache) public function create(Event $event) { return $this->cache->store($this->store)->add( - $event->mutexName(), true, $event->expiresAt + $event->mutexName(), true, $event->expiresAt * 60 ); }
true
Other
laravel
framework
c537be971fb0c2da051d4c35438dca327ab9efca.json
Update components with new cache TTL
src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php
@@ -42,7 +42,7 @@ public function __construct(Cache $cache) public function create(Event $event, DateTimeInterface $time) { return $this->cache->store($this->store)->add( - $event->mutexName().$time->format('Hi'), true, 60 + $event->mutexName().$time->format('Hi'), true, 3600 ); }
true
Other
laravel
framework
c537be971fb0c2da051d4c35438dca327ab9efca.json
Update components with new cache TTL
src/Illuminate/Filesystem/Cache.php
@@ -22,9 +22,9 @@ class Cache extends AbstractCache protected $key; /** - * The cache expiration time in minutes. + * The cache expiration time in seconds. * - * @var int + * @var int|null */ protected $expire; @@ -39,10 +39,7 @@ public function __construct(Repository $repository, $key = 'flysystem', $expire { $this->key = $key; $this->repository = $repository; - - if (! is_null($expire)) { - $this->expire = (int) ceil($expire / 60); - } + $this->expire = $expire; } /**
true
Other
laravel
framework
c537be971fb0c2da051d4c35438dca327ab9efca.json
Update components with new cache TTL
src/Illuminate/Foundation/Auth/ThrottlesLogins.php
@@ -33,7 +33,7 @@ protected function hasTooManyLoginAttempts(Request $request) protected function incrementLoginAttempts(Request $request) { $this->limiter()->hit( - $this->throttleKey($request), $this->decayMinutes() + $this->throttleKey($request), $this->decayMinutes() * 60 ); }
true
Other
laravel
framework
c537be971fb0c2da051d4c35438dca327ab9efca.json
Update components with new cache TTL
src/Illuminate/Routing/Middleware/ThrottleRequests.php
@@ -53,7 +53,7 @@ public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes throw $this->buildException($key, $maxAttempts); } - $this->limiter->hit($key, $decayMinutes); + $this->limiter->hit($key, $decayMinutes * 60); $response = $next($request);
true
Other
laravel
framework
c537be971fb0c2da051d4c35438dca327ab9efca.json
Update components with new cache TTL
src/Illuminate/Session/CacheBasedSessionHandler.php
@@ -63,7 +63,7 @@ public function read($sessionId) */ public function write($sessionId, $data) { - return $this->cache->put($sessionId, $data, $this->minutes); + return $this->cache->put($sessionId, $data, $this->minutes * 60); } /**
true
Other
laravel
framework
c537be971fb0c2da051d4c35438dca327ab9efca.json
Update components with new cache TTL
tests/Console/Scheduling/CacheSchedulingMutexTest.php
@@ -52,23 +52,23 @@ public function setUp() public function testMutexReceivesCorrectCreate() { - $this->cacheRepository->shouldReceive('add')->once()->with($this->event->mutexName().$this->time->format('Hi'), true, 60)->andReturn(true); + $this->cacheRepository->shouldReceive('add')->once()->with($this->event->mutexName().$this->time->format('Hi'), true, 3600)->andReturn(true); $this->assertTrue($this->cacheMutex->create($this->event, $this->time)); } public function testCanUseCustomConnection() { $this->cacheFactory->shouldReceive('store')->with('test')->andReturn($this->cacheRepository); - $this->cacheRepository->shouldReceive('add')->once()->with($this->event->mutexName().$this->time->format('Hi'), true, 60)->andReturn(true); + $this->cacheRepository->shouldReceive('add')->once()->with($this->event->mutexName().$this->time->format('Hi'), true, 3600)->andReturn(true); $this->cacheMutex->useStore('test'); $this->assertTrue($this->cacheMutex->create($this->event, $this->time)); } public function testPreventsMultipleRuns() { - $this->cacheRepository->shouldReceive('add')->once()->with($this->event->mutexName().$this->time->format('Hi'), true, 60)->andReturn(false); + $this->cacheRepository->shouldReceive('add')->once()->with($this->event->mutexName().$this->time->format('Hi'), true, 3600)->andReturn(false); $this->assertFalse($this->cacheMutex->create($this->event, $this->time)); }
true
Other
laravel
framework
a091aec8add9f7a603918e60873a242cc7e84cdc.json
Add missing fallback to put method
src/Illuminate/Contracts/Cache/Repository.php
@@ -24,7 +24,7 @@ public function pull($key, $default = null); * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @return bool */ - public function put($key, $value, $minutes); + public function put($key, $value, $minutes = null); /** * Store an item in the cache if the key does not exist.
false
Other
laravel
framework
33eff6c5ed4e48e79eb36811fb6246e7c35dfda2.json
Implement higher order orWhere for simpler scopes
src/Illuminate/Database/Eloquent/Builder.php
@@ -3,17 +3,20 @@ namespace Illuminate\Database\Eloquent; use Closure; +use Exception; use BadMethodCallException; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Pagination\Paginator; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Traits\ForwardsCalls; use Illuminate\Database\Concerns\BuildsQueries; +use Illuminate\Support\HigherOrderBuilderProxy; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Query\Builder as QueryBuilder; /** + * @property-read HigherOrderBuilderProxy $orWhere * @mixin \Illuminate\Database\Query\Builder */ class Builder @@ -1360,4 +1363,21 @@ public function __clone() { $this->query = clone $this->query; } + + /** + * Dynamically access builder proxies. + * + * @param string $key + * @return mixed + * + * @throws \Exception + */ + public function __get($key) + { + if ($key === 'orWhere') { + return new HigherOrderBuilderProxy($this, $key); + } + + throw new Exception("Property [{$key}] does not exist on this builder instance."); + } }
true
Other
laravel
framework
33eff6c5ed4e48e79eb36811fb6246e7c35dfda2.json
Implement higher order orWhere for simpler scopes
src/Illuminate/Support/HigherOrderBuilderProxy.php
@@ -0,0 +1,51 @@ +<?php + +namespace Illuminate\Support; + +use Illuminate\Database\Eloquent\Builder; + +/** + * @mixin \Illuminate\Database\Eloquent\Builder + */ +class HigherOrderBuilderProxy +{ + /** + * The collection being operated on. + * + * @var \Illuminate\Database\Eloquent\Builder + */ + protected $builder; + + /** + * The method being proxied. + * + * @var string + */ + protected $method; + + /** + * Create a new proxy instance. + * + * @param Builder $builder + * @param string $method + */ + public function __construct(Builder $builder, $method) + { + $this->method = $method; + $this->builder = $builder; + } + + /** + * Proxy a scope call onto the query builder. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + return $this->builder->{$this->method}(function ($value) use ($method, $parameters) { + return $value->{$method}(...$parameters); + }); + } +}
true
Other
laravel
framework
33eff6c5ed4e48e79eb36811fb6246e7c35dfda2.json
Implement higher order orWhere for simpler scopes
tests/Database/DatabaseEloquentBuilderTest.php
@@ -628,6 +628,22 @@ public function testRealNestedWhereWithMultipleScopesAndOneDeadScope() $this->assertEquals(['bar', 9000], $query->getBindings()); } + public function testRealQueryHigherOrderOrWhereScopes() + { + $model = new EloquentBuilderTestHigherOrderWhereScopeStub; + $this->mockConnectionForModel($model, 'SQLite'); + $query = $model->newQuery()->one()->orWhere->two(); + $this->assertEquals('select * from "table" where "one" = ? or ("two" = ?)', $query->toSql()); + } + + public function testRealQueryChainedHigherOrderOrWhereScopes() + { + $model = new EloquentBuilderTestHigherOrderWhereScopeStub; + $this->mockConnectionForModel($model, 'SQLite'); + $query = $model->newQuery()->one()->orWhere->two()->orWhere->three(); + $this->assertEquals('select * from "table" where "one" = ? or ("two" = ?) or ("three" = ?)', $query->toSql()); + } + public function testSimpleWhere() { $builder = $this->getBuilder(); @@ -1105,6 +1121,26 @@ public function scopeApproved($query) } } +class EloquentBuilderTestHigherOrderWhereScopeStub extends Model +{ + protected $table = 'table'; + + public function scopeOne($query) + { + $query->where('one', 'foo'); + } + + public function scopeTwo($query) + { + $query->where('two', 'bar'); + } + + public function scopeThree($query) + { + $query->where('three', 'baz'); + } +} + class EloquentBuilderTestNestedStub extends Model { protected $table = 'table';
true
Other
laravel
framework
df153ce876e644c74357dd1310dedd983dc40446.json
Use config for verification expiry time
src/Illuminate/Auth/Notifications/VerifyEmail.php
@@ -59,7 +59,7 @@ public function toMail($notifiable) protected function verificationUrl($notifiable) { return URL::temporarySignedRoute( - 'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()] + 'verification.verify', Carbon::now()->addMinutes(config('auth.verification.expire', 60)), ['id' => $notifiable->getKey()] ); }
false
Other
laravel
framework
0e7e8e52e9925662774e67ed24dd4f98ffd53cbd.json
Fix return type
src/Illuminate/Cache/CacheManager.php
@@ -222,7 +222,7 @@ protected function createDatabaseDriver(array $config) * Create an instance of the DynamoDB cache driver. * * @param array $config - * @return \Illuminate\Cache\DynamoDbStore + * @return \Illuminate\Cache\Repository */ protected function createDynamodbDriver(array $config) {
false
Other
laravel
framework
83510499970ca402c0a97d7fb3e310c4cf801cbe.json
Fix method signature in DocBlock
src/Illuminate/Support/Facades/URL.php
@@ -12,8 +12,8 @@ * @method static string route(string $name, $parameters = [], bool $absolute = true) * @method static string action(string $action, $parameters = [], bool $absolute = true) * @method static \Illuminate\Contracts\Routing\UrlGenerator setRootControllerNamespace(string $rootNamespace) - * @method static string signedRoute(string $name, array $parameters = [], \DateTimeInterface|int $expiration = null) - * @method static string temporarySignedRoute(string $name, \DateTimeInterface|int $expiration, array $parameters = []) + * @method static string signedRoute(string $name, array $parameters = [], \DateTimeInterface|\DateInterval|int $expiration = null) + * @method static string temporarySignedRoute(string $name, \DateTimeInterface|\DateInterval|int $expiration, array $parameters = []) * @method static string hasValidSignature(\Illuminate\Http\Request $request, bool $absolute) * @method static void defaults(array $defaults) *
false
Other
laravel
framework
e89a7bfb7f5dcf322bf9a2ea2f20a849122d4bdb.json
Rename the test functions.
tests/Pagination/LengthAwarePaginatorTest.php
@@ -104,7 +104,7 @@ public function testLengthAwarePaginatorCorrectlyGenerateUrlsWithQueryAndSpaces( $this->p->url($this->p->currentPage())); } - public function testItRetrievesPaginatorOptions() + public function testItRetrievesThePaginatorOptions() { $this->assertSame($this->options, $this->p->getOptions()); }
true
Other
laravel
framework
e89a7bfb7f5dcf322bf9a2ea2f20a849122d4bdb.json
Rename the test functions.
tests/Pagination/PaginatorTest.php
@@ -47,7 +47,7 @@ public function testPaginatorGeneratesUrlsWithoutTrailingSlash() $this->assertEquals('http://website.com/test?page=1', $p->previousPageUrl()); } - public function testItRetrievesPaginatorOptions() + public function testItRetrievesThePaginatorOptions() { $p = new Paginator($array = ['item1', 'item2', 'item3'], 2, 2, $options = ['path' => 'http://website.com/test']);
true
Other
laravel
framework
9e25f7d21721a0c13d04679fa59a68a8c788fdbc.json
Apply parameters to entire localization array When calling ```php __('foobar', ['foo' => 'bar']); ``` to retrieve an entire localization array, the parameters are not applied. This minor change applies parameters to all lines retrieved.
src/Illuminate/Translation/Translator.php
@@ -244,6 +244,9 @@ protected function getLine($namespace, $group, $locale, $item, array $replace) if (is_string($line)) { return $this->makeReplacements($line, $replace); } elseif (is_array($line) && count($line) > 0) { + foreach($line as $key => $val) { + $line[$key] = $this->makeReplacements($val, $replace); + } return $line; } }
false
Other
laravel
framework
3c5fd2873f7225d884e1c88fb5877ae69ce8b644.json
Fix return types in CacheManager The current return types aren't correct as an instance of a repository is returned each time instead of the store itself.
src/Illuminate/Cache/CacheManager.php
@@ -124,7 +124,7 @@ protected function callCustomCreator(array $config) * Create an instance of the APC cache driver. * * @param array $config - * @return \Illuminate\Cache\ApcStore + * @return \Illuminate\Cache\Repository */ protected function createApcDriver(array $config) { @@ -136,7 +136,7 @@ protected function createApcDriver(array $config) /** * Create an instance of the array cache driver. * - * @return \Illuminate\Cache\ArrayStore + * @return \Illuminate\Cache\Repository */ protected function createArrayDriver() { @@ -147,7 +147,7 @@ protected function createArrayDriver() * Create an instance of the file cache driver. * * @param array $config - * @return \Illuminate\Cache\FileStore + * @return \Illuminate\Cache\Repository */ protected function createFileDriver(array $config) { @@ -158,7 +158,7 @@ protected function createFileDriver(array $config) * Create an instance of the Memcached cache driver. * * @param array $config - * @return \Illuminate\Cache\MemcachedStore + * @return \Illuminate\Cache\Repository */ protected function createMemcachedDriver(array $config) { @@ -177,7 +177,7 @@ protected function createMemcachedDriver(array $config) /** * Create an instance of the Null cache driver. * - * @return \Illuminate\Cache\NullStore + * @return \Illuminate\Cache\Repository */ protected function createNullDriver() { @@ -188,7 +188,7 @@ protected function createNullDriver() * Create an instance of the Redis cache driver. * * @param array $config - * @return \Illuminate\Cache\RedisStore + * @return \Illuminate\Cache\Repository */ protected function createRedisDriver(array $config) { @@ -203,7 +203,7 @@ protected function createRedisDriver(array $config) * Create an instance of the database cache driver. * * @param array $config - * @return \Illuminate\Cache\DatabaseStore + * @return \Illuminate\Cache\Repository */ protected function createDatabaseDriver(array $config) { @@ -300,7 +300,7 @@ public function forgetDriver($name = null) /** * Register a custom driver creator Closure. * - * @param string $driver + * @param string $driver * @param \Closure $callback * @return $this */ @@ -315,7 +315,7 @@ public function extend($driver, Closure $callback) * Dynamically call the default driver instance. * * @param string $method - * @param array $parameters + * @param array $parameters * @return mixed */ public function __call($method, $parameters)
false
Other
laravel
framework
5a6a46bcb8dfd556c1e84e47df77cee8fc108ad7.json
Fix some docblocks and smaller things
src/Illuminate/Cache/DynamoDbStore.php
@@ -31,21 +31,21 @@ class DynamoDbStore implements Store /** * The name of the attribute that should hold the key. * - * @var string + * @var string */ protected $keyAttribute; /** * The name of the attribute that should hold the value. * - * @var string + * @var string */ protected $valueAttribute; /** * The name of the attribute that should hold the expiration timestamp. * - * @var string + * @var string */ protected $expirationAttribute; @@ -214,7 +214,7 @@ public function put($key, $value, $minutes) * * @param array $values * @param float|int $minutes - * @return void + * @return bool */ public function putMany(array $values, $minutes) { @@ -256,7 +256,7 @@ public function putMany(array $values, $minutes) public function add($key, $value, $minutes) { try { - $response = $this->dynamo->putItem([ + $this->dynamo->putItem([ 'TableName' => $this->table, 'Item' => [ $this->keyAttribute => [ @@ -295,7 +295,7 @@ public function add($key, $value, $minutes) * Increment the value of an item in the cache. * * @param string $key - * @param mixed $value + * @param mixed $value * @return int|bool */ public function increment($key, $value = 1) @@ -340,7 +340,7 @@ public function increment($key, $value = 1) * Decrement the value of an item in the cache. * * @param string $key - * @param mixed $value + * @param mixed $value * @return int|bool */ public function decrement($key, $value = 1) @@ -385,8 +385,8 @@ public function decrement($key, $value = 1) * Store an item in the cache indefinitely. * * @param string $key - * @param mixed $value - * @return void + * @param mixed $value + * @return bool */ public function forever($key, $value) {
false
Other
laravel
framework
1a43d7dbfc98f45841f817b0b6f45f2781275817.json
Use config to resolve database value.
src/Illuminate/Foundation/Testing/RefreshDatabase.php
@@ -25,9 +25,9 @@ public function refreshDatabase() */ protected function usingInMemoryDatabase() { - return config('database.connections')[ - config('database.default') - ]['database'] === ':memory:'; + $default = config('database.default'); + + return config("database.connections.$default.database") === ':memory:'; } /**
false
Other
laravel
framework
0a0442bf3d3516562c8f8e15a97cf69e0dfaece5.json
Use a Lua script for RedisQueue::push
src/Illuminate/Queue/LuaScripts.php
@@ -104,6 +104,26 @@ public static function migrateExpiredJobs() end return val +LUA; + } + + /** + * Get the Lua script for pushing jobs onto the queue. + * + * KEYS[1] - The queue to push the job onto, for example: queues:foo + * KEYS[2] - The notification list fot the queue we are pushing jobs onto, for example: queues:foo:notify + * ARGV[1] - The job payload + * + * @return string + */ + public static function push() + { + return <<<'LUA' +redis.call('rpush', KEYS[1], ARGV[1]) +if KEYS[2] ~= nil then + redis.call('rpush', KEYS[2], 1) +end +return cjson.decode(ARGV[1])['id'] LUA; } }
true
Other
laravel
framework
0a0442bf3d3516562c8f8e15a97cf69e0dfaece5.json
Use a Lua script for RedisQueue::push
src/Illuminate/Queue/RedisQueue.php
@@ -88,16 +88,7 @@ public function size($queue = null) */ public function push($job, $data = '', $queue = null) { - if (is_null($this->blockFor)) { - return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue); - } - - $this->getConnection()->multi(); - $this->getConnection()->rpush($this->getQueue($queue).':notify', '1'); - $id = $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue); - $this->getConnection()->exec(); - - return $id; + return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue); } /** @@ -110,9 +101,10 @@ public function push($job, $data = '', $queue = null) */ public function pushRaw($payload, $queue = null, array $options = []) { - $this->getConnection()->rpush($this->getQueue($queue), $payload); - - return json_decode($payload, true)['id'] ?? null; + return $this->getConnection()->eval( + LuaScripts::push(), 2, $this->getQueue($queue), + $this->blockFor ? $this->getQueue($queue).':notify' : null, $payload + ); } /**
true
Other
laravel
framework
0a0442bf3d3516562c8f8e15a97cf69e0dfaece5.json
Use a Lua script for RedisQueue::push
tests/Queue/QueueRedisQueueTest.php
@@ -6,6 +6,7 @@ use Illuminate\Queue\Queue; use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; +use Illuminate\Queue\LuaScripts; use Illuminate\Queue\RedisQueue; use Illuminate\Contracts\Redis\Factory; @@ -21,7 +22,7 @@ public function testPushProperlyPushesJobOntoRedis() $queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock(); $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo')); $redis->shouldReceive('connection')->once()->andReturn($redis); - $redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'id' => 'foo', 'attempts' => 0])); + $redis->shouldReceive('eval')->once()->with(LuaScripts::push(), 2, 'queues:default', null, json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'id' => 'foo', 'attempts' => 0]))->andReturn('foo'); $id = $queue->push('foo', ['data']); $this->assertEquals('foo', $id); @@ -32,7 +33,7 @@ public function testPushProperlyPushesJobOntoRedisWithCustomPayloadHook() $queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock(); $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo')); $redis->shouldReceive('connection')->once()->andReturn($redis); - $redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'custom' => 'taylor', 'id' => 'foo', 'attempts' => 0])); + $redis->shouldReceive('eval')->once()->with(LuaScripts::push(), 2, 'queues:default', null, json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'custom' => 'taylor', 'id' => 'foo', 'attempts' => 0]))->andReturn('foo'); Queue::createPayloadUsing(function ($connection, $queue, $payload) { return ['custom' => 'taylor']; @@ -49,7 +50,7 @@ public function testPushProperlyPushesJobOntoRedisWithTwoCustomPayloadHook() $queue = $this->getMockBuilder(RedisQueue::class)->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock(Factory::class), 'default'])->getMock(); $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo')); $redis->shouldReceive('connection')->once()->andReturn($redis); - $redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'custom' => 'taylor', 'bar' => 'foo', 'id' => 'foo', 'attempts' => 0])); + $redis->shouldReceive('eval')->once()->with(LuaScripts::push(), 2, 'queues:default', null, json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'custom' => 'taylor', 'bar' => 'foo', 'id' => 'foo', 'attempts' => 0]))->andReturn('foo'); Queue::createPayloadUsing(function ($connection, $queue, $payload) { return ['custom' => 'taylor'];
true
Other
laravel
framework
b15236fb5c6557eab73282bbf4ba84d5ad2d116b.json
Apply fixes from StyleCI (#27232)
tests/Integration/Cache/MemcachedCacheLockTest.php
@@ -4,7 +4,6 @@ use Memcached; use Illuminate\Support\Carbon; -use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Cache; /**
true
Other
laravel
framework
b15236fb5c6557eab73282bbf4ba84d5ad2d116b.json
Apply fixes from StyleCI (#27232)
tests/Integration/Cache/MemcachedIntegrationTest.php
@@ -3,9 +3,7 @@ namespace Illuminate\Tests\Integration\Cache; use Memcached; -use Illuminate\Support\Carbon; use Orchestra\Testbench\TestCase; -use Illuminate\Support\Facades\Cache; /** * @group integration
true
Other
laravel
framework
b15236fb5c6557eab73282bbf4ba84d5ad2d116b.json
Apply fixes from StyleCI (#27232)
tests/Integration/Cache/MemcachedTaggedCacheTest.php
@@ -3,8 +3,6 @@ namespace Illuminate\Tests\Integration\Cache; use Memcached; -use Illuminate\Support\Carbon; -use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Cache; /** @@ -35,7 +33,6 @@ public function test_memcached_can_store_and_retrieve_tagged_cache_items() $this->assertNull($store->tags(['people', 'artists'])->get('John')); } - public function test_memcached_can_store_many_tagged_cache_items() { $store = Cache::store('memcached');
true
Other
laravel
framework
b0a087370c9595efd426506439f52967b1711eaa.json
Simplify file cache Thanks to the changes of the cache repository we can simplify this call.
src/Illuminate/Filesystem/Cache.php
@@ -68,10 +68,6 @@ public function save() { $contents = $this->getForStorage(); - if (! is_null($this->expire)) { - $this->repository->put($this->key, $contents, $this->expire); - } else { - $this->repository->forever($this->key, $contents); - } + $this->repository->put($this->key, $contents, $this->expire); } }
false
Other
laravel
framework
eb6087c370a3584a1f1e232d564194e551694349.json
Fix PSR-16 TTL conformity These changes to the Cache Repository interface and implementation will make our cache implementation compliant with the PSR-16 standard's TTL requirements. It contains some significant changes in how we handle and store cache values. The main change that was done is that now a TTL with a value of NULL will be considerd an attempt to store the item forever. In addition to this, any value with a TTL equal or lower than zero will be considerd an attempt to remove the item from the cache. The `put`, `putMany` and `add` methods were updated to reflect these changes. Before these changes a request like `Cache::put('foo', 'bar')` wouldn't do anything since a NULL TTL meant that the call was simply ignored. Now any request without a specified TTL will have the default TTL of NULL and thus the request is considered to attempting to store the item forever. For the `putMany` call a NULL TTL now means that every single item will be stored forever individually. As there isn't a `putManyForever` equivalent on the Repository or the PSR interface, there was no way to tell a cache store to store the given items in one go. For the `add` call, the behavior to ignore the call when a zero or less TTL was given is kept but when a NULL TTL is now passed, it's correctly passed to the cache store. This will ignore a custom `add` method on the cache store as any NULL TTL simply could be considered to re-store the item indefinitely. No changes were made to the cache stores themselves. Only the Repository was modified. This way, the cache stores keep their current behavior as theyaren't implementations of the PSR Simple Cache interface. All in all these changes will now make us conform with the PSR specs much better.
src/Illuminate/Cache/RedisTaggedCache.php
@@ -22,11 +22,15 @@ class RedisTaggedCache extends TaggedCache * * @param string $key * @param mixed $value - * @param \DateTime|float|int|null $minutes + * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @return bool */ public function put($key, $value, $minutes = null) { + if ($minutes === null) { + return $this->forever($key, $value); + } + $this->pushStandardKeys($this->tags->getNamespace(), $key); return parent::put($key, $value, $minutes);
true
Other
laravel
framework
eb6087c370a3584a1f1e232d564194e551694349.json
Fix PSR-16 TTL conformity These changes to the Cache Repository interface and implementation will make our cache implementation compliant with the PSR-16 standard's TTL requirements. It contains some significant changes in how we handle and store cache values. The main change that was done is that now a TTL with a value of NULL will be considerd an attempt to store the item forever. In addition to this, any value with a TTL equal or lower than zero will be considerd an attempt to remove the item from the cache. The `put`, `putMany` and `add` methods were updated to reflect these changes. Before these changes a request like `Cache::put('foo', 'bar')` wouldn't do anything since a NULL TTL meant that the call was simply ignored. Now any request without a specified TTL will have the default TTL of NULL and thus the request is considered to attempting to store the item forever. For the `putMany` call a NULL TTL now means that every single item will be stored forever individually. As there isn't a `putManyForever` equivalent on the Repository or the PSR interface, there was no way to tell a cache store to store the given items in one go. For the `add` call, the behavior to ignore the call when a zero or less TTL was given is kept but when a NULL TTL is now passed, it's correctly passed to the cache store. This will ignore a custom `add` method on the cache store as any NULL TTL simply could be considered to re-store the item indefinitely. No changes were made to the cache stores themselves. Only the Repository was modified. This way, the cache stores keep their current behavior as theyaren't implementations of the PSR Simple Cache interface. All in all these changes will now make us conform with the PSR specs much better.
src/Illuminate/Cache/Repository.php
@@ -44,7 +44,7 @@ class Repository implements CacheContract, ArrayAccess /** * The default number of minutes to store items. * - * @var float|int + * @var float|int|null */ protected $default = 60; @@ -199,22 +199,26 @@ public function pull($key, $default = null) public function put($key, $value, $minutes = null) { if (is_array($key)) { - $result = $this->putMany($key, $value); + return $this->putMany($key, $value); + } - return $result; + if ($minutes === null) { + return $this->forever($key, $value); } - if (! is_null($minutes = $this->getMinutes($minutes))) { - $result = $this->store->put($this->itemKey($key), $value, $minutes); + $minutes = $this->getMinutes($minutes); - if ($result) { - $this->event(new KeyWritten($key, $value, $minutes)); - } + if ($minutes <= 0) { + return $this->delete($key); + } + + $result = $this->store->put($this->itemKey($key), $value, $minutes); - return $result; + if ($result) { + $this->event(new KeyWritten($key, $value, $minutes)); } - return false; + return $result; } /** @@ -229,24 +233,52 @@ public function set($key, $value, $ttl = null) * Store multiple items in the cache for a given number of minutes. * * @param array $values - * @param \DateTimeInterface|\DateInterval|float|int $minutes + * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @return bool */ - public function putMany(array $values, $minutes) + public function putMany(array $values, $minutes = null) { - if (! is_null($minutes = $this->getMinutes($minutes))) { - $result = $this->store->putMany($values, $minutes); + if ($minutes === null) { + return $this->putManyForever($values); + } - if ($result) { - foreach ($values as $key => $value) { - $this->event(new KeyWritten($key, $value, $minutes)); - } + $minutes = $this->getMinutes($minutes); + + if ($minutes <= 0) { + return $this->deleteMultiple(array_keys($values)); + } + + $result = $this->store->putMany($values, $minutes); + + if ($result) { + foreach ($values as $key => $value) { + $this->event(new KeyWritten($key, $value, $minutes)); } + } + + return $result; + } - return $result; + /** + * Store multiple items in the cache indefinitely. + * + * @param array $values + * @return bool + */ + protected function putManyForever(array $values) + { + $result = true; + + // We'll loop over every item and attempt to store it indefinitely. + // If we notice that one of the items can't be stored forever we + // will return false. Otherwise we'll return a success result. + foreach ($values as $key => $value) { + if (! $this->forever($key, $value)) { + $result = false; + } } - return false; + return $result; } /** @@ -262,22 +294,26 @@ public function setMultiple($values, $ttl = null) * * @param string $key * @param mixed $value - * @param \DateTimeInterface|\DateInterval|float|int $minutes + * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @return bool */ - public function add($key, $value, $minutes) + public function add($key, $value, $minutes = null) { - if (is_null($minutes = $this->getMinutes($minutes))) { - return false; - } + if ($minutes !== null) { + if ($this->getMinutes($minutes) <= 0) { + return false; + } + + // If the store has an "add" method we will call the method on the store so it + // has a chance to override this logic. Some drivers better support the way + // this operation should work with a total "atomic" implementation of it. + if (method_exists($this->store, 'add')) { + $minutes = $this->getMinutes($minutes); - // If the store has an "add" method we will call the method on the store so it - // has a chance to override this logic. Some drivers better support the way - // this operation should work with a total "atomic" implementation of it. - if (method_exists($this->store, 'add')) { - return $this->store->add( - $this->itemKey($key), $value, $minutes - ); + return $this->store->add( + $this->itemKey($key), $value, $minutes + ); + } } // If the value did not exist in the cache, we will put the value in the cache @@ -336,7 +372,7 @@ public function forever($key, $value) * Get an item from the cache, or execute the given Closure and store the result. * * @param string $key - * @param \DateTimeInterface|\DateInterval|float|int $minutes + * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @param \Closure $callback * @return mixed */ @@ -479,7 +515,7 @@ public function getDefaultCacheTime() /** * Set the default cache time in minutes. * - * @param float|int $minutes + * @param float|int|null $minutes * @return $this */ public function setDefaultCacheTime($minutes) @@ -571,18 +607,18 @@ public function offsetUnset($key) /** * Calculate the number of minutes with the given duration. * - * @param \DateTimeInterface|\DateInterval|float|int $duration - * @return float|int|null + * @param \DateTimeInterface|\DateInterval|float|int $minutes + * @return float|int */ - protected function getMinutes($duration) + protected function getMinutes($minutes) { - $duration = $this->parseDateInterval($duration); + $duration = $this->parseDateInterval($minutes); if ($duration instanceof DateTimeInterface) { $duration = Carbon::now()->diffInRealSeconds($duration, false) / 60; } - return (int) ($duration * 60) > 0 ? $duration : null; + return (int) ($duration * 60) > 0 ? $duration : 0; } /**
true
Other
laravel
framework
eb6087c370a3584a1f1e232d564194e551694349.json
Fix PSR-16 TTL conformity These changes to the Cache Repository interface and implementation will make our cache implementation compliant with the PSR-16 standard's TTL requirements. It contains some significant changes in how we handle and store cache values. The main change that was done is that now a TTL with a value of NULL will be considerd an attempt to store the item forever. In addition to this, any value with a TTL equal or lower than zero will be considerd an attempt to remove the item from the cache. The `put`, `putMany` and `add` methods were updated to reflect these changes. Before these changes a request like `Cache::put('foo', 'bar')` wouldn't do anything since a NULL TTL meant that the call was simply ignored. Now any request without a specified TTL will have the default TTL of NULL and thus the request is considered to attempting to store the item forever. For the `putMany` call a NULL TTL now means that every single item will be stored forever individually. As there isn't a `putManyForever` equivalent on the Repository or the PSR interface, there was no way to tell a cache store to store the given items in one go. For the `add` call, the behavior to ignore the call when a zero or less TTL was given is kept but when a NULL TTL is now passed, it's correctly passed to the cache store. This will ignore a custom `add` method on the cache store as any NULL TTL simply could be considered to re-store the item indefinitely. No changes were made to the cache stores themselves. Only the Repository was modified. This way, the cache stores keep their current behavior as theyaren't implementations of the PSR Simple Cache interface. All in all these changes will now make us conform with the PSR specs much better.
src/Illuminate/Cache/TaggedCache.php
@@ -6,7 +6,9 @@ class TaggedCache extends Repository { - use RetrievesMultipleKeys; + use RetrievesMultipleKeys { + putMany as putManyAlias; + } /** * The tag set instance. @@ -29,6 +31,22 @@ public function __construct(Store $store, TagSet $tags) $this->tags = $tags; } + /** + * Store multiple items in the cache for a given number of minutes. + * + * @param array $values + * @param float|int|null $minutes + * @return bool + */ + public function putMany(array $values, $minutes = null) + { + if ($minutes === null) { + return $this->putManyForever($values); + } + + return $this->putManyAlias($values, $minutes); + } + /** * Increment the value of an item in the cache. *
true
Other
laravel
framework
eb6087c370a3584a1f1e232d564194e551694349.json
Fix PSR-16 TTL conformity These changes to the Cache Repository interface and implementation will make our cache implementation compliant with the PSR-16 standard's TTL requirements. It contains some significant changes in how we handle and store cache values. The main change that was done is that now a TTL with a value of NULL will be considerd an attempt to store the item forever. In addition to this, any value with a TTL equal or lower than zero will be considerd an attempt to remove the item from the cache. The `put`, `putMany` and `add` methods were updated to reflect these changes. Before these changes a request like `Cache::put('foo', 'bar')` wouldn't do anything since a NULL TTL meant that the call was simply ignored. Now any request without a specified TTL will have the default TTL of NULL and thus the request is considered to attempting to store the item forever. For the `putMany` call a NULL TTL now means that every single item will be stored forever individually. As there isn't a `putManyForever` equivalent on the Repository or the PSR interface, there was no way to tell a cache store to store the given items in one go. For the `add` call, the behavior to ignore the call when a zero or less TTL was given is kept but when a NULL TTL is now passed, it's correctly passed to the cache store. This will ignore a custom `add` method on the cache store as any NULL TTL simply could be considered to re-store the item indefinitely. No changes were made to the cache stores themselves. Only the Repository was modified. This way, the cache stores keep their current behavior as theyaren't implementations of the PSR Simple Cache interface. All in all these changes will now make us conform with the PSR specs much better.
src/Illuminate/Contracts/Cache/Repository.php
@@ -21,7 +21,7 @@ public function pull($key, $default = null); * * @param string $key * @param mixed $value - * @param \DateTimeInterface|\DateInterval|float|int $minutes + * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @return bool */ public function put($key, $value, $minutes); @@ -31,10 +31,10 @@ public function put($key, $value, $minutes); * * @param string $key * @param mixed $value - * @param \DateTimeInterface|\DateInterval|float|int $minutes + * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @return bool */ - public function add($key, $value, $minutes); + public function add($key, $value, $minutes = null); /** * Increment the value of an item in the cache. @@ -67,7 +67,7 @@ public function forever($key, $value); * Get an item from the cache, or execute the given Closure and store the result. * * @param string $key - * @param \DateTimeInterface|\DateInterval|float|int $minutes + * @param \DateTimeInterface|\DateInterval|float|int|null $minutes * @param \Closure $callback * @return mixed */
true
Other
laravel
framework
eb6087c370a3584a1f1e232d564194e551694349.json
Fix PSR-16 TTL conformity These changes to the Cache Repository interface and implementation will make our cache implementation compliant with the PSR-16 standard's TTL requirements. It contains some significant changes in how we handle and store cache values. The main change that was done is that now a TTL with a value of NULL will be considerd an attempt to store the item forever. In addition to this, any value with a TTL equal or lower than zero will be considerd an attempt to remove the item from the cache. The `put`, `putMany` and `add` methods were updated to reflect these changes. Before these changes a request like `Cache::put('foo', 'bar')` wouldn't do anything since a NULL TTL meant that the call was simply ignored. Now any request without a specified TTL will have the default TTL of NULL and thus the request is considered to attempting to store the item forever. For the `putMany` call a NULL TTL now means that every single item will be stored forever individually. As there isn't a `putManyForever` equivalent on the Repository or the PSR interface, there was no way to tell a cache store to store the given items in one go. For the `add` call, the behavior to ignore the call when a zero or less TTL was given is kept but when a NULL TTL is now passed, it's correctly passed to the cache store. This will ignore a custom `add` method on the cache store as any NULL TTL simply could be considered to re-store the item indefinitely. No changes were made to the cache stores themselves. Only the Repository was modified. This way, the cache stores keep their current behavior as theyaren't implementations of the PSR Simple Cache interface. All in all these changes will now make us conform with the PSR specs much better.
tests/Cache/CacheRepositoryTest.php
@@ -137,24 +137,30 @@ public function testSettingMultipleItemsInCache() $this->assertTrue($result); } - public function testPutWithDatetimeInPastOrZeroSecondsDoesntSaveItem() + public function testPutWithNullTTLRemembersItemForever() + { + $repo = $this->getRepository(); + $repo->getStore()->shouldReceive('forever')->once()->with('foo', 'bar')->andReturn(true); + $this->assertTrue($repo->put('foo', 'bar')); + } + + public function testPutWithDatetimeInPastOrZeroSecondsRemovesOldItem() { $repo = $this->getRepository(); $repo->getStore()->shouldReceive('put')->never(); + $repo->getStore()->shouldReceive('forget')->twice()->andReturn(true); $result = $repo->put('foo', 'bar', Carbon::now()->subMinutes(10)); - $this->assertFalse($result); + $this->assertTrue($result); $result = $repo->put('foo', 'bar', Carbon::now()); - $this->assertFalse($result); + $this->assertTrue($result); } - public function testAddWithDatetimeInPastOrZeroSecondsReturnsImmediately() + public function testPutManyWithNullTTLRemembersItemsForever() { $repo = $this->getRepository(); - $repo->getStore()->shouldReceive('add', 'get', 'put')->never(); - $result = $repo->add('foo', 'bar', Carbon::now()->subMinutes(10)); - $this->assertFalse($result); - $result = $repo->add('foo', 'bar', Carbon::now()); - $this->assertFalse($result); + $repo->getStore()->shouldReceive('forever')->with('foo', 'bar')->andReturn(true); + $repo->getStore()->shouldReceive('forever')->with('bar', 'baz')->andReturn(true); + $this->assertTrue($repo->putMany(['foo' => 'bar', 'bar' => 'baz'])); } public function testAddWithStoreFailureReturnsFalse() @@ -174,6 +180,24 @@ public function testCacheAddCallsRedisStoreAdd() $this->assertTrue($repository->add('k', 'v', 60)); } + public function testAddWithNullTTLRemembersItemForever() + { + $repo = $this->getRepository(); + $repo->getStore()->shouldReceive('get')->once()->with('foo')->andReturn(null); + $repo->getStore()->shouldReceive('forever')->once()->with('foo', 'bar')->andReturn(true); + $this->assertTrue($repo->add('foo', 'bar')); + } + + public function testAddWithDatetimeInPastOrZeroSecondsReturnsImmediately() + { + $repo = $this->getRepository(); + $repo->getStore()->shouldReceive('add', 'get', 'put')->never(); + $result = $repo->add('foo', 'bar', Carbon::now()->subMinutes(10)); + $this->assertFalse($result); + $result = $repo->add('foo', 'bar', Carbon::now()); + $this->assertFalse($result); + } + public function dataProviderTestGetMinutes() { Carbon::setTestNow(Carbon::parse($this->getTestDate()));
true
Other
laravel
framework
eb6087c370a3584a1f1e232d564194e551694349.json
Fix PSR-16 TTL conformity These changes to the Cache Repository interface and implementation will make our cache implementation compliant with the PSR-16 standard's TTL requirements. It contains some significant changes in how we handle and store cache values. The main change that was done is that now a TTL with a value of NULL will be considerd an attempt to store the item forever. In addition to this, any value with a TTL equal or lower than zero will be considerd an attempt to remove the item from the cache. The `put`, `putMany` and `add` methods were updated to reflect these changes. Before these changes a request like `Cache::put('foo', 'bar')` wouldn't do anything since a NULL TTL meant that the call was simply ignored. Now any request without a specified TTL will have the default TTL of NULL and thus the request is considered to attempting to store the item forever. For the `putMany` call a NULL TTL now means that every single item will be stored forever individually. As there isn't a `putManyForever` equivalent on the Repository or the PSR interface, there was no way to tell a cache store to store the given items in one go. For the `add` call, the behavior to ignore the call when a zero or less TTL was given is kept but when a NULL TTL is now passed, it's correctly passed to the cache store. This will ignore a custom `add` method on the cache store as any NULL TTL simply could be considered to re-store the item indefinitely. No changes were made to the cache stores themselves. Only the Repository was modified. This way, the cache stores keep their current behavior as theyaren't implementations of the PSR Simple Cache interface. All in all these changes will now make us conform with the PSR specs much better.
tests/Cache/CacheTaggedCacheTest.php
@@ -111,6 +111,23 @@ public function testRedisCacheTagsPushStandardKeysCorrectly() $conn->shouldReceive('sadd')->once()->with('prefix:foo:standard_ref', 'prefix:'.sha1('foo|bar').':key1'); $conn->shouldReceive('sadd')->once()->with('prefix:bar:standard_ref', 'prefix:'.sha1('foo|bar').':key1'); $store->shouldReceive('push')->with(sha1('foo|bar').':key1', 'key1:value'); + $store->shouldReceive('put')->andReturn(true); + + $redis->put('key1', 'key1:value', 60); + } + + public function testRedisCacheTagsPushForeverKeysCorrectlyWithNullTTL() + { + $store = m::mock(Store::class); + $tagSet = m::mock(TagSet::class, [$store, ['foo', 'bar']]); + $tagSet->shouldReceive('getNamespace')->andReturn('foo|bar'); + $tagSet->shouldReceive('getNames')->andReturn(['foo', 'bar']); + $redis = new RedisTaggedCache($store, $tagSet); + $store->shouldReceive('getPrefix')->andReturn('prefix:'); + $store->shouldReceive('connection')->andReturn($conn = m::mock(stdClass::class)); + $conn->shouldReceive('sadd')->once()->with('prefix:foo:forever_ref', 'prefix:'.sha1('foo|bar').':key1'); + $conn->shouldReceive('sadd')->once()->with('prefix:bar:forever_ref', 'prefix:'.sha1('foo|bar').':key1'); + $store->shouldReceive('forever')->with(sha1('foo|bar').':key1', 'key1:value'); $redis->put('key1', 'key1:value'); }
true
Other
laravel
framework
8aa403ebafde3fd51048e427aaf2ae8081c2ff9d.json
update dynamo store
src/Illuminate/Cache/DynamoDbStore.php
@@ -172,7 +172,7 @@ protected function isExpired(array $item, $expiration = null) * @param string $key * @param mixed $value * @param float|int $minutes - * @return void + * @return bool */ public function put($key, $value, $minutes) { @@ -190,6 +190,8 @@ public function put($key, $value, $minutes) ], ], ]); + + return true; } /**
false
Other
laravel
framework
cf8238d45e6c037566619e9ca0c01a91e8816f69.json
Fix return of add method in Cache Repository The success should depend on the result of the put method call.
src/Illuminate/Cache/Repository.php
@@ -284,9 +284,7 @@ public function add($key, $value, $minutes) // so it exists for subsequent requests. Then, we will return true so it is // easy to know if the value gets added. Otherwise, we will return false. if (is_null($this->get($key))) { - $this->put($key, $value, $minutes); - - return true; + return $this->put($key, $value, $minutes); } return false;
true
Other
laravel
framework
cf8238d45e6c037566619e9ca0c01a91e8816f69.json
Fix return of add method in Cache Repository The success should depend on the result of the put method call.
tests/Cache/CacheRepositoryTest.php
@@ -157,6 +157,15 @@ public function testAddWithDatetimeInPastOrZeroSecondsReturnsImmediately() $this->assertFalse($result); } + public function testAddWithStoreFailureReturnsFalse() + { + $repo = $this->getRepository(); + $repo->getStore()->shouldReceive('add')->never(); + $repo->getStore()->shouldReceive('get')->andReturn(null); + $repo->getStore()->shouldReceive('put')->andReturn(false); + $this->assertFalse($repo->add('foo', 'bar', 60)); + } + public function testCacheAddCallsRedisStoreAdd() { $store = m::mock(RedisStore::class);
true
Other
laravel
framework
ac09aa395d0f05842e5bf37e8aaeecf639e08bb6.json
Simplify booleans in RedisStore
src/Illuminate/Cache/RedisStore.php
@@ -89,11 +89,9 @@ public function many(array $keys) */ public function put($key, $value, $minutes) { - $result = $this->connection()->setex( + return (bool) $this->connection()->setex( $this->prefix.$key, (int) max(1, $minutes * 60), $this->serialize($value) ); - - return $result ? true : false; } /** @@ -170,9 +168,7 @@ public function decrement($key, $value = 1) */ public function forever($key, $value) { - $result = $this->connection()->set($this->prefix.$key, $this->serialize($value)); - - return $result ? true : false; + return (bool) $this->connection()->set($this->prefix.$key, $this->serialize($value)); } /**
false
Other
laravel
framework
51c6bb8e6430dcf5479565a02ceca52884393daf.json
Remove overwritten methods on Repository interface These methods are already defined on the PSR contract and it's unnecessary to define them twice.
src/Illuminate/Contracts/Cache/Repository.php
@@ -7,23 +7,6 @@ interface Repository extends CacheInterface { - /** - * Determine if an item exists in the cache. - * - * @param string $key - * @return bool - */ - public function has($key); - - /** - * Retrieve an item from the cache by key. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function get($key, $default = null); - /** * Retrieve an item from the cache and delete it. *
false
Other
laravel
framework
3f62df631e480dd253fb6f2a5dec8cc5fa94ebf6.json
Adjust Cache::remember() to work with ArrayStore
src/Illuminate/Cache/ArrayStore.php
@@ -2,9 +2,11 @@ namespace Illuminate\Cache; +use Illuminate\Support\InteractsWithTime; + class ArrayStore extends TaggableStore { - use RetrievesMultipleKeys; + use RetrievesMultipleKeys, InteractsWithTime; /** * The array of stored values. @@ -21,7 +23,18 @@ class ArrayStore extends TaggableStore */ public function get($key) { - return $this->storage[$key] ?? null; + if (! isset($this->storage[$key])) { + return null; + } + + $item = $this->storage[$key]; + if ($item['expiresAt'] !== 0 && $this->currentTime() > $item['expiresAt']) { + $this->forget($key); + + return null; + } + + return $item['value']; } /** @@ -34,7 +47,10 @@ public function get($key) */ public function put($key, $value, $minutes) { - $this->storage[$key] = $value; + $this->storage[$key] = [ + 'value' => $value, + 'expiresAt' => $this->calculateExpiration($minutes) + ]; return true; } @@ -48,10 +64,15 @@ public function put($key, $value, $minutes) */ public function increment($key, $value = 1) { - $this->storage[$key] = ! isset($this->storage[$key]) - ? $value : ((int) $this->storage[$key]) + $value; + if (! isset($this->storage[$key])) { + $this->forever($key, $value); + + return $this->storage[$key]['value']; + } - return $this->storage[$key]; + $this->storage[$key]['value'] = ((int) $this->storage[$key]['value']) + $value; + + return $this->storage[$key]['value']; } /** @@ -112,4 +133,26 @@ public function getPrefix() { return ''; } + + /** + * Get the expiration time of the key. + * + * @param int $minutes + * @return int + */ + protected function calculateExpiration($minutes) + { + return $this->toTimestamp($minutes); + } + + /** + * Get the UNIX timestamp for the given number of minutes. + * + * @param int $minutes + * @return int + */ + protected function toTimestamp($minutes) + { + return $minutes > 0 ? $this->availableAt($minutes * 60) : 0; + } }
true
Other
laravel
framework
3f62df631e480dd253fb6f2a5dec8cc5fa94ebf6.json
Adjust Cache::remember() to work with ArrayStore
tests/Cache/CacheArrayStoreTest.php
@@ -2,6 +2,7 @@ namespace Illuminate\Tests\Cache; +use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Cache\ArrayStore; @@ -33,6 +34,19 @@ public function testMultipleItemsCanBeSetAndRetrieved() ], $store->many(['foo', 'fizz', 'quz', 'norf'])); } + public function testItemsCanExpire(): void + { + Carbon::setTestNow(Carbon::now()); + $store = new ArrayStore; + + $store->put('foo', 'bar', 10); + Carbon::setTestNow(Carbon::now()->addMinutes(10)->addSecond()); + $result = $store->get('foo'); + + $this->assertNull($result); + Carbon::setTestNow(null); + } + public function testStoreItemForeverProperlyStoresInArray() { $mock = $this->getMockBuilder(ArrayStore::class)->setMethods(['put'])->getMock(); @@ -47,22 +61,25 @@ public function testValuesCanBeIncremented() { $store = new ArrayStore; $store->put('foo', 1, 10); - $store->increment('foo'); + $result = $store->increment('foo'); + $this->assertEquals(2, $result); $this->assertEquals(2, $store->get('foo')); } public function testNonExistingKeysCanBeIncremented() { $store = new ArrayStore; - $store->increment('foo'); + $result = $store->increment('foo'); + $this->assertEquals(1, $result); $this->assertEquals(1, $store->get('foo')); } public function testValuesCanBeDecremented() { $store = new ArrayStore; $store->put('foo', 1, 10); - $store->decrement('foo'); + $result = $store->decrement('foo'); + $this->assertEquals(0, $result); $this->assertEquals(0, $store->get('foo')); }
true
Other
laravel
framework
cca9bfffc1f0a33bbb42d843208383c8fd3f83ec.json
Extract Container extend tests
tests/Container/ContainerExtendTest.php
@@ -0,0 +1,200 @@ +<?php + +namespace Illuminate\Tests\Container; + +use stdClass; +use PHPUnit\Framework\TestCase; +use Illuminate\Container\Container; + +class ContainerExtendTest extends TestCase +{ + public function testExtendedBindings() + { + $container = new Container; + $container['foo'] = 'foo'; + $container->extend('foo', function ($old, $container) { + return $old.'bar'; + }); + + $this->assertEquals('foobar', $container->make('foo')); + + $container = new Container; + + $container->singleton('foo', function () { + return (object) ['name' => 'taylor']; + }); + $container->extend('foo', function ($old, $container) { + $old->age = 26; + + return $old; + }); + + $result = $container->make('foo'); + + $this->assertEquals('taylor', $result->name); + $this->assertEquals(26, $result->age); + $this->assertSame($result, $container->make('foo')); + } + + public function testExtendInstancesArePreserved() + { + $container = new Container; + $container->bind('foo', function () { + $obj = new stdClass; + $obj->foo = 'bar'; + + return $obj; + }); + + $obj = new stdClass; + $obj->foo = 'foo'; + $container->instance('foo', $obj); + $container->extend('foo', function ($obj, $container) { + $obj->bar = 'baz'; + + return $obj; + }); + $container->extend('foo', function ($obj, $container) { + $obj->baz = 'foo'; + + return $obj; + }); + + $this->assertEquals('foo', $container->make('foo')->foo); + $this->assertEquals('baz', $container->make('foo')->bar); + $this->assertEquals('foo', $container->make('foo')->baz); + } + + public function testExtendIsLazyInitialized() + { + ContainerLazyExtendStub::$initialized = false; + + $container = new Container; + $container->bind(ContainerLazyExtendStub::class); + $container->extend(ContainerLazyExtendStub::class, function ($obj, $container) { + $obj->init(); + + return $obj; + }); + $this->assertFalse(ContainerLazyExtendStub::$initialized); + $container->make(ContainerLazyExtendStub::class); + $this->assertTrue(ContainerLazyExtendStub::$initialized); + } + + public function testExtendCanBeCalledBeforeBind() + { + $container = new Container; + $container->extend('foo', function ($old, $container) { + return $old.'bar'; + }); + $container['foo'] = 'foo'; + + $this->assertEquals('foobar', $container->make('foo')); + } + + public function testExtendInstanceRebindingCallback() + { + $_SERVER['_test_rebind'] = false; + + $container = new Container; + $container->rebinding('foo', function () { + $_SERVER['_test_rebind'] = true; + }); + + $obj = new stdClass; + $container->instance('foo', $obj); + + $container->extend('foo', function ($obj, $container) { + return $obj; + }); + + $this->assertTrue($_SERVER['_test_rebind']); + } + + public function testExtendBindRebindingCallback() + { + $_SERVER['_test_rebind'] = false; + + $container = new Container; + $container->rebinding('foo', function () { + $_SERVER['_test_rebind'] = true; + }); + $container->bind('foo', function () { + return new stdClass; + }); + + $this->assertFalse($_SERVER['_test_rebind']); + + $container->make('foo'); + + $container->extend('foo', function ($obj, $container) { + return $obj; + }); + + $this->assertTrue($_SERVER['_test_rebind']); + } + + public function testExtensionWorksOnAliasedBindings() + { + $container = new Container; + $container->singleton('something', function () { + return 'some value'; + }); + $container->alias('something', 'something-alias'); + $container->extend('something-alias', function ($value) { + return $value.' extended'; + }); + + $this->assertEquals('some value extended', $container->make('something')); + } + + public function testMultipleExtends() + { + $container = new Container; + $container['foo'] = 'foo'; + $container->extend('foo', function ($old, $container) { + return $old.'bar'; + }); + $container->extend('foo', function ($old, $container) { + return $old.'baz'; + }); + + $this->assertEquals('foobarbaz', $container->make('foo')); + } + + public function testUnsetExtend() + { + $container = new Container; + $container->bind('foo', function () { + $obj = new stdClass; + $obj->foo = 'bar'; + + return $obj; + }); + + $container->extend('foo', function ($obj, $container) { + $obj->bar = 'baz'; + + return $obj; + }); + + unset($container['foo']); + $container->forgetExtenders('foo'); + + $container->bind('foo', function () { + return 'foo'; + }); + + $this->assertEquals('foo', $container->make('foo')); + } +} + +class ContainerLazyExtendStub +{ + public static $initialized = false; + + public function init() + { + static::$initialized = true; + } +}
true
Other
laravel
framework
cca9bfffc1f0a33bbb42d843208383c8fd3f83ec.json
Extract Container extend tests
tests/Container/ContainerTest.php
@@ -151,48 +151,6 @@ public function testBindingsCanBeOverridden() $this->assertEquals('baz', $container['foo']); } - public function testExtendedBindings() - { - $container = new Container; - $container['foo'] = 'foo'; - $container->extend('foo', function ($old, $container) { - return $old.'bar'; - }); - - $this->assertEquals('foobar', $container->make('foo')); - - $container = new Container; - - $container->singleton('foo', function () { - return (object) ['name' => 'taylor']; - }); - $container->extend('foo', function ($old, $container) { - $old->age = 26; - - return $old; - }); - - $result = $container->make('foo'); - - $this->assertEquals('taylor', $result->name); - $this->assertEquals(26, $result->age); - $this->assertSame($result, $container->make('foo')); - } - - public function testMultipleExtends() - { - $container = new Container; - $container['foo'] = 'foo'; - $container->extend('foo', function ($old, $container) { - return $old.'bar'; - }); - $container->extend('foo', function ($old, $container) { - return $old.'baz'; - }); - - $this->assertEquals('foobarbaz', $container->make('foo')); - } - public function testBindingAnInstanceReturnsTheInstance() { $container = new Container; @@ -203,129 +161,6 @@ public function testBindingAnInstanceReturnsTheInstance() $this->assertSame($bound, $resolved); } - public function testExtendInstancesArePreserved() - { - $container = new Container; - $container->bind('foo', function () { - $obj = new stdClass; - $obj->foo = 'bar'; - - return $obj; - }); - $obj = new stdClass; - $obj->foo = 'foo'; - $container->instance('foo', $obj); - $container->extend('foo', function ($obj, $container) { - $obj->bar = 'baz'; - - return $obj; - }); - $container->extend('foo', function ($obj, $container) { - $obj->baz = 'foo'; - - return $obj; - }); - - $this->assertEquals('foo', $container->make('foo')->foo); - $this->assertEquals('baz', $container->make('foo')->bar); - $this->assertEquals('foo', $container->make('foo')->baz); - } - - public function testExtendIsLazyInitialized() - { - ContainerLazyExtendStub::$initialized = false; - - $container = new Container; - $container->bind(ContainerLazyExtendStub::class); - $container->extend(ContainerLazyExtendStub::class, function ($obj, $container) { - $obj->init(); - - return $obj; - }); - $this->assertFalse(ContainerLazyExtendStub::$initialized); - $container->make(ContainerLazyExtendStub::class); - $this->assertTrue(ContainerLazyExtendStub::$initialized); - } - - public function testExtendCanBeCalledBeforeBind() - { - $container = new Container; - $container->extend('foo', function ($old, $container) { - return $old.'bar'; - }); - $container['foo'] = 'foo'; - - $this->assertEquals('foobar', $container->make('foo')); - } - - public function testExtendInstanceRebindingCallback() - { - $_SERVER['_test_rebind'] = false; - - $container = new Container; - $container->rebinding('foo', function () { - $_SERVER['_test_rebind'] = true; - }); - - $obj = new stdClass; - $container->instance('foo', $obj); - - $container->extend('foo', function ($obj, $container) { - return $obj; - }); - - $this->assertTrue($_SERVER['_test_rebind']); - } - - public function testExtendBindRebindingCallback() - { - $_SERVER['_test_rebind'] = false; - - $container = new Container; - $container->rebinding('foo', function () { - $_SERVER['_test_rebind'] = true; - }); - $container->bind('foo', function () { - return new stdClass; - }); - - $this->assertFalse($_SERVER['_test_rebind']); - - $container->make('foo'); - - $container->extend('foo', function ($obj, $container) { - return $obj; - }); - - $this->assertTrue($_SERVER['_test_rebind']); - } - - public function testUnsetExtend() - { - $container = new Container; - $container->bind('foo', function () { - $obj = new stdClass; - $obj->foo = 'bar'; - - return $obj; - }); - - $container->extend('foo', function ($obj, $container) { - $obj->bar = 'baz'; - - return $obj; - }); - - unset($container['foo']); - $container->forgetExtenders('foo'); - - $container->bind('foo', function () { - return 'foo'; - }); - - $this->assertEquals('foo', $container->make('foo')); - } - public function testResolutionOfDefaultParameters() { $container = new Container; @@ -608,20 +443,6 @@ public function testContainerGetFactory() $this->assertEquals($container->make('name'), $factory()); } - public function testExtensionWorksOnAliasedBindings() - { - $container = new Container; - $container->singleton('something', function () { - return 'some value'; - }); - $container->alias('something', 'something-alias'); - $container->extend('something-alias', function ($value) { - return $value.' extended'; - }); - - $this->assertEquals('some value extended', $container->make('something')); - } - public function testMakeWithMethodIsAnAliasForMakeMethod() { $mock = $this->getMockBuilder(Container::class) @@ -833,16 +654,6 @@ public function __construct($first, ContainerConcreteStub $stub, $last) } } -class ContainerLazyExtendStub -{ - public static $initialized = false; - - public function init() - { - static::$initialized = true; - } -} - class ContainerInjectVariableStub { public $something;
true
Other
laravel
framework
77e668fbf2d9dc41ac5f0df86ee8b4f6dee99a80.json
Extract App::call tests into a file
tests/Container/ContainerCallTest.php
@@ -0,0 +1,195 @@ +<?php + +namespace Illuminate\Tests\Container; + +use Closure; +use stdClass; +use PHPUnit\Framework\TestCase; +use Illuminate\Container\Container; + +class ContainerCallTest extends TestCase +{ + /** + * @expectedException \ReflectionException + * @expectedExceptionMessage Function ContainerTestCallStub() does not exist + */ + public function testCallWithAtSignBasedClassReferencesWithoutMethodThrowsException() + { + $container = new Container; + $container->call('ContainerTestCallStub'); + } + + public function testCallWithAtSignBasedClassReferences() + { + $container = new Container; + $result = $container->call(ContainerTestCallStub::class.'@work', ['foo', 'bar']); + $this->assertEquals(['foo', 'bar'], $result); + + $container = new Container; + $result = $container->call(ContainerTestCallStub::class.'@inject'); + $this->assertInstanceOf(ContainerCallConcreteStub::class, $result[0]); + $this->assertEquals('taylor', $result[1]); + + $container = new Container; + $result = $container->call(ContainerTestCallStub::class.'@inject', ['default' => 'foo']); + $this->assertInstanceOf(ContainerCallConcreteStub::class, $result[0]); + $this->assertEquals('foo', $result[1]); + + $container = new Container; + $result = $container->call(ContainerTestCallStub::class, ['foo', 'bar'], 'work'); + $this->assertEquals(['foo', 'bar'], $result); + } + + public function testCallWithCallableArray() + { + $container = new Container; + $stub = new ContainerTestCallStub; + $result = $container->call([$stub, 'work'], ['foo', 'bar']); + $this->assertEquals(['foo', 'bar'], $result); + } + + public function testCallWithStaticMethodNameString() + { + $container = new Container; + $result = $container->call('Illuminate\Tests\Container\ContainerStaticMethodStub::inject'); + $this->assertInstanceOf(ContainerCallConcreteStub::class, $result[0]); + $this->assertEquals('taylor', $result[1]); + } + + public function testCallWithGlobalMethodName() + { + $container = new Container; + $result = $container->call('Illuminate\Tests\Container\containerTestInject'); + $this->assertInstanceOf(ContainerCallConcreteStub::class, $result[0]); + $this->assertEquals('taylor', $result[1]); + } + + public function testCallWithBoundMethod() + { + $container = new Container; + $container->bindMethod(ContainerTestCallStub::class.'@unresolvable', function ($stub) { + return $stub->unresolvable('foo', 'bar'); + }); + $result = $container->call(ContainerTestCallStub::class.'@unresolvable'); + $this->assertEquals(['foo', 'bar'], $result); + + $container = new Container; + $container->bindMethod(ContainerTestCallStub::class.'@unresolvable', function ($stub) { + return $stub->unresolvable('foo', 'bar'); + }); + $result = $container->call([new ContainerTestCallStub, 'unresolvable']); + $this->assertEquals(['foo', 'bar'], $result); + + $container = new Container; + $result = $container->call([new ContainerTestCallStub, 'inject'], ['_stub' => 'foo', 'default' => 'bar']); + $this->assertInstanceOf(ContainerCallConcreteStub::class, $result[0]); + $this->assertEquals('bar', $result[1]); + + $container = new Container; + $result = $container->call([new ContainerTestCallStub, 'inject'], ['_stub' => 'foo']); + $this->assertInstanceOf(ContainerCallConcreteStub::class, $result[0]); + $this->assertEquals('taylor', $result[1]); + } + + public function testBindMethodAcceptsAnArray() + { + $container = new Container; + $container->bindMethod([ContainerTestCallStub::class, 'unresolvable'], function ($stub) { + return $stub->unresolvable('foo', 'bar'); + }); + $result = $container->call(ContainerTestCallStub::class.'@unresolvable'); + $this->assertEquals(['foo', 'bar'], $result); + + $container = new Container; + $container->bindMethod([ContainerTestCallStub::class, 'unresolvable'], function ($stub) { + return $stub->unresolvable('foo', 'bar'); + }); + $result = $container->call([new ContainerTestCallStub, 'unresolvable']); + $this->assertEquals(['foo', 'bar'], $result); + } + + public function testClosureCallWithInjectedDependency() + { + $container = new Container; + $container->call(function (ContainerCallConcreteStub $stub) { + }, ['foo' => 'bar']); + + $container->call(function (ContainerCallConcreteStub $stub) { + }, ['foo' => 'bar', 'stub' => new ContainerCallConcreteStub]); + } + + public function testCallWithDependencies() + { + $container = new Container; + $result = $container->call(function (stdClass $foo, $bar = []) { + return func_get_args(); + }); + + $this->assertInstanceOf(stdClass::class, $result[0]); + $this->assertEquals([], $result[1]); + + $result = $container->call(function (stdClass $foo, $bar = []) { + return func_get_args(); + }, ['bar' => 'taylor']); + + $this->assertInstanceOf(stdClass::class, $result[0]); + $this->assertEquals('taylor', $result[1]); + + $stub = new ContainerCallConcreteStub; + $result = $container->call(function (stdClass $foo, ContainerCallConcreteStub $bar) { + return func_get_args(); + }, [ContainerCallConcreteStub::class => $stub]); + + $this->assertInstanceOf(stdClass::class, $result[0]); + $this->assertSame($stub, $result[1]); + + /* + * Wrap a function... + */ + $result = $container->wrap(function (stdClass $foo, $bar = []) { + return func_get_args(); + }, ['bar' => 'taylor']); + + $this->assertInstanceOf(Closure::class, $result); + $result = $result(); + + $this->assertInstanceOf(stdClass::class, $result[0]); + $this->assertEquals('taylor', $result[1]); + } +} + +class ContainerTestCallStub +{ + public function work() + { + return func_get_args(); + } + + public function inject(ContainerCallConcreteStub $stub, $default = 'taylor') + { + return func_get_args(); + } + + public function unresolvable($foo, $bar) + { + return func_get_args(); + } +} + +class ContainerCallConcreteStub +{ + // +} + +function containerTestInject(ContainerCallConcreteStub $stub, $default = 'taylor') +{ + return func_get_args(); +} + +class ContainerStaticMethodStub +{ + public static function inject(ContainerCallConcreteStub $stub, $default = 'taylor') + { + return func_get_args(); + } +}
true
Other
laravel
framework
77e668fbf2d9dc41ac5f0df86ee8b4f6dee99a80.json
Extract App::call tests into a file
tests/Container/ContainerTest.php
@@ -2,7 +2,6 @@ namespace Illuminate\Tests\Container; -use Closure; use stdClass; use PHPUnit\Framework\TestCase; use Illuminate\Container\Container; @@ -435,144 +434,6 @@ public function testBindingResolutionExceptionMessageIncludesBuildStack() $container->make(ContainerTestContextInjectOne::class, []); } - public function testCallWithDependencies() - { - $container = new Container; - $result = $container->call(function (stdClass $foo, $bar = []) { - return func_get_args(); - }); - - $this->assertInstanceOf(stdClass::class, $result[0]); - $this->assertEquals([], $result[1]); - - $result = $container->call(function (stdClass $foo, $bar = []) { - return func_get_args(); - }, ['bar' => 'taylor']); - - $this->assertInstanceOf(stdClass::class, $result[0]); - $this->assertEquals('taylor', $result[1]); - - $stub = new ContainerConcreteStub; - $result = $container->call(function (stdClass $foo, ContainerConcreteStub $bar) { - return func_get_args(); - }, [ContainerConcreteStub::class => $stub]); - - $this->assertInstanceOf(stdClass::class, $result[0]); - $this->assertSame($stub, $result[1]); - - /* - * Wrap a function... - */ - $result = $container->wrap(function (stdClass $foo, $bar = []) { - return func_get_args(); - }, ['bar' => 'taylor']); - - $this->assertInstanceOf(Closure::class, $result); - $result = $result(); - - $this->assertInstanceOf(stdClass::class, $result[0]); - $this->assertEquals('taylor', $result[1]); - } - - /** - * @expectedException \ReflectionException - * @expectedExceptionMessage Function ContainerTestCallStub() does not exist - */ - public function testCallWithAtSignBasedClassReferencesWithoutMethodThrowsException() - { - $container = new Container; - $container->call('ContainerTestCallStub'); - } - - public function testCallWithAtSignBasedClassReferences() - { - $container = new Container; - $result = $container->call(ContainerTestCallStub::class.'@work', ['foo', 'bar']); - $this->assertEquals(['foo', 'bar'], $result); - - $container = new Container; - $result = $container->call(ContainerTestCallStub::class.'@inject'); - $this->assertInstanceOf(ContainerConcreteStub::class, $result[0]); - $this->assertEquals('taylor', $result[1]); - - $container = new Container; - $result = $container->call(ContainerTestCallStub::class.'@inject', ['default' => 'foo']); - $this->assertInstanceOf(ContainerConcreteStub::class, $result[0]); - $this->assertEquals('foo', $result[1]); - - $container = new Container; - $result = $container->call(ContainerTestCallStub::class, ['foo', 'bar'], 'work'); - $this->assertEquals(['foo', 'bar'], $result); - } - - public function testCallWithCallableArray() - { - $container = new Container; - $stub = new ContainerTestCallStub; - $result = $container->call([$stub, 'work'], ['foo', 'bar']); - $this->assertEquals(['foo', 'bar'], $result); - } - - public function testCallWithStaticMethodNameString() - { - $container = new Container; - $result = $container->call('Illuminate\Tests\Container\ContainerStaticMethodStub::inject'); - $this->assertInstanceOf(ContainerConcreteStub::class, $result[0]); - $this->assertEquals('taylor', $result[1]); - } - - public function testCallWithGlobalMethodName() - { - $container = new Container; - $result = $container->call('Illuminate\Tests\Container\containerTestInject'); - $this->assertInstanceOf(ContainerConcreteStub::class, $result[0]); - $this->assertEquals('taylor', $result[1]); - } - - public function testCallWithBoundMethod() - { - $container = new Container; - $container->bindMethod(ContainerTestCallStub::class.'@unresolvable', function ($stub) { - return $stub->unresolvable('foo', 'bar'); - }); - $result = $container->call(ContainerTestCallStub::class.'@unresolvable'); - $this->assertEquals(['foo', 'bar'], $result); - - $container = new Container; - $container->bindMethod(ContainerTestCallStub::class.'@unresolvable', function ($stub) { - return $stub->unresolvable('foo', 'bar'); - }); - $result = $container->call([new ContainerTestCallStub, 'unresolvable']); - $this->assertEquals(['foo', 'bar'], $result); - - $container = new Container; - $result = $container->call([new ContainerTestCallStub, 'inject'], ['_stub' => 'foo', 'default' => 'bar']); - $this->assertInstanceOf(ContainerConcreteStub::class, $result[0]); - $this->assertEquals('bar', $result[1]); - - $container = new Container; - $result = $container->call([new ContainerTestCallStub, 'inject'], ['_stub' => 'foo']); - $this->assertInstanceOf(ContainerConcreteStub::class, $result[0]); - $this->assertEquals('taylor', $result[1]); - } - - public function testBindMethodAcceptsAnArray() - { - $container = new Container; - $container->bindMethod([ContainerTestCallStub::class, 'unresolvable'], function ($stub) { - return $stub->unresolvable('foo', 'bar'); - }); - $result = $container->call(ContainerTestCallStub::class.'@unresolvable'); - $this->assertEquals(['foo', 'bar'], $result); - - $container = new Container; - $container->bindMethod([ContainerTestCallStub::class, 'unresolvable'], function ($stub) { - return $stub->unresolvable('foo', 'bar'); - }); - $result = $container->call([new ContainerTestCallStub, 'unresolvable']); - $this->assertEquals(['foo', 'bar'], $result); - } - public function testContainerCanInjectDifferentImplementationsDependingOnContext() { $container = new Container; @@ -1107,16 +968,6 @@ public function testContainerCanResolveClasses() $this->assertInstanceOf(ContainerConcreteStub::class, $class); } - - public function testClosureCallWithInjectedDependency() - { - $container = new Container; - $container->call(function (ContainerConcreteStub $stub) { - }, ['foo' => 'bar']); - - $container->call(function (ContainerConcreteStub $stub) { - }, ['foo' => 'bar', 'stub' => new ContainerConcreteStub]); - } } class ContainerConcreteStub @@ -1205,24 +1056,6 @@ public function init() } } -class ContainerTestCallStub -{ - public function work() - { - return func_get_args(); - } - - public function inject(ContainerConcreteStub $stub, $default = 'taylor') - { - return func_get_args(); - } - - public function unresolvable($foo, $bar) - { - return func_get_args(); - } -} - class ContainerTestContextInjectOne { public $impl; @@ -1252,13 +1085,6 @@ public function __construct(IContainerContractStub $impl) $this->impl = $impl; } } -class ContainerStaticMethodStub -{ - public static function inject(ContainerConcreteStub $stub, $default = 'taylor') - { - return func_get_args(); - } -} class ContainerInjectVariableStub { @@ -1280,11 +1106,6 @@ public function __construct(ContainerConcreteStub $concrete, $something) } } -function containerTestInject(ContainerConcreteStub $stub, $default = 'taylor') -{ - return func_get_args(); -} - class ContainerTestContextInjectInstantiations implements IContainerContractStub { public static $instantiations;
true
Other
laravel
framework
a7a0c65b3d2ee1eae68d3d7e749ba41aba7caa72.json
Apply fixes from StyleCI (#27127)
src/Illuminate/Cache/DynamoDbLock.php
@@ -2,9 +2,6 @@ namespace Illuminate\Cache; -use Illuminate\Cache\Lock; -use Aws\DynamoDb\DynamoDbClient; - class DynamoDbLock extends Lock { /**
true
Other
laravel
framework
a7a0c65b3d2ee1eae68d3d7e749ba41aba7caa72.json
Apply fixes from StyleCI (#27127)
src/Illuminate/Cache/DynamoDbStore.php
@@ -124,10 +124,10 @@ public function many(array $keys) 'Keys' => collect($keys)->map(function ($key) { return [ $this->keyAttribute => [ - 'S' => $key - ] + 'S' => $key, + ], ]; - })->all() + })->all(), ], ], ]); @@ -413,7 +413,7 @@ public function forget($key) */ public function flush() { - throw new RuntimeException("DynamoDb does not support flushing an entire table. Please create a new table."); + throw new RuntimeException('DynamoDb does not support flushing an entire table. Please create a new table.'); } /**
true