Skip to content

Commit

Permalink
Merge branch '5.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Apr 7, 2020
2 parents 27607ed + 4607429 commit 3149291
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 86 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Expand Up @@ -7,7 +7,6 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/CHANGELOG-*.md export-ignore
/phpunit.xml export-ignore
Expand Down
29 changes: 0 additions & 29 deletions .scrutinizer.yml

This file was deleted.

20 changes: 20 additions & 0 deletions CHANGELOG-5.x.md
Expand Up @@ -2,6 +2,26 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/tenanti`.

## 5.0.2

Released: 2020-04-06

### Fixes

* Fixes variable used when merging `$migrator` for command output.

## 5.0.1

Released: 2020-04-03

### Changes

* Throw exception when trying to make migration file without `--table` option on shared database configuration.

### Fixes

* Fixes migration stub files.

## 5.0.0

Released: 2020-04-03
Expand Down
2 changes: 1 addition & 1 deletion src/Console/MigrateMakeCommand.php
Expand Up @@ -81,7 +81,7 @@ protected function getOptions()
{
return [
['create', false, InputOption::VALUE_OPTIONAL, 'The table to be created.'],
['table', null, InputOption::VALUE_OPTIONAL, 'The table to migrate.'],
['table', null, InputOption::VALUE_REQUIRED, 'The table to migrate.'],
];
}
}
5 changes: 5 additions & 0 deletions src/Migrator/MigrationWriter.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Migrations\MigrationCreator;
use Illuminate\Filesystem\Filesystem;
use InvalidArgumentException;
use Orchestra\Support\Str;
use Orchestra\Tenanti\TenantiManager;

Expand Down Expand Up @@ -42,6 +43,10 @@ public function __invoke(
}

if ($this->tenant->config("{$driver}.shared", true) === true) {
if (empty($table)) {
throw new InvalidArgumentException('Require table name for shared database migration!');
}

$table = Str::replace($migrator->tablePrefix()."_{$table}", ['id' => '{$id}']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Migrator/Migrator.php
Expand Up @@ -105,7 +105,7 @@ public function resolve($file)
public function outputUsing(?Notice $notice)
{
if ($notice instanceof Notice) {
$notice->mergeWith($migrator);
$notice->mergeWith($this);
}

return $this;
Expand Down
Expand Up @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;

class DummyClass extends Migration
class {{ class }} extends Migration
{
/**
* Run the migrations.
Expand All @@ -17,8 +17,8 @@ class DummyClass extends Migration
*/
public function up($id, Model $model)
{
Schema::create("DummyTable", function (Blueprint $table) {
$table->increments('id');
Schema::create("{{ table }}", function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
Expand All @@ -33,6 +33,6 @@ class DummyClass extends Migration
*/
public function down($id, Model $model)
{
Schema::drop("DummyTable");
Schema::drop("{{ table }}");
}
}
Expand Up @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;

class DummyClass extends Migration
class {{ class }} extends Migration
{
/**
* Run the migrations.
Expand Down
Expand Up @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;

class DummyClass extends Migration
class {{ class }} extends Migration
{
/**
* Run the migrations.
Expand All @@ -17,7 +17,7 @@ class DummyClass extends Migration
*/
public function up($id, Model $model)
{
Schema::table("DummyTable", function (Blueprint $table) {
Schema::table("{{ table }}", function (Blueprint $table) {

});
}
Expand All @@ -32,7 +32,7 @@ class DummyClass extends Migration
*/
public function down($id, Model $model)
{
Schema::table("DummyTable", function (Blueprint $table) {
Schema::table("{{ table }}", function (Blueprint $table) {

});
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/Console/MigrateMakeCommandTest.php
Expand Up @@ -43,11 +43,11 @@ public function testMakeWithOneDriverWithOneArgument()
->with('tenant')
->andReturn($factory);

$writer->shouldReceive('__invoke')->with('tenant', 'add_migration', null, null)->once()
$writer->shouldReceive('__invoke')->with('tenant', 'create_users_table', 'users', false)->once()
->andReturn('2014_10_12_000000_create_users_table.php');

$this->app['artisan']->add(new MigrateMakeCommand());
$this->artisan('tenanti:make', ['driver' => 'tenant', 'name' => 'add_migration']);
$this->artisan('tenanti:make', ['driver' => 'tenant', 'name' => 'create_users_table', '--table' => 'users']);
}

public function testTinkerWithOneDriverWithTwoArguments()
Expand All @@ -63,11 +63,11 @@ public function testTinkerWithOneDriverWithTwoArguments()
'tenant1' => [],
]);

$writer->shouldReceive('__invoke')->with('tenant1', 'add_migration', null, null)->once()
->andReturn('2014_10_12_000000_create_users_table.php');
$writer->shouldReceive('__invoke')->with('tenant1', 'update_users_table', 'users', false)->once()
->andReturn('2014_10_12_000000_update_users_table.php');

$this->app['artisan']->add(new MigrateMakeCommand());
$this->artisan('tenanti:make', ['driver' => 'tenant1', 'name' => 'add_migration']);
$this->artisan('tenanti:make', ['driver' => 'tenant1', 'name' => 'update_users_table', '--table' => 'users']);
}

public function testTinkerWithTwoDriversWithOneArgument()
Expand Down Expand Up @@ -112,10 +112,10 @@ public function testTinkerWithTwoDriversWithTwoArguments()
]);


$writer->shouldReceive('__invoke')->with('tenant2', 'add_migration', null, null)->once()
$writer->shouldReceive('__invoke')->with('tenant2', 'create_users_table', 'users', true)->once()
->andReturn('2014_10_12_000000_create_users_table.php');

$this->app['artisan']->add(new MigrateMakeCommand());
$this->artisan('tenanti:make', ['driver' => 'tenant2', 'name' => 'add_migration']);
$this->artisan('tenanti:make', ['driver' => 'tenant2', 'name' => 'create_users_table', '--create' => 'users']);
}
}
64 changes: 25 additions & 39 deletions tests/Unit/Migrator/MigratorTest.php
Expand Up @@ -6,6 +6,7 @@
use Mockery as m;
use Orchestra\Tenanti\Migrator\Migrator;
use PHPUnit\Framework\TestCase;
use Orchestra\Tenanti\Notice\Command as NoticeCommand;

class MigratorTest extends TestCase
{
Expand All @@ -17,13 +18,8 @@ protected function tearDown(): void
m::close();
}

/**
* Test Orchestra\Tenanti\Migrator\Migrator::setEntity()
* method.
*
* @test
*/
public function testSetEntityMethod()
/** @test */
public function it_can_set_entity_method()
{
$repository = m::mock('Illuminate\Database\Migrations\MigrationRepositoryInterface');
$resolver = m::mock('Illuminate\Database\ConnectionResolver');
Expand All @@ -36,12 +32,22 @@ public function testSetEntityMethod()
}

/**
* Test Orchestra\Tenanti\Migrator\Migrator::runUp()
* method.
*
* @test
*/
public function testRunUpMethod()
public function it_can_set_notice_resolver_to_migrator()
{
$output = m::mock('Symfony\Component\Console\Output\OutputInterface');
$notice = new NoticeCommand($output);

$migrator = m::mock(Migrator::class);
$migrator->shouldReceive('setOutput')->once()->with($output)->andReturnSelf();

$notice->mergeWith($migrator);
$this->addToAssertionCount(1);
}

/** @test */
public function it_can_run_up_migration()
{
$repository = m::mock('Illuminate\Database\Migrations\MigrationRepositoryInterface');
$resolver = m::mock('Illuminate\Database\ConnectionResolver');
Expand Down Expand Up @@ -71,13 +77,8 @@ public function testRunUpMethod()
$this->assertNull($stub->runUp($file, $batch, $pretend));
}

/**
* Test Orchestra\Tenanti\Migrator\Migrator::runUp()
* method when pretending.
*
* @test
*/
public function testRunUpMethodWhenPretending()
/** @test */
public function it_can_run_up_migration_while_pretending()
{
$repository = m::mock('Illuminate\Database\Migrations\MigrationRepositoryInterface');
$resolver = m::mock('Illuminate\Database\ConnectionResolver');
Expand All @@ -103,13 +104,8 @@ public function testRunUpMethodWhenPretending()
$this->assertNull($stub->runUp($file, $batch, $pretend));
}

/**
* Test Orchestra\Tenanti\Migrator\Migrator::runDown()
* method.
*
* @test
*/
public function testRunDownMethod()
/** @test */
public function it_can_run_down_migration()
{
$repository = m::mock('Illuminate\Database\Migrations\MigrationRepositoryInterface');
$resolver = m::mock('Illuminate\Database\ConnectionResolver');
Expand Down Expand Up @@ -139,13 +135,8 @@ public function testRunDownMethod()
$this->assertNull($stub->runDown($file, $migration, $pretend));
}

/**
* Test Orchestra\Tenanti\Migrator\Migrator::runDown()
* method when pretending.
*
* @test
*/
public function testRunDownMethodWhenPretending()
/** @test */
public function it_can_run_down_migration_while_pretending()
{
$repository = m::mock('Illuminate\Database\Migrations\MigrationRepositoryInterface');
$resolver = m::mock('Illuminate\Database\ConnectionResolver');
Expand All @@ -171,13 +162,8 @@ public function testRunDownMethodWhenPretending()
$this->assertNull($stub->runDown($file, $migration, $pretend));
}

/**
* Test Orchestra\Tenanti\Migrator\Migrator::getQueries()
* method when pretending.
*
* @test
*/
public function testGetQueriesMethodWhenPretending()
/** @test */
public function it_can_get_queries_while_pretending()
{
$repository = m::mock('Illuminate\Database\Migrations\MigrationRepositoryInterface');
$resolver = m::mock('Illuminate\Database\ConnectionResolver');
Expand Down

0 comments on commit 3149291

Please sign in to comment.