Skip to content

Commit

Permalink
Add tests for ordered seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Šarūnas Norkus committed Nov 26, 2017
1 parent b7b9ac9 commit bc9fe48
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Phinx/Migration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public function setSeeds(array $seeds)
/**
* Get seed dependencies instances from seed dependency array
*
* @param OrderedSeedInterface $seed
* @param OrderedSeedInterface $seed Seed
*
* @return AbstractSeed[]
*/
Expand All @@ -791,13 +791,14 @@ protected function getSeedDependenciesInstances(OrderedSeedInterface $seed)
}
}
}

return $dependenciesInstances;
}

/**
* Order seeds by dependencies
*
* @param AbstractSeed[] $seeds
* @param AbstractSeed[] $seeds Seeds
*
* @return AbstractSeed[]
*/
Expand All @@ -816,6 +817,7 @@ protected function orderSeedsByDependencies(array $seeds)
$orderedSeeds[$key] = $seed;
}
}

return $orderedSeeds;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Phinx/Migration/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5406,6 +5406,14 @@ public function testExecuteANonExistentSeedWorksAsExpectedWithMixedNamespace()
$this->assertContains('Foo\Bar\UserSeeder', $output);
}

public function testOrderSeeds()
{
$seeds = array_values($this->manager->getSeeds());
$this->assertInstanceOf('UserSeeder', $seeds[0]);
$this->assertInstanceOf('GSeeder', $seeds[1]);
$this->assertInstanceOf('PostSeeder', $seeds[2]);
}

public function testGettingInputObject()
{
$migrations = $this->manager->getMigrations();
Expand Down
11 changes: 10 additions & 1 deletion tests/Phinx/Migration/_files/seeds/PostSeeder.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use Phinx\Seed\AbstractSeed;
use Phinx\Seed\OrderedSeedInterface;

class PostSeeder extends AbstractSeed
class PostSeeder extends AbstractSeed implements OrderedSeedInterface
{
public function run()
{
Expand All @@ -21,4 +22,12 @@ public function run()
$posts->insert($data)
->save();
}

public function getDependencies()
{
return [
'UserSeeder',
'GSeeder',
];
}
}

0 comments on commit bc9fe48

Please sign in to comment.