Skip to content

Commit

Permalink
Fix test and phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 27, 2024
1 parent fa26f5a commit 8e5faa4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Migration/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function executeMigration(MigrationInterface $migration, string $directio
/**
* Executes the specified seeder on this environment.
*
* @param \Migrations\Seed\SeedInterface $seed Seed
* @param \Migrations\SeedInterface $seed Seed
* @return void
*/
public function executeSeed(SeedInterface $seed): void
Expand Down
7 changes: 4 additions & 3 deletions src/Migration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public function executeMigration(MigrationInterface $migration, string $directio
/**
* Execute a seeder against the specified environment.
*
* @param \Migrations\Seed\SeedInterface $seed Seed
* @param \Migrations\SeedInterface $seed Seed
* @return void
*/
public function executeSeed(SeedInterface $seed): void
Expand Down Expand Up @@ -522,7 +522,7 @@ protected function printMigrationStatus(MigrationInterface $migration, string $s
/**
* Print Seed Status
*
* @param \Migrations\Seed\SeedInterface $seed Seed
* @param \Migrations\SeedInterface $seed Seed
* @param string $status Status of the seed
* @param string|null $duration Duration the seed took the be executed
* @return void
Expand Down Expand Up @@ -992,7 +992,7 @@ public function getSeeds(): array
}

// instantiate it
/** @var \Phinx\Seed\AbstractSeed $seed */
/** @var \Phinx\Seed\AbstractSeed|\Migrations\SeedInterface $seed */
if (isset($this->container)) {
$seed = $this->container->get($class);
} else {
Expand All @@ -1003,6 +1003,7 @@ public function getSeeds(): array
if ($seed instanceof PhinxSeedInterface) {
$seed = new SeedAdapter($seed);
}
/** @var \Migrations\SeedInterface $seed */
$seed->setIo($io);
$seed->setConfig($config);

Expand Down
2 changes: 0 additions & 2 deletions src/SeedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Migrations\Config\ConfigInterface;
use Migrations\Db\Adapter\AdapterInterface;
use Migrations\Db\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Seed interface
Expand Down
4 changes: 4 additions & 0 deletions src/Shim/SeedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public function setAdapter(AdapterInterface $adapter)
*/
public function getAdapter(): AdapterInterface
{
if (!$this->adapter) {
throw new RuntimeException('Cannot call getAdapter() until after setAdapter().');
}

return $this->adapter;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Migration/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Migrations\Db\Adapter\AdapterWrapper;
use Migrations\Db\Adapter\PdoAdapter;
use Migrations\Migration\Environment;
use Migrations\Shim\SeedAdapter;
use Phinx\Migration\AbstractMigration;
use Phinx\Migration\MigrationInterface;
use Phinx\Seed\AbstractSeed;
Expand Down Expand Up @@ -314,7 +315,6 @@ public function testExecuteSeedInit()

$this->environment->setAdapter($adapterStub);

// up
$seed = new class ('mockenv', 20110301080000) extends AbstractSeed {
public bool $initExecuted = false;
public bool $runExecuted = false;
Expand All @@ -330,7 +330,9 @@ public function run(): void
}
};

$this->environment->executeSeed($seed);
$seedWrapper = new SeedAdapter($seed);
$this->environment->executeSeed($seedWrapper);

$this->assertTrue($seed->initExecuted);
$this->assertTrue($seed->runExecuted);
}
Expand Down

0 comments on commit 8e5faa4

Please sign in to comment.