-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from lemberg/feature/203-allow-mysql-all-hosts
Allow connecting to the MySQL instance from any host
- Loading branch information
Showing
6 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lemberg\Draft\Environment\Config\Update\Step; | ||
|
||
use Lemberg\Draft\Environment\Config\Update\UpdateStepInterface; | ||
|
||
/** | ||
* Allows connecting to the MySQL instance from any host. | ||
*/ | ||
final class AllowAllHostsMysql extends AbstractUpdateStep implements UpdateStepInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getWeight(): int { | ||
return 6; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function update(array &$config): void { | ||
if (array_key_exists('mysql_users', $config)) { | ||
foreach ($config['mysql_users'] as &$value) { | ||
$value['host'] = $value['host'] ?? '%'; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
tests/Unit/Config/Update/Step/AllowAllHostsMysqlTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lemberg\Tests\Unit\Draft\Environment\Config\Update\Step; | ||
|
||
use Composer\Composer; | ||
use Composer\Config as ComposerConfig; | ||
use Composer\IO\IOInterface; | ||
use Lemberg\Draft\Environment\Config\Config; | ||
use Lemberg\Draft\Environment\Config\Manager\UpdateManager; | ||
use Lemberg\Draft\Environment\Config\Update\Step\AllowAllHostsMysql; | ||
use Lemberg\Draft\Environment\Utility\Filesystem; | ||
use org\bovigo\vfs\vfsStream; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Tests adding id to the synced folders configuration. | ||
* | ||
* @covers \Lemberg\Draft\Environment\Config\Update\Step\AbstractUpdateStep | ||
* @covers \Lemberg\Draft\Environment\Config\Update\Step\AllowAllHostsMysql | ||
*/ | ||
final class AllowAllHostsMysqlTest extends TestCase { | ||
|
||
/** | ||
* @var \Composer\Composer | ||
*/ | ||
private $composer; | ||
|
||
/** | ||
* @var \Composer\IO\IOInterface | ||
*/ | ||
private $io; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $root; | ||
|
||
/** | ||
* @var \Lemberg\Draft\Environment\Config\Manager\UpdateManagerInterface | ||
*/ | ||
private $configUpdateManager; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp(): void { | ||
$this->composer = new Composer(); | ||
$this->composer->setConfig(new ComposerConfig()); | ||
$this->io = $this->createMock(IOInterface::class); | ||
|
||
// Mock source and target configuration directories. | ||
$this->root = vfsStream::setup()->url(); | ||
$fs = new Filesystem(); | ||
$fs->mkdir(["$this->root/source", "$this->root/target"]); | ||
|
||
$configObject = new Config("$this->root/source", "$this->root/target"); | ||
$this->configUpdateManager = new UpdateManager($this->composer, $this->io, $configObject); | ||
} | ||
|
||
/** | ||
* Tests step weight getter. | ||
*/ | ||
final public function testGetWeight(): void { | ||
$step = new AllowAllHostsMysql($this->composer, $this->io, $this->configUpdateManager); | ||
self::assertSame(6, $step->getWeight()); | ||
} | ||
|
||
/** | ||
* Tests update step execution. | ||
* | ||
* @param array<string,mixed> $config | ||
* @param array<string,mixed> $expectedConfig | ||
* | ||
* @dataProvider updateDataProvider | ||
*/ | ||
final public function testUpdate(array $config, array $expectedConfig): void { | ||
$step = new AllowAllHostsMysql($this->composer, $this->io, $this->configUpdateManager); | ||
|
||
$step->update($config); | ||
self::assertSame($config, $expectedConfig); | ||
} | ||
|
||
/** | ||
* Data provider for the ::testUpdate(). | ||
* | ||
* @return array<int,array<int,string|array<string,mixed>>> | ||
*/ | ||
final public function updateDataProvider(): array { | ||
return [ | ||
[ | ||
[ | ||
'mysql_users' => [ | ||
[ | ||
'name' => 'drupal', | ||
'password' => 'drupal', | ||
'priv' => 'drupal.*:ALL', | ||
], | ||
[ | ||
'name' => 'drupal2', | ||
'password' => 'drupal2', | ||
'priv' => 'drupal.*:ALL', | ||
], | ||
[ | ||
'name' => 'drupal3', | ||
'password' => 'drupal3', | ||
'priv' => 'drupal.*:ALL', | ||
'host' => 'localhost', | ||
], | ||
], | ||
], | ||
[ | ||
'mysql_users' => [ | ||
[ | ||
'name' => 'drupal', | ||
'password' => 'drupal', | ||
'priv' => 'drupal.*:ALL', | ||
'host' => '%', | ||
], | ||
[ | ||
'name' => 'drupal2', | ||
'password' => 'drupal2', | ||
'priv' => 'drupal.*:ALL', | ||
'host' => '%', | ||
], | ||
[ | ||
'name' => 'drupal3', | ||
'password' => 'drupal3', | ||
'priv' => 'drupal.*:ALL', | ||
'host' => 'localhost', | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
} |