-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":1,"defects":{"CreateTest::testTable":5},"times":{"CreateTest::testTable":0.041,"DeleteTest::testAll":0.049,"DeleteTest::testWhere":0.07,"DeleteTest::testLike":0.052,"InsertTest::testInsert":0.048,"MySqlTest::testConstructor with data set #0":0.015,"MySqlTest::testConstructor with data set #1":0.002,"MySqlTest::testQueryAndFetch":0.005,"SelectTest::testAll":0.007,"SelectTest::testWhere":0.003,"SelectTest::testLike":0.003}} |
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
<?php | ||
|
||
namespace DinoDev\MySql\Classes; | ||
|
||
class Create extends MySql | ||
{ | ||
protected MySql $MySql; | ||
|
||
public function __construct(MySql $_MySql) | ||
{ | ||
$this->MySql = $_MySql; | ||
} | ||
|
||
public function Table(string $tableName, array $valuesName, array $valuesType) | ||
{ | ||
$sql = $this->generateSql($tableName, $valuesName, $valuesType); | ||
|
||
return $this->MySql->query($sql); | ||
} | ||
|
||
protected function generateSql(string $tableName, array $valuesName, array $valuesType) | ||
{ | ||
$valuesName = $this->removeSpaces($valuesName); | ||
|
||
$sql = "CREATE TABLE "; | ||
$sql .= $tableName . " ( "; | ||
foreach ($valuesName as $key => $value) { | ||
$sql .= $value . " " . $valuesType[$key] . " "; | ||
|
||
$sql .= $key === array_key_last($valuesName) ? ");" : ", "; | ||
} | ||
|
||
return $sql; | ||
} | ||
|
||
protected function removeSpaces($valueToCheck) | ||
{ | ||
return str_replace(" ", "", $valueToCheck); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use DinoDev\MySql\Classes\MySql; | ||
use DinoDev\MySql\Classes\Create; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
class CreateTest extends TestCase | ||
{ | ||
public MySql $MySql; | ||
public Create $Create; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->MySql = new MySql("localhost", "root", "MySql", "world", $state); | ||
$this->Create = new Create($this->MySql); | ||
} | ||
|
||
public function testTable() | ||
{ | ||
//Drop table, case exists | ||
$this->dropTestTable(); | ||
|
||
$this->assertTrue($this->Create->Table("Test", ["Value 1", "Value 2"], ["varchar(20)", "varchar(20)"])); | ||
|
||
$this->assertFalse($this->Create->Table("Test", ["Value 1", "Value 2"], ["varchar(20)", "varchar(20)"])); | ||
} | ||
|
||
public function dropTestTable() | ||
{ | ||
$this->MySql->query("DROP TABLE Test"); | ||
} | ||
} |
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