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 | 615ba9a6ead3608ef2cf6956c85a6fc71ac37e57.json | Allow multiple folders for migrations | src/Illuminate/Database/Console/Migrations/ResetCommand.php | @@ -7,7 +7,7 @@
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption;
-class ResetCommand extends Command
+class ResetCommand extends BaseCommand
{
use ConfirmableTrait;
@@ -66,7 +66,11 @@ public function fire()
$pretend = $this->input->getOption('pretend');
- $this->migrator->reset($pretend);
+ $paths[] = $this->getMigrationPath();
+
+ $paths = array_merge($paths, $this->migrator->paths());
+
+ $this->migrator->reset($paths, $pretend);
// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having | true |
Other | laravel | framework | 615ba9a6ead3608ef2cf6956c85a6fc71ac37e57.json | Allow multiple folders for migrations | src/Illuminate/Database/Console/Migrations/RollbackCommand.php | @@ -7,7 +7,7 @@
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption;
-class RollbackCommand extends Command
+class RollbackCommand extends BaseCommand
{
use ConfirmableTrait;
@@ -60,7 +60,11 @@ public function fire()
$pretend = $this->input->getOption('pretend');
- $this->migrator->rollback($pretend);
+ $paths[] = $this->getMigrationPath();
+
+ $paths = array_merge($paths, $this->migrator->paths());
+
+ $this->migrator->rollback($paths, $pretend);
// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having | true |
Other | laravel | framework | 615ba9a6ead3608ef2cf6956c85a6fc71ac37e57.json | Allow multiple folders for migrations | src/Illuminate/Database/Console/Migrations/StatusCommand.php | @@ -55,17 +55,19 @@ public function fire()
$this->migrator->setConnection($this->input->getOption('database'));
if (! is_null($path = $this->input->getOption('path'))) {
- $path = $this->laravel->basePath().'/'.$path;
+ $paths[] = $this->laravel->basePath().'/'.$path;
} else {
- $path = $this->getMigrationPath();
+ $paths[] = $this->getMigrationPath();
+
+ $paths = array_merge($paths, $this->migrator->paths());
}
$ran = $this->migrator->getRepository()->getRan();
$migrations = [];
- foreach ($this->getAllMigrationFiles($path) as $migration) {
- $migrations[] = in_array($migration, $ran) ? ['<info>Y</info>', $migration] : ['<fg=red>N</fg=red>', $migration];
+ foreach ($this->getAllMigrationFiles($paths) as $migration) {
+ $migrations[] = in_array($this->migrator->getMigrationName($migration), $ran) ? ['<info>Y</info>', $this->migrator->getMigrationName($migration)] : ['<fg=red>N</fg=red>', $this->migrator->getMigrationName($migration)];
}
if (count($migrations) > 0) {
@@ -78,12 +80,12 @@ public function fire()
/**
* Get all of the migration files.
*
- * @param string $path
+ * @param array $paths
* @return array
*/
- protected function getAllMigrationFiles($path)
+ protected function getAllMigrationFiles(array $paths)
{
- return $this->migrator->getMigrationFiles($path);
+ return $this->migrator->getMigrationFiles($paths);
}
/** | true |
Other | laravel | framework | 615ba9a6ead3608ef2cf6956c85a6fc71ac37e57.json | Allow multiple folders for migrations | src/Illuminate/Database/Migrations/Migrator.php | @@ -44,6 +44,13 @@ class Migrator
*/
protected $notes = [];
+ /**
+ * The paths for all migration files.
+ *
+ * @var array
+ */
+ protected $paths = [];
+
/**
* Create a new migrator instance.
*
@@ -64,24 +71,30 @@ public function __construct(MigrationRepositoryInterface $repository,
/**
* Run the outstanding migrations at a given path.
*
- * @param string $path
+ * @param string|array $paths
* @param array $options
* @return void
*/
- public function run($path, array $options = [])
+ public function run($paths, array $options = [])
{
$this->notes = [];
- $files = $this->getMigrationFiles($path);
+ $files = $this->getMigrationFiles($paths);
// Once we grab all of the migration files for the path, we will compare them
// against the migrations that have already been run for this package then
// run each of the outstanding migrations against a database connection.
$ran = $this->repository->getRan();
- $migrations = array_diff($files, $ran);
+ $migrations = [];
+
+ foreach ($files as $file) {
+ if (! in_array($this->getMigrationName($file), $ran)) {
+ $migrations[] = $file;
+ }
+ }
- $this->requireFiles($path, $migrations);
+ $this->requireFiles($migrations);
$this->runMigrationList($migrations, $options);
}
@@ -135,6 +148,8 @@ public function runMigrationList($migrations, array $options = [])
*/
protected function runUp($file, $batch, $pretend)
{
+ $file = $this->getMigrationName($file);
+
// First we will resolve a "real" instance of the migration class from this
// migration file name. Once we have the instances we can run the actual
// command such as "up" or "down", or we can just simulate the action.
@@ -157,10 +172,11 @@ protected function runUp($file, $batch, $pretend)
/**
* Rollback the last migration operation.
*
+ * @param string|array $paths
* @param bool $pretend
* @return int
*/
- public function rollback($pretend = false)
+ public function rollback(array $paths, $pretend = false)
{
$this->notes = [];
@@ -171,14 +187,21 @@ public function rollback($pretend = false)
$count = count($migrations);
+ $files = $this->getMigrationFiles($paths);
+
if ($count === 0) {
$this->note('<info>Nothing to rollback.</info>');
} else {
// We need to reverse these migrations so that they are "downed" in reverse
// to what they run on "up". It lets us backtrack through the migrations
// and properly reverse the entire database schema operation that ran.
+ $this->requireFiles($files);
foreach ($migrations as $migration) {
- $this->runDown((object) $migration, $pretend);
+ foreach ($files as $file) {
+ if ($this->getMigrationName($file) == $migration->migration) {
+ $this->runDown($file, (object) $migration, $pretend);
+ }
+ }
}
}
@@ -188,22 +211,30 @@ public function rollback($pretend = false)
/**
* Rolls all of the currently applied migrations back.
*
+ * @param string|array $paths
* @param bool $pretend
* @return int
*/
- public function reset($pretend = false)
+ public function reset($paths, $pretend = false)
{
$this->notes = [];
+ $files = $this->getMigrationFiles($paths);
+
$migrations = array_reverse($this->repository->getRan());
$count = count($migrations);
if ($count === 0) {
$this->note('<info>Nothing to rollback.</info>');
} else {
+ $this->requireFiles($files);
foreach ($migrations as $migration) {
- $this->runDown((object) ['migration' => $migration], $pretend);
+ foreach ($files as $file) {
+ if ($this->getMigrationName($file) == $migration) {
+ $this->runDown($file, (object) ['migration' => $migration], $pretend);
+ }
+ }
}
}
@@ -213,13 +244,14 @@ public function reset($pretend = false)
/**
* Run "down" a migration instance.
*
+ * @param string $file
* @param object $migration
* @param bool $pretend
* @return void
*/
- protected function runDown($migration, $pretend)
+ protected function runDown($file, $migration, $pretend)
{
- $file = $migration->migration;
+ $file = $this->getMigrationName($file);
// First we will get the file name of the migration so we can resolve out an
// instance of the migration. Once we get an instance we can either run a
@@ -243,44 +275,57 @@ protected function runDown($migration, $pretend)
/**
* Get all of the migration files in a given path.
*
- * @param string $path
+ * @param string|array $paths
* @return array
*/
- public function getMigrationFiles($path)
+ public function getMigrationFiles($paths)
{
- $files = $this->files->glob($path.'/*_*.php');
+ $files = [];
+
+ $paths = is_array($paths) ? $paths : [$paths];
+
+ foreach ($paths as $path) {
+ $files[] = $this->files->glob($path.'/*_*.php');
+ }
+
+ $files = array_flatten($files);
+
+ $files = array_filter($files);
// Once we have the array of files in the directory we will just remove the
// extension and take the basename of the file which is all we need when
// finding the migrations that haven't been run against the databases.
- if ($files === false) {
+ if (empty($files)) {
return [];
}
- $files = array_map(function ($file) {
- return str_replace('.php', '', basename($file));
+ // Now we have a full list of file names we will sort them and because they
+ // all start with a timestamp this should give us the migrations in the
+ // order they were actually created in by the application developers.
+ usort($files, function ($a, $b) {
+ $a = $this->getMigrationName($a);
+ $b = $this->getMigrationName($b);
- }, $files);
+ if ($a == $b) {
+ return 0;
+ }
- // Once we have all of the formatted file names we will sort them and since
- // they all start with a timestamp this should give us the migrations in
- // the order they were actually created by the application developers.
- sort($files);
+ return ($a < $b) ? -1 : 1;
+ });
return $files;
}
/**
* Require in all the migration files in a given path.
*
- * @param string $path
* @param array $files
* @return void
*/
- public function requireFiles($path, array $files)
+ public function requireFiles(array $files)
{
foreach ($files as $file) {
- $this->files->requireOnce($path.'/'.$file.'.php');
+ $this->files->requireOnce($file);
}
}
@@ -414,4 +459,29 @@ public function getFilesystem()
{
return $this->files;
}
+
+ /**
+ * Set a path which contains migration files.
+ *
+ * @param string $path
+ */
+ public function path($path)
+ {
+ $this->paths[] = $path;
+ }
+
+ /**
+ * Get all custom migration paths.
+ *
+ * @return array
+ */
+ public function paths()
+ {
+ return $this->paths;
+ }
+
+ public function getMigrationName($path)
+ {
+ return str_replace('.php', '', basename($path));
+ }
} | true |
Other | laravel | framework | 615ba9a6ead3608ef2cf6956c85a6fc71ac37e57.json | Allow multiple folders for migrations | tests/Database/DatabaseMigrationMigrateCommandTest.php | @@ -17,8 +17,9 @@ public function testBasicMigrationsCallMigratorWithProperArguments()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -32,8 +33,9 @@ public function testMigrationRepositoryCreatedWhenNecessary()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(false);
$command->expects($this->once())->method('call')->with($this->equalTo('migrate:install'), $this->equalTo(['--database' => null]));
@@ -47,8 +49,9 @@ public function testTheCommandMayBePretended()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => true, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => true, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -61,8 +64,9 @@ public function testTheDatabaseMayBeSet()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
- $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -75,8 +79,9 @@ public function testStepMayBeSet()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => true]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], ['pretend' => false, 'step' => true]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
| true |
Other | laravel | framework | 615ba9a6ead3608ef2cf6956c85a6fc71ac37e57.json | Allow multiple folders for migrations | tests/Database/DatabaseMigrationResetCommandTest.php | @@ -1,6 +1,7 @@
<?php
use Mockery as m;
+use Illuminate\Foundation\Application;
use Illuminate\Database\Console\Migrations\ResetCommand;
class DatabaseMigrationResetCommandTest extends PHPUnit_Framework_TestCase
@@ -13,10 +14,13 @@ public function tearDown()
public function testResetCommandCallsMigratorWithProperArguments()
{
$command = new ResetCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationStub());
+ $app = new ApplicationDatabaseResetStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
- $migrator->shouldReceive('reset')->once()->with(false);
+ $migrator->shouldReceive('reset')->once()->with([__DIR__.'/migrations'], false);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command);
@@ -25,10 +29,13 @@ public function testResetCommandCallsMigratorWithProperArguments()
public function testResetCommandCanBePretended()
{
$command = new ResetCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationStub());
+ $app = new ApplicationDatabaseResetStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
- $migrator->shouldReceive('reset')->once()->with(true);
+ $migrator->shouldReceive('reset')->once()->with([__DIR__.'/migrations'], true);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo']);
@@ -40,8 +47,15 @@ protected function runCommand($command, $input = [])
}
}
-class AppDatabaseMigrationStub extends Illuminate\Foundation\Application
+class ApplicationDatabaseResetStub extends Application
{
+ public function __construct(array $data = [])
+ {
+ foreach ($data as $abstract => $instance) {
+ $this->instance($abstract, $instance);
+ }
+ }
+
public function environment()
{
return 'development'; | true |
Other | laravel | framework | 615ba9a6ead3608ef2cf6956c85a6fc71ac37e57.json | Allow multiple folders for migrations | tests/Database/DatabaseMigrationRollbackCommandTest.php | @@ -14,9 +14,12 @@ public function tearDown()
public function testRollbackCommandCallsMigratorWithProperArguments()
{
$command = new RollbackCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationRollbackStub());
+ $app = new ApplicationDatabaseRollbackStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('rollback')->once()->with(false);
+ $migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], false);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command);
@@ -25,9 +28,12 @@ public function testRollbackCommandCallsMigratorWithProperArguments()
public function testRollbackCommandCanBePretended()
{
$command = new RollbackCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationRollbackStub());
+ $app = new ApplicationDatabaseRollbackStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
- $migrator->shouldReceive('rollback')->once()->with(true);
+ $migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], true);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo']);
@@ -39,8 +45,15 @@ protected function runCommand($command, $input = [])
}
}
-class AppDatabaseMigrationRollbackStub extends Application
+class ApplicationDatabaseRollbackStub extends Application
{
+ public function __construct(array $data = [])
+ {
+ foreach ($data as $abstract => $instance) {
+ $this->instance($abstract, $instance);
+ }
+ }
+
public function environment()
{
return 'development'; | true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | src/Illuminate/Database/Console/Migrations/MigrateCommand.php | @@ -66,12 +66,14 @@ public function fire()
// we will use the path relative to the root of this installation folder
// so that migrations may be run for any path within the applications.
if (! is_null($path = $this->input->getOption('path'))) {
- $path = $this->laravel->basePath().'/'.$path;
+ $paths[] = $this->laravel->basePath().'/'.$path;
} else {
- $path = $this->getMigrationPath();
+ $paths[] = $this->getMigrationPath();
+
+ $paths = array_merge($paths, $this->migrator->paths());
}
- $this->migrator->run($path, [
+ $this->migrator->run($paths, [
'pretend' => $pretend,
'step' => $this->input->getOption('step'),
]); | true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | src/Illuminate/Database/Console/Migrations/ResetCommand.php | @@ -7,7 +7,7 @@
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption;
-class ResetCommand extends Command
+class ResetCommand extends BaseCommand
{
use ConfirmableTrait;
@@ -66,7 +66,11 @@ public function fire()
$pretend = $this->input->getOption('pretend');
- $this->migrator->reset($pretend);
+ $paths[] = $this->getMigrationPath();
+
+ $paths = array_merge($paths, $this->migrator->paths());
+
+ $this->migrator->reset($paths, $pretend);
// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having | true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | src/Illuminate/Database/Console/Migrations/RollbackCommand.php | @@ -7,7 +7,7 @@
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption;
-class RollbackCommand extends Command
+class RollbackCommand extends BaseCommand
{
use ConfirmableTrait;
@@ -60,7 +60,11 @@ public function fire()
$pretend = $this->input->getOption('pretend');
- $this->migrator->rollback($pretend);
+ $paths[] = $this->getMigrationPath();
+
+ $paths = array_merge($paths, $this->migrator->paths());
+
+ $this->migrator->rollback($paths, $pretend);
// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having | true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | src/Illuminate/Database/Console/Migrations/StatusCommand.php | @@ -55,17 +55,19 @@ public function fire()
$this->migrator->setConnection($this->input->getOption('database'));
if (! is_null($path = $this->input->getOption('path'))) {
- $path = $this->laravel->basePath().'/'.$path;
+ $paths[] = $this->laravel->basePath().'/'.$path;
} else {
- $path = $this->getMigrationPath();
+ $paths[] = $this->getMigrationPath();
+
+ $paths = array_merge($paths, $this->migrator->paths());
}
$ran = $this->migrator->getRepository()->getRan();
$migrations = [];
- foreach ($this->getAllMigrationFiles($path) as $migration) {
- $migrations[] = in_array($migration, $ran) ? ['<info>Y</info>', $migration] : ['<fg=red>N</fg=red>', $migration];
+ foreach ($this->getAllMigrationFiles($paths) as $migration) {
+ $migrations[] = in_array($this->migrator->getMigrationName($migration), $ran) ? ['<info>Y</info>', $this->migrator->getMigrationName($migration)] : ['<fg=red>N</fg=red>', $this->migrator->getMigrationName($migration)];
}
if (count($migrations) > 0) {
@@ -78,12 +80,12 @@ public function fire()
/**
* Get all of the migration files.
*
- * @param string $path
+ * @param array $paths
* @return array
*/
- protected function getAllMigrationFiles($path)
+ protected function getAllMigrationFiles(array $paths)
{
- return $this->migrator->getMigrationFiles($path);
+ return $this->migrator->getMigrationFiles($paths);
}
/** | true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | src/Illuminate/Database/Migrations/Migrator.php | @@ -44,6 +44,13 @@ class Migrator
*/
protected $notes = [];
+ /**
+ * The paths for all migration files.
+ *
+ * @var array
+ */
+ protected $paths = [];
+
/**
* Create a new migrator instance.
*
@@ -64,24 +71,30 @@ public function __construct(MigrationRepositoryInterface $repository,
/**
* Run the outstanding migrations at a given path.
*
- * @param string $path
+ * @param string|array $paths
* @param array $options
* @return void
*/
- public function run($path, array $options = [])
+ public function run($paths, array $options = [])
{
$this->notes = [];
- $files = $this->getMigrationFiles($path);
+ $files = $this->getMigrationFiles($paths);
// Once we grab all of the migration files for the path, we will compare them
// against the migrations that have already been run for this package then
// run each of the outstanding migrations against a database connection.
$ran = $this->repository->getRan();
- $migrations = array_diff($files, $ran);
+ $migrations = [];
+
+ foreach ($files as $file) {
+ if (! in_array($this->getMigrationName($file), $ran)) {
+ $migrations[] = $file;
+ }
+ }
- $this->requireFiles($path, $migrations);
+ $this->requireFiles($migrations);
$this->runMigrationList($migrations, $options);
}
@@ -135,6 +148,8 @@ public function runMigrationList($migrations, array $options = [])
*/
protected function runUp($file, $batch, $pretend)
{
+ $file = $this->getMigrationName($file);
+
// First we will resolve a "real" instance of the migration class from this
// migration file name. Once we have the instances we can run the actual
// command such as "up" or "down", or we can just simulate the action.
@@ -157,10 +172,11 @@ protected function runUp($file, $batch, $pretend)
/**
* Rollback the last migration operation.
*
+ * @param string|array $paths
* @param bool $pretend
* @return int
*/
- public function rollback($pretend = false)
+ public function rollback(array $paths, $pretend = false)
{
$this->notes = [];
@@ -171,14 +187,21 @@ public function rollback($pretend = false)
$count = count($migrations);
+ $files = $this->getMigrationFiles($paths);
+
if ($count === 0) {
$this->note('<info>Nothing to rollback.</info>');
} else {
// We need to reverse these migrations so that they are "downed" in reverse
// to what they run on "up". It lets us backtrack through the migrations
// and properly reverse the entire database schema operation that ran.
+ $this->requireFiles($files);
foreach ($migrations as $migration) {
- $this->runDown((object) $migration, $pretend);
+ foreach ($files as $file) {
+ if ($this->getMigrationName($file) == $migration->migration) {
+ $this->runDown($file, (object) $migration, $pretend);
+ }
+ }
}
}
@@ -188,22 +211,30 @@ public function rollback($pretend = false)
/**
* Rolls all of the currently applied migrations back.
*
+ * @param string|array $paths
* @param bool $pretend
* @return int
*/
- public function reset($pretend = false)
+ public function reset($paths, $pretend = false)
{
$this->notes = [];
+ $files = $this->getMigrationFiles($paths);
+
$migrations = array_reverse($this->repository->getRan());
$count = count($migrations);
if ($count === 0) {
$this->note('<info>Nothing to rollback.</info>');
} else {
+ $this->requireFiles($files);
foreach ($migrations as $migration) {
- $this->runDown((object) ['migration' => $migration], $pretend);
+ foreach ($files as $file) {
+ if ($this->getMigrationName($file) == $migration) {
+ $this->runDown($file, (object) ['migration' => $migration], $pretend);
+ }
+ }
}
}
@@ -213,13 +244,14 @@ public function reset($pretend = false)
/**
* Run "down" a migration instance.
*
+ * @param string $file
* @param object $migration
* @param bool $pretend
* @return void
*/
- protected function runDown($migration, $pretend)
+ protected function runDown($file, $migration, $pretend)
{
- $file = $migration->migration;
+ $file = $this->getMigrationName($file);
// First we will get the file name of the migration so we can resolve out an
// instance of the migration. Once we get an instance we can either run a
@@ -243,44 +275,57 @@ protected function runDown($migration, $pretend)
/**
* Get all of the migration files in a given path.
*
- * @param string $path
+ * @param string|array $paths
* @return array
*/
- public function getMigrationFiles($path)
+ public function getMigrationFiles($paths)
{
- $files = $this->files->glob($path.'/*_*.php');
+ $files = [];
+
+ $paths = is_array($paths) ? $paths : [$paths];
+
+ foreach ($paths as $path) {
+ $files[] = $this->files->glob($path.'/*_*.php');
+ }
+
+ $files = array_flatten($files);
+
+ $files = array_filter($files);
// Once we have the array of files in the directory we will just remove the
// extension and take the basename of the file which is all we need when
// finding the migrations that haven't been run against the databases.
- if ($files === false) {
+ if (empty($files)) {
return [];
}
- $files = array_map(function ($file) {
- return str_replace('.php', '', basename($file));
+ // Now we have a full list of file names we will sort them and because they
+ // all start with a timestamp this should give us the migrations in the
+ // order they were actually created in by the application developers.
+ usort($files, function ($a, $b) {
+ $a = $this->getMigrationName($a);
+ $b = $this->getMigrationName($b);
- }, $files);
+ if ($a == $b) {
+ return 0;
+ }
- // Once we have all of the formatted file names we will sort them and since
- // they all start with a timestamp this should give us the migrations in
- // the order they were actually created by the application developers.
- sort($files);
+ return ($a < $b) ? -1 : 1;
+ });
return $files;
}
/**
* Require in all the migration files in a given path.
*
- * @param string $path
* @param array $files
* @return void
*/
- public function requireFiles($path, array $files)
+ public function requireFiles(array $files)
{
foreach ($files as $file) {
- $this->files->requireOnce($path.'/'.$file.'.php');
+ $this->files->requireOnce($file);
}
}
@@ -414,4 +459,29 @@ public function getFilesystem()
{
return $this->files;
}
+
+ /**
+ * Set a path which contains migration files.
+ *
+ * @param string $path
+ */
+ public function path($path)
+ {
+ $this->paths[] = $path;
+ }
+
+ /**
+ * Get all custom migration paths.
+ *
+ * @return array
+ */
+ public function paths()
+ {
+ return $this->paths;
+ }
+
+ public function getMigrationName($path)
+ {
+ return str_replace('.php', '', basename($path));
+ }
} | true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | tests/Database/DatabaseMigrationMigrateCommandTest.php | @@ -17,8 +17,9 @@ public function testBasicMigrationsCallMigratorWithProperArguments()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.'/migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -32,8 +33,9 @@ public function testMigrationRepositoryCreatedWhenNecessary()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.'/migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(false);
$command->expects($this->once())->method('call')->with($this->equalTo('migrate:install'), $this->equalTo(['--database' => null]));
@@ -47,8 +49,9 @@ public function testTheCommandMayBePretended()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => true, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.'/migrations'], ['pretend' => true, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -61,8 +64,9 @@ public function testTheDatabaseMayBeSet()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.'/migrations'], ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -75,8 +79,9 @@ public function testStepMayBeSet()
$app = new ApplicationDatabaseMigrationStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => true]);
+ $migrator->shouldReceive('run')->once()->with([__DIR__.'/migrations'], ['pretend' => false, 'step' => true]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
| true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | tests/Database/DatabaseMigrationResetCommandTest.php | @@ -1,6 +1,7 @@
<?php
use Mockery as m;
+use Illuminate\Foundation\Application;
use Illuminate\Database\Console\Migrations\ResetCommand;
class DatabaseMigrationResetCommandTest extends PHPUnit_Framework_TestCase
@@ -13,10 +14,13 @@ public function tearDown()
public function testResetCommandCallsMigratorWithProperArguments()
{
$command = new ResetCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationStub());
+ $app = new ApplicationDatabaseResetStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
- $migrator->shouldReceive('reset')->once()->with(false);
+ $migrator->shouldReceive('reset')->once()->with([__DIR__.'/migrations'], false);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command);
@@ -25,10 +29,13 @@ public function testResetCommandCallsMigratorWithProperArguments()
public function testResetCommandCanBePretended()
{
$command = new ResetCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationStub());
+ $app = new ApplicationDatabaseResetStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
- $migrator->shouldReceive('reset')->once()->with(true);
+ $migrator->shouldReceive('reset')->once()->with([__DIR__.'/migrations'], true);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo']);
@@ -40,8 +47,15 @@ protected function runCommand($command, $input = [])
}
}
-class AppDatabaseMigrationStub extends Illuminate\Foundation\Application
+class ApplicationDatabaseResetStub extends Application
{
+ public function __construct(array $data = [])
+ {
+ foreach ($data as $abstract => $instance) {
+ $this->instance($abstract, $instance);
+ }
+ }
+
public function environment()
{
return 'development'; | true |
Other | laravel | framework | cc6666e6e448906c17fc129130aedb6474172a48.json | Allow multiple folders for migrations | tests/Database/DatabaseMigrationRollbackCommandTest.php | @@ -14,9 +14,12 @@ public function tearDown()
public function testRollbackCommandCallsMigratorWithProperArguments()
{
$command = new RollbackCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationRollbackStub());
+ $app = new ApplicationDatabaseRollbackStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('rollback')->once()->with(false);
+ $migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], false);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command);
@@ -25,9 +28,12 @@ public function testRollbackCommandCallsMigratorWithProperArguments()
public function testRollbackCommandCanBePretended()
{
$command = new RollbackCommand($migrator = m::mock('Illuminate\Database\Migrations\Migrator'));
- $command->setLaravel(new AppDatabaseMigrationRollbackStub());
+ $app = new ApplicationDatabaseRollbackStub(['path.database' => __DIR__]);
+ $app->useDatabasePath(__DIR__);
+ $command->setLaravel($app);
+ $migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
- $migrator->shouldReceive('rollback')->once()->with(true);
+ $migrator->shouldReceive('rollback')->once()->with([__DIR__.'/migrations'], true);
$migrator->shouldReceive('getNotes')->andReturn([]);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo']);
@@ -39,8 +45,15 @@ protected function runCommand($command, $input = [])
}
}
-class AppDatabaseMigrationRollbackStub extends Application
+class ApplicationDatabaseRollbackStub extends Application
{
+ public function __construct(array $data = [])
+ {
+ foreach ($data as $abstract => $instance) {
+ $this->instance($abstract, $instance);
+ }
+ }
+
public function environment()
{
return 'development'; | true |
Other | laravel | framework | f35019fe4504344a6b74437d0da7e5e72f5863f2.json | Fix sqlserver grammar (#13458)
Added square brackets to the table name. This fixes issues where the table name is equal to a keyword, like user. | src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php | @@ -149,7 +149,7 @@ public function compileDrop(Blueprint $blueprint, Fluent $command)
*/
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
{
- return 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = \''.$blueprint->getTable().'\') drop table '.$blueprint->getTable();
+ return 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = \''.$blueprint->getTable().'\') drop table ['.$blueprint->getTable().']';
}
/** | false |
Other | laravel | framework | 594e1f5e94b1ea710357d96d209d94b7fb56cc32.json | Fix migration tests on windows (#13438) | tests/Database/DatabaseMigrationMakeCommandTest.php | @@ -20,7 +20,7 @@ public function testBasicCreateDumpsAutoload()
$app = new Illuminate\Foundation\Application;
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
- $creator->shouldReceive('create')->once()->with('create_foo', __DIR__.'/migrations', null, false);
+ $creator->shouldReceive('create')->once()->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', null, false);
$composer->shouldReceive('dumpAutoloads')->once();
$this->runCommand($command, ['name' => 'create_foo']);
@@ -36,7 +36,7 @@ public function testBasicCreateGivesCreatorProperArguments()
$app = new Illuminate\Foundation\Application;
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
- $creator->shouldReceive('create')->once()->with('create_foo', __DIR__.'/migrations', null, false);
+ $creator->shouldReceive('create')->once()->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', null, false);
$this->runCommand($command, ['name' => 'create_foo']);
}
@@ -51,7 +51,7 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenTableIsSet()
$app = new Illuminate\Foundation\Application;
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
- $creator->shouldReceive('create')->once()->with('create_foo', __DIR__.'/migrations', 'users', true);
+ $creator->shouldReceive('create')->once()->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true);
$this->runCommand($command, ['name' => 'create_foo', '--create' => 'users']);
} | true |
Other | laravel | framework | 594e1f5e94b1ea710357d96d209d94b7fb56cc32.json | Fix migration tests on windows (#13438) | tests/Database/DatabaseMigrationMigrateCommandTest.php | @@ -18,7 +18,7 @@ public function testBasicMigrationsCallMigratorWithProperArguments()
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -33,7 +33,7 @@ public function testMigrationRepositoryCreatedWhenNecessary()
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(false);
$command->expects($this->once())->method('call')->with($this->equalTo('migrate:install'), $this->equalTo(['--database' => null]));
@@ -48,7 +48,7 @@ public function testTheCommandMayBePretended()
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => true, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => true, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -62,7 +62,7 @@ public function testTheDatabaseMayBeSet()
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$migrator->shouldReceive('setConnection')->once()->with('foo');
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => false]);
+ $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => false]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
@@ -76,7 +76,7 @@ public function testStepMayBeSet()
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$migrator->shouldReceive('setConnection')->once()->with(null);
- $migrator->shouldReceive('run')->once()->with(__DIR__.'/migrations', ['pretend' => false, 'step' => true]);
+ $migrator->shouldReceive('run')->once()->with(__DIR__.DIRECTORY_SEPARATOR.'migrations', ['pretend' => false, 'step' => true]);
$migrator->shouldReceive('getNotes')->andReturn([]);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
| true |
Other | laravel | framework | 9b5dfdf3be34e1c729edabae2c9e02d95fe2ab7e.json | fix config call | src/Illuminate/Session/SessionManager.php | @@ -151,7 +151,7 @@ protected function createCacheBased($driver)
*/
protected function createCacheHandler($driver)
{
- $store = array_get($this->app['config'], 'session.store', $driver);
+ $store = $this->app['config']->get('session.store', $driver);
$minutes = $this->app['config']['session.lifetime'];
| false |
Other | laravel | framework | a6ddacb568c1d4fa2d4b6e9f739830692c055973.json | Add test for SessionGuard::onceUsingId() (#13408) | tests/Auth/AuthGuardTest.php | @@ -272,6 +272,18 @@ public function testLoginUsingIdFailure()
$this->assertFalse($guard->loginUsingId(11));
}
+ public function testOnceUsingIdSetsUser()
+ {
+ list($session, $provider, $request, $cookie) = $this->getMocks();
+ $guard = m::mock('Illuminate\Auth\SessionGuard', ['default', $provider, $session])->makePartial();
+
+ $user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
+ $guard->getProvider()->shouldReceive('retrieveById')->once()->with(10)->andReturn($user);
+ $guard->shouldReceive('setUser')->once()->with($user);
+
+ $this->assertTrue($guard->onceUsingId(10));
+ }
+
public function testOnceUsingIdFailure()
{
list($session, $provider, $request, $cookie) = $this->getMocks(); | false |
Other | laravel | framework | 6dc5c7c9edb9a9aa9ea031b80b4b0c832eea78bb.json | Fix style issues with previous commit | src/Illuminate/Database/Query/Processors/SqlServerProcessor.php | @@ -20,13 +20,12 @@ public function processInsertGetId(Builder $query, $sql, $values, $sequence = nu
$connection = $query->getConnection();
$connection->insert($sql, $values);
if ($connection->getConfig('odbc') === true) {
- $result = $connection->select("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) AS insertid");
- if (!$result) {
+ $result = $connection->select('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) AS insertid');
+ if (! $result) {
throw new Exception('Error retrieving lastInsertId');
}
$id = $result[0]->insertid;
- }
- else {
+ } else {
$id = $connection->getPdo()->lastInsertId();
}
| false |
Other | laravel | framework | d9cc1bdc6c624f81222ca8b467374409ebcd737b.json | Fix scope nesting (#13413) | src/Illuminate/Database/Eloquent/Builder.php | @@ -1149,7 +1149,7 @@ protected function applyScope($scope, $builder)
*/
protected function shouldNestWheresForScope(QueryBuilder $query, $originalWhereCount)
{
- return $originalWhereCount && count($query->wheres) > $originalWhereCount;
+ return count($query->wheres) > $originalWhereCount;
}
/** | true |
Other | laravel | framework | d9cc1bdc6c624f81222ca8b467374409ebcd737b.json | Fix scope nesting (#13413) | tests/Database/DatabaseEloquentGlobalScopesTest.php | @@ -69,6 +69,10 @@ public function testGlobalScopesWithOrWhereConditionsAreNested()
{
$model = new EloquentClosureGlobalScopesWithOrTestModel();
+ $query = $model->newQuery();
+ $this->assertEquals('select "email", "password" from "table" where ("email" = ? or "email" = ?) and "active" = ? order by "name" asc', $query->toSql());
+ $this->assertEquals(['taylor@gmail.com', 'someone@else.com', 1], $query->getBindings());
+
$query = $model->newQuery()->where('col1', 'val1')->orWhere('col2', 'val2');
$this->assertEquals('select "email", "password" from "table" where ("col1" = ? or "col2" = ?) and ("email" = ? or "email" = ?) and "active" = ? order by "name" asc', $query->toSql());
$this->assertEquals(['val1', 'val2', 'taylor@gmail.com', 'someone@else.com', 1], $query->getBindings()); | true |
Other | laravel | framework | 8d64b76dd9d820551c7b5b2d9b83fb292bd8b150.json | Add selectCount tests for Eloquent Builder | tests/Database/DatabaseEloquentBuilderTest.php | @@ -455,6 +455,28 @@ public function testDeleteOverride()
$this->assertEquals(['foo' => $builder], $builder->delete());
}
+ public function testSelectCount()
+ {
+ $model = new EloquentBuilderTestModelParentStub;
+
+ $builder = $model->selectCount('foo', 'fooCount');
+
+ $this->assertEquals('select (select count(*) from "eloquent_builder_test_model_close_related_stubs" where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id") as "fooCount" from "eloquent_builder_test_model_parent_stubs"', $builder->toSql());
+ }
+
+ public function testSelectCountWithSelectAndContraintsAndHaving()
+ {
+ $model = new EloquentBuilderTestModelParentStub;
+
+ $builder = $model->where('bar', 'baz')->select('*');
+ $builder->selectCount('foo', 'fooCount', function ($q) {
+ $q->where('bam', '>', 'qux');
+ })->having('fooCount', '>=', 1);
+
+ $this->assertEquals('select *, (select count(*) from "eloquent_builder_test_model_close_related_stubs" where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id" and "bam" > ?) as "fooCount" from "eloquent_builder_test_model_parent_stubs" where "bar" = ? having "fooCount" >= ?', $builder->toSql());
+ $this->assertEquals(['qux', 'baz', 1], $builder->getBindings());
+ }
+
public function testHasWithContraintsAndHavingInSubquery()
{
$model = new EloquentBuilderTestModelParentStub; | false |
Other | laravel | framework | e2da63875bd44d9359dd69a9aeebcba648e195bf.json | use request socket if passed | src/Illuminate/Broadcasting/BroadcastManager.php | @@ -77,6 +77,10 @@ public function socket($request = null)
$request = $request ?: $this->app['request'];
+ if ($request->has('socket')) {
+ return $request->input('socket');
+ }
+
return $this->app['cache']->get(
'pusher:socket:'.$request->session()->getId()
); | false |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Auth/AuthEloquentUserProviderTest.php | @@ -61,7 +61,7 @@ protected function getProviderMock()
{
$hasher = m::mock('Illuminate\Contracts\Hashing\Hasher');
- return $this->getMock('Illuminate\Auth\EloquentUserProvider', ['createModel'], [$hasher, 'foo']);
+ return $this->getMockBuilder('Illuminate\Auth\EloquentUserProvider')->setMethods(['createModel'])->setConstructorArgs([$hasher, 'foo'])->getMock();
}
}
| true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Auth/AuthGuardTest.php | @@ -73,7 +73,7 @@ public function testAttemptCallsRetrieveByCredentials()
public function testAttemptReturnsUserInterface()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $guard = $this->getMock('Illuminate\Auth\SessionGuard', ['login'], ['default', $provider, $session, $request]);
+ $guard = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['login'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$guard->setDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('fire')->once()->with(m::type(Attempting::class));
$user = $this->getMock('Illuminate\Contracts\Auth\Authenticatable');
@@ -95,7 +95,7 @@ public function testAttemptReturnsFalseIfUserNotGiven()
public function testLoginStoresIdentifierInSession()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $mock = $this->getMock('Illuminate\Auth\SessionGuard', ['getName'], ['default', $provider, $session, $request]);
+ $mock = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['getName'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
$mock->expects($this->once())->method('getName')->will($this->returnValue('foo'));
$user->shouldReceive('getAuthIdentifier')->once()->andReturn('bar');
@@ -107,7 +107,7 @@ public function testLoginStoresIdentifierInSession()
public function testLoginFiresLoginEvent()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $mock = $this->getMock('Illuminate\Auth\SessionGuard', ['getName'], ['default', $provider, $session, $request]);
+ $mock = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['getName'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$mock->setDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
$events->shouldReceive('fire')->once()->with(m::type('Illuminate\Auth\Events\Login'));
@@ -130,7 +130,7 @@ public function testIsAuthedReturnsTrueWhenUserIsNotNull()
public function testIsAuthedReturnsFalseWhenUserIsNull()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $mock = $this->getMock('Illuminate\Auth\SessionGuard', ['user'], ['default', $provider, $session, $request]);
+ $mock = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['user'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$mock->expects($this->exactly(2))->method('user')->will($this->returnValue(null));
$this->assertFalse($mock->check());
$this->assertTrue($mock->guest());
@@ -164,7 +164,7 @@ public function testUserIsSetToRetrievedUser()
public function testLogoutRemovesSessionTokenAndRememberMeCookie()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $mock = $this->getMock('Illuminate\Auth\SessionGuard', ['getName', 'getRecallerName', 'getRecaller'], ['default', $provider, $session, $request]);
+ $mock = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['getName', 'getRecallerName', 'getRecaller'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$mock->setCookieJar($cookies = m::mock('Illuminate\Cookie\CookieJar'));
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
$user->shouldReceive('setRememberToken')->once();
@@ -185,7 +185,7 @@ public function testLogoutRemovesSessionTokenAndRememberMeCookie()
public function testLogoutDoesNotEnqueueRememberMeCookieForDeletionIfCookieDoesntExist()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $mock = $this->getMock('Illuminate\Auth\SessionGuard', ['getName', 'getRecaller'], ['default', $provider, $session, $request]);
+ $mock = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['getName', 'getRecaller'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$mock->setCookieJar($cookies = m::mock('Illuminate\Cookie\CookieJar'));
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
$user->shouldReceive('setRememberToken')->once();
@@ -202,7 +202,7 @@ public function testLogoutDoesNotEnqueueRememberMeCookieForDeletionIfCookieDoesn
public function testLogoutFiresLogoutEvent()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $mock = $this->getMock('Illuminate\Auth\SessionGuard', ['clearUserDataFromStorage'], ['default', $provider, $session, $request]);
+ $mock = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['clearUserDataFromStorage'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$mock->expects($this->once())->method('clearUserDataFromStorage');
$mock->setDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$user = m::mock('Illuminate\Contracts\Auth\Authenticatable');
@@ -252,7 +252,7 @@ public function testLoginMethodCreatesRememberTokenIfOneDoesntExist()
public function testLoginUsingIdStoresInSessionAndLogsInWithUser()
{
list($session, $provider, $request, $cookie) = $this->getMocks();
- $guard = $this->getMock('Illuminate\Auth\SessionGuard', ['login', 'user'], ['default', $provider, $session, $request]);
+ $guard = $this->getMockBuilder('Illuminate\Auth\SessionGuard')->setMethods(['login', 'user'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
$guard->getSession()->shouldReceive('set')->once()->with($guard->getName(), 10);
$guard->getProvider()->shouldReceive('retrieveById')->once()->with(10)->andReturn($user = m::mock('Illuminate\Contracts\Auth\Authenticatable'));
$guard->expects($this->once())->method('login')->with($this->equalTo($user), $this->equalTo(false))->will($this->returnValue($user)); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Cache/CacheFileStoreTest.php | @@ -30,7 +30,7 @@ public function testExpiredItemsReturnNull()
$files = $this->mockFilesystem();
$contents = '0000000000';
$files->expects($this->once())->method('get')->will($this->returnValue($contents));
- $store = $this->getMock('Illuminate\Cache\FileStore', ['forget'], [$files, __DIR__]);
+ $store = $this->getMockBuilder('Illuminate\Cache\FileStore')->setMethods(['forget'])->setConstructorArgs([$files, __DIR__])->getMock();
$store->expects($this->once())->method('forget');
$value = $store->get('foo');
$this->assertNull($value);
@@ -48,7 +48,7 @@ public function testValidItemReturnsContents()
public function testStoreItemProperlyStoresValues()
{
$files = $this->mockFilesystem();
- $store = $this->getMock('Illuminate\Cache\FileStore', ['expiration'], [$files, __DIR__]);
+ $store = $this->getMockBuilder('Illuminate\Cache\FileStore')->setMethods(['expiration'])->setConstructorArgs([$files, __DIR__])->getMock();
$store->expects($this->once())->method('expiration')->with($this->equalTo(10))->will($this->returnValue(1111111111));
$contents = '1111111111'.serialize('Hello World');
$hash = sha1('foo'); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Database/DatabaseEloquentCollectionTest.php | @@ -98,7 +98,7 @@ public function testFindMethodFindsModelById()
public function testLoadMethodEagerLoadsGivenRelationships()
{
- $c = $this->getMock('Illuminate\Database\Eloquent\Collection', ['first'], [['foo']]);
+ $c = $this->getMockBuilder('Illuminate\Database\Eloquent\Collection')->setMethods(['first'])->setConstructorArgs([['foo']])->getMock();
$mockItem = m::mock('StdClass');
$c->expects($this->once())->method('first')->will($this->returnValue($mockItem));
$mockItem->shouldReceive('newQuery')->once()->andReturn($mockItem); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Database/DatabaseEloquentPivotTest.php | @@ -81,7 +81,7 @@ public function testDeleteMethodDeletesModelByKeys()
$parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName]');
$parent->guard([]);
$parent->shouldReceive('getConnectionName')->once()->andReturn('connection');
- $pivot = $this->getMock('Illuminate\Database\Eloquent\Relations\Pivot', ['newQuery'], [$parent, ['foo' => 'bar'], 'table']);
+ $pivot = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\Pivot')->setMethods(['newQuery'])->setConstructorArgs([$parent, ['foo' => 'bar'], 'table'])->getMock();
$pivot->setPivotKeys('foreign', 'other');
$pivot->foreign = 'foreign.value';
$pivot->other = 'other.value'; | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Database/DatabaseMigrationCreatorTest.php | @@ -49,6 +49,6 @@ protected function getCreator()
{
$files = m::mock('Illuminate\Filesystem\Filesystem');
- return $this->getMock('Illuminate\Database\Migrations\MigrationCreator', ['getDatePrefix'], [$files]);
+ return $this->getMockBuilder('Illuminate\Database\Migrations\MigrationCreator')->setMethods(['getDatePrefix'])->setConstructorArgs([$files])->getMock();
}
} | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Database/DatabaseSchemaBlueprintTest.php | @@ -20,7 +20,7 @@ public function testToSqlRunsCommandsFromBlueprint()
$conn->shouldReceive('statement')->once()->with('foo');
$conn->shouldReceive('statement')->once()->with('bar');
$grammar = m::mock('Illuminate\Database\Schema\Grammars\MySqlGrammar');
- $blueprint = $this->getMock('Illuminate\Database\Schema\Blueprint', ['toSql'], ['users']);
+ $blueprint = $this->getMockBuilder('Illuminate\Database\Schema\Blueprint')->setMethods(['toSql'])->setConstructorArgs(['users'])->getMock();
$blueprint->expects($this->once())->method('toSql')->with($this->equalTo($conn), $this->equalTo($grammar))->will($this->returnValue(['foo', 'bar']));
$blueprint->build($conn, $grammar); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Foundation/FoundationComposerTest.php | @@ -13,7 +13,7 @@ public function testDumpAutoloadRunsTheCorrectCommand()
{
$escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\'';
- $composer = $this->getMock('Illuminate\Support\Composer', ['getProcess'], [$files = m::mock('Illuminate\Filesystem\Filesystem'), __DIR__]);
+ $composer = $this->getMockBuilder('Illuminate\Support\Composer')->setMethods(['getProcess'])->setConstructorArgs([$files = m::mock('Illuminate\Filesystem\Filesystem'), __DIR__])->getMock();
$files->shouldReceive('exists')->once()->with(__DIR__.'/composer.phar')->andReturn(true);
$process = m::mock('stdClass');
$composer->expects($this->once())->method('getProcess')->will($this->returnValue($process));
@@ -25,7 +25,7 @@ public function testDumpAutoloadRunsTheCorrectCommand()
public function testDumpAutoloadRunsTheCorrectCommandWhenComposerIsntPresent()
{
- $composer = $this->getMock('Illuminate\Support\Composer', ['getProcess'], [$files = m::mock('Illuminate\Filesystem\Filesystem'), __DIR__]);
+ $composer = $this->getMockBuilder('Illuminate\Support\Composer')->setMethods(['getProcess'])->setConstructorArgs([$files = m::mock('Illuminate\Filesystem\Filesystem'), __DIR__])->getMock();
$files->shouldReceive('exists')->once()->with(__DIR__.'/composer.phar')->andReturn(false);
$process = m::mock('stdClass');
$composer->expects($this->once())->method('getProcess')->will($this->returnValue($process)); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Mail/MailMessageTest.php | @@ -96,7 +96,7 @@ public function testGetSwiftMessageMethod()
public function testBasicAttachment()
{
$swift = m::mock('StdClass');
- $message = $this->getMock('Illuminate\Mail\Message', ['createAttachmentFromPath'], [$swift]);
+ $message = $this->getMockBuilder('Illuminate\Mail\Message')->setMethods(['createAttachmentFromPath'])->setConstructorArgs([$swift])->getMock();
$attachment = m::mock('StdClass');
$message->expects($this->once())->method('createAttachmentFromPath')->with($this->equalTo('foo.jpg'))->will($this->returnValue($attachment));
$swift->shouldReceive('attach')->once()->with($attachment);
@@ -108,7 +108,7 @@ public function testBasicAttachment()
public function testDataAttachment()
{
$swift = m::mock('StdClass');
- $message = $this->getMock('Illuminate\Mail\Message', ['createAttachmentFromData'], [$swift]);
+ $message = $this->getMockBuilder('Illuminate\Mail\Message')->setMethods(['createAttachmentFromData'])->setConstructorArgs([$swift])->getMock();
$attachment = m::mock('StdClass');
$message->expects($this->once())->method('createAttachmentFromData')->with($this->equalTo('foo'), $this->equalTo('name'))->will($this->returnValue($attachment));
$swift->shouldReceive('attach')->once()->with($attachment); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Queue/QueueDatabaseQueueTest.php | @@ -11,7 +11,7 @@ public function tearDown()
public function testPushProperlyPushesJobOntoDatabase()
{
- $queue = $this->getMock('Illuminate\Queue\DatabaseQueue', ['getTime'], [$database = m::mock('Illuminate\Database\Connection'), 'table', 'default']);
+ $queue = $this->getMockBuilder('Illuminate\Queue\DatabaseQueue')->setMethods(['getTime'])->setConstructorArgs([$database = m::mock('Illuminate\Database\Connection'), 'table', 'default'])->getMock();
$queue->expects($this->any())->method('getTime')->will($this->returnValue('time'));
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('insertGetId')->once()->andReturnUsing(function ($array) {
@@ -50,7 +50,7 @@ public function testDelayedPushProperlyPushesJobOntoDatabase()
public function testBulkBatchPushesOntoDatabase()
{
$database = m::mock('Illuminate\Database\Connection');
- $queue = $this->getMock('Illuminate\Queue\DatabaseQueue', ['getTime', 'getAvailableAt'], [$database, 'table', 'default']);
+ $queue = $this->getMockBuilder('Illuminate\Queue\DatabaseQueue')->setMethods(['getTime', 'getAvailableAt'])->setConstructorArgs([$database, 'table', 'default'])->getMock();
$queue->expects($this->any())->method('getTime')->will($this->returnValue('created'));
$queue->expects($this->any())->method('getAvailableAt')->will($this->returnValue('available'));
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock('StdClass')); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Queue/QueueRedisQueueTest.php | @@ -11,7 +11,7 @@ public function tearDown()
public function testPushProperlyPushesJobOntoRedis()
{
- $queue = $this->getMock('Illuminate\Queue\RedisQueue', ['getRandomId'], [$redis = m::mock('Illuminate\Redis\Database'), 'default']);
+ $queue = $this->getMockBuilder('Illuminate\Queue\RedisQueue')->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock('Illuminate\Redis\Database'), '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(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 1]));
@@ -22,7 +22,7 @@ public function testPushProperlyPushesJobOntoRedis()
public function testDelayedPushProperlyPushesJobOntoRedis()
{
- $queue = $this->getMock('Illuminate\Queue\RedisQueue', ['getSeconds', 'getTime', 'getRandomId'], [$redis = m::mock('Illuminate\Redis\Database'), 'default']);
+ $queue = $this->getMockBuilder('Illuminate\Queue\RedisQueue')->setMethods(['getSeconds', 'getTime', 'getRandomId'])->setConstructorArgs([$redis = m::mock('Illuminate\Redis\Database'), 'default'])->getMock();
$queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
$queue->expects($this->once())->method('getSeconds')->with(1)->will($this->returnValue(1));
$queue->expects($this->once())->method('getTime')->will($this->returnValue(1));
@@ -41,7 +41,7 @@ public function testDelayedPushProperlyPushesJobOntoRedis()
public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis()
{
$date = Carbon\Carbon::now();
- $queue = $this->getMock('Illuminate\Queue\RedisQueue', ['getSeconds', 'getTime', 'getRandomId'], [$redis = m::mock('Illuminate\Redis\Database'), 'default']);
+ $queue = $this->getMockBuilder('Illuminate\Queue\RedisQueue')->setMethods(['getSeconds', 'getTime', 'getRandomId'])->setConstructorArgs([$redis = m::mock('Illuminate\Redis\Database'), 'default'])->getMock();
$queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
$queue->expects($this->once())->method('getSeconds')->with($date)->will($this->returnValue(1));
$queue->expects($this->once())->method('getTime')->will($this->returnValue(1)); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Queue/QueueSqsJobTest.php | @@ -60,7 +60,7 @@ public function testDeleteRemovesTheJobFromSqs()
->setMethods(['deleteMessage'])
->disableOriginalConstructor()
->getMock();
- $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['getQueue'], [$this->mockedSqsClient, $this->queueName, $this->account]);
+ $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['getQueue'])->setConstructorArgs([$this->mockedSqsClient, $this->queueName, $this->account])->getMock();
$queue->setContainer($this->mockedContainer);
$job = $this->getJob();
$job->getSqs()->expects($this->once())->method('deleteMessage')->with(['QueueUrl' => $this->queueUrl, 'ReceiptHandle' => $this->mockedReceiptHandle]);
@@ -73,7 +73,7 @@ public function testReleaseProperlyReleasesTheJobOntoSqs()
->setMethods(['changeMessageVisibility'])
->disableOriginalConstructor()
->getMock();
- $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['getQueue'], [$this->mockedSqsClient, $this->queueName, $this->account]);
+ $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['getQueue'])->setConstructorArgs([$this->mockedSqsClient, $this->queueName, $this->account])->getMock();
$queue->setContainer($this->mockedContainer);
$job = $this->getJob();
$job->getSqs()->expects($this->once())->method('changeMessageVisibility')->with(['QueueUrl' => $this->queueUrl, 'ReceiptHandle' => $this->mockedReceiptHandle, 'VisibilityTimeout' => $this->releaseDelay]); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Queue/QueueSqsQueueTest.php | @@ -47,7 +47,7 @@ public function setUp()
public function testPopProperlyPopsJobOffOfSqs()
{
- $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['getQueue'], [$this->sqs, $this->queueName, $this->account]);
+ $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock();
$queue->setContainer(m::mock('Illuminate\Container\Container'));
$queue->expects($this->once())->method('getQueue')->with($this->queueName)->will($this->returnValue($this->queueUrl));
$this->sqs->shouldReceive('receiveMessage')->once()->with(['QueueUrl' => $this->queueUrl, 'AttributeNames' => ['ApproximateReceiveCount']])->andReturn($this->mockedReceiveMessageResponseModel);
@@ -57,7 +57,7 @@ public function testPopProperlyPopsJobOffOfSqs()
public function testPopProperlyPopsJobOffOfSqsWithCustomJobCreator()
{
- $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['getQueue'], [$this->sqs, $this->queueName, $this->account]);
+ $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock();
$queue->createJobsUsing(function () { return 'job!'; });
$queue->setContainer(m::mock('Illuminate\Container\Container'));
$queue->expects($this->once())->method('getQueue')->with($this->queueName)->will($this->returnValue($this->queueUrl));
@@ -69,7 +69,7 @@ public function testPopProperlyPopsJobOffOfSqsWithCustomJobCreator()
public function testDelayedPushWithDateTimeProperlyPushesJobOntoSqs()
{
$now = Carbon\Carbon::now();
- $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['createPayload', 'getSeconds', 'getQueue'], [$this->sqs, $this->queueName, $this->account]);
+ $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['createPayload', 'getSeconds', 'getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock();
$queue->expects($this->once())->method('createPayload')->with($this->mockedJob, $this->mockedData)->will($this->returnValue($this->mockedPayload));
$queue->expects($this->once())->method('getSeconds')->with($now)->will($this->returnValue(5));
$queue->expects($this->once())->method('getQueue')->with($this->queueName)->will($this->returnValue($this->queueUrl));
@@ -80,7 +80,7 @@ public function testDelayedPushWithDateTimeProperlyPushesJobOntoSqs()
public function testDelayedPushProperlyPushesJobOntoSqs()
{
- $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['createPayload', 'getSeconds', 'getQueue'], [$this->sqs, $this->queueName, $this->account]);
+ $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['createPayload', 'getSeconds', 'getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock();
$queue->expects($this->once())->method('createPayload')->with($this->mockedJob, $this->mockedData)->will($this->returnValue($this->mockedPayload));
$queue->expects($this->once())->method('getSeconds')->with($this->mockedDelay)->will($this->returnValue($this->mockedDelay));
$queue->expects($this->once())->method('getQueue')->with($this->queueName)->will($this->returnValue($this->queueUrl));
@@ -91,7 +91,7 @@ public function testDelayedPushProperlyPushesJobOntoSqs()
public function testPushProperlyPushesJobOntoSqs()
{
- $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['createPayload', 'getQueue'], [$this->sqs, $this->queueName, $this->account]);
+ $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['createPayload', 'getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock();
$queue->expects($this->once())->method('createPayload')->with($this->mockedJob, $this->mockedData)->will($this->returnValue($this->mockedPayload));
$queue->expects($this->once())->method('getQueue')->with($this->queueName)->will($this->returnValue($this->queueUrl));
$this->sqs->shouldReceive('sendMessage')->once()->with(['QueueUrl' => $this->queueUrl, 'MessageBody' => $this->mockedPayload])->andReturn($this->mockedSendMessageResponseModel); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Queue/QueueWorkerTest.php | @@ -11,7 +11,7 @@ public function tearDown()
public function testJobIsPoppedOffQueueAndProcessed()
{
- $worker = $this->getMock('Illuminate\Queue\Worker', ['process'], [$manager = m::mock('Illuminate\Queue\QueueManager')]);
+ $worker = $this->getMockBuilder('Illuminate\Queue\Worker')->setMethods(['process'])->setConstructorArgs([$manager = m::mock('Illuminate\Queue\QueueManager')])->getMock();
$manager->shouldReceive('connection')->once()->with('connection')->andReturn($connection = m::mock('StdClass'));
$manager->shouldReceive('getName')->andReturn('connection');
$job = m::mock('Illuminate\Contracts\Queue\Job');
@@ -23,7 +23,7 @@ public function testJobIsPoppedOffQueueAndProcessed()
public function testJobIsPoppedOffFirstQueueInListAndProcessed()
{
- $worker = $this->getMock('Illuminate\Queue\Worker', ['process'], [$manager = m::mock('Illuminate\Queue\QueueManager')]);
+ $worker = $this->getMockBuilder('Illuminate\Queue\Worker')->setMethods(['process'])->setConstructorArgs([$manager = m::mock('Illuminate\Queue\QueueManager')])->getMock();
$manager->shouldReceive('connection')->once()->with('connection')->andReturn($connection = m::mock('StdClass'));
$manager->shouldReceive('getName')->andReturn('connection');
$job = m::mock('Illuminate\Contracts\Queue\Job');
@@ -36,7 +36,7 @@ public function testJobIsPoppedOffFirstQueueInListAndProcessed()
public function testWorkerSleepsIfNoJobIsPresentAndSleepIsEnabled()
{
- $worker = $this->getMock('Illuminate\Queue\Worker', ['process', 'sleep'], [$manager = m::mock('Illuminate\Queue\QueueManager')]);
+ $worker = $this->getMockBuilder('Illuminate\Queue\Worker')->setMethods(['process', 'sleep'])->setConstructorArgs([$manager = m::mock('Illuminate\Queue\QueueManager')])->getMock();
$manager->shouldReceive('connection')->once()->with('connection')->andReturn($connection = m::mock('StdClass'));
$connection->shouldReceive('pop')->once()->with('queue')->andReturn(null);
$worker->expects($this->never())->method('process'); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Translation/TranslationTranslatorTest.php | @@ -11,28 +11,28 @@ public function tearDown()
public function testHasMethodReturnsFalseWhenReturnedTranslationIsNull()
{
- $t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'))->will($this->returnValue('foo'));
$this->assertFalse($t->has('foo', 'bar'));
- $t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en', 'sp']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en', 'sp'])->getMock();
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'))->will($this->returnValue('bar'));
$this->assertTrue($t->has('foo', 'bar'));
- $t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'), false)->will($this->returnValue('bar'));
$this->assertTrue($t->hasForLocale('foo', 'bar'));
- $t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'), false)->will($this->returnValue('foo'));
$this->assertFalse($t->hasForLocale('foo', 'bar'));
- $t = $this->getMock('Illuminate\Translation\Translator', ['load', 'getLine'], [$this->getLoader(), 'en']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['load', 'getLine'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('load')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'))->will($this->returnValue(null));
$t->expects($this->once())->method('getLine')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'), null, $this->equalTo([]))->will($this->returnValue('bar'));
$this->assertTrue($t->hasForLocale('foo'));
- $t = $this->getMock('Illuminate\Translation\Translator', ['load', 'getLine'], [$this->getLoader(), 'en']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['load', 'getLine'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('load')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'))->will($this->returnValue(null));
$t->expects($this->once())->method('getLine')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'), null, $this->equalTo([]))->will($this->returnValue('foo'));
$this->assertFalse($t->hasForLocale('foo'));
@@ -64,7 +64,7 @@ public function testGetMethodProperlyLoadsAndRetrievesItemForGlobalNamespace()
public function testChoiceMethodProperlyLoadsAndRetrievesItem()
{
- $t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(['replace']), $this->equalTo('en'))->will($this->returnValue('line'));
$t->setSelector($selector = m::mock('Symfony\Component\Translation\MessageSelector'));
$selector->shouldReceive('choose')->once()->with('line', 10, 'en')->andReturn('choiced');
@@ -74,7 +74,7 @@ public function testChoiceMethodProperlyLoadsAndRetrievesItem()
public function testChoiceMethodProperlyCountsCollectionsAndLoadsAndRetrievesItem()
{
- $t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
+ $t = $this->getMockBuilder('Illuminate\Translation\Translator')->setMethods(['get'])->setConstructorArgs([$this->getLoader(), 'en'])->getMock();
$t->expects($this->exactly(2))->method('get')->with($this->equalTo('foo'), $this->equalTo(['replace']), $this->equalTo('en'))->will($this->returnValue('line'));
$t->setSelector($selector = m::mock('Symfony\Component\Translation\MessageSelector'));
$selector->shouldReceive('choose')->twice()->with('line', 3, 'en')->andReturn('choiced'); | true |
Other | laravel | framework | 49f4ce54b0e687088996fe0ac0f55eb42afcca98.json | fix first batch | tests/Validation/ValidationValidatorTest.php | @@ -1025,13 +1025,13 @@ public function testValidateSize()
$v = new Validator($trans, ['foo' => [1, 2, 3]], ['foo' => 'Array|Size:4']);
$this->assertFalse($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\File', ['getSize'], [__FILE__, false]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')->setMethods(['getSize'])->setConstructorArgs([__FILE__, false])->getMock();
$file->expects($this->any())->method('getSize')->will($this->returnValue(3072));
$v = new Validator($trans, [], ['photo' => 'Size:3']);
$v->setFiles(['photo' => $file]);
$this->assertTrue($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\File', ['getSize'], [__FILE__, false]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')->setMethods(['getSize'])->setConstructorArgs([__FILE__, false])->getMock();
$file->expects($this->any())->method('getSize')->will($this->returnValue(4072));
$v = new Validator($trans, [], ['photo' => 'Size:3']);
$v->setFiles(['photo' => $file]);
@@ -1065,13 +1065,13 @@ public function testValidateBetween()
$v = new Validator($trans, ['foo' => [1, 2, 3]], ['foo' => 'Array|Between:1,2']);
$this->assertFalse($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\File', ['getSize'], [__FILE__, false]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')->setMethods(['getSize'])->setConstructorArgs([__FILE__, false])->getMock();
$file->expects($this->any())->method('getSize')->will($this->returnValue(3072));
$v = new Validator($trans, [], ['photo' => 'Between:1,5']);
$v->setFiles(['photo' => $file]);
$this->assertTrue($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\File', ['getSize'], [__FILE__, false]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')->setMethods(['getSize'])->setConstructorArgs([__FILE__, false])->getMock();
$file->expects($this->any())->method('getSize')->will($this->returnValue(4072));
$v = new Validator($trans, [], ['photo' => 'Between:1,2']);
$v->setFiles(['photo' => $file]);
@@ -1099,13 +1099,13 @@ public function testValidateMin()
$v = new Validator($trans, ['foo' => [1, 2]], ['foo' => 'Array|Min:3']);
$this->assertFalse($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\File', ['getSize'], [__FILE__, false]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')->setMethods(['getSize'])->setConstructorArgs([__FILE__, false])->getMock();
$file->expects($this->any())->method('getSize')->will($this->returnValue(3072));
$v = new Validator($trans, [], ['photo' => 'Min:2']);
$v->setFiles(['photo' => $file]);
$this->assertTrue($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\File', ['getSize'], [__FILE__, false]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')->setMethods(['getSize'])->setConstructorArgs([__FILE__, false])->getMock();
$file->expects($this->any())->method('getSize')->will($this->returnValue(4072));
$v = new Validator($trans, [], ['photo' => 'Min:10']);
$v->setFiles(['photo' => $file]);
@@ -1133,21 +1133,21 @@ public function testValidateMax()
$v = new Validator($trans, ['foo' => [1, 2, 3]], ['foo' => 'Array|Max:2']);
$this->assertFalse($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\UploadedFile', ['isValid', 'getSize'], [__FILE__, basename(__FILE__)]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['isValid', 'getSize'])->setConstructorArgs([__FILE__, basename(__FILE__)])->getMock();
$file->expects($this->at(0))->method('isValid')->will($this->returnValue(true));
$file->expects($this->at(1))->method('getSize')->will($this->returnValue(3072));
$v = new Validator($trans, [], ['photo' => 'Max:10']);
$v->setFiles(['photo' => $file]);
$this->assertTrue($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\UploadedFile', ['isValid', 'getSize'], [__FILE__, basename(__FILE__)]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['isValid', 'getSize'])->setConstructorArgs([__FILE__, basename(__FILE__)])->getMock();
$file->expects($this->at(0))->method('isValid')->will($this->returnValue(true));
$file->expects($this->at(1))->method('getSize')->will($this->returnValue(4072));
$v = new Validator($trans, [], ['photo' => 'Max:2']);
$v->setFiles(['photo' => $file]);
$this->assertFalse($v->passes());
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\UploadedFile', ['isValid'], [__FILE__, basename(__FILE__)]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['isValid'])->setConstructorArgs([__FILE__, basename(__FILE__)])->getMock();
$file->expects($this->any())->method('isValid')->will($this->returnValue(false));
$v = new Validator($trans, [], ['photo' => 'Max:10']);
$v->setFiles(['photo' => $file]);
@@ -1168,7 +1168,7 @@ public function testProperMessagesAreReturnedForSizes()
$v->messages()->setFormat(':message');
$this->assertEquals('string', $v->messages()->first('name'));
- $file = $this->getMock('Symfony\Component\HttpFoundation\File\File', ['getSize'], [__FILE__, false]);
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')->setMethods(['getSize'])->setConstructorArgs([__FILE__, false])->getMock();
$file->expects($this->any())->method('getSize')->will($this->returnValue(4072));
$v = new Validator($trans, [], ['photo' => 'Max:3']);
$v->setFiles(['photo' => $file]); | true |
Other | laravel | framework | 46fd7dd7d794eb5fe6406198880d06a1b33d85e7.json | Fix Issue #11169 (#13360) | src/Illuminate/Database/Eloquent/Model.php | @@ -798,7 +798,7 @@ public function morphTo($name = null, $type = null, $id = null)
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
- if (is_null($class = $this->$type)) {
+ if (empty($class = $this->$type)) {
return new MorphTo(
$this->newQuery(), $this, $id, null, $type, $name
); | false |
Other | laravel | framework | 2e12e8ac272699172bbc928c3f203202dc8fa855.json | rearrange check order | src/Illuminate/Database/Query/Builder.php | @@ -589,7 +589,7 @@ protected function invalidOperatorAndValue($operator, $value)
{
$isOperator = in_array($operator, $this->operators);
- return $isOperator && ! in_array($operator, ['=', '<>', '!=']) && is_null($value);
+ return is_null($value) && $isOperator && ! in_array($operator, ['=', '<>', '!=']);
}
/** | false |
Other | laravel | framework | 59525ab14b5c3083db494c65459360ba3338ac6f.json | remove nested ternary | src/Illuminate/Validation/Validator.php | @@ -841,8 +841,11 @@ protected function validateRequiredIf($attribute, $value, $parameters)
if (is_bool($data)) {
array_walk($values, function (&$value) {
- $value = $value == 'true' ?
- true : ($value == 'false' ? false : $value);
+ if ($value === 'true') {
+ $value = true;
+ } elseif ($value === 'false') {
+ $value = false;
+ }
});
}
| false |
Other | laravel | framework | 0a26661949db13fb3f3c878177f77d8d3a8fa987.json | Fix postgres Schema::hastable (#13008) | src/Illuminate/Database/PostgresConnection.php | @@ -2,13 +2,28 @@
namespace Illuminate\Database;
+use Illuminate\Database\Schema\PostgresBuilder;
use Doctrine\DBAL\Driver\PDOPgSql\Driver as DoctrineDriver;
use Illuminate\Database\Query\Processors\PostgresProcessor;
use Illuminate\Database\Query\Grammars\PostgresGrammar as QueryGrammar;
use Illuminate\Database\Schema\Grammars\PostgresGrammar as SchemaGrammar;
class PostgresConnection extends Connection
{
+ /**
+ * Get a schema builder instance for the connection.
+ *
+ * @return \Illuminate\Database\Schema\PostgresBuilder
+ */
+ public function getSchemaBuilder()
+ {
+ if (is_null($this->schemaGrammar)) {
+ $this->useDefaultSchemaGrammar();
+ }
+
+ return new PostgresBuilder($this);
+ }
+
/**
* Get the default query grammar instance.
* | true |
Other | laravel | framework | 0a26661949db13fb3f3c878177f77d8d3a8fa987.json | Fix postgres Schema::hastable (#13008) | src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php | @@ -28,7 +28,7 @@ class PostgresGrammar extends Grammar
*/
public function compileTableExists()
{
- return 'select * from information_schema.tables where table_name = ?';
+ return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
}
/** | true |
Other | laravel | framework | 0a26661949db13fb3f3c878177f77d8d3a8fa987.json | Fix postgres Schema::hastable (#13008) | src/Illuminate/Database/Schema/PostgresBuilder.php | @@ -0,0 +1,23 @@
+<?php
+
+namespace Illuminate\Database\Schema;
+
+class PostgresBuilder extends Builder
+{
+ /**
+ * Determine if the given table exists.
+ *
+ * @param string $table
+ * @return bool
+ */
+ public function hasTable($table)
+ {
+ $sql = $this->grammar->compileTableExists();
+
+ $schema = $this->connection->getConfig('schema');
+
+ $table = $this->connection->getTablePrefix().$table;
+
+ return count($this->connection->select($sql, [$schema, $table])) > 0;
+ }
+} | true |
Other | laravel | framework | b3a9b21e6a3c7bacc4349ec986b8488a9e7d622f.json | change config name | src/Illuminate/Database/Connectors/SqlServerConnector.php | @@ -60,8 +60,8 @@ protected function getDsn(array $config)
*/
protected function getOdbcDsn(array $config)
{
- if (isset($config['ODBC_DATA_SOURCE_NAME'])) {
- return 'odbc:'.$config['ODBC_DATA_SOURCE_NAME'];
+ if (isset($config['odbc_datasource_name'])) {
+ return 'odbc:'.$config['odbc_datasource_name'];
} else {
return '';
} | false |
Other | laravel | framework | 0073655789b4297ed3667897ccf705c83f210462.json | Change config param get method | src/Illuminate/Database/Connectors/SqlServerConnector.php | @@ -46,12 +46,27 @@ protected function getDsn(array $config)
if (in_array('dblib', $this->getAvailableDrivers())) {
return $this->getDblibDsn($config);
} elseif (in_array('odbc', $this->getAvailableDrivers())) {
- return 'odbc:'.(isset($config('ODBC_DATA_SOURCE_NAME')) ? $config('ODBC_DATA_SOURCE_NAME') : '');
+ return $this->getOdbcDsn($config);
} else {
return $this->getSqlSrvDsn($config);
}
}
+ /**
+ * Get the DSN string for a ODBC connection.
+ *
+ * @param array $config
+ * @return string
+ */
+ protected function getOdbcDsn(array $config)
+ {
+ if (isset($config['ODBC_DATA_SOURCE_NAME'])) {
+ return 'odbc:'.$config['ODBC_DATA_SOURCE_NAME'];
+ } else {
+ return '';
+ }
+ }
+
/**
* Get the DSN string for a DbLib connection.
* | false |
Other | laravel | framework | c69a78303557305577568c1745119ababe67ae33.json | Change config param get method | src/Illuminate/Database/Connectors/SqlServerConnector.php | @@ -46,7 +46,7 @@ protected function getDsn(array $config)
if (in_array('dblib', $this->getAvailableDrivers())) {
return $this->getDblibDsn($config);
} elseif (in_array('odbc', $this->getAvailableDrivers())) {
- return 'odbc:'.env('ODBC_DATA_SOURCE_NAME');
+ return 'odbc:'.(isset($config('ODBC_DATA_SOURCE_NAME')) ? $config('ODBC_DATA_SOURCE_NAME') : '');
} else {
return $this->getSqlSrvDsn($config);
} | false |
Other | laravel | framework | 4219f0ac29615626be29940a6e20f047cb8204b9.json | Update saveMany parameter hint (#13257)
It works great with any traversable objects, not only collections (and specifically eloquent collections as was hinted before) | src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php | @@ -221,8 +221,8 @@ public function save(Model $model)
/**
* Attach a collection of models to the parent instance.
*
- * @param \Illuminate\Database\Eloquent\Collection|array $models
- * @return \Illuminate\Database\Eloquent\Collection|array
+ * @param \Traversable|array $models
+ * @return \Traversable|array
*/
public function saveMany($models)
{ | false |
Other | laravel | framework | 5a52bebd203bb887e339e588aa75d938ae2d2ed7.json | Add Collection tests. (#13227) | tests/Support/SupportCollectionTest.php | @@ -1216,6 +1216,21 @@ public function testCombineWithCollection()
$this->assertSame($expected, $actual);
}
+
+ public function testReduce()
+ {
+ $data = new Collection([1, 2, 3]);
+ $this->assertEquals(6, $data->reduce(function ($carry, $element) { return $carry += $element; }));
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testRandomThrowsAnExceptionUsingAmountBiggerThanCollectionSize()
+ {
+ $data = new Collection([1, 2, 3]);
+ $data->random(4);
+ }
}
class TestAccessorEloquentTestStub | false |
Other | laravel | framework | f13bb7f0a3db39c9c9cf8618cb70c0c309a54090.json | Remove unused parameter (#13206) | src/Illuminate/Foundation/helpers.php | @@ -612,12 +612,11 @@ function response($content = '', $status = 200, array $headers = [])
* @param string $name
* @param array $parameters
* @param bool $absolute
- * @param \Illuminate\Routing\Route $route
* @return string
*/
- function route($name, $parameters = [], $absolute = true, $route = null)
+ function route($name, $parameters = [], $absolute = true)
{
- return app('url')->route($name, $parameters, $absolute, $route);
+ return app('url')->route($name, $parameters, $absolute);
}
}
| false |
Other | laravel | framework | d0b5291098d856c3fb07075197feb165efb65c07.json | Move ability map to a method (#13214) | src/Illuminate/Foundation/Auth/Access/AuthorizesResources.php | @@ -6,21 +6,6 @@
trait AuthorizesResources
{
- /**
- * Map of resource methods to ability names.
- *
- * @var array
- */
- protected $resourceAbilityMap = [
- 'index' => 'view',
- 'create' => 'create',
- 'store' => 'create',
- 'show' => 'view',
- 'edit' => 'update',
- 'update' => 'update',
- 'delete' => 'delete',
- ];
-
/**
* Authorize a resource action based on the incoming request.
*
@@ -34,14 +19,34 @@ public function authorizeResource($model, $name = null, array $options = [], $re
{
$method = array_last(explode('@', with($request ?: request())->route()->getActionName()));
- if (! in_array($method, array_keys($this->resourceAbilityMap))) {
+ $map = $this->resourceAbilityMap();
+
+ if (! in_array($method, array_keys($map))) {
return new ControllerMiddlewareOptions($options);
}
if (! in_array($method, ['index', 'create', 'store'])) {
$model = $name ?: strtolower(class_basename($model));
}
- return $this->middleware("can:{$this->resourceAbilityMap[$method]},{$model}", $options);
+ return $this->middleware("can:{$map[$method]},{$model}", $options);
+ }
+
+ /**
+ * Get the map of resource methods to ability names.
+ *
+ * @return array
+ */
+ protected function resourceAbilityMap()
+ {
+ return [
+ 'index' => 'view',
+ 'create' => 'create',
+ 'store' => 'create',
+ 'show' => 'view',
+ 'edit' => 'update',
+ 'update' => 'update',
+ 'delete' => 'delete',
+ ];
}
} | false |
Other | laravel | framework | 73e7b702b19c0039cda702c6f17b4ef9a767e29f.json | Add more test on View (#13192) | tests/View/ViewFlowTest.php | @@ -2,127 +2,202 @@
use Mockery as m;
use Illuminate\View\Factory;
+use Illuminate\Filesystem\Filesystem;
+use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Compilers\BladeCompiler;
class ViewFlowTest extends PHPUnit_Framework_TestCase
{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $files = new Filesystem;
+ $this->tempDir = __DIR__.'/tmp';
+
+ if (!$files->exists($this->tempDir)) {
+ $files->makeDirectory($this->tempDir);
+ }
+ }
+
public function tearDown()
{
+ $files = new Filesystem;
+ $files->deleteDirectory($this->tempDir);
+
m::close();
}
public function testPushWithExtend()
{
- $files = new Illuminate\Filesystem\Filesystem;
-
+ $files = new Filesystem;
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
- $files->put(__DIR__.'/fixtures/child.php', $compiler->compileString('
+ $files->put($this->tempDir.'/child.php', $compiler->compileString('
@extends("layout")
@push("content")
World
@endpush'));
- $files->put(__DIR__.'/fixtures/layout.php', $compiler->compileString('
+ $files->put($this->tempDir.'/layout.php', $compiler->compileString('
@push("content")
Hello
@endpush
@stack("content")'));
- $engine = new Illuminate\View\Engines\CompilerEngine(m::mock('Illuminate\View\Compilers\CompilerInterface'));
- $engine->getCompiler()->shouldReceive('getCompiledPath')->andReturnUsing(function ($path) { return $path; });
- $engine->getCompiler()->shouldReceive('isExpired')->times(2)->andReturn(false);
-
- $factory = $this->getFactory();
- $factory->getEngineResolver()->shouldReceive('resolve')->times(2)->andReturn($engine);
- $factory->getFinder()->shouldReceive('find')->once()->with('child')->andReturn(__DIR__.'/fixtures/child.php');
- $factory->getFinder()->shouldReceive('find')->once()->with('layout')->andReturn(__DIR__.'/fixtures/layout.php');
- $factory->getDispatcher()->shouldReceive('fire')->times(4);
-
+ $factory = $this->prepareCommonFactory();
$this->assertEquals("Hello\nWorld\n", $factory->make('child')->render());
-
- $files->delete(__DIR__.'/fixtures/layout.php');
- $files->delete(__DIR__.'/fixtures/child.php');
}
public function testPushWithMultipleExtends()
{
- $files = new Illuminate\Filesystem\Filesystem;
-
+ $files = new Filesystem;
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
- $files->put(__DIR__.'/fixtures/a.php', $compiler->compileString('
+ $files->put($this->tempDir.'/a.php', $compiler->compileString('
a
@stack("me")'));
- $files->put(__DIR__.'/fixtures/b.php', $compiler->compileString('
+ $files->put($this->tempDir.'/b.php', $compiler->compileString('
@extends("a")
@push("me")
b
-@endpush("me")'));
+@endpush'));
- $files->put(__DIR__.'/fixtures/c.php', $compiler->compileString('
+ $files->put($this->tempDir.'/c.php', $compiler->compileString('
@extends("b")
@push("me")
c
-@endpush("me")'));
-
- $engine = new Illuminate\View\Engines\CompilerEngine(m::mock('Illuminate\View\Compilers\CompilerInterface'));
- $engine->getCompiler()->shouldReceive('getCompiledPath')->andReturnUsing(function ($path) { return $path; });
- $engine->getCompiler()->shouldReceive('isExpired')->andReturn(false);
-
- $factory = $this->getFactory();
- $factory->getEngineResolver()->shouldReceive('resolve')->andReturn($engine);
- $factory->getFinder()->shouldReceive('find')->andReturnUsing(function ($path) {
- return __DIR__.'/fixtures/'.$path.'.php';
- });
- $factory->getDispatcher()->shouldReceive('fire');
+@endpush'));
+ $factory = $this->prepareCommonFactory();
$this->assertEquals("a\nb\nc\n", $factory->make('c')->render());
-
- $files->delete(__DIR__.'/fixtures/a.php');
- $files->delete(__DIR__.'/fixtures/b.php');
- $files->delete(__DIR__.'/fixtures/c.php');
}
public function testPushWithInputAndExtend()
{
- $files = new Illuminate\Filesystem\Filesystem;
-
+ $files = new Filesystem;
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
- $files->put(__DIR__.'/fixtures/aa.php', $compiler->compileString('
+ $files->put($this->tempDir.'/aa.php', $compiler->compileString('
a
@stack("me")'));
- $files->put(__DIR__.'/fixtures/bb.php', $compiler->compileString('
+ $files->put($this->tempDir.'/bb.php', $compiler->compileString('
@push("me")
b
-@endpush("me")'));
+@endpush'));
- $files->put(__DIR__.'/fixtures/cc.php', $compiler->compileString('
+ $files->put($this->tempDir.'/cc.php', $compiler->compileString('
@extends("aa")
@include("bb")
@push("me")
c
-@endpush("me")'));
+@endpush'));
+
+ $factory = $this->prepareCommonFactory();
+ $this->assertEquals("a\nc\nb\n", $factory->make('cc')->render());
+ }
+
+ public function testExtends()
+ {
+ $files = new Filesystem;
+ $compiler = new BladeCompiler($this->getFiles(), __DIR__);
+
+ $files->put($this->tempDir.'/extends-a.php', $compiler->compileString('
+yield:
+@yield("me")'));
+
+ $files->put($this->tempDir.'/extends-b.php', $compiler->compileString('
+@extends("extends-a")
+@section("me")
+b
+@endsection'));
+
+ $files->put($this->tempDir.'/extends-c.php', $compiler->compileString('
+@extends("extends-b")
+@section("me")
+c
+@endsection'));
+
+ $factory = $this->prepareCommonFactory();
+ $this->assertEquals("yield:\nb\n", $factory->make('extends-b')->render());
+ $this->assertEquals("yield:\nc\n", $factory->make('extends-c')->render());
+ }
- $engine = new Illuminate\View\Engines\CompilerEngine(m::mock('Illuminate\View\Compilers\CompilerInterface'));
- $engine->getCompiler()->shouldReceive('getCompiledPath')->andReturnUsing(function ($path) { return $path; });
+ public function testExtendsWithParent()
+ {
+ $files = new Filesystem;
+ $compiler = new BladeCompiler($this->getFiles(), __DIR__);
+
+ $files->put($this->tempDir.'/extends-layout.php', $compiler->compileString('
+yield:
+@yield("me")'));
+
+ $files->put($this->tempDir.'/extends-dad.php', $compiler->compileString('
+@extends("extends-layout")
+@section("me")
+dad
+@endsection'));
+
+ $files->put($this->tempDir.'/extends-child.php', $compiler->compileString('
+@extends("extends-dad")
+@section("me")
+@parent
+child
+@endsection'));
+
+ $factory = $this->prepareCommonFactory();
+ $this->assertEquals("yield:\ndad\n\nchild\n", $factory->make('extends-child')->render());
+ }
+
+ public function testExtendsWithVariable()
+ {
+ $files = new Filesystem;
+ $compiler = new BladeCompiler($this->getFiles(), __DIR__);
+
+ $files->put($this->tempDir.'/extends-variable-layout.php', $compiler->compileString('
+yield:
+@yield("me")'));
+
+ $files->put($this->tempDir.'/extends-variable-dad.php', $compiler->compileString('
+@extends("extends-variable-layout")
+@section("me")
+dad
+@endsection'));
+
+ $files->put($this->tempDir.'/extends-variable-child-a.php', $compiler->compileString('
+@extends("extends-variable-dad")
+@section("me")
+{{ $title }}
+@endsection'));
+
+ $files->put($this->tempDir.'/extends-variable-child-b.php', $compiler->compileString('
+@extends("extends-variable-dad")
+@section("me")
+{{ $title }}
+@endsection'));
+
+ $factory = $this->prepareCommonFactory();
+ $this->assertEquals("yield:\ntitle\n", $factory->make('extends-variable-child-a', ['title' => 'title'])->render());
+ $this->assertEquals("yield:\ndad\n\n", $factory->make('extends-variable-child-b', ['title' => '@parent'])->render());
+ }
+
+ protected function prepareCommonFactory()
+ {
+ $engine = new CompilerEngine(m::mock('Illuminate\View\Compilers\CompilerInterface'));
+ $engine->getCompiler()->shouldReceive('getCompiledPath')
+ ->andReturnUsing(function ($path) { return $path; });
$engine->getCompiler()->shouldReceive('isExpired')->andReturn(false);
$factory = $this->getFactory();
$factory->getEngineResolver()->shouldReceive('resolve')->andReturn($engine);
$factory->getFinder()->shouldReceive('find')->andReturnUsing(function ($path) {
- return __DIR__.'/fixtures/'.$path.'.php';
+ return $this->tempDir.'/'.$path.'.php';
});
$factory->getDispatcher()->shouldReceive('fire');
- $this->assertEquals("a\nc\nb\n", $factory->make('cc')->render());
-
- $files->delete(__DIR__.'/fixtures/aa.php');
- $files->delete(__DIR__.'/fixtures/bb.php');
- $files->delete(__DIR__.'/fixtures/cc.php');
+ return $factory;
}
protected function getFactory() | false |
Other | laravel | framework | 29e4b14a619a9af0009b71a25d608788be53f4ad.json | Move ability map to a property (#13193) | src/Illuminate/Foundation/Auth/Access/AuthorizesResources.php | @@ -6,6 +6,21 @@
trait AuthorizesResources
{
+ /**
+ * Map of resource methods to ability names.
+ *
+ * @var array
+ */
+ protected $resourceAbilityMap = [
+ 'index' => 'view',
+ 'create' => 'create',
+ 'store' => 'create',
+ 'show' => 'view',
+ 'edit' => 'update',
+ 'update' => 'update',
+ 'delete' => 'delete',
+ ];
+
/**
* Authorize a resource action based on the incoming request.
*
@@ -17,21 +32,16 @@ trait AuthorizesResources
*/
public function authorizeResource($model, $name = null, array $options = [], $request = null)
{
- $action = with($request ?: request())->route()->getActionName();
+ $method = array_last(explode('@', with($request ?: request())->route()->getActionName()));
- $map = [
- 'index' => 'view', 'create' => 'create', 'store' => 'create', 'show' => 'view',
- 'edit' => 'update', 'update' => 'update', 'delete' => 'delete',
- ];
-
- if (! in_array($method = array_last(explode('@', $action)), array_keys($map))) {
+ if (! in_array($method, array_keys($this->resourceAbilityMap))) {
return new ControllerMiddlewareOptions($options);
}
- $name = $name ?: strtolower(class_basename($model));
-
- $model = in_array($method, ['index', 'create', 'store']) ? $model : $name;
+ if (! in_array($method, ['index', 'create', 'store'])) {
+ $model = $name ?: strtolower(class_basename($model));
+ }
- return $this->middleware("can:{$map[$method]},{$model}", $options);
+ return $this->middleware("can:{$this->resourceAbilityMap[$method]},{$model}", $options);
}
} | false |
Other | laravel | framework | 8444190a742d7d77818f3938b214a95a4585ea35.json | Remove extra space | src/Illuminate/Support/Collection.php | @@ -1021,7 +1021,6 @@ public function toArray()
{
return array_map(function ($value) {
return $value instanceof Arrayable ? $value->toArray() : $value;
-
}, $this->items);
}
| false |
Other | laravel | framework | fbcf44403bfa651e4e624922411c6339399c30bf.json | fix documentation typo (#13149)
is() calls currentRouteName() not currentRouteNamed() | src/Illuminate/Routing/Router.php | @@ -1164,7 +1164,7 @@ public function currentRouteName()
}
/**
- * Alias for the "currentRouteNamed" method.
+ * Alias for the "currentRouteName" method.
*
* @param mixed string
* @return bool | false |
Other | laravel | framework | cd21d824846ad8be983ca97a7a627df993bbacf6.json | Add the ability to get routes keyed by method | src/Illuminate/Routing/RouteCollection.php | @@ -240,7 +240,7 @@ protected function check(array $routes, $request, $includingMethod = true)
* @param string|null $method
* @return array
*/
- protected function get($method = null)
+ public function get($method = null)
{
if (is_null($method)) {
return $this->getRoutes();
@@ -292,6 +292,16 @@ public function getRoutes()
return array_values($this->allRoutes);
}
+ /**
+ * Get all of the routes keyed by method in the collection.
+ *
+ * @return array
+ */
+ public function getKeyedRoutes()
+ {
+ return $this->routes;
+ }
+
/**
* Get an iterator for the items.
* | false |
Other | laravel | framework | 307917505bbc1ef9f8e3b9442c92bbbf79cafa45.json | Fix bug in listener generation.
This prevents the framework from generating listeners for listeners
that are defined in packages outside of the App namespace. | src/Illuminate/Foundation/Console/ListenerMakeCommand.php | @@ -84,6 +84,17 @@ protected function getStub()
}
}
+ /**
+ * Determine if the class already exists.
+ *
+ * @param string $rawName
+ * @return bool
+ */
+ protected function alreadyExists($rawName)
+ {
+ return class_exists($rawName);
+ }
+
/**
* Get the default namespace for the class.
* | false |
Other | laravel | framework | cebc939e8ea6a5a17921b729333808a9bc8e814b.json | Add array pull and array forget tests | tests/Support/SupportArrTest.php | @@ -305,6 +305,18 @@ public function testPull()
$name = Arr::pull($array, 'name');
$this->assertEquals('Desk', $name);
$this->assertEquals(['price' => 100], $array);
+
+ // Only works on first level keys
+ $array = ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane'];
+ $name = Arr::pull($array, 'joe@example.com');
+ $this->assertEquals('Joe', $name);
+ $this->assertEquals(['jane@localhost' => 'Jane'], $array);
+
+ // Does not work for nested keys
+ $array = ['emails' => ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane']];
+ $name = Arr::pull($array, 'emails.joe@example.com');
+ $this->assertEquals(null, $name);
+ $this->assertEquals(['emails' => ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane']], $array);
}
public function testSet()
@@ -438,5 +450,15 @@ public function testForget()
$array = ['products' => ['desk' => ['price' => 50], null => 'something']];
Arr::forget($array, ['products.amount.all', 'products.desk.price']);
$this->assertEquals(['products' => ['desk' => [], null => 'something']], $array);
+
+ // Only works on first level keys
+ $array = ['joe@example.com' => 'Joe', 'jane@example.com' => 'Jane'];
+ Arr::forget($array, 'joe@example.com');
+ $this->assertEquals(['jane@example.com' => 'Jane'], $array);
+
+ // Does not work for nested keys
+ $array = ['emails' => ['joe@example.com' => ['name' => 'Joe'], 'jane@localhost' => ['name' => 'Jane']]];
+ Arr::forget($array, ['emails.joe@example.com','emails.jane@localhost']);
+ $this->assertEquals(['emails' => ['joe@example.com' => ['name' => 'Joe']]], $array);
}
} | false |
Other | laravel | framework | 6b95535b4358967c603807804bf8116a36a0c8a8.json | Remove key when key exists | src/Illuminate/Support/Arr.php | @@ -233,6 +233,11 @@ public static function forget(&$array, $keys)
}
foreach ($keys as $key) {
+ if (static::exists($array, $key)) {
+ unset($array[$key]);
+ continue;
+ }
+
$parts = explode('.', $key);
// clean up before each pass | false |
Other | laravel | framework | 28e60c2f5ddfdee35564833ac36d0f13450690e7.json | remove extra spacing | src/Illuminate/Routing/Route.php | @@ -449,9 +449,7 @@ public function bindParameters(Request $request)
// compile that and get the parameter matches for this domain. We will then
// merge them into this parameters array so that this array is completed.
$params = $this->matchToKeys(
-
array_slice($this->bindPathParameters($request), 1)
-
);
// If the route has a regular expression for the host part of the URI, we will | false |
Other | laravel | framework | 2ca9ca69043230b422d518d7fbc7cf797cc4e2a6.json | Update SqlServerGrammar.php (#13089)
The description of 'compileAdd' function seems copied from 'compileCreate'. Suggested a clearer (hopefully) description for the function. | src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php | @@ -59,7 +59,7 @@ public function compileCreate(Blueprint $blueprint, Fluent $command)
}
/**
- * Compile a create table command.
+ * Compile a column addition table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command | false |
Other | laravel | framework | da62677cea29ce3f5e6348c416218f11459ca3d6.json | Allow numerics for unix timestamps. | src/Illuminate/Validation/Validator.php | @@ -1383,7 +1383,7 @@ protected function validateDate($attribute, $value)
return true;
}
- if (! is_string($value) || strtotime($value) === false) {
+ if ((! is_string($value) && ! is_numeric($value)) || strtotime($value) === false) {
return false;
}
@@ -1404,7 +1404,7 @@ protected function validateDateFormat($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'date_format');
- if (! is_string($value)) {
+ if (! is_string($value) && ! is_numeric($value)) {
return false;
}
@@ -1425,7 +1425,7 @@ protected function validateBefore($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'before');
- if (! is_string($value)) {
+ if (! is_string($value) && ! is_numeric($value)) {
return false;
}
@@ -1467,7 +1467,7 @@ protected function validateAfter($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'after');
- if (! is_string($value)) {
+ if (! is_string($value) && ! is_numeric($value)) {
return false;
}
| false |
Other | laravel | framework | 4f1ea6d756c309d29544eda7069cc0de0965a6f5.json | update assets + use SRI checking | src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub | @@ -8,11 +8,11 @@
<title>Laravel</title>
<!-- Fonts -->
- <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel='stylesheet' type='text/css'>
+ <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-XdYbMnZ/QjLh6iI4ogqCTaIjrFk87ip+ekIjefZch0Y+PvJ8CDYtEs1ipDmPorQ+" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700" rel='stylesheet' type='text/css'>
<!-- Styles -->
- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
+ <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
{{-- <link href="{{ elixir('css/app.css') }}" rel="stylesheet"> --}}
<style>
@@ -75,8 +75,8 @@
@yield('content')
<!-- JavaScripts -->
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
+ <script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
{{-- <script src="{{ elixir('js/app.js') }}"></script> --}}
</body>
</html> | false |
Other | laravel | framework | 360bfab90ef63305820dbc608832887af371636d.json | fix multibyte string functions | src/Illuminate/Support/Str.php | @@ -66,7 +66,7 @@ public static function camel($value)
public static function contains($haystack, $needles)
{
foreach ((array) $needles as $needle) {
- if ($needle != '' && strpos($haystack, $needle) !== false) {
+ if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
return true;
}
}
@@ -84,7 +84,7 @@ public static function contains($haystack, $needles)
public static function endsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
- if ((string) $needle === substr($haystack, -strlen($needle))) {
+ if ((string) $needle === static::substr($haystack, -static::length($needle))) {
return true;
}
}
@@ -103,7 +103,7 @@ public static function finish($value, $cap)
{
$quoted = preg_quote($cap, '/');
- return preg_replace('/(?:'.$quoted.')+$/', '', $value).$cap;
+ return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
}
/**
@@ -126,7 +126,7 @@ public static function is($pattern, $value)
// pattern such as "library/*", making any string check convenient.
$pattern = str_replace('\*', '.*', $pattern).'\z';
- return (bool) preg_match('#^'.$pattern.'#', $value);
+ return (bool) preg_match('#^'.$pattern.'#u', $value);
}
/**
@@ -180,7 +180,7 @@ public static function words($value, $words = 100, $end = '...')
{
preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches);
- if (! isset($matches[0]) || strlen($value) === strlen($matches[0])) {
+ if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) {
return $value;
}
@@ -221,12 +221,12 @@ public static function random($length = 16)
{
$string = '';
- while (($len = strlen($string)) < $length) {
+ while (($len = static::length($string)) < $length) {
$size = $length - $len;
$bytes = static::randomBytes($size);
- $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
+ $string .= static::substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
}
return $string;
@@ -255,7 +255,7 @@ public static function quickRandom($length = 16)
{
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
+ return static::substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
}
/**
@@ -283,9 +283,9 @@ public static function equals($knownString, $userInput)
return hash_equals($knownString, $userInput);
}
- $knownLength = mb_strlen($knownString, '8bit');
+ $knownLength = static::length($knownString, '8bit');
- if (mb_strlen($userInput, '8bit') !== $knownLength) {
+ if (static::length($userInput, '8bit') !== $knownLength) {
return false;
}
@@ -372,9 +372,9 @@ public static function snake($value, $delimiter = '_')
}
if (! ctype_lower($value)) {
- $value = preg_replace('/\s+/', '', $value);
+ $value = preg_replace('/\s+/u', '', $value);
- $value = static::lower(preg_replace('/(.)(?=[A-Z])/', '$1'.$delimiter, $value));
+ $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
}
return static::$snakeCache[$key] = $value;
@@ -390,7 +390,7 @@ public static function snake($value, $delimiter = '_')
public static function startsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
- if ($needle != '' && strpos($haystack, $needle) === 0) {
+ if ($needle != '' && mb_strpos($haystack, $needle) === 0) {
return true;
}
} | false |
Other | laravel | framework | 8031ca04f8c39a3650a84abc109db5fe8880c75f.json | Use relation setter | src/Illuminate/Database/Eloquent/Model.php | @@ -2694,7 +2694,9 @@ protected function getRelationshipFromMethod($method)
.'Illuminate\Database\Eloquent\Relations\Relation');
}
- return $this->relations[$method] = $relations->getResults();
+ $this->setRelation($method, $results = $relations->getResults());
+
+ return $results;
}
/** | false |
Other | laravel | framework | ab4bad7d2caf5535e6d3e65ce5937e4495853528.json | Reverse a breaking addition in router | src/Illuminate/Routing/Route.php | @@ -235,15 +235,7 @@ protected function extractOptionalParameters()
public function middleware($middleware = null)
{
if (is_null($middleware)) {
- $middlewares = (array) Arr::get($this->action, 'middleware', []);
-
- if (is_string($this->action['uses'])) {
- $middlewares = array_merge(
- $middlewares, $this->controllerMiddleware()
- );
- }
-
- return $middlewares;
+ return (array) Arr::get($this->action, 'middleware', []);
}
if (is_string($middleware)) { | false |
Other | laravel | framework | 4ef35884eceb4ff17c7eaf7f6f9ba6fa551e32cf.json | Remove duplicate 'just' | src/Illuminate/Database/Query/Grammars/Grammar.php | @@ -142,9 +142,9 @@ protected function compileJoins(Builder $query, $joins)
$type = $join->type;
- // Cross joins generate a cartesian product between the first table and the joined
- // table. Since they don't expect any "on" clauses to perform the join, we just
- // just append the SQL statement and jump to the next iteration of this loop.
+ // Cross joins generate a cartesian product between the first table and the
+ // joined table. Since they don't expect any "on" clauses to perform the
+ // join, we append the SQL and jump to the next iteration of the loop.
if ($type === 'cross') {
$sql[] = "cross join $table";
| false |
Other | laravel | framework | 914582b4a6312a131db6935ef1939de3214fc7ca.json | Fix indentation in `Route::controllerMiddleware` | src/Illuminate/Routing/Route.php | @@ -269,7 +269,7 @@ protected function controllerMiddleware()
$controller = $this->container->make($class);
return (new ControllerDispatcher($this->router, $this->container))
- ->getMiddleware($controller, $method);
+ ->getMiddleware($controller, $method);
}
/** | false |
Other | laravel | framework | 7642f12d7199456e5bf634a3e449023e3ee0160d.json | add defualt value | src/Illuminate/Validation/Validator.php | @@ -369,7 +369,7 @@ public function extractValuesForWildcards($data, $attribute)
* @param string|array $rules
* @return $this
*/
- public function mergeRules($attribute, $rules)
+ public function mergeRules($attribute, $rules = [])
{
if (is_array($attribute)) {
foreach ($attribute as $innerAttribute => $innerRules) { | false |
Other | laravel | framework | 424f15785ab8d4815f251c0f44e5eb9005fab891.json | Add Filesystem tests. | tests/Filesystem/FilesystemTest.php | @@ -324,4 +324,40 @@ public function testSharedGet()
$this->assertTrue($result === 1);
@unlink(__DIR__.'/file.txt');
}
+
+ public function testRequireOnceRequiresFileProperly()
+ {
+ $filesystem = new Filesystem;
+ mkdir(__DIR__.'/foo');
+ file_put_contents(__DIR__.'/foo/foo.php', '<?php function random_function_xyz(){};');
+ $filesystem->requireOnce(__DIR__.'/foo/foo.php');
+ $this->assertTrue(function_exists('random_function_xyz'));
+ @unlink(__DIR__.'/foo/foo.php');
+ @rmdir(__DIR__.'/foo');
+ }
+
+ public function testCopyCopiesFileProperly()
+ {
+ $filesystem = new Filesystem;
+ $data = 'contents';
+ mkdir(__DIR__.'/foo');
+ file_put_contents(__DIR__.'/foo/foo.txt', $data);
+ $filesystem->copy(__DIR__.'/foo/foo.txt', __DIR__.'/foo/foo2.txt');
+ $this->assertTrue(file_exists(__DIR__.'/foo/foo2.txt'));
+ $this->assertEquals($data, file_get_contents(__DIR__.'/foo/foo2.txt'));
+ @unlink(__DIR__.'/foo/foo.txt');
+ @unlink(__DIR__.'/foo/foo2.txt');
+ @rmdir(__DIR__.'/foo');
+ }
+
+ public function testIsFileChecksFilesProperly()
+ {
+ $filesystem = new Filesystem;
+ mkdir(__DIR__.'/foo');
+ file_put_contents(__DIR__.'/foo/foo.txt', 'contents');
+ $this->assertTrue($filesystem->isFile(__DIR__.'/foo/foo.txt'));
+ $this->assertFalse($filesystem->isFile(__DIR__.'./foo'));
+ @unlink('/foo/foo.txt');
+ @rmdir(__DIR__.'/foo');
+ }
} | false |
Other | laravel | framework | 052c4c6f0c0483909a5bb2aa814c86897bf33892.json | Add email options closure | src/Illuminate/Foundation/Auth/ResetsPasswords.php | @@ -62,9 +62,7 @@ public function sendResetLinkEmail(Request $request)
$broker = $this->getBroker();
- $response = Password::broker($broker)->sendResetLink($request->only('email'), function (Message $message) {
- $message->subject($this->getEmailSubject());
- });
+ $response = Password::broker($broker)->sendResetLink($request->only('email'), $this->getEmailOptionsClosure());
switch ($response) {
case Password::RESET_LINK_SENT:
@@ -76,6 +74,18 @@ public function sendResetLinkEmail(Request $request)
}
}
+ /**
+ * Get the closure which is used to configure email options.
+ *
+ * @return \Closure
+ */
+ protected function getEmailOptionsClosure()
+ {
+ return function (Message $message) {
+ $message->subject($this->getEmailSubject());
+ };
+ }
+
/**
* Get the e-mail subject line to be used for the reset link email.
* | false |
Other | laravel | framework | 65907a6be614554b7b55d53aab24bbdf3a7e2b1e.json | Move the Authorize middleware into Foundation | src/Illuminate/Foundation/Auth/Access/Middleware/Authorize.php | @@ -1,6 +1,6 @@
<?php
-namespace Illuminate\Auth\Access\Middleware;
+namespace Illuminate\Foundation\Auth\Access\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Access\Gate; | true |
Other | laravel | framework | 65907a6be614554b7b55d53aab24bbdf3a7e2b1e.json | Move the Authorize middleware into Foundation | tests/Foundation/FoundationAuthorizeMiddlewareTest.php | @@ -5,11 +5,11 @@
use Illuminate\Auth\Access\Gate;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
-use Illuminate\Auth\Access\Middleware\Authorize;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
+use Illuminate\Foundation\Auth\Access\Middleware\Authorize;
-class AuthorizeTest extends PHPUnit_Framework_TestCase
+class FoundationAuthorizeMiddlewareTest extends PHPUnit_Framework_TestCase
{
protected $container;
protected $user; | true |
Other | laravel | framework | 80bb82a6398d51fe9b132ef450c268d78e95c165.json | Create AuthorizesResources trait | src/Illuminate/Foundation/Auth/Access/AuthorizesResources.php | @@ -0,0 +1,41 @@
+<?php
+
+namespace Illuminate\Foundation\Auth\Access;
+
+use Illuminate\Routing\ControllerMiddlewareOptions;
+
+trait AuthorizesResources
+{
+ /**
+ * Authorize a resource action.
+ *
+ * @param string $name
+ * @param string $model
+ * @param array $options
+ * @param \Illuminate\Http\Request|null $request
+ * @return \Illuminate\Routing\ControllerMiddlewareOptions
+ */
+ public function authorizeResource($name, $model, array $options = [], $request = null)
+ {
+ $action = with($request ?: request())->route()->getActionName();
+
+ $method = array_last(explode('@', $action));
+
+ $map = [
+ 'index' => 'view', 'create' => 'create', 'store' => 'create', 'show' => 'view',
+ 'edit' => 'update', 'update' => 'update', 'delete' => 'delete',
+ ];
+
+ if (property_exists($this, 'abilityMap')) {
+ $map = array_merge($map, $this->abilityMap);
+ }
+
+ if (! in_array($method, array_keys($map))) {
+ return new ControllerMiddlewareOptions($options);
+ }
+
+ $model = in_array($method, ['index', 'create', 'store']) ? $model : $name;
+
+ return $this->middleware("can:{$map[$method]},{$model}", $options);
+ }
+} | false |
Other | laravel | framework | d32dd12bad0116e66e0e41020b2d7f04f9468c7d.json | Test the Authorize middleware | tests/Auth/AuthorizeTest.php | @@ -0,0 +1,157 @@
+<?php
+
+use Illuminate\Http\Request;
+use Illuminate\Routing\Router;
+use Illuminate\Auth\Access\Gate;
+use Illuminate\Events\Dispatcher;
+use Illuminate\Container\Container;
+use Illuminate\Auth\Access\Middleware\Authorize;
+use Illuminate\Auth\Access\AuthorizationException;
+use Illuminate\Contracts\Auth\Access\Gate as GateContract;
+
+class AuthorizeTest extends PHPUnit_Framework_TestCase
+{
+ protected $container;
+ protected $user;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->user = new stdClass;
+
+ $this->container = new Container;
+
+ $this->container->singleton(GateContract::class, function () {
+ return new Gate($this->container, function () {
+ return $this->user;
+ });
+ });
+
+ $this->router = new Router(new Dispatcher, $this->container);
+ }
+
+ public function testSimpleAbilityUnauthorized()
+ {
+ $this->setExpectedException(AuthorizationException::class);
+
+ $this->gate()->define('view-dashboard', function ($user, $additional = null) {
+ $this->assertNull($additional);
+
+ return false;
+ });
+
+ $this->router->get('dashboard', [
+ 'middleware' => Authorize::class.':view-dashboard',
+ 'uses' => function () { return 'success'; },
+ ]);
+
+ $this->router->dispatch(Request::create('dashboard', 'GET'));
+ }
+
+ public function testSimpleAbilityAuthorized()
+ {
+ $this->gate()->define('view-dashboard', function ($user) {
+ return true;
+ });
+
+ $this->router->get('dashboard', [
+ 'middleware' => Authorize::class.':view-dashboard',
+ 'uses' => function () { return 'success'; },
+ ]);
+
+ $response = $this->router->dispatch(Request::create('dashboard', 'GET'));
+
+ $this->assertEquals($response->content(), 'success');
+ }
+
+ public function testModelTypeUnauthorized()
+ {
+ $this->setExpectedException(AuthorizationException::class);
+
+ $this->gate()->define('create', function ($user, $model) {
+ $this->assertEquals($model, 'App\User');
+
+ return false;
+ });
+
+ $this->router->get('users/create', [
+ 'middleware' => Authorize::class.':create,App\User',
+ 'uses' => function () { return 'success'; },
+ ]);
+
+ $this->router->dispatch(Request::create('users/create', 'GET'));
+ }
+
+ public function testModelTypeAuthorized()
+ {
+ $this->gate()->define('create', function ($user, $model) {
+ $this->assertEquals($model, 'App\User');
+
+ return true;
+ });
+
+ $this->router->get('users/create', [
+ 'middleware' => Authorize::class.':create,App\User',
+ 'uses' => function () { return 'success'; },
+ ]);
+
+ $response = $this->router->dispatch(Request::create('users/create', 'GET'));
+
+ $this->assertEquals($response->content(), 'success');
+ }
+
+ public function testModelUnauthorized()
+ {
+ $this->setExpectedException(AuthorizationException::class);
+
+ $post = new stdClass;
+
+ $this->router->bind('post', function () use ($post) { return $post; });
+
+ $this->gate()->define('edit', function ($user, $model) use ($post) {
+ $this->assertSame($model, $post);
+
+ return false;
+ });
+
+ $this->router->get('posts/{post}/edit', [
+ 'middleware' => Authorize::class.':edit,post',
+ 'uses' => function () { return 'success'; },
+ ]);
+
+ $this->router->dispatch(Request::create('posts/1/edit', 'GET'));
+ }
+
+ public function testModelAuthorized()
+ {
+ $post = new stdClass;
+
+ $this->router->bind('post', function () use ($post) { return $post; });
+
+ $this->gate()->define('edit', function ($user, $model) use ($post) {
+ $this->assertSame($model, $post);
+
+ return true;
+ });
+
+ $this->router->get('posts/{post}/edit', [
+ 'middleware' => Authorize::class.':edit,post',
+ 'uses' => function () { return 'success'; },
+ ]);
+
+ $response = $this->router->dispatch(Request::create('posts/1/edit', 'GET'));
+
+ $this->assertEquals($response->content(), 'success');
+ }
+
+ /**
+ * Get the Gate instance from the container.
+ *
+ * @return \Illuminate\Auth\Access\Gate
+ */
+ protected function gate()
+ {
+ return $this->container->make(GateContract::class);
+ }
+} | false |
Other | laravel | framework | 648fa7e35b1163e255a6f1a8939d79900761087c.json | Create Authorize middleware | src/Illuminate/Auth/Access/Middleware/Authorize.php | @@ -0,0 +1,68 @@
+<?php
+
+namespace Illuminate\Auth\Access\Middleware;
+
+use Closure;
+use Illuminate\Contracts\Auth\Access\Gate;
+
+class Authorize
+{
+ /**
+ * The gate instance.
+ *
+ * @var \Illuminate\Contracts\Auth\Access\Gate
+ */
+ protected $gate;
+
+ /**
+ * Create a new middleware instance.
+ *
+ * @param \Illuminate\Contracts\Auth\Access\Gate $gate
+ * @return void
+ */
+ public function __construct(Gate $gate)
+ {
+ $this->gate = $gate;
+ }
+
+ /**
+ * Handle an incoming request.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param \Closure $next
+ * @param string $ability
+ * @param string|null $model
+ * @return mixed
+ *
+ * @throws \Illuminate\Auth\Access\AuthorizationException
+ */
+ public function handle($request, Closure $next, $ability, $model = null)
+ {
+ $this->gate->authorize($ability, $this->getGateArguments($request, $model));
+
+ return $next($request);
+ }
+
+ /**
+ * Get the arguments parameter for the gate.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param string|null $model
+ * @return array|string|\Illuminate\Database\Eloquent\Model
+ */
+ protected function getGateArguments($request, $model)
+ {
+ // If there's no model, we'll pass an empty array to the gate. If it
+ // looks like a FQCN of a model, we'll send it to the gate as is.
+ // Otherwise, we'll resolve the Eloquent model from the route.
+ if (is_null($model)) {
+ return [];
+ }
+
+ if (strpos($model, '\\') !== false) {
+ return $model;
+ }
+
+ return $request->route($model);
+ }
+} | false |
Other | laravel | framework | f946f279a5f1e92a350d1e765239d08d70c365ca.json | Trim the input name in the generator commands | src/Illuminate/Console/GeneratorCommand.php | @@ -202,7 +202,7 @@ protected function replaceClass($stub, $name)
*/
protected function getNameInput()
{
- return $this->argument('name');
+ return trim($this->argument('name'));
}
/** | true |
Other | laravel | framework | f946f279a5f1e92a350d1e765239d08d70c365ca.json | Trim the input name in the generator commands | src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php | @@ -63,7 +63,7 @@ public function fire()
// It's possible for the developer to specify the tables to modify in this
// schema operation. The developer may also specify if this table needs
// to be freshly created so we can create the appropriate migrations.
- $name = $this->input->getArgument('name');
+ $name = trim($this->input->getArgument('name'));
$table = $this->input->getOption('table');
| true |
Other | laravel | framework | b5efbbc0a836ad292c2427bdb617bb5d17d73a8f.json | remove git junk | src/Illuminate/Database/Query/Builder.php | @@ -1664,13 +1664,7 @@ public function chunkById($count, callable $callback, $column = 'id')
return false;
}
-<<<<<<< HEAD
- if ($column) {
- $lastId = $results->last()->{$column};
- }
-=======
- $lastId = last($results)->{$column};
->>>>>>> 5.2
+ $lastId = $results->last()->{$column};
$results = $this->forPageAfterId($count, $lastId, $column)->get();
} | false |
Other | laravel | framework | 185447cbd5374770d98cf8d869996c05dcb6e09e.json | Apply a middleware only once | src/Illuminate/Routing/Route.php | @@ -242,9 +242,9 @@ public function middleware($middleware = null)
$middleware = [$middleware];
}
- $this->action['middleware'] = array_merge(
+ $this->action['middleware'] = array_unique(array_merge(
(array) Arr::get($this->action, 'middleware', []), $middleware
- );
+ ));
return $this;
} | true |
Other | laravel | framework | 185447cbd5374770d98cf8d869996c05dcb6e09e.json | Apply a middleware only once | tests/Routing/RoutingRouteTest.php | @@ -575,6 +575,20 @@ public function testRouteMiddlewareMergeWithMiddlewareAttributesAsStrings()
);
}
+ public function testRouteMiddlewareAppliedOnlyOnce()
+ {
+ $router = $this->getRouter();
+ $router->group(['middleware' => 'foo'], function () use ($router) {
+ $router->get('bar', function () { return 'hello'; })->middleware(['foo', 'foo']);
+ });
+ $routes = $router->getRoutes()->getRoutes();
+ $route = $routes[0];
+ $this->assertEquals(
+ ['foo'],
+ $route->middleware()
+ );
+ }
+
public function testRoutePrefixing()
{
/* | true |
Other | laravel | framework | ab24e0d1f68584e973ece32d41a2302110e97d74.json | Adjust whitespace in one more docblock | src/Illuminate/Database/Query/Builder.php | @@ -1621,8 +1621,8 @@ protected function restoreFieldsForCount()
/**
* Chunk the results of the query.
*
- * @param int $count
- * @param callable $callback
+ * @param int $count
+ * @param callable $callback
* @return bool
*/
public function chunk($count, callable $callback) | false |
Other | laravel | framework | 130a405547eef1c2e3931548a9c38a82c360ca53.json | Revert a param name | src/Illuminate/Database/Query/Builder.php | @@ -1650,23 +1650,23 @@ public function chunk($count, callable $callback)
*
* @param int $count
* @param callable $callback
- * @param string $idColumn
+ * @param string $column
* @return bool
*/
- public function chunkById($count, callable $callback, $idColumn = 'id')
+ public function chunkById($count, callable $callback, $column = 'id')
{
$lastId = null;
- $results = $this->pageAfterId($count, 0, $idColumn)->get();
+ $results = $this->pageAfterId($count, 0, $column)->get();
while (! empty($results)) {
if (call_user_func($callback, $results) === false) {
return false;
}
- $lastId = last($results)->{$idColumn};
+ $lastId = last($results)->{$column};
- $results = $this->pageAfterId($count, $lastId, $idColumn)->get();
+ $results = $this->pageAfterId($count, $lastId, $column)->get();
}
return true; | false |
Other | laravel | framework | 3ddd15e15840f165dc49a9e5dbd15881030d6c0b.json | Fix docblock formats | src/Illuminate/Database/Eloquent/Builder.php | @@ -330,8 +330,8 @@ public function value($column)
/**
* Chunk the results of the query.
*
- * @param int $count
- * @param callable $callback
+ * @param int $count
+ * @param callable $callback
* @return bool
*/
public function chunk($count, callable $callback)
@@ -357,9 +357,9 @@ public function chunk($count, callable $callback)
/**
* Chunk the results of a query by comparing numeric IDs.
*
- * @param int $count
- * @param callable $callback
- * @param string $column
+ * @param int $count
+ * @param callable $callback
+ * @param string $column
* @return bool
*/
public function chunkById($count, callable $callback, $column = 'id') | true |
Other | laravel | framework | 3ddd15e15840f165dc49a9e5dbd15881030d6c0b.json | Fix docblock formats | src/Illuminate/Database/Query/Builder.php | @@ -1335,10 +1335,10 @@ public function forPage($page, $perPage = 15)
/**
* Constrain the query to the next "page" of results after a given ID.
*
- * @param int $perPage
- * @param int $column
- * @param string $column
- * @return Builder|static
+ * @param int $perPage
+ * @param int $lastId
+ * @param string $column
+ * @return \Illuminate\Database\Query\Builder|static
*/
public function pageAfterId($perPage = 15, $lastId = 0, $column = 'id')
{
@@ -1648,9 +1648,9 @@ public function chunk($count, callable $callback)
/**
* Chunk the results of a query by comparing numeric IDs.
*
- * @param int $count
- * @param callable $callback
- * @param string $column
+ * @param int $count
+ * @param callable $callback
+ * @param string $idColumn
* @return bool
*/
public function chunkById($count, callable $callback, $column = 'id') | true |
Other | laravel | framework | 88d42be19a6fdc7c87d3b17bdf815080c94481c5.json | Remove route group from make:auth stub | src/Illuminate/Auth/Console/stubs/make/routes.stub | @@ -1,6 +1,4 @@
-Route::group(['middleware' => 'web'], function () {
- Route::auth();
+Route::auth();
- Route::get('/home', 'HomeController@index');
-});
+Route::get('/home', 'HomeController@index'); | false |
Other | laravel | framework | e6f806cf35e1352d849d97b62e217398ab2c7f99.json | Add support for testing eloquent model events | src/Illuminate/Foundation/Testing/Concerns/MocksApplicationServices.php | @@ -4,6 +4,7 @@
use Mockery;
use Exception;
+use Illuminate\Database\Eloquent\Model;
trait MocksApplicationServices
{
@@ -88,7 +89,14 @@ protected function withoutEvents()
$this->firedEvents[] = $called;
});
+ $mock->shouldReceive('until')->andReturnUsing(function ($called) {
+ $this->firedEvents[] = $called;
+
+ return true;
+ });
+
$this->app->instance('events', $mock);
+ Model::setEventDispatcher($mock);
return $this;
} | false |
Other | laravel | framework | 70e504da5ad395d87467826e528dc9edf3f36ef3.json | Fix engine issueing
Fix that a view (`welcomeblade.php`) would run the `BladeEngine` instead of the `PhpEngine`. | src/Illuminate/View/Factory.php | @@ -308,7 +308,7 @@ protected function getExtension($path)
$extensions = array_keys($this->extensions);
return Arr::first($extensions, function ($key, $value) use ($path) {
- return Str::endsWith($path, $value);
+ return Str::endsWith($path, '.'.$value);
});
}
| false |
Other | laravel | framework | c00e3dab384c42a8e9db793ec27b38212b1c8778.json | fix another bug | src/Illuminate/Database/Query/Builder.php | @@ -1659,7 +1659,7 @@ public function chunkById($count, callable $callback, $column = 'id')
$results = $this->pageAfterId($count, 0, $column)->get();
- while (! $results->isEmpty()) {
+ while (! empty($results)) {
if (call_user_func($callback, $results) === false) {
return false;
} | false |
Other | laravel | framework | 31fc2a3ccdc8564fa8f0589ad22a83ec199d17ca.json | fix formatting and comments | src/Illuminate/Database/Eloquent/Builder.php | @@ -355,31 +355,29 @@ public function chunk($count, callable $callback)
}
/**
- * Chunk the results of a query, when the ID to query by is known.
+ * Chunk the results of a query by comparing numeric IDs.
*
- * Because if we know the ID to key by, then we can get through each page much faster,
- * especially in larger sets of data.
- *
- * @param $count
- * @param callable $callback
- * @param $idField
+ * @param int $count
+ * @param callable $callback
+ * @param string $column
* @return bool
*/
- public function chunkById($count, callable $callback, $idField)
+ public function chunkById($count, callable $callback, $column = 'id')
{
$lastId = null;
- $results = $this->pageAfterId($count, $idField)->get();
+
+ $results = $this->pageAfterId($count, 0, $column)->get();
while (! $results->isEmpty()) {
if (call_user_func($callback, $results) === false) {
return false;
}
- if ($idField) {
- $lastId = last($results->all())->{$idField};
+ if ($column) {
+ $lastId = $results->last()->{$column};
}
- $results = $this->pageAfterId($count, $idField, $lastId)->get();
+ $results = $this->pageAfterId($count, $lastId, $column)->get();
}
return true; | true |
Other | laravel | framework | 31fc2a3ccdc8564fa8f0589ad22a83ec199d17ca.json | fix formatting and comments | src/Illuminate/Database/Query/Builder.php | @@ -1333,20 +1333,19 @@ public function forPage($page, $perPage = 15)
}
/**
- * Set the limit and query for the next set of results, given the
- * last scene ID in a set.
+ * Constrain the query to the next "page" of results after a given ID.
*
- * @param int $perPage
- * @param $idField
- * @param int $lastId
+ * @param int $perPage
+ * @param int $column
+ * @param string $column
* @return Builder|static
*/
- public function pageAfterId($perPage = 15, $idField = 'id', $lastId = 0)
+ public function pageAfterId($perPage = 15, $lastId = 0, $column = 'id')
{
- return $this->select($idField)
- ->where($idField, '>', $lastId)
- ->orderBy($idField, 'asc')
- ->take($perPage);
+ return $this->select($column)
+ ->where($column, '>', $lastId)
+ ->orderBy($column, 'asc')
+ ->take($perPage);
}
/**
@@ -1647,31 +1646,29 @@ public function chunk($count, callable $callback)
}
/**
- * Chunk the results of a query, when the ID to query by is known.
+ * Chunk the results of a query by comparing numeric IDs.
*
- * Because if we know the ID to key by, then we can get through each page much faster,
- * especially in larger sets of data.
- *
- * @param $count
- * @param callable $callback
- * @param $idField
+ * @param int $count
+ * @param callable $callback
+ * @param string $column
* @return bool
*/
- public function chunkById($count, callable $callback, $idField)
+ public function chunkById($count, callable $callback, $column = 'id')
{
$lastId = null;
- $results = $this->pageAfterId($count, $idField)->get();
+
+ $results = $this->pageAfterId($count, 0, $column)->get();
while (! $results->isEmpty()) {
if (call_user_func($callback, $results) === false) {
return false;
}
- if ($idField) {
- $lastId = last($results->all())->{$idField};
+ if ($column) {
+ $lastId = last($results->all())->{$column};
}
- $results = $this->pageAfterId($count, $idField, $lastId)->get();
+ $results = $this->pageAfterId($count, $lastId, $column)->get();
}
return true; | true |
Other | laravel | framework | 31fc2a3ccdc8564fa8f0589ad22a83ec199d17ca.json | fix formatting and comments | tests/Database/DatabaseEloquentBuilderTest.php | @@ -197,9 +197,9 @@ public function testChunkCanBeStoppedByReturningFalse()
public function testChunkPaginatesUsingWhereBetweenIds()
{
$builder = m::mock('Illuminate\Database\Eloquent\Builder[pageAfterId,get]', [$this->getMockQueryBuilder()]);
- $builder->shouldReceive('pageAfterId')->once()->with(2, 'someIdField')->andReturn($builder);
- $builder->shouldReceive('pageAfterId')->once()->with(2, 'someIdField', 2)->andReturn($builder);
- $builder->shouldReceive('pageAfterId')->once()->with(2, 'someIdField', 10)->andReturn($builder);
+ $builder->shouldReceive('pageAfterId')->once()->with(2, 0, 'someIdField')->andReturn($builder);
+ $builder->shouldReceive('pageAfterId')->once()->with(2, 2, 'someIdField')->andReturn($builder);
+ $builder->shouldReceive('pageAfterId')->once()->with(2, 10, 'someIdField')->andReturn($builder);
$builder->shouldReceive('get')->times(3)->andReturn(
new Collection([(object) ['someIdField' => 1], (object) ['someIdField' => 2]]), | true |
Other | laravel | framework | dfd1b507041818c3ffee53a9c9fe2670406482e6.json | Fix FormRequest tests. | tests/Foundation/FoundationFormRequestTest.php | @@ -3,27 +3,25 @@
use Mockery as m;
use Illuminate\Container\Container;
-class FoundationFormRequestTestCase extends PHPUnit_Framework_TestCase
+class FoundationFormRequestTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
- unset($_SERVER['__request.validated']);
}
public function testValidateFunctionRunsValidatorOnSpecifiedRules()
{
$request = FoundationTestFormRequestStub::create('/', 'GET', ['name' => 'abigail']);
- $request->setContainer(new Container);
+ $request->setContainer($container = new Container);
$factory = m::mock('Illuminate\Validation\Factory');
- $factory->shouldReceive('make')->once()->with(['name' => 'abigail'], ['name' => 'required'])->andReturn(
+ $factory->shouldReceive('make')->once()->with(['name' => 'abigail'], ['name' => 'required'], [], [])->andReturn(
$validator = m::mock('Illuminate\Validation\Validator')
);
- $validator->shouldReceive('fails')->once()->andReturn(false);
+ $container->instance('Illuminate\Contracts\Validation\Factory', $factory);
+ $validator->shouldReceive('passes')->once()->andReturn(true);
$request->validate($factory);
-
- $this->assertTrue($_SERVER['__request.validated']);
}
/**
@@ -33,14 +31,15 @@ public function testValidateFunctionThrowsHttpResponseExceptionIfValidationFails
{
$request = m::mock('FoundationTestFormRequestStub[response]');
$request->initialize(['name' => null]);
- $request->setContainer(new Container);
+ $request->setContainer($container = new Container);
$factory = m::mock('Illuminate\Validation\Factory');
- $factory->shouldReceive('make')->once()->with(['name' => null], ['name' => 'required'])->andReturn(
+ $factory->shouldReceive('make')->once()->with(['name' => null], ['name' => 'required'], [], [])->andReturn(
$validator = m::mock('Illuminate\Validation\Validator')
);
- $validator->shouldReceive('fails')->once()->andReturn(true);
- $validator->shouldReceive('errors')->once()->andReturn($messages = m::mock('StdClass'));
- $messages->shouldReceive('all')->once()->andReturn([]);
+ $container->instance('Illuminate\Contracts\Validation\Factory', $factory);
+ $validator->shouldReceive('passes')->once()->andReturn(false);
+ $validator->shouldReceive('getMessageBag')->once()->andReturn($messages = m::mock('Illuminate\Support\MessageBag'));
+ $messages->shouldReceive('toArray')->once()->andReturn(['name' => ['Name required']]);
$request->shouldReceive('response')->once()->andReturn(new Illuminate\Http\Response);
$request->validate($factory);
@@ -53,12 +52,13 @@ public function testValidateFunctionThrowsHttpResponseExceptionIfAuthorizationFa
{
$request = m::mock('FoundationTestFormRequestForbiddenStub[forbiddenResponse]');
$request->initialize(['name' => null]);
- $request->setContainer(new Container);
+ $request->setContainer($container = new Container);
$factory = m::mock('Illuminate\Validation\Factory');
- $factory->shouldReceive('make')->once()->with(['name' => null], ['name' => 'required'])->andReturn(
+ $factory->shouldReceive('make')->once()->with(['name' => null], ['name' => 'required'], [], [])->andReturn(
$validator = m::mock('Illuminate\Validation\Validator')
);
- $validator->shouldReceive('fails')->once()->andReturn(false);
+ $container->instance('Illuminate\Contracts\Validation\Factory', $factory);
+ $validator->shouldReceive('passes')->never();
$request->shouldReceive('forbiddenResponse')->once()->andReturn(new Illuminate\Http\Response);
$request->validate($factory);
@@ -72,28 +72,23 @@ public function testRedirectResponseIsProperlyCreatedWithGivenErrors()
$redirector->shouldReceive('getUrlGenerator')->andReturn($url = m::mock('StdClass'));
$url->shouldReceive('previous')->once()->andReturn('previous');
$response->shouldReceive('withInput')->andReturn($response);
- $response->shouldReceive('withErrors')->with(['errors'])->andReturn($response);
+ $response->shouldReceive('withErrors')->with(['errors'], 'default')->andReturn($response);
$request->response(['errors']);
}
}
class FoundationTestFormRequestStub extends Illuminate\Foundation\Http\FormRequest
{
- public function rules(StdClass $dep)
+ public function rules()
{
return ['name' => 'required'];
}
- public function authorize(StdClass $dep)
+ public function authorize()
{
return true;
}
-
- public function validated(StdClass $dep)
- {
- $_SERVER['__request.validated'] = true;
- }
}
class FoundationTestFormRequestForbiddenStub extends Illuminate\Foundation\Http\FormRequest | false |
Other | laravel | framework | f4dc2615ec22ab6cfdea14a73f0f047886db3393.json | escape function call | src/Illuminate/Encryption/Encrypter.php | @@ -64,7 +64,7 @@ public function encrypt($value)
{
$iv = Str::randomBytes($this->getIvSize());
- $value = openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);
+ $value = \openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);
if ($value === false) {
throw new EncryptException('Could not encrypt the data.');
@@ -98,7 +98,7 @@ public function decrypt($payload)
$iv = base64_decode($payload['iv']);
- $decrypted = openssl_decrypt($payload['value'], $this->cipher, $this->key, 0, $iv);
+ $decrypted = \openssl_decrypt($payload['value'], $this->cipher, $this->key, 0, $iv);
if ($decrypted === false) {
throw new DecryptException('Could not decrypt the data.'); | false |
Other | laravel | framework | 12a1823803ac007fbd650227c8236ba2915621c1.json | add method assertSessionMissing(), fixe #12859
add method assertSessionMissing() like assertViewMissing() | src/Illuminate/Foundation/Testing/Concerns/InteractsWithSession.php | @@ -109,6 +109,23 @@ public function assertSessionHasAll(array $bindings)
}
}
+ /**
+ * Assert that the session has not a given key.
+ *
+ * @param string|array $key
+ * @return void
+ */
+ public function assertSessionMissing($key)
+ {
+ if (is_array($key)) {
+ foreach( $key as $k )
+ $this->assertSessionMissing($k);
+ return ;
+ }
+
+ PHPUnit::assertFalse($this->app['session.store']->has($key), "Session has key: $key");
+ }
+
/**
* Assert that the session has errors bound.
* | false |
Other | laravel | framework | 2b951e43a042f1931d2253ed4749207366556cb6.json | fix suffix check | src/Illuminate/View/Factory.php | @@ -308,7 +308,7 @@ protected function getExtension($path)
$extensions = array_keys($this->extensions);
return Arr::first($extensions, function ($value) use ($path) {
- return Str::endsWith($path, $value);
+ return Str::endsWith($path, '.'.$value);
});
}
| false |
Other | laravel | framework | be8af6910def484ad8ee70d1b3025fc59223f2e3.json | Update docblock typo
There was a letter 'n' missing on line 121 | src/Illuminate/Foundation/Http/FormRequest.php | @@ -118,7 +118,7 @@ protected function passesAuthorization()
*
* @return mixed
*
- * @throws \\Illuminate\Http\Exception\HttpResponseExceptio
+ * @throws \\Illuminate\Http\Exception\HttpResponseException
*/
protected function failedAuthorization()
{ | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.