Skip to content

Commit

Permalink
feat: implement Aurora MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Mar 23, 2024
1 parent f83b854 commit 601cb68
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
24 changes: 17 additions & 7 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class Search
*/
public static $loaded = false;

public const ANY = -1;
public const MYSQL = 1;
public const MARIADB = 2;
public const DS = DIRECTORY_SEPARATOR;
public const ANY = -1;
public const MYSQL = 1;
public const MARIADB = 2;
public const AURORA_MYSQL = 3;
public const DS = DIRECTORY_SEPARATOR;

/**
* The directory where the data is located
Expand Down Expand Up @@ -90,15 +91,24 @@ public static function getByName(string $name, int $type = Search::ANY): string
$kbEntries = self::getVariable($name);
if (isset($kbEntries->a)) {
foreach ($kbEntries->a as $kbEntry) {
$urlEnd = isset($kbEntry->a) ? '#' . $kbEntry->a : '';

if ($type === Search::ANY) {
return Search::$data->urls[$kbEntry->u] . '#' . $kbEntry->a;
return Search::$data->urls[$kbEntry->u] . $urlEnd;
} elseif ($type === Search::MYSQL) {
if ($kbEntry->t === Search::MYSQL) {
return Search::$data->urls[$kbEntry->u] . '#' . $kbEntry->a;
return Search::$data->urls[$kbEntry->u] . $urlEnd;
}
if ($kbEntry->t === Search::AURORA_MYSQL) {
return Search::$data->urls[$kbEntry->u] . $urlEnd;
}
} elseif ($type === Search::MARIADB) {
if ($kbEntry->t === Search::MARIADB) {
return Search::$data->urls[$kbEntry->u] . '#' . $kbEntry->a;
return Search::$data->urls[$kbEntry->u] . $urlEnd;
}
} elseif ($type === Search::AURORA_MYSQL) {
if ($kbEntry->t === Search::AURORA_MYSQL) {
return Search::$data->urls[$kbEntry->u] . $urlEnd;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/SlimData.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ public function jsonSerialize(): array
if ($entry->a === null) {
unset($entry->a);
}
if (preg_match('!^(https|http)://mariadb.com!', $kbd->getUrl())) {
if (preg_match('!^https://mariadb.com!', $kbd->getUrl())) {
$entry->t = $this->types['MARIADB'];
} elseif (preg_match('!^(https|http)://dev.mysql.com!', $kbd->getUrl())) {
} elseif (preg_match('!^https://dev.mysql.com!', $kbd->getUrl())) {
$entry->t = $this->types['MYSQL'];
} elseif (preg_match('!^https://docs.aws.amazon.com!', $kbd->getUrl())) {
$entry->t = $this->types['AURORA-MYSQL'];
}
if (isset($entry->t)) {// If has no valid type, skip.
//Do not allow other urls.
Expand Down
23 changes: 22 additions & 1 deletion test/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public static function setUpBeforeClass(): void
$variable4 = $sd->addVariable('variable-4', null, false);
$variable4->addDocumentation('https://mariadb.com/testurl/for/variable/4', 'myanchor');
$variable4->addDocumentation('https://dev.mysql.com/testurl_for-variable/4', 'my_anchor');
$variable5 = $sd->addVariable('variable-5', null, false);
$variable5->addDocumentation('https://docs.aws.amazon.com/testurl/for/variable/5#myanchor', null);

Search::loadTestData($sd);
}

Expand All @@ -51,6 +54,24 @@ public function testGetByNameMYSQL(): void
$this->assertEquals('https://dev.mysql.com/testurl_for-variable/4#my_anchor', $found);
}

/**
* test get by name for Aurora MySQL
*/
public function testGetByNameMYSQLAurora(): void
{
$found = Search::getByName('variable-5', Search::AURORA_MYSQL);
$this->assertEquals('https://docs.aws.amazon.com/testurl/for/variable/5#myanchor', $found);
}

/**
* test get by name for Aurora MySQL but the engine is MYSQL
*/
public function testGetByNameMYSQLAuroraEngineMySQL(): void
{
$found = Search::getByName('variable-5', Search::MYSQL);
$this->assertEquals('https://docs.aws.amazon.com/testurl/for/variable/5#myanchor', $found);
}

/**
* test get by name for MARIADB
*
Expand Down Expand Up @@ -151,7 +172,7 @@ public function testGetVariablesWithDynamic(): void
$static = Search::getVariablesWithDynamic(false);
$this->assertEquals($static, Search::getStaticVariables());
$this->assertEquals(2, count($dynamic));
$this->assertEquals(1, count($static));
$this->assertEquals(2, count($static));
$common = \array_intersect($dynamic, $static);
$this->assertEquals(0, count($common));// Impossible to be dynamic and not
}
Expand Down
2 changes: 1 addition & 1 deletion test/SlimDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testCreateInstance(): SlimData
*/
public function testToJsonEmpty(SlimData $slimData): void
{
$this->assertEquals('{"version":1}', json_encode($slimData));
$this->assertEquals('{"version":2}', json_encode($slimData));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions test/data/ultraSlimDataTestWithVariables.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
]
}
},
"version": 1,
"version": 2,
"types": {
"1": "MYSQL",
"2": "MARIADB"
"2": "MARIADB",
"3": "AURORA-MYSQL"
},
"varTypes": {
"1": "string",
Expand Down

0 comments on commit 601cb68

Please sign in to comment.