Skip to content

Commit

Permalink
Prevent make:migration from creating duplicate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
richards-square committed Jul 22, 2016
1 parent ceccdf7 commit 49002cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Illuminate/Database/Migrations/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ public function __construct(Filesystem $files)
* @param string $table
* @param bool $create
* @return string
* @throws \Exception
*/
public function create($name, $path, $table = null, $create = false)
{
// Prevent creating a duplicate class name.
$className = $this->getClassName($name);
if (class_exists($className)) {
throw new \Exception("$className already exists");
}

$path = $this->getPath($name, $path);

// First we will get the stub file for the migration, which serves as a type
Expand Down
15 changes: 15 additions & 0 deletions tests/Database/DatabaseMigrationCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ public function testTableCreationMigrationStoresMigrationFile()
$creator->create('create_bar', 'foo', 'baz', true);
}

public function testTableUpdateMigrationWontCreateDuplicateClass()
{
$creator = $this->getCreator();
eval("class UpdateBar{}");

try {
$creator->create('update_bar', 'foo');
} catch(\Exception $e) {
$this->assertEquals($e->getMessage(), "UpdateBar already exists");
return;
}

$this->fail();
}

protected function getCreator()
{
$files = m::mock('Illuminate\Filesystem\Filesystem');
Expand Down

0 comments on commit 49002cf

Please sign in to comment.