Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Prevent make:migration from creating duplicate classes #14432

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Illuminate/Database/Migrations/MigrationCreator.php
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/Database/DatabaseMigrationCreatorTest.php
Original file line number Diff line number Diff line change
@@ -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');