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
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/ImpersonatesUsers.php
@@ -1,6 +1,6 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; use Illuminate\Contracts\Auth\Authenticatable as UserContract;
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php
@@ -1,6 +1,6 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; use Illuminate\Contracts\Console\Kernel;
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/InteractsWithContainer.php
@@ -1,6 +1,6 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; trait InteractsWithContainer {
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php
@@ -1,6 +1,6 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; trait InteractsWithDatabase {
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php
@@ -1,12 +1,13 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; use Exception; use Illuminate\Support\Str; use InvalidArgumentException; use Symfony\Component\DomCrawler\Form; use Symfony\Component\DomCrawler\Crawler; +use Illuminate\Foundation\Testing\HttpException; use Symfony\Component\HttpFoundation\File\UploadedFile; use PHPUnit_Framework_ExpectationFailedException as PHPUnitException;
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/InteractsWithSession.php
@@ -1,6 +1,6 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; use PHPUnit_Framework_Assert as PHPUnit;
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
@@ -1,6 +1,6 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; use Illuminate\Support\Str; use Illuminate\Http\Request;
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php
@@ -1,6 +1,6 @@ <?php -namespace Illuminate\Foundation\Testing; +namespace Illuminate\Foundation\Testing\Concerns; use Mockery; use Exception;
true
Other
laravel
framework
613f17fb6f1c76105111169deacac8fe8605d303.json
Move some classes.
src/Illuminate/Foundation/Testing/TestCase.php
@@ -7,13 +7,13 @@ abstract class TestCase extends PHPUnit_Framework_TestCase { - use InteractsWithContainer, - MakesHttpRequests, - ImpersonatesUsers, - InteractsWithConsole, - InteractsWithDatabase, - InteractsWithSession, - MocksApplicationServices; + use Concerns\InteractsWithContainer, + Concerns\MakesHttpRequests, + Concerns\ImpersonatesUsers, + Concerns\InteractsWithConsole, + Concerns\InteractsWithDatabase, + Concerns\InteractsWithSession, + Concerns\MocksApplicationServices; /** * The Illuminate application instance.
true
Other
laravel
framework
934bb07cdafe0b086740bdb163691f0d7cc9364b.json
Skip non-arrays when collapsing
src/Illuminate/Support/Arr.php
@@ -60,6 +60,10 @@ public static function collapse($array) $values = $values->all(); } + if (! is_array($values)) { + continue; + } + $results = array_merge($results, $values); }
false
Other
laravel
framework
c7da89d4d45e69c5302551854962a65948e38401.json
Remove comments (missing commit) laravel/framework#10704
src/Illuminate/Database/Connection.php
@@ -352,7 +352,7 @@ public function insert($query, $bindings = []) * * @param string $query * @param array $bindings - * @return int Number of rows affected by the query + * @return int */ public function update($query, $bindings = []) { @@ -364,7 +364,7 @@ public function update($query, $bindings = []) * * @param string $query * @param array $bindings - * @return int Number of rows affected by the query + * @return int */ public function delete($query, $bindings = []) {
true
Other
laravel
framework
c7da89d4d45e69c5302551854962a65948e38401.json
Remove comments (missing commit) laravel/framework#10704
src/Illuminate/Database/Query/Builder.php
@@ -1789,7 +1789,7 @@ public function insertGetId(array $values, $sequence = null) * Update a record in the database. * * @param array $values - * @return int Number of rows affected by the query + * @return int */ public function update(array $values) {
true
Other
laravel
framework
79f64b8929cf2d3d71eefddc6e284a1aea1d772f.json
Fix Collection JSON serializing logic
src/Illuminate/Support/Collection.php
@@ -922,7 +922,15 @@ public function toArray() */ public function jsonSerialize() { - return $this->toArray(); + return array_map(function ($value) { + if ($value instanceof JsonSerializable) { + return $value->jsonSerialize(); + } elseif ($value instanceof Arrayable) { + return $value->toArray(); + } else { + return $value; + } + }, $this->items); } /** @@ -933,7 +941,7 @@ public function jsonSerialize() */ public function toJson($options = 0) { - return json_encode($this->toArray(), $options); + return json_encode($this->jsonSerialize(), $options); } /**
true
Other
laravel
framework
79f64b8929cf2d3d71eefddc6e284a1aea1d772f.json
Fix Collection JSON serializing logic
tests/Support/SupportCollectionTest.php
@@ -112,19 +112,31 @@ public function testToArrayCallsToArrayOnEachItemInCollection() $this->assertEquals(['foo.array', 'bar.array'], $results); } - public function testToJsonEncodesTheToArrayResult() + public function testJsonSerializeCallsToArrayOrJsonSerializeOnEachItemInCollection() { - $c = $this->getMock('Illuminate\Support\Collection', ['toArray']); - $c->expects($this->once())->method('toArray')->will($this->returnValue('foo')); + $item1 = m::mock('JsonSerializable'); + $item1->shouldReceive('jsonSerialize')->once()->andReturn('foo.json'); + $item2 = m::mock('Illuminate\Contracts\Support\Arrayable'); + $item2->shouldReceive('toArray')->once()->andReturn('bar.array'); + $c = new Collection([$item1, $item2]); + $results = $c->jsonSerialize(); + + $this->assertEquals(['foo.json', 'bar.array'], $results); + } + + public function testToJsonEncodesTheJsonSerializeResult() + { + $c = $this->getMock('Illuminate\Support\Collection', ['jsonSerialize']); + $c->expects($this->once())->method('jsonSerialize')->will($this->returnValue('foo')); $results = $c->toJson(); $this->assertJsonStringEqualsJsonString(json_encode('foo'), $results); } public function testCastingToStringJsonEncodesTheToArrayResult() { - $c = $this->getMock('Illuminate\Database\Eloquent\Collection', ['toArray']); - $c->expects($this->once())->method('toArray')->will($this->returnValue('foo')); + $c = $this->getMock('Illuminate\Database\Eloquent\Collection', ['jsonSerialize']); + $c->expects($this->once())->method('jsonSerialize')->will($this->returnValue('foo')); $this->assertJsonStringEqualsJsonString(json_encode('foo'), (string) $c); }
true
Other
laravel
framework
fb644538937e91b922135161355d7466600f7a03.json
Move session assertions.
src/Illuminate/Foundation/Testing/InteractsWithSession.php
@@ -55,4 +55,89 @@ public function flushSession() $this->app['session']->flush(); } + + /** + * Assert that the session has a given list of values. + * + * @param string|array $key + * @param mixed $value + * @return void + */ + public function seeInSession($key, $value = null) + { + $this->assertSessionHas($key, $value); + + return $this; + } + + /** + * Assert that the session has a given list of values. + * + * @param string|array $key + * @param mixed $value + * @return void + */ + public function assertSessionHas($key, $value = null) + { + if (is_array($key)) { + return $this->assertSessionHasAll($key); + } + + if (is_null($value)) { + PHPUnit::assertTrue($this->app['session.store']->has($key), "Session missing key: $key"); + } else { + PHPUnit::assertEquals($value, $this->app['session.store']->get($key)); + } + } + + /** + * Assert that the session has a given list of values. + * + * @param array $bindings + * @return void + */ + public function assertSessionHasAll(array $bindings) + { + foreach ($bindings as $key => $value) { + if (is_int($key)) { + $this->assertSessionHas($value); + } else { + $this->assertSessionHas($key, $value); + } + } + } + + /** + * Assert that the session has errors bound. + * + * @param string|array $bindings + * @param mixed $format + * @return void + */ + public function assertSessionHasErrors($bindings = [], $format = null) + { + $this->assertSessionHas('errors'); + + $bindings = (array) $bindings; + + $errors = $this->app['session.store']->get('errors'); + + foreach ($bindings as $key => $value) { + if (is_int($key)) { + PHPUnit::assertTrue($errors->has($value), "Session missing error: $value"); + } else { + PHPUnit::assertContains($value, $errors->get($key, $format)); + } + } + } + + /** + * Assert that the session has old input. + * + * @return void + */ + public function assertHasOldInput() + { + $this->assertSessionHas('_old_input'); + } }
true
Other
laravel
framework
fb644538937e91b922135161355d7466600f7a03.json
Move session assertions.
src/Illuminate/Foundation/Testing/MakesHttpRequests.php
@@ -635,91 +635,6 @@ public function assertRedirectedToAction($name, $parameters = [], $with = []) $this->assertRedirectedTo($this->app['url']->action($name, $parameters), $with); } - /** - * Assert that the session has a given list of values. - * - * @param string|array $key - * @param mixed $value - * @return void - */ - public function seeInSession($key, $value = null) - { - $this->assertSessionHas($key, $value); - - return $this; - } - - /** - * Assert that the session has a given list of values. - * - * @param string|array $key - * @param mixed $value - * @return void - */ - public function assertSessionHas($key, $value = null) - { - if (is_array($key)) { - return $this->assertSessionHasAll($key); - } - - if (is_null($value)) { - PHPUnit::assertTrue($this->app['session.store']->has($key), "Session missing key: $key"); - } else { - PHPUnit::assertEquals($value, $this->app['session.store']->get($key)); - } - } - - /** - * Assert that the session has a given list of values. - * - * @param array $bindings - * @return void - */ - public function assertSessionHasAll(array $bindings) - { - foreach ($bindings as $key => $value) { - if (is_int($key)) { - $this->assertSessionHas($value); - } else { - $this->assertSessionHas($key, $value); - } - } - } - - /** - * Assert that the session has errors bound. - * - * @param string|array $bindings - * @param mixed $format - * @return void - */ - public function assertSessionHasErrors($bindings = [], $format = null) - { - $this->assertSessionHas('errors'); - - $bindings = (array) $bindings; - - $errors = $this->app['session.store']->get('errors'); - - foreach ($bindings as $key => $value) { - if (is_int($key)) { - PHPUnit::assertTrue($errors->has($value), "Session missing error: $value"); - } else { - PHPUnit::assertContains($value, $errors->get($key, $format)); - } - } - } - - /** - * Assert that the session has old input. - * - * @return void - */ - public function assertHasOldInput() - { - $this->assertSessionHas('_old_input'); - } - /** * Dump the content from the last response. *
true
Other
laravel
framework
7d89a3ea6c74bfeb1f82e7cf47aedc4aff2c8d6d.json
Fix Eloquent Collection tests
tests/Database/DatabaseEloquentCollectionTest.php
@@ -235,12 +235,12 @@ public function testNonModelRelatedMethods() { $a = new Collection([['foo' => 'bar'], ['foo' => 'baz']]); $b = new Collection(['a', 'b', 'c']); - $this->assertInstanceOf(BaseCollection::class, $a->pluck('foo')); - $this->assertInstanceOf(BaseCollection::class, $a->keys()); - $this->assertInstanceOf(BaseCollection::class, $a->collapse()); - $this->assertInstanceOf(BaseCollection::class, $a->flatten()); - $this->assertInstanceOf(BaseCollection::class, $a->zip(['a', 'b'], ['c', 'd'])); - $this->assertInstanceOf(BaseCollection::class, $b->flip()); + $this->assertEquals(get_class($a->pluck('foo')), BaseCollection::class); + $this->assertEquals(get_class($a->keys()), BaseCollection::class); + $this->assertEquals(get_class($a->collapse()), BaseCollection::class); + $this->assertEquals(get_class($a->flatten()), BaseCollection::class); + $this->assertEquals(get_class($a->zip(['a', 'b'], ['c', 'd'])), BaseCollection::class); + $this->assertEquals(get_class($b->flip()), BaseCollection::class); } }
false
Other
laravel
framework
e0c7d76bbbc829c4069bf142fe5d56545252b99e.json
Allow negative condition in presence verifier
src/Illuminate/Validation/DatabasePresenceVerifier.php
@@ -2,6 +2,7 @@ namespace Illuminate\Validation; +use Illuminate\Support\Str; use Illuminate\Database\ConnectionResolverInterface; class DatabasePresenceVerifier implements PresenceVerifierInterface @@ -91,6 +92,8 @@ protected function addWhere($query, $key, $extraValue) $query->whereNull($key); } elseif ($extraValue === 'NOT_NULL') { $query->whereNotNull($key); + } elseif (Str::startsWith($extraValue, '!')) { + $query->where($key, '!=', mb_substr($extraValue, 1)); } else { $query->where($key, $extraValue); }
true
Other
laravel
framework
e0c7d76bbbc829c4069bf142fe5d56545252b99e.json
Allow negative condition in presence verifier
tests/Validation/ValidationDatabasePresenceVerifierTest.php
@@ -16,11 +16,12 @@ public function testBasicCount() $db->shouldReceive('connection')->once()->with('connection')->andReturn($conn = m::mock('StdClass')); $conn->shouldReceive('table')->once()->with('table')->andReturn($builder = m::mock('StdClass')); $builder->shouldReceive('where')->with('column', '=', 'value')->andReturn($builder); - $extra = ['foo' => 'NULL', 'bar' => 'NOT_NULL', 'baz' => 'taylor', 'faz' => true]; + $extra = ['foo' => 'NULL', 'bar' => 'NOT_NULL', 'baz' => 'taylor', 'faz' => true, 'not' => '!admin']; $builder->shouldReceive('whereNull')->with('foo'); $builder->shouldReceive('whereNotNull')->with('bar'); $builder->shouldReceive('where')->with('baz', 'taylor'); $builder->shouldReceive('where')->with('faz', true); + $builder->shouldReceive('where')->with('not', '!=', 'admin'); $builder->shouldReceive('count')->once()->andReturn(100); $this->assertEquals(100, $verifier->getCount('table', 'column', 'value', null, null, $extra));
true
Other
laravel
framework
0ad5b36932a87bd76736d763aef858d60d9f4fa7.json
Make queued jobs the default.
src/Illuminate/Foundation/Console/JobMakeCommand.php
@@ -35,10 +35,10 @@ class JobMakeCommand extends GeneratorCommand */ protected function getStub() { - if ($this->option('queued')) { - return __DIR__.'/stubs/job-queued.stub'; - } else { + if ($this->option('sync')) { return __DIR__.'/stubs/job.stub'; + } else { + return __DIR__.'/stubs/job-queued.stub'; } } @@ -61,7 +61,7 @@ protected function getDefaultNamespace($rootNamespace) protected function getOptions() { return [ - ['queued', null, InputOption::VALUE_NONE, 'Indicates that job should be queued.'], + ['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'], ]; } }
false
Other
laravel
framework
00e2c2b503e603ca78035abbce9dfe05c2a2965b.json
Remove unused imports
src/Illuminate/Foundation/Testing/CrawlerTrait.php
@@ -2,7 +2,6 @@ namespace Illuminate\Foundation\Testing; -use Exception; use Illuminate\Support\Str; use Illuminate\Http\Request;
true
Other
laravel
framework
00e2c2b503e603ca78035abbce9dfe05c2a2965b.json
Remove unused imports
src/Illuminate/Foundation/Testing/InteractsWithPages.php
@@ -4,7 +4,6 @@ use Exception; use Illuminate\Support\Str; -use Illuminate\Http\Request; use InvalidArgumentException; use Symfony\Component\DomCrawler\Form; use Symfony\Component\DomCrawler\Crawler;
true
Other
laravel
framework
5311a22735cad8ae34e42e8b4e76b03d5e928399.json
Prevent $config conflicts within config files
src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
@@ -50,10 +50,10 @@ public function bootstrap(Application $app) * @param \Illuminate\Contracts\Config\Repository $config * @return void */ - protected function loadConfigurationFiles(Application $app, RepositoryContract $config) + protected function loadConfigurationFiles(Application $app, RepositoryContract $configRepo) { foreach ($this->getConfigurationFiles($app) as $key => $path) { - $config->set($key, require $path); + $configRepo->set($key, require $path); } }
false
Other
laravel
framework
2f5a4ccf7834c82c465767fc6fcbf8e7b8278b61.json
Add other test
tests/Database/DatabaseEloquentBuilderTest.php
@@ -433,6 +433,21 @@ public function testHasWithContraintsAndHavingInSubquery() $this->assertEquals(['baz', 'qux', 'quuux'], $builder->getBindings()); } + public function testHasWithContraintsAndJoinAndHavingInSubquery() + { + $model = new EloquentBuilderTestModelParentStub; + $builder = $model->where('bar', 'baz'); + $builder->whereHas('foo', function ($q) { + $q->join('quuuux', function ($j) { + $j->on('quuuuux', '=', 'quuuuuux', 'and', true); + }); + $q->having('bam', '>', 'qux'); + })->where('quux', 'quuux'); + + $this->assertEquals('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? and (select count(*) from "eloquent_builder_test_model_close_related_stubs" inner join "quuuux" on "quuuuux" = ? where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id" having "bam" > ?) >= 1 and "quux" = ?', $builder->toSql()); + $this->assertEquals(['baz', 'quuuuuux', 'qux', 'quuux'], $builder->getBindings()); + } + public function testHasNestedWithConstraints() { $model = new EloquentBuilderTestModelParentStub;
false
Other
laravel
framework
acfdc3e5b90a43eeede56f496356009fa87bdee8.json
Apply StyleCI fixes
src/Illuminate/Foundation/Validation/ValidationException.php
@@ -6,32 +6,32 @@ class ValidationException extends Exception { - /** - * The validator instance. - * - * @var \Illuminate\Validation\Validator - */ - public $validator; + /** + * The validator instance. + * + * @var \Illuminate\Validation\Validator + */ + public $validator; - /** - * The recommended response to send to the client. - * - * @var \Illuminate\Http\Response|null - */ - public $response; + /** + * The recommended response to send to the client. + * + * @var \Illuminate\Http\Response|null + */ + public $response; - /** - * Create a new exception instance. - * - * @param \Illuminate\Validation\Validator $validator - * @param \Illuminate\Http\Response $response - * @return void - */ - public function __construct($validator, $response = null) - { - parent::__construct("The given data failed to pass validation."); + /** + * Create a new exception instance. + * + * @param \Illuminate\Validation\Validator $validator + * @param \Illuminate\Http\Response $response + * @return void + */ + public function __construct($validator, $response = null) + { + parent::__construct('The given data failed to pass validation.'); - $this->response = $response; - $this->validator = $validator; - } + $this->response = $response; + $this->validator = $validator; + } }
false
Other
laravel
framework
65f69f0ebf1622ae5e0ffb23d8e1ac1e178b03fa.json
Make Seeder and its run() method abstract
src/Illuminate/Database/Seeder.php
@@ -5,7 +5,7 @@ use Illuminate\Console\Command; use Illuminate\Container\Container; -class Seeder +abstract class Seeder { /** * The container instance. @@ -26,10 +26,7 @@ class Seeder * * @return void */ - public function run() - { - // - } + abstract public function run(); /** * Seed the given connection from the given path.
true
Other
laravel
framework
65f69f0ebf1622ae5e0ffb23d8e1ac1e178b03fa.json
Make Seeder and its run() method abstract
tests/Database/DatabaseSeederTest.php
@@ -3,6 +3,14 @@ use Mockery as m; use Illuminate\Database\Seeder; +class TestSeeder extends Seeder +{ + public function run() + { + // + } +} + class DatabaseSeederTest extends PHPUnit_Framework_TestCase { public function tearDown() @@ -12,7 +20,7 @@ public function tearDown() public function testCallResolveTheClassAndCallsRun() { - $seeder = new Seeder; + $seeder = new TestSeeder; $seeder->setContainer($container = m::mock('Illuminate\Container\Container')); $output = m::mock('Symfony\Component\Console\Output\OutputInterface'); $output->shouldReceive('writeln')->once()->andReturn('foo'); @@ -29,14 +37,14 @@ public function testCallResolveTheClassAndCallsRun() public function testSetContainer() { - $seeder = new Seeder; + $seeder = new TestSeeder; $container = m::mock('Illuminate\Container\Container'); $this->assertEquals($seeder->setContainer($container), $seeder); } public function testSetCommand() { - $seeder = new Seeder; + $seeder = new TestSeeder; $command = m::mock('Illuminate\Console\Command'); $this->assertEquals($seeder->setCommand($command), $seeder); }
true
Other
laravel
framework
bc38e1494b1130415456de9702a93db071c248fe.json
Fix performance on getSize method Not is more faster only return $value for numeric types There is some special reason search again the value Arr::get($this->data, $attribute)
src/Illuminate/Validation/Validator.php
@@ -960,7 +960,7 @@ protected function getSize($attribute, $value) // is the size. If it is a file, we take kilobytes, and for a string the // entire length of the string will be considered the attribute size. if (is_numeric($value) && $hasNumeric) { - return Arr::get($this->data, $attribute); + return $value; } elseif (is_array($value)) { return count($value); } elseif ($value instanceof File) {
false
Other
laravel
framework
489a06810e8027a46c869827f94f114ff24a5286.json
Add a failing test for resource "update" route
tests/Routing/RoutingRouteTest.php
@@ -573,6 +573,12 @@ public function testResourceRouting() $routes = $router->getRoutes(); $this->assertCount(8, $routes); + $router = $this->getRouter(); + $router->resource('foo', 'FooController', ['only' => ['update']]); + $routes = $router->getRoutes(); + + $this->assertCount(1, $routes); + $router = $this->getRouter(); $router->resource('foo', 'FooController', ['only' => ['show', 'destroy']]); $routes = $router->getRoutes();
false
Other
laravel
framework
377596b316319569ab62cdb8d31408a16d5b08cf.json
Add AuthorizesRequests returns responses test
tests/Foundation/FoundationAuthorizesRequestsTraitTest.php
@@ -1,6 +1,7 @@ <?php use Illuminate\Container\Container; +use Illuminate\Auth\Access\Response; use Illuminate\Contracts\Auth\Access\Gate; class FoundationAuthorizesRequestsTraitTest extends PHPUnit_Framework_TestCase @@ -17,8 +18,9 @@ public function test_basic_gate_check() return true; }); - (new FoundationTestAuthorizeTraitClass)->authorize('foo'); + $response = (new FoundationTestAuthorizeTraitClass)->authorize('foo'); + $this->assertInstanceOf(Response::class, $response); $this->assertTrue($_SERVER['_test.authorizes.trait']); } @@ -44,8 +46,9 @@ public function test_policies_may_be_called() $gate->policy(FoundationAuthorizesRequestTestClass::class, FoundationAuthorizesRequestTestPolicy::class); - (new FoundationTestAuthorizeTraitClass)->authorize('update', new FoundationAuthorizesRequestTestClass); + $response = (new FoundationTestAuthorizeTraitClass)->authorize('update', new FoundationAuthorizesRequestTestClass); + $this->assertInstanceOf(Response::class, $response); $this->assertTrue($_SERVER['_test.authorizes.trait.policy']); } @@ -57,8 +60,9 @@ public function test_policy_method_may_be_guessed() $gate->policy(FoundationAuthorizesRequestTestClass::class, FoundationAuthorizesRequestTestPolicy::class); - (new FoundationTestAuthorizeTraitClass)->authorize([new FoundationAuthorizesRequestTestClass]); + $response = (new FoundationTestAuthorizeTraitClass)->authorize([new FoundationAuthorizesRequestTestClass]); + $this->assertInstanceOf(Response::class, $response); $this->assertTrue($_SERVER['_test.authorizes.trait.policy']); }
false
Other
laravel
framework
29e07131b79b63098b6db9b77df3c0f7d7e4e19a.json
Return access response from AuthorizesRequests
src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php
@@ -13,15 +13,15 @@ trait AuthorizesRequests * * @param mixed $ability * @param mixed|array $arguments - * @return void + * @return \Illuminate\Auth\Access\Response * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ public function authorize($ability, $arguments = []) { list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments); - $this->authorizeAtGate(app(Gate::class), $ability, $arguments); + return $this->authorizeAtGate(app(Gate::class), $ability, $arguments); } /** @@ -30,7 +30,7 @@ public function authorize($ability, $arguments = []) * @param \Illuminate\Contracts\Auth\Authenticatable|mixed $user * @param mixed $ability * @param mixed|array $arguments - * @return void + * @return \Illuminate\Auth\Access\Response * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ @@ -40,7 +40,7 @@ public function authorizeForUser($user, $ability, $arguments = []) $gate = app(Gate::class)->forUser($user); - $this->authorizeAtGate($gate, $ability, $arguments); + return $this->authorizeAtGate($gate, $ability, $arguments); } /** @@ -49,14 +49,14 @@ public function authorizeForUser($user, $ability, $arguments = []) * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @param mixed $ability * @param mixed|array $arguments - * @return void + * @return \Illuminate\Auth\Access\Response * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ public function authorizeAtGate(Gate $gate, $ability, $arguments) { try { - $gate->authorize($ability, $arguments); + return $gate->authorize($ability, $arguments); } catch (UnauthorizedException $e) { throw $this->createGateUnauthorizedException( $ability, $arguments, $e->getMessage()
false
Other
laravel
framework
367e456bcbf73b16f60fababd366a21db802b14d.json
Add gate authorize tests
tests/Auth/AuthAccessGateTest.php
@@ -2,6 +2,8 @@ use Illuminate\Auth\Access\Gate; use Illuminate\Container\Container; +use Illuminate\Auth\Access\Response; +use Illuminate\Auth\Access\HandlesAuthorization; class GateTest extends PHPUnit_Framework_TestCase { @@ -122,7 +124,7 @@ public function test_policy_default_to_false_if_method_does_not_exist() public function test_policy_classes_can_be_defined_to_handle_checks_for_given_class_name() { - $gate = $this->getBasicGate(); + $gate = $this->getBasicGate(true); $gate->policy(AccessGateTestDummy::class, AccessGateTestPolicy::class); @@ -163,9 +165,49 @@ public function test_for_user_method_attaches_a_new_user_to_a_new_gate_instance( $this->assertTrue($gate->forUser((object) ['id' => 2])->check('foo')); } - protected function getBasicGate() + /** + * @expectedException \Illuminate\Auth\Access\UnauthorizedException + */ + public function test_authorize_throws_unauthorized_exception() + { + $gate = $this->getBasicGate(); + + $gate->policy(AccessGateTestDummy::class, AccessGateTestPolicy::class); + + $gate->authorize('create', new AccessGateTestDummy); + } + + public function test_authorize_returns_allowed_response() + { + $gate = $this->getBasicGate(true); + + $gate->policy(AccessGateTestDummy::class, AccessGateTestPolicy::class); + + $check = $gate->check('create', new AccessGateTestDummy); + $response = $gate->authorize('create', new AccessGateTestDummy); + + $this->assertInstanceOf(Response::class, $response); + $this->assertNull($response->message()); + $this->assertTrue($check); + } + + public function test_authorize_returns_an_allowed_response_for_a_truthy_return() + { + $gate = $this->getBasicGate(); + + $gate->policy(AccessGateTestDummy::class, AccessGateTestPolicy::class); + + $response = $gate->authorize('update', new AccessGateTestDummy); + + $this->assertInstanceOf(Response::class, $response); + $this->assertNull($response->message()); + } + + protected function getBasicGate($isAdmin = false) { - return new Gate(new Container, function () { return (object) ['id' => 1]; }); + return new Gate(new Container, function () use ($isAdmin) { + return (object) ['id' => 1, 'isAdmin' => $isAdmin]; + }); } } @@ -184,14 +226,16 @@ class AccessGateTestDummy class AccessGateTestPolicy { + use HandlesAuthorization; + public function create($user) { - return true; + return $user->isAdmin ? $this->allow() : $this->deny('You are not an admin.'); } public function update($user, AccessGateTestDummy $dummy) { - return $user instanceof StdClass; + return ! $user->isAdmin; } }
false
Other
laravel
framework
150cbf7d7d8f4b1ea6160799c73f862606636564.json
Add HandlesAuthorization to policy stub
src/Illuminate/Foundation/Console/stubs/policy.stub
@@ -2,8 +2,12 @@ namespace DummyNamespace; +use Illuminate\Auth\Access\HandlesAuthorization; + class DummyClass { + use HandlesAuthorization; + /** * Create a new policy instance. *
false
Other
laravel
framework
cf3440799657486757a2e39b077a051cddd7756c.json
Allow passing of permissions on local file driver.
src/Illuminate/Filesystem/FilesystemManager.php
@@ -125,7 +125,11 @@ protected function callCustomCreator(array $config) */ public function createLocalDriver(array $config) { - return $this->adapt(new Flysystem(new LocalAdapter($config['root']))); + $permissions = isset($config['permissions']) ? $config['permissions'] : []; + + return $this->adapt(new Flysystem(new LocalAdapter( + $config['root'], LOCK_EX, LocalAdapter::DISALLOW_LINKS, $permissions + ))); } /**
false
Other
laravel
framework
b6113ebc5a23905474548a9d0eea448da2c178e3.json
remove container check
src/Illuminate/Routing/Router.php
@@ -741,7 +741,7 @@ protected function substituteImplicitBindings($route) foreach ($route->callableParameters(Model::class) as $parameter) { $class = $parameter->getClass(); - if (array_key_exists($parameter->name, $parameters) && ! $this->container->bound($class->name)) { + if (array_key_exists($parameter->name, $parameters)) { $method = $parameter->isDefaultValueAvailable() ? 'find' : 'findOrFail'; $route->setParameter(
false
Other
laravel
framework
0c34df04ff0eb63f4377c8bc0807411e08b517e9.json
Have the $commands property initialized by default With this change, the developers can bind "Illuminate\Foundation\Console\Kernel" to "Illuminate\Contracts\Console\Kernel".
src/Illuminate/Foundation/Console/Kernel.php
@@ -49,6 +49,14 @@ class Kernel implements KernelContract 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders', ]; + + /** + * The Artisan commands provided by the application. + * Initialized as empty here, in case there is no need of separate Console Kernel. + * + * @var array + */ + protected $commands = []; /** * Create a new console kernel instance.
false
Other
laravel
framework
afe7528cc296b0ea873a1f608a819df70e0a6496.json
Use $this in closure Supported since PHP 5.4
tests/Mail/MailMailerTest.php
@@ -173,9 +173,8 @@ public function testGlobalFromIsRespectedOnAllMessages() $view->shouldReceive('render')->once()->andReturn('rendered.view'); $this->setSwiftMailer($mailer); $mailer->alwaysFrom('taylorotwell@gmail.com', 'Taylor Otwell'); - $me = $this; - $mailer->getSwiftMailer()->shouldReceive('send')->once()->with(m::type('Swift_Message'), [])->andReturnUsing(function ($message) use ($me) { - $me->assertEquals(['taylorotwell@gmail.com' => 'Taylor Otwell'], $message->getFrom()); + $mailer->getSwiftMailer()->shouldReceive('send')->once()->with(m::type('Swift_Message'), [])->andReturnUsing(function ($message) { + $this->assertEquals(['taylorotwell@gmail.com' => 'Taylor Otwell'], $message->getFrom()); }); $mailer->send('foo', ['data'], function ($m) {}); }
false
Other
laravel
framework
2d4dd33f87a604716beb4e03e9526c1a9d4e5a54.json
Add note to remember method's purpose.
src/Illuminate/Foundation/Testing/CrawlerTrait.php
@@ -145,6 +145,8 @@ public function delete($uri, array $data = [], array $headers = []) /** * Send the given request through the application. * + * This method allows you to fully customize the entire Request object. + * * @param \Illuminate\Http\Request $request * @return $this */
false
Other
laravel
framework
052ebceb4a26b47d294600976d8756f77245eee2.json
Get exception property only if it exists
src/Illuminate/Foundation/Testing/CrawlerTrait.php
@@ -289,7 +289,7 @@ protected function assertPageLoaded($uri, $message = null) } catch (PHPUnitException $e) { $message = $message ?: "A request to [{$uri}] failed. Received status code [{$status}]."; - throw new HttpException($message, null, $this->response->exception); + throw new HttpException($message, null, data_get($this->response, 'exception')); } }
false
Other
laravel
framework
87f0fab78b63d17def5f79cd28220119b5995709.json
Remove unused imports
src/Illuminate/Routing/RoutingServiceProvider.php
@@ -4,8 +4,6 @@ use Illuminate\Support\ServiceProvider; use Zend\Diactoros\Response as PsrResponse; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; class RoutingServiceProvider extends ServiceProvider
false
Other
laravel
framework
7b1a0732e8e3b70c811f31ce1ed85166e7a0b772.json
Use proper assertions
tests/Database/DatabaseEloquentModelTest.php
@@ -571,7 +571,7 @@ public function testToArray() $model->setRelation('multi', new Illuminate\Database\Eloquent\Collection); $array = $model->toArray(); - $this->assertTrue(is_array($array)); + $this->assertInternalType('array', $array); $this->assertEquals('foo', $array['name']); $this->assertEquals('baz', $array['names'][0]['bar']); $this->assertEquals('boom', $array['names'][1]['bam']);
true
Other
laravel
framework
7b1a0732e8e3b70c811f31ce1ed85166e7a0b772.json
Use proper assertions
tests/Filesystem/FilesystemTest.php
@@ -16,7 +16,7 @@ public function testPutStoresFiles() { $files = new Filesystem; $files->put(__DIR__.'/file.txt', 'Hello World'); - $this->assertEquals('Hello World', file_get_contents(__DIR__.'/file.txt')); + $this->assertStringEqualsFile(__DIR__.'/file.txt', 'Hello World'); @unlink(__DIR__.'/file.txt'); } @@ -34,15 +34,15 @@ public function testPrependExistingFiles() $files = new Filesystem; $files->put(__DIR__.'/file.txt', 'World'); $files->prepend(__DIR__.'/file.txt', 'Hello '); - $this->assertEquals('Hello World', file_get_contents(__DIR__.'/file.txt')); + $this->assertStringEqualsFile(__DIR__.'/file.txt', 'Hello World'); @unlink(__DIR__.'/file.txt'); } public function testPrependNewFiles() { $files = new Filesystem; $files->prepend(__DIR__.'/file.txt', 'Hello World'); - $this->assertEquals('Hello World', file_get_contents(__DIR__.'/file.txt')); + $this->assertStringEqualsFile(__DIR__.'/file.txt', 'Hello World'); @unlink(__DIR__.'/file.txt'); }
true
Other
laravel
framework
7b1a0732e8e3b70c811f31ce1ed85166e7a0b772.json
Use proper assertions
tests/Queue/QueueDatabaseQueueTest.php
@@ -20,7 +20,7 @@ public function testPushProperlyPushesJobOntoDatabase() $this->assertEquals(0, $array['attempts']); $this->assertEquals(0, $array['reserved']); $this->assertNull($array['reserved_at']); - $this->assertTrue(is_int($array['available_at'])); + $this->assertInternalType('int', $array['available_at']); }); $queue->push('foo', ['data']); @@ -41,7 +41,7 @@ public function testDelayedPushProperlyPushesJobOntoDatabase() $this->assertEquals(0, $array['attempts']); $this->assertEquals(0, $array['reserved']); $this->assertNull($array['reserved_at']); - $this->assertTrue(is_int($array['available_at'])); + $this->assertInternalType('int', $array['available_at']); }); $queue->later(10, 'foo', ['data']);
true
Other
laravel
framework
7b1a0732e8e3b70c811f31ce1ed85166e7a0b772.json
Use proper assertions
tests/Support/SupportCollectionTest.php
@@ -118,15 +118,15 @@ public function testToJsonEncodesTheToArrayResult() $c->expects($this->once())->method('toArray')->will($this->returnValue('foo')); $results = $c->toJson(); - $this->assertEquals(json_encode('foo'), $results); + $this->assertJsonStringEqualsJsonString(json_encode('foo'), $results); } public function testCastingToStringJsonEncodesTheToArrayResult() { $c = $this->getMock('Illuminate\Database\Eloquent\Collection', ['toArray']); $c->expects($this->once())->method('toArray')->will($this->returnValue('foo')); - $this->assertEquals(json_encode('foo'), (string) $c); + $this->assertJsonStringEqualsJsonString(json_encode('foo'), (string) $c); } public function testOffsetAccess()
true
Other
laravel
framework
7b1a0732e8e3b70c811f31ce1ed85166e7a0b772.json
Use proper assertions
tests/Support/SupportFluentTest.php
@@ -93,7 +93,7 @@ public function testToJsonEncodesTheToArrayResult() $fluent->expects($this->once())->method('toArray')->will($this->returnValue('foo')); $results = $fluent->toJson(); - $this->assertEquals(json_encode('foo'), $results); + $this->assertJsonStringEqualsJsonString(json_encode('foo'), $results); } }
true
Other
laravel
framework
7b1a0732e8e3b70c811f31ce1ed85166e7a0b772.json
Use proper assertions
tests/Support/SupportHelpersTest.php
@@ -187,7 +187,7 @@ public function testStrIs() public function testStrRandom() { $result = Str::random(20); - $this->assertTrue(is_string($result)); + $this->assertInternalType('string', $result); $this->assertEquals(20, strlen($result)); }
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Console/composer.json
@@ -17,7 +17,7 @@ "php": ">=5.5.9", "illuminate/contracts": "5.2.*", "illuminate/support": "5.2.*", - "symfony/console": "3.0.*", + "symfony/console": "2.8.*|3.0.*", "nesbot/carbon": "~1.20" }, "autoload": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Cookie/composer.json
@@ -17,8 +17,8 @@ "php": ">=5.5.9", "illuminate/contracts": "5.2.*", "illuminate/support": "5.2.*", - "symfony/http-kernel": "3.0.*", - "symfony/http-foundation": "3.0.*" + "symfony/http-kernel": "2.8.*|3.0.*", + "symfony/http-foundation": "2.8.*|3.0.*" }, "autoload": { "psr-4": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Filesystem/composer.json
@@ -17,7 +17,7 @@ "php": ">=5.5.9", "illuminate/contracts": "5.2.*", "illuminate/support": "5.2.*", - "symfony/finder": "3.0.*" + "symfony/finder": "2.8.*|3.0.*" }, "autoload": { "psr-4": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Http/composer.json
@@ -17,8 +17,8 @@ "php": ">=5.5.9", "illuminate/session": "5.2.*", "illuminate/support": "5.2.*", - "symfony/http-foundation": "3.0.*", - "symfony/http-kernel": "3.0.*" + "symfony/http-foundation": "2.8.*|3.0.*", + "symfony/http-kernel": "2.8.*|3.0.*" }, "autoload": { "psr-4": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Queue/composer.json
@@ -20,7 +20,7 @@ "illuminate/container": "5.2.*", "illuminate/http": "5.2.*", "illuminate/support": "5.2.*", - "symfony/process": "3.0.*", + "symfony/process": "2.8.*|3.0.*", "nesbot/carbon": "~1.20" }, "autoload": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Routing/composer.json
@@ -21,9 +21,9 @@ "illuminate/pipeline": "5.2.*", "illuminate/session": "5.2.*", "illuminate/support": "5.2.*", - "symfony/http-foundation": "3.0.*", - "symfony/http-kernel": "3.0.*", - "symfony/routing": "3.0.*" + "symfony/http-foundation": "2.8.*|3.0.*", + "symfony/http-kernel": "2.8.*|3.0.*", + "symfony/routing": "2.8.*|3.0.*" }, "autoload": { "psr-4": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Session/composer.json
@@ -18,8 +18,8 @@ "illuminate/contracts": "5.2.*", "illuminate/support": "5.2.*", "nesbot/carbon": "~1.20", - "symfony/finder": "3.0.*", - "symfony/http-foundation": "3.0.*" + "symfony/finder": "2.8.*|3.0.*", + "symfony/http-foundation": "2.8.*|3.0.*" }, "autoload": { "psr-4": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Translation/composer.json
@@ -17,7 +17,7 @@ "php": ">=5.5.9", "illuminate/filesystem": "5.2.*", "illuminate/support": "5.2.*", - "symfony/translation": "3.0.*" + "symfony/translation": "2.8.*|3.0.*" }, "autoload": { "psr-4": {
true
Other
laravel
framework
2a896c5e23e44b657dab27f87561fd05f5859bf0.json
Update components for 2.8|3.0
src/Illuminate/Validation/composer.json
@@ -18,8 +18,8 @@ "illuminate/container": "5.2.*", "illuminate/contracts": "5.2.*", "illuminate/support": "5.2.*", - "symfony/http-foundation": "3.0.*", - "symfony/translation": "3.0.*" + "symfony/http-foundation": "2.8.*|3.0.*", + "symfony/translation": "2.8.*|3.0.*" }, "autoload": { "psr-4": {
true
Other
laravel
framework
47e2f092d052303b47caa08c6ab5e7d481c103e9.json
Allow both Symfony 2.8 and 3.0
composer.json
@@ -29,17 +29,17 @@ "paragonie/random_compat": "^1.0.4", "psy/psysh": "~0.5.1", "swiftmailer/swiftmailer": "~5.1", - "symfony/console": "3.0.*", - "symfony/css-selector": "3.0.*", - "symfony/debug": "3.0.*", - "symfony/dom-crawler": "3.0.*", - "symfony/finder": "3.0.*", - "symfony/http-foundation": "3.0.*", - "symfony/http-kernel": "3.0.*", - "symfony/process": "3.0.*", - "symfony/routing": "3.0.*", - "symfony/translation": "3.0.*", - "symfony/var-dumper": "3.0.*", + "symfony/console": "2.8.*|3.0.*", + "symfony/css-selector": "2.8.*|3.0.*", + "symfony/debug": "2.8.*|3.0.*", + "symfony/dom-crawler": "2.8.*|3.0.*", + "symfony/finder": "2.8.*|3.0.*", + "symfony/http-foundation": "2.8.*|3.0.*", + "symfony/http-kernel": "2.8.*|3.0.*", + "symfony/process": "2.8.*|3.0.*", + "symfony/routing": "2.8.*|3.0.*", + "symfony/translation": "2.8.*|3.0.*", + "symfony/var-dumper": "2.8.*|3.0.*", "vlucas/phpdotenv": "~1.0" }, "replace": {
false
Other
laravel
framework
c34ad52bdeea9163b8283e4793c2cb9a951469bf.json
Fix union with join issue
src/Illuminate/Database/Query/Builder.php
@@ -337,9 +337,13 @@ public function join($table, $one, $operator = null, $two = null, $type = 'inner // is trying to build a join with a complex "on" clause containing more than // one condition, so we'll add the join and call a Closure with the query. if ($one instanceof Closure) { - $this->joins[] = new JoinClause($type, $table); + $join = new JoinClause($type, $table); + + call_user_func($one, $join); - call_user_func($one, end($this->joins)); + $this->joins[] = $join; + + $this->addBinding($join->bindings, 'join'); } // If the column is simply a string, we can assume the join simply has a basic @@ -351,6 +355,8 @@ public function join($table, $one, $operator = null, $two = null, $type = 'inner $this->joins[] = $join->on( $one, $operator, $two, 'and', $where ); + + $this->addBinding($join->bindings, 'join'); } return $this;
true
Other
laravel
framework
c34ad52bdeea9163b8283e4793c2cb9a951469bf.json
Fix union with join issue
tests/Database/DatabaseQueryBuilderTest.php
@@ -371,7 +371,7 @@ public function testUnionWithJoin() { $builder = $this->getBuilder(); $builder->select('*')->from('users'); - $builder->union($this->getBuilder()->select('*')->from('dogs')->join('breeds', function($join) { + $builder->union($this->getBuilder()->select('*')->from('dogs')->join('breeds', function ($join) { $join->on('dogs.breed_id', '=', 'breeds.id') ->where('breeds.is_native', '=', 1); }));
true
Other
laravel
framework
e7f4c52114a51604e0fb3b00fb794ae821b1a62c.json
use file object instead of file_exists
src/Illuminate/Cache/FileStore.php
@@ -110,12 +110,8 @@ public function put($key, $value, $minutes) */ protected function createCacheDirectory($path) { - try { - if (! file_exists(dirname($path))) { - $this->files->makeDirectory(dirname($path), 0777, true, true); - } - } catch (Exception $e) { - // + if (! $this->files->exists(dirname($path))) { + $this->files->makeDirectory(dirname($path), 0777, true, true); } }
false
Other
laravel
framework
ba3bcebbe32f87a54da37ef99581c164fe22ef2c.json
change code style to match with style ci
src/Illuminate/Cache/FileStore.php
@@ -111,7 +111,7 @@ public function put($key, $value, $minutes) protected function createCacheDirectory($path) { try { - if (!file_exists(dirname($path))) { + if (! file_exists(dirname($path))) { $this->files->makeDirectory(dirname($path), 0777, true, true); } } catch (Exception $e) {
false
Other
laravel
framework
fc38e00289d848163c4da024877f31951c55b353.json
fix missing round bracket
src/Illuminate/Cache/FileStore.php
@@ -111,7 +111,7 @@ public function put($key, $value, $minutes) protected function createCacheDirectory($path) { try { - if (!file_exists(dirname($path)) { + if (!file_exists(dirname($path))) { $this->files->makeDirectory(dirname($path), 0777, true, true); } } catch (Exception $e) {
false
Other
laravel
framework
ab902adb2e9b28012f9c4f1a95005891f8bc040b.json
Resolve validation factory contract in FormRequest Replaces resolution of the concrete implementation of the validation factory with resolution of the contract.
src/Illuminate/Foundation/Http/FormRequest.php
@@ -11,6 +11,7 @@ use Illuminate\Http\Exception\HttpResponseException; use Illuminate\Validation\ValidatesWhenResolvedTrait; use Illuminate\Contracts\Validation\ValidatesWhenResolved; +use Illuminate\Contracts\Validation\Factory as ValidationFactory; class FormRequest extends Request implements ValidatesWhenResolved { @@ -72,7 +73,7 @@ class FormRequest extends Request implements ValidatesWhenResolved */ protected function getValidatorInstance() { - $factory = $this->container->make('Illuminate\Validation\Factory'); + $factory = $this->container->make(ValidationFactory::class); if (method_exists($this, 'validator')) { return $this->container->call([$this, 'validator'], compact('factory'));
false
Other
laravel
framework
55f415bcff70c991a6accee9a17deee46a9e29c1.json
fix undefined variable
src/Illuminate/Database/Query/Builder.php
@@ -1668,7 +1668,7 @@ public function avg($column) */ public function average($column) { - return $this->avg($key); + return $this->avg($column); } /**
false
Other
laravel
framework
6f7a98ea4a62fae6eace3c410d189fa5fd8c4ace.json
Remove the array_fetch helper
src/Illuminate/Support/helpers.php
@@ -112,22 +112,6 @@ function array_except($array, $keys) } } -if (! function_exists('array_fetch')) { - /** - * Fetch a flattened array of a nested array element. - * - * @param array $array - * @param string $key - * @return array - * - * @deprecated since version 5.1. Use array_pluck instead. - */ - function array_fetch($array, $key) - { - return Arr::fetch($array, $key); - } -} - if (! function_exists('array_first')) { /** * Return the first element in an array passing a given truth test.
false
Other
laravel
framework
0fb1a0ec95e7ac1784dcb5ad49503ec758006f93.json
fix code style
src/Illuminate/Database/Capsule/Manager.php
@@ -6,9 +6,9 @@ use Illuminate\Container\Container; use Illuminate\Database\DatabaseManager; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Support\Traits\CapsuleManagerTrait; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Database\Connectors\ConnectionFactory; -use Illuminate\Support\Traits\CapsuleManagerTrait; class Manager {
false
Other
laravel
framework
306d04cc04fa00d57cddac810b0f329af101d598.json
Fix CS and add Int as a numericRule
src/Illuminate/Validation/Validator.php
@@ -139,7 +139,7 @@ class Validator implements ValidatorContract * * @var array */ - protected $numericRules = ['Numeric', 'Integer']; + protected $numericRules = ['Numeric', 'Integer', 'Int']; /** * The validation rules that imply the field is required. @@ -2600,8 +2600,7 @@ protected function requireParameterCount($count, $parameters, $rule) /** * Normalizes a rule so that we can accept short types. * - * @param string $rule - * + * @param string $rule * @return string */ protected function normalizeRule($rule)
false
Other
laravel
framework
e4c9bdb8e3761584c0899661a7667784831467f9.json
Fix small typo in comments
src/Illuminate/Routing/UrlGenerator.php
@@ -138,7 +138,7 @@ public function previous() } /** - * Generate a absolute URL to the given path. + * Generate an absolute URL to the given path. * * @param string $path * @param mixed $extra
false
Other
laravel
framework
7873cdb3c266721204b6ac593e440c1e064d4d7a.json
Remove unnecessary brackets
src/Illuminate/Encryption/Encrypter.php
@@ -47,7 +47,7 @@ public static function supported($key, $cipher) { $length = mb_strlen($key, '8bit'); - return ($cipher === 'AES-128-CBC' && ($length === 16)) || ($cipher === 'AES-256-CBC' && $length === 32); + return ($cipher === 'AES-128-CBC' && $length === 16) || ($cipher === 'AES-256-CBC' && $length === 32); } /**
false
Other
laravel
framework
23d409b450ae7cc0b236a396003ac7ea15b7538a.json
simplify request isset
src/Illuminate/Http/Request.php
@@ -881,42 +881,30 @@ public function offsetUnset($offset) } /** - * Get an input element from the request. + * Check if an input element is set on the request. * * @param string $key - * @return mixed + * @return bool */ - public function __get($key) + public function __isset($key) { - $all = $this->all(); - - if (array_key_exists($key, $all)) { - return $all[$key]; - } else { - return $this->route($key); - } + return ! is_null($this->__get($key)); } /** - * Check if an input element was set in request. + * Get an input element from the request. * * @param string $key - * @return bool + * @return mixed */ - public function __isset($key) + public function __get($key) { $all = $this->all(); if (array_key_exists($key, $all)) { - return true; - } - - $route = call_user_func($this->getRouteResolver()); - - if (is_null($route)) { - return false; + return $all[$key]; + } else { + return $this->route($key); } - - return array_key_exists($key, $route->parameters()); } }
false
Other
laravel
framework
d410a6bf3f279b5e766d6d7c2a7bb49fb93c88d9.json
Fix code style;
tests/Http/HttpRequestTest.php
@@ -565,7 +565,7 @@ public function testMagicMethods() $this->assertEquals(empty($request->undefined), true); // Simulates Route parameters. - $request = Request::create('/example/bar', 'GET', [ 'xyz' => 'overwrited' ]); + $request = Request::create('/example/bar', 'GET', ['xyz' => 'overwrited']); $request->setRouteResolver(function () use ($request) { $route = new Route('GET', '/example/{foo}/{xyz?}/{undefined?}', []); $route->bind($request);
false
Other
laravel
framework
4824f4b2fd402b597dfa9e93d27075497e411afd.json
Turn tests inline to make more clear;
tests/Http/HttpRequestTest.php
@@ -543,43 +543,74 @@ public function testCreateFromBase() * Tests for Http\Request magic methods `__get()` and `__isset()`. * * @link https://github.com/laravel/framework/issues/10403 Form request object attribute returns empty when have some string. - * @dataProvider magicMethodsProvider */ - public function testMagicMethods($uri, $route, $parameters, $property, $propertyValue, $propertyIsset, $propertyEmpty) - { - $request = Request::create($uri, 'GET', $parameters); + public function testMagicMethods() + { + // Simulates QueryStrings. + $request = Request::create('/', 'GET', ['foo' => 'bar', 'empty' => '']); + + // Parameter 'foo' is 'bar', then it ISSET and is NOT EMPTY. + $this->assertEquals($request->foo, 'bar'); + $this->assertEquals(isset($request->foo), true); + $this->assertEquals(empty($request->foo), false); + + // Parameter 'empty' is '', then it ISSET and is EMPTY. + $this->assertEquals($request->empty, ''); + $this->assertEquals(isset($request->empty), true); + $this->assertEquals(empty($request->empty), true); + + // Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY. + $this->assertEquals($request->undefined, null); + $this->assertEquals(isset($request->undefined), false); + $this->assertEquals(empty($request->undefined), true); + + // Simulates Route parameters. + $request = Request::create('/example/bar', 'GET', [ 'xyz' => 'overwrited' ]); + $request->setRouteResolver(function () use ($request) { + $route = new Route('GET', '/example/{foo}/{xyz?}/{undefined?}', []); + $route->bind($request); + + return $route; + }); + + // Router parameter 'foo' is 'bar', then it ISSET and is NOT EMPTY. + $this->assertEquals($request->foo, 'bar'); + $this->assertEquals(isset($request->foo), true); + $this->assertEquals(empty($request->foo), false); + + // Router parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY. + $this->assertEquals($request->undefined, null); + $this->assertEquals(isset($request->undefined), false); + $this->assertEquals(empty($request->undefined), true); + + // Special case: router parameter 'xyz' is 'overwrited' by QueryString, then it ISSET and is NOT EMPTY. + // Basically, QueryStrings have priority over router parameters. + $this->assertEquals($request->xyz, 'overwrited'); + $this->assertEquals(isset($request->foo), true); + $this->assertEquals(empty($request->foo), false); + + // Simulates empty QueryString and Routes. + $request = Request::create('/', 'GET'); + $request->setRouteResolver(function () use ($request) { + $route = new Route('GET', '/', []); + $route->bind($request); - // Allow to simulates when a route is inaccessible or undefined. - if (! is_null($route)) { - $request->setRouteResolver(function () use ($request, $route) { - $route = new Route('GET', $route, []); - $route->bind($request); + return $route; + }); - return $route; - }); - } + // Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY. + $this->assertEquals($request->undefined, null); + $this->assertEquals(isset($request->undefined), false); + $this->assertEquals(empty($request->undefined), true); - $this->assertEquals($request->{$property}, $propertyValue); - $this->assertEquals(isset($request->{$property}), $propertyIsset); - $this->assertEquals(empty($request->{$property}), $propertyEmpty); - } + // Special case: simulates empty QueryString and Routes, without the Route Resolver. + // It'll happen when you try to get a parameter outside a route. + $request = Request::create('/', 'GET'); - public function magicMethodsProvider() - { - return [ - // Simulates QueryStrings. - ['/', null, ['foo' => 'bar', 'empty' => ''], 'foo', 'bar', true, false], - ['/', null, ['foo' => 'bar', 'empty' => ''], 'empty', '', true, true], - ['/', null, ['foo' => 'bar', 'empty' => ''], 'undefined', null, false, true], - - // Simulates Routes. - ['/example/bar', '/example/{foo}/{undefined?}', [], 'foo', 'bar', true, false], - ['/example/bar', '/example/{foo}/{undefined?}', [], 'undefined', null, false, true], - - // Simulates no QueryStrings or Routes. - ['/', '/', [], 'undefined', null, false, true], - ['/', null, [], 'undefined', null, false, true], - ]; + // Parameter 'undefined' is undefined/null, then it NOT ISSET and is EMPTY. + $this->assertEquals($request->undefined, null); + $this->assertEquals(isset($request->undefined), false); + $this->assertEquals(empty($request->undefined), true); } public function testHttpRequestFlashCallsSessionFlashInputWithInputData()
false
Other
laravel
framework
01e42d1a6cd15acf4989390721eb663b57a8407c.json
Fix code style;
tests/Http/HttpRequestTest.php
@@ -540,15 +540,15 @@ public function testCreateFromBase() } /** - * Tests to issue https://github.com/laravel/framework/issues/10403 + * Tests to https://github.com/laravel/framework/issues/10403 issue. * @dataProvider magicMethodsProvider */ public function testMagicMethods($uri, $route, $parameters, $property, $propertyValue, $propertyIsset, $propertyEmpty) { $request = Request::create($uri, 'GET', $parameters); // Allow to simulates when a route is inaccessible or undefined. - if (!is_null($route)) { + if (! is_null($route)) { $request->setRouteResolver(function () use ($request, $route) { $route = new Route('GET', $route, []); $route->bind($request); @@ -566,17 +566,17 @@ public function magicMethodsProvider() { return [ // Simulates QueryStrings. - [ '/', null, [ 'foo' => 'bar', 'empty' => '' ], 'foo', 'bar', true, false ], - [ '/', null, [ 'foo' => 'bar', 'empty' => '' ], 'empty', '', true, true ], - [ '/', null, [ 'foo' => 'bar', 'empty' => '' ], 'undefined', null, false, true ], + ['/', null, ['foo' => 'bar', 'empty' => ''], 'foo', 'bar', true, false], + ['/', null, ['foo' => 'bar', 'empty' => ''], 'empty', '', true, true], + ['/', null, ['foo' => 'bar', 'empty' => ''], 'undefined', null, false, true], // Simulates Routes. - [ '/example/bar', '/example/{foo}/{undefined?}', [], 'foo', 'bar', true, false ], - [ '/example/bar', '/example/{foo}/{undefined?}', [], 'undefined', null, false, true ], + ['/example/bar', '/example/{foo}/{undefined?}', [], 'foo', 'bar', true, false], + ['/example/bar', '/example/{foo}/{undefined?}', [], 'undefined', null, false, true], // Simulates no QueryStrings or Routes. - [ '/', '/', [], 'undefined', null, false, true ], - [ '/', null, [], 'undefined', null, false, true ], + ['/', '/', [], 'undefined', null, false, true], + ['/', null, [], 'undefined', null, false, true], ]; }
false
Other
laravel
framework
e064596297bd045650e8981c4114a94ceacafe97.json
code formatting issues
src/Illuminate/Cache/RateLimiter.php
@@ -34,13 +34,9 @@ public function __construct(Cache $cache) */ public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1) { - $attempts = $this->cache->get( - $key, 0 - ); - $lockedOut = $this->cache->has($key.':lockout'); - if ($attempts > $maxAttempts || $lockedOut) { + if ($this->attempts($key) > $maxAttempts || $lockedOut) { if (! $lockedOut) { $this->cache->add($key.':lockout', time() + ($decayMinutes * 60), $decayMinutes); } @@ -51,17 +47,6 @@ public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1) return false; } - /** - * Get the number of attempts using key. - * - * @param string $key - * @return mixed - */ - public function attempts($key) - { - return $this->cache->get($key, 0); - } - /** * Increment the counter for a given key for a given decay time. * @@ -76,6 +61,17 @@ public function hit($key, $decayMinutes = 1) return (int) $this->cache->increment($key); } + /** + * Get the number of attempts for the given key. + * + * @param string $key + * @return mixed + */ + public function attempts($key) + { + return $this->cache->get($key, 0); + } + /** * Clear the hits and lockout for the given key. *
true
Other
laravel
framework
e064596297bd045650e8981c4114a94ceacafe97.json
code formatting issues
src/Illuminate/Foundation/Auth/ThrottlesLogins.php
@@ -23,31 +23,31 @@ protected function hasTooManyLoginAttempts(Request $request) } /** - * Determine how many retries left. + * Increment the login attempts for the user. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return int */ - protected function retriesLeft(Request $request) + protected function incrementLoginAttempts(Request $request) { - $key = $request->input($this->loginUsername()).$request->ip(); - - $attempts = app(RateLimiter::class)->attempts($key); - - return $this->maxLoginAttempts() - $attempts + 1; + app(RateLimiter::class)->hit( + $request->input($this->loginUsername()).$request->ip() + ); } /** - * Increment the login attempts for the user. + * Determine how many retries are left for the user. * * @param \Illuminate\Http\Request $request * @return int */ - protected function incrementLoginAttempts(Request $request) + protected function retriesLeft(Request $request) { - app(RateLimiter::class)->hit( + $attempts = app(RateLimiter::class)->attempts( $request->input($this->loginUsername()).$request->ip() ); + + return $this->maxLoginAttempts() - $attempts + 1; } /**
true
Other
laravel
framework
7bebac8dd5282918f16a3b553dbd6f4e1089a8b9.json
Simplify code of View::renderSections()
src/Illuminate/View/View.php
@@ -121,10 +121,8 @@ protected function renderContents() */ public function renderSections() { - $env = $this->factory; - - return $this->render(function ($view) use ($env) { - return $env->getSections(); + return $this->render(function () { + return $this->factory->getSections(); }); }
false
Other
laravel
framework
b877dadfe9d892244a7418f4ea446e1dd4dbc8c0.json
Fix incorrect @return value in docblock On the `createMany()` method of the `BelongsToMany` relation, the `$instances` variable being returned is an array and not an `\Illuminate\Database\Eloquent\Model` instance as the @return tag in the docblock states.
src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -731,7 +731,7 @@ public function create(array $attributes, array $joining = [], $touch = true) * * @param array $records * @param array $joinings - * @return \Illuminate\Database\Eloquent\Model + * @return array */ public function createMany(array $records, array $joinings = []) {
false
Other
laravel
framework
b9a51803b7fd191e9665db1fd9f9686db6755ad4.json
remove unused method.
src/Illuminate/Database/Eloquent/Model.php
@@ -684,20 +684,6 @@ public static function findOrNew($id, $columns = ['*']) return new static; } - /** - * Refresh the current model with the current attributes from the database. - * - * @return void - */ - protected function refresh() - { - $fresh = $this->fresh(); - - $this->setRawAttributes($fresh->getAttributes()); - - $this->setRelations($fresh->getRelations()); - } - /** * Reload a fresh model instance from the database. *
false
Other
laravel
framework
d9dd691526dcf17eb87390b2dbcf3574388d53ac.json
change method order.
src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
@@ -199,6 +199,20 @@ public function compileTruncate(Builder $query) return ['truncate table '.$this->wrapTable($query->from) => []]; } + /** + * Compile a "where date" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDate(Builder $query, $where) + { + $value = $this->parameter($where['value']); + + return 'cast('.$this->wrap($where['column']).' as date) '.$where['operator'].' '.$value; + } + /** * Determine if the grammar supports savepoints. * @@ -233,18 +247,4 @@ protected function wrapValue($value) return '['.str_replace(']', ']]', $value).']'; } - - /** - * Compile a "where date" clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $where - * @return string - */ - protected function whereDate(Builder $query, $where) - { - $value = $this->parameter($where['value']); - - return 'cast('.$this->wrap($where['column']).' as date) '.$where['operator'].' '.$value; - } }
false
Other
laravel
framework
99ba29aeeb210f33e24c7dbeedda6cce9ec916dd.json
Return instance from more eloquent methods
src/Illuminate/Database/Eloquent/Model.php
@@ -1344,11 +1344,13 @@ public function getObservableEvents() * Set the observable event names. * * @param array $observables - * @return void + * @return $this */ public function setObservableEvents(array $observables) { $this->observables = $observables; + + return $this; } /** @@ -1757,22 +1759,26 @@ protected function updateTimestamps() * Set the value of the "created at" attribute. * * @param mixed $value - * @return void + * @return $this */ public function setCreatedAt($value) { $this->{static::CREATED_AT} = $value; + + return $this; } /** * Set the value of the "updated at" attribute. * * @param mixed $value - * @return void + * @return $this */ public function setUpdatedAt($value) { $this->{static::UPDATED_AT} = $value; + + return $this; } /** @@ -1955,11 +1961,13 @@ public function getTable() * Set the table associated with the model. * * @param string $table - * @return void + * @return $this */ public function setTable($table) { $this->table = $table; + + return $this; } /** @@ -1996,11 +2004,13 @@ public function getKeyName() * Set the primary key for the model. * * @param string $key - * @return void + * @return $this */ public function setKeyName($key) { $this->primaryKey = $key; + + return $this; } /** @@ -2092,11 +2102,13 @@ public function getPerPage() * Set the number of models to return per page. * * @param int $perPage - * @return void + * @return $this */ public function setPerPage($perPage) { $this->perPage = $perPage; + + return $this; } /** @@ -2381,11 +2393,13 @@ public function getTouchedRelations() * Set the relationships that are touched on save. * * @param array $touches - * @return void + * @return $this */ public function setTouchedRelations(array $touches) { $this->touches = $touches; + + return $this; } /** @@ -2402,11 +2416,13 @@ public function getIncrementing() * Set whether IDs are incrementing. * * @param bool $value - * @return void + * @return $this */ public function setIncrementing($value) { $this->incrementing = $value; + + return $this; } /** @@ -2834,7 +2850,7 @@ protected function castAttribute($key, $value) * * @param string $key * @param mixed $value - * @return void + * @return $this */ public function setAttribute($key, $value) { @@ -2859,6 +2875,8 @@ public function setAttribute($key, $value) } $this->attributes[$key] = $value; + + return $this; } /** @@ -3011,7 +3029,7 @@ public function getAttributes() * * @param array $attributes * @param bool $sync - * @return void + * @return $this */ public function setRawAttributes(array $attributes, $sync = false) { @@ -3020,6 +3038,8 @@ public function setRawAttributes(array $attributes, $sync = false) if ($sync) { $this->syncOriginal(); } + + return $this; } /**
false
Other
laravel
framework
f59d8a8ca4a2ddc08415634f473d604ec7b4ffdd.json
Return instance from eloquent setters
src/Illuminate/Database/Eloquent/Model.php
@@ -2172,11 +2172,13 @@ public function getVisible() * Set the visible attributes for the model. * * @param array $visible - * @return void + * @return $this */ public function setVisible(array $visible) { $this->visible = $visible; + + return $this; } /** @@ -2196,11 +2198,13 @@ public function addVisible($attributes = null) * Set the accessors to append to model arrays. * * @param array $appends - * @return void + * @return $this */ public function setAppends(array $appends) { $this->appends = $appends; + + return $this; } /**
false
Other
laravel
framework
f19151762b38e7386a5d85d4bbc948de6d123cd8.json
Return instance from setHidden
src/Illuminate/Database/Eloquent/Model.php
@@ -2123,11 +2123,13 @@ public function getHidden() * Set the hidden attributes for the model. * * @param array $hidden - * @return void + * @return $this */ public function setHidden(array $hidden) { $this->hidden = $hidden; + + return $this; } /**
false
Other
laravel
framework
3f695312a174f5b5c39171ec740d136442a9d186.json
Replace double quotes with single quotes
tests/Database/DatabaseEloquentIntegrationTest.php
@@ -61,9 +61,9 @@ public function setUp() $this->schema()->create('photos', function ($table) { $table->increments('id'); - $table->unsignedInteger("imageable_id")->nullable(); - $table->string("imageable_type")->nullable(); - $table->index(["imageable_id", "imageable_type"]); + $table->unsignedInteger('imageable_id')->nullable(); + $table->string('imageable_type')->nullable(); + $table->index(['imageable_id', 'imageable_type']); $table->string('name'); $table->timestamps(); });
false
Other
laravel
framework
8c36b31e36f9073edaa1672e892d81e819528fd1.json
Add docblock and comment
src/Illuminate/Database/Eloquent/Model.php
@@ -1621,13 +1621,20 @@ protected function performInsert(Builder $query, array $options = []) $this->wasRecentlyCreated = true; + // When inserting newly created models, they might have default values for some + // attributes. So it's important that we refresh the model after it has been + // saved so that any missing fields with database defaults are populated. $this->refresh(); $this->fireModelEvent('created', false); return true; } + /** + * Refresh the current model with the current attributes from the database. + * @return void + */ protected function refresh() { $fresh = $this->fresh();
false
Other
laravel
framework
067c6276826799f8223b8c58db4443d1fb0d9677.json
Fix fluent route name in groups.
src/Illuminate/Routing/Route.php
@@ -927,7 +927,7 @@ public function getName() */ public function name($name) { - $this->action['as'] = $name; + $this->action['as'] = isset($this->action['as']) ? $this->action['as'].$name : $name; return $this; }
true
Other
laravel
framework
067c6276826799f8223b8c58db4443d1fb0d9677.json
Fix fluent route name in groups.
tests/Routing/RoutingRouteTest.php
@@ -92,6 +92,16 @@ public function testBasicDispatchingOfRoutes() $this->assertEquals('closure', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent()); } + public function testFluentRouteNamingWithinAGroup() + { + $router = $this->getRouter(); + $router->group(['as' => 'foo.'], function () use ($router) { + $router->get('bar', function () { return 'bar'; })->name('bar'); + }); + $this->assertEquals('bar', $router->dispatch(Request::create('bar', 'GET'))->getContent()); + $this->assertEquals('foo.bar', $router->currentRouteName()); + } + public function testMacro() { $router = $this->getRouter();
true
Other
laravel
framework
ebbae988f5697b0a456f27c0c865515b4c0ab51a.json
Use proper assertion
tests/Cache/CacheArrayStoreTest.php
@@ -55,6 +55,6 @@ public function testItemsCanBeFlushed() public function testCacheKey() { $store = new ArrayStore; - $this->assertEquals('', $store->getPrefix()); + $this->assertEmpty($store->getPrefix()); } }
true
Other
laravel
framework
ebbae988f5697b0a456f27c0c865515b4c0ab51a.json
Use proper assertion
tests/Cache/CacheMemcachedStoreTest.php
@@ -67,6 +67,6 @@ public function testGetAndSetPrefix() $store->setPrefix('foo'); $this->assertEquals('foo:', $store->getPrefix()); $store->setPrefix(null); - $this->assertSame('', $store->getPrefix()); + $this->assertEmpty($store->getPrefix()); } }
true
Other
laravel
framework
ebbae988f5697b0a456f27c0c865515b4c0ab51a.json
Use proper assertion
tests/Cache/CacheRedisStoreTest.php
@@ -88,7 +88,7 @@ public function testGetAndSetPrefix() $redis->setPrefix('foo'); $this->assertEquals('foo:', $redis->getPrefix()); $redis->setPrefix(null); - $this->assertSame('', $redis->getPrefix()); + $this->assertEmpty($redis->getPrefix()); } protected function getRedis()
true
Other
laravel
framework
ebbae988f5697b0a456f27c0c865515b4c0ab51a.json
Use proper assertion
tests/Cache/CacheRepositoryTest.php
@@ -85,9 +85,9 @@ public function testAddWithDatetimeInPastOrZeroMinutesReturnsImmediately() $repo = $this->getRepository(); $repo->getStore()->shouldReceive('add', 'get', 'put')->never(); $result = $repo->add('foo', 'bar', Carbon::now()->subMinutes(10)); - $this->assertSame(false, $result); + $this->assertFalse($result); $result = $repo->add('foo', 'bar', Carbon::now()->addSeconds(5)); - $this->assertSame(false, $result); + $this->assertFalse($result); } public function testRegisterMacroWithNonStaticCall()
true
Other
laravel
framework
ebbae988f5697b0a456f27c0c865515b4c0ab51a.json
Use proper assertion
tests/Routing/RoutingRouteTest.php
@@ -72,11 +72,11 @@ public function testBasicDispatchingOfRoutes() $router = $this->getRouter(); $router->get('foo/bar', function () { return 'hello'; }); - $this->assertEquals('', $router->dispatch(Request::create('foo/bar', 'HEAD'))->getContent()); + $this->assertEmpty($router->dispatch(Request::create('foo/bar', 'HEAD'))->getContent()); $router = $this->getRouter(); $router->any('foo/bar', function () { return 'hello'; }); - $this->assertEquals('', $router->dispatch(Request::create('foo/bar', 'HEAD'))->getContent()); + $this->assertEmpty($router->dispatch(Request::create('foo/bar', 'HEAD'))->getContent()); $router = $this->getRouter(); $router->get('foo/bar', function () { return 'first'; }); @@ -142,7 +142,7 @@ public function testHeadDispatcher() $response = $router->dispatch(Request::create('foo', 'HEAD')); $this->assertEquals(200, $response->getStatusCode()); - $this->assertEquals('', $response->getContent()); + $this->assertEmpty($response->getContent()); $router = $this->getRouter(); $router->match(['GET'], 'foo', function () { return 'bar'; });
true
Other
laravel
framework
ebbae988f5697b0a456f27c0c865515b4c0ab51a.json
Use proper assertion
tests/Support/SupportStrTest.php
@@ -164,13 +164,13 @@ public function testSubstr() $this->assertEquals('ЛЁ', Str::substr('БГДЖИЛЁ', -2)); $this->assertEquals('И', Str::substr('БГДЖИЛЁ', -3, 1)); $this->assertEquals('ДЖИЛ', Str::substr('БГДЖИЛЁ', 2, -1)); - $this->assertEquals(false, Str::substr('БГДЖИЛЁ', 4, -4)); + $this->assertEmpty(Str::substr('БГДЖИЛЁ', 4, -4)); $this->assertEquals('ИЛ', Str::substr('БГДЖИЛЁ', -3, -1)); $this->assertEquals('ГДЖИЛЁ', Str::substr('БГДЖИЛЁ', 1)); $this->assertEquals('ГДЖ', Str::substr('БГДЖИЛЁ', 1, 3)); $this->assertEquals('БГДЖ', Str::substr('БГДЖИЛЁ', 0, 4)); $this->assertEquals('Ё', Str::substr('БГДЖИЛЁ', -1, 1)); - $this->assertEquals(false, Str::substr('Б', 2)); + $this->assertEmpty(Str::substr('Б', 2)); } public function testUcfirst()
true
Other
laravel
framework
ebbae988f5697b0a456f27c0c865515b4c0ab51a.json
Use proper assertion
tests/View/ViewFactoryTest.php
@@ -312,7 +312,7 @@ public function testInjectStartsSectionWithContent() public function testEmptyStringIsReturnedForNonSections() { $factory = $this->getFactory(); - $this->assertEquals('', $factory->yieldContent('foo')); + $this->assertEmpty($factory->yieldContent('foo')); } public function testSectionFlushing()
true
Other
laravel
framework
7fe79c5f43820ed64d1bed86ed6d709c7bf51e73.json
Use static instead of self
src/Illuminate/Support/Arr.php
@@ -424,11 +424,11 @@ public static function sortRecursive($array) { foreach ($array as &$value) { if (is_array($value)) { - $value = self::sortRecursive($value); + $value = static::sortRecursive($value); } } - if (self::isAssoc($array)) { + if (static::isAssoc($array)) { ksort($array); } else { sort($array);
false
Other
laravel
framework
94d3c6e2ca575b5babd1bbe410ea44602c459123.json
Add avg() method to Collection
src/Illuminate/Support/Collection.php
@@ -53,6 +53,19 @@ public function all() return $this->items; } + /** + * Get the average value of a given key. + * + * @param string|null $key + * @return mixed + */ + public function avg($key = null) + { + if ($count = $this->count()) { + return $this->sum($key) / $count; + } + } + /** * Collapse the collection of items into a single array. *
true
Other
laravel
framework
94d3c6e2ca575b5babd1bbe410ea44602c459123.json
Add avg() method to Collection
tests/Support/SupportCollectionTest.php
@@ -798,6 +798,21 @@ public function testGettingMinItemsFromCollection() $c = new Collection(); $this->assertNull($c->min()); } + + public function testGettingAvgItemsFromCollection() + { + $c = new Collection([(object) ['foo' => 10], (object) ['foo' => 20]]); + $this->assertEquals(15, $c->avg('foo')); + + $c = new Collection([['foo' => 10], ['foo' => 20]]); + $this->assertEquals(15, $c->avg('foo')); + + $c = new Collection([1, 2, 3, 4, 5]); + $this->assertEquals(3, $c->avg()); + + $c = new Collection(); + $this->assertNull($c->avg()); + } } class TestAccessorEloquentTestStub
true
Other
laravel
framework
13cf97954b639572d167393e4531910aa0bf5c97.json
Improve query builder implode method Removed a redundant `is_null()` check. Also, the docs recommend against using implode in this way.
src/Illuminate/Database/Query/Builder.php
@@ -1576,12 +1576,8 @@ protected function getListSelect($column, $key) * @param string $glue * @return string */ - public function implode($column, $glue = null) + public function implode($column, $glue = '') { - if (is_null($glue)) { - return implode($this->lists($column)); - } - return implode($glue, $this->lists($column)); }
false
Other
laravel
framework
854e6b231484715df2eb325ebf7ebd1b11cd8adf.json
Create access admission and unauthorized exception
src/Illuminate/Auth/Access/Admission.php
@@ -0,0 +1,33 @@ +<?php + +namespace Illuminate\Auth\Access; + +class Admission +{ + /** + * The reason admission was granted. + * + * @var string|null + */ + protected $reason; + + /** + * Create an admission instance. + * + * @param string|null $reason + */ + public function __construct($reason = null) + { + $this->reason = $reason; + } + + /** + * Get the reason for admission. + * + * @return string + */ + public function reason() + { + return $this->reason; + } +}
true
Other
laravel
framework
854e6b231484715df2eb325ebf7ebd1b11cd8adf.json
Create access admission and unauthorized exception
src/Illuminate/Auth/Access/Gate.php
@@ -8,6 +8,8 @@ class Gate implements GateContract { + use HandlesAuthorization; + /** * The container instance. * @@ -162,13 +164,13 @@ public function denies($ability, $arguments = []) } /** - * Determine if the given ability should be granted for the current user. + * Get the raw result for the given ability for the current user. * * @param string $ability * @param array|mixed $arguments * @return bool */ - public function check($ability, $arguments = []) + public function approach($ability, $arguments = []) { if (! $user = $this->resolveUser()) { return false; @@ -187,6 +189,44 @@ public function check($ability, $arguments = []) return call_user_func_array($callback, array_merge([$user], $arguments)); } + /** + * Determine if the given ability should be granted for the current user. + * + * @param string $ability + * @param array|mixed $arguments + * @return \Illuminate\Auth\Access\Admission + * + * @throws \Illuminate\Auth\Access\UnauthorizedException + */ + public function authorize($ability, $arguments = []) + { + $result = $this->approach($ability, $arguments); + + if ($result instanceof Admission) { + return $result; + } + + return $result ? $this->allow() : $this->deny(); + } + + /** + * Determine if the given ability should be granted for the current user. + * + * @param string $ability + * @param array|mixed $arguments + * @return bool + */ + public function check($ability, $arguments = []) + { + try { + $result = $this->approach($ability, $arguments); + } catch (UnauthorizedException $e) { + return false; + } + + return (bool) $result; + } + /** * Call all of the before callbacks and return if a result is given. *
true
Other
laravel
framework
854e6b231484715df2eb325ebf7ebd1b11cd8adf.json
Create access admission and unauthorized exception
src/Illuminate/Auth/Access/HandlesAuthorization.php
@@ -0,0 +1,29 @@ +<?php + +namespace Illuminate\Auth\Access; + +trait HandlesAuthorization +{ + /** + * Create a new admission instance. + * + * @return \Illuminate\Auth\Access\Admission + */ + protected function allow($reason = null) + { + return new Admission($reason); + } + + /** + * Throws an unauthorized exception. + * + * @param string $reason + * @return void + * + * @throws \Illuminate\Auth\Access\UnauthorizedException + */ + protected function deny($reason = 'This action is unauthorized.') + { + throw new UnauthorizedException($reason); + } +}
true
Other
laravel
framework
854e6b231484715df2eb325ebf7ebd1b11cd8adf.json
Create access admission and unauthorized exception
src/Illuminate/Auth/Access/UnauthorizedException.php
@@ -0,0 +1,10 @@ +<?php + +namespace Illuminate\Auth\Access; + +use Exception; + +class UnauthorizedException extends Exception +{ + // +}
true