-
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
10 changed files
with
84 additions
and
171 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 |
---|---|---|
@@ -1,18 +1,30 @@ | ||
<?php | ||
use Ilias\Maestro\Database\Delete; | ||
|
||
require_once("./vendor/autoload.php"); | ||
|
||
use Ilias\Maestro\Core\Maestro; | ||
use Ilias\Maestro\Core\Manager; | ||
use Ilias\Maestro\Database\Insert; | ||
use Ilias\Maestro\Database\PDOConnection; | ||
use Ilias\Maestro\Database\Select; | ||
use Ilias\Maestro\Types\Timestamp; | ||
use Ilias\Maestro\Utils\Utils; | ||
use Maestro\Example\MaestroDb; | ||
use Maestro\Example\User; | ||
|
||
require_once("./vendor/autoload.php"); | ||
|
||
// $coreDatabase = new Manager(); | ||
// $agrofastDB = new MaestroDb(); | ||
$coreDatabase = new Manager(); | ||
$agrofastDB = new MaestroDb(); | ||
// new User("nickname", "email", "password", true, new Timestamp()); | ||
|
||
// print implode("\n", $coreDatabase->createDatabase($agrofastDB, false)) . "\n"; | ||
// print implode("\n", $coreDatabase->createDatabase($agrofastDB, true)) . "\n"; | ||
|
||
$insert = new Insert(Maestro::SQL_NO_PREDICT, PDOConnection::getInstance()); | ||
$user = new User("nickname'-- drop table", 'John', 'Doe', 'email@example.com', 'password', true, new Timestamp()); | ||
$result = $insert->into($user)->values($user)->returning(['id'])->execute(); | ||
var_dump($result); | ||
|
||
var_dump([new stdClass() => "test"]); | ||
$delete = new Delete(Maestro::SQL_NO_PREDICT, PDOConnection::getInstance()); | ||
$delete->from($user)->where(['id' => $result[0]['id']])->execute(); | ||
|
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
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 |
---|---|---|
@@ -1,91 +0,0 @@ | ||
<?php | ||
|
||
namespace Maestro\Tests\Integration; | ||
|
||
use Ilias\Maestro\Database\Select; | ||
use Ilias\Maestro\Core\Maestro; | ||
use Ilias\Maestro\Core\Manager; | ||
use Ilias\Maestro\Database\Delete; | ||
use Ilias\Maestro\Database\Insert; | ||
use Ilias\Maestro\Database\PDOConnection; | ||
use Ilias\Maestro\Database\Update; | ||
use Maestro\Example\Hr; | ||
use Maestro\Example\User; | ||
use PHPUnit\Framework\TestCase; | ||
use PDO; | ||
|
||
class IntegrationTest extends TestCase | ||
{ | ||
private PDO $pdo; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->pdo = PDOConnection::getInstance(); | ||
} | ||
|
||
public function testCreateSchema() | ||
{ | ||
$coreDatabase = new Manager(); | ||
$coreDatabase->executeQuery($this->pdo, | ||
$coreDatabase->createSchema(Hr::class) | ||
); | ||
} | ||
|
||
public function testCreateTable() | ||
{ | ||
$coreDatabase = new Manager(); | ||
$coreDatabase->executeQuery($this->pdo, | ||
$coreDatabase->createTable(User::class) | ||
); | ||
} | ||
|
||
public function testSelectIntegration() | ||
{ | ||
$select = new Select(Maestro::SQL_NO_PREDICT, $this->pdo); | ||
$select->from([User::class], ['id', 'email'])->where(['email' => 'email@example.com']); | ||
|
||
$stmt = $this->pdo->prepare($select->getSql()); | ||
$stmt->execute($select->getParameters()); | ||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
|
||
$this->assertNotEmpty($result); | ||
$this->assertEquals('email@example.com', $result[0]['email']); | ||
} | ||
|
||
public function testInsertIntegration() | ||
{ | ||
$insert = new Insert(Maestro::SQL_NO_PREDICT, $this->pdo); | ||
$data = ['nickname' => 'nickname', 'email' => 'email@example.com', 'password' => 'password']; | ||
$insert->into(User::class)->values($data); | ||
|
||
$stmt = $this->pdo->prepare($insert->getSql()); | ||
$stmt->execute($insert->getParameters()); | ||
|
||
$this->assertEquals(1, $stmt->rowCount()); | ||
} | ||
|
||
public function testUpdateIntegration() | ||
{ | ||
$update = new Update(Maestro::SQL_NO_PREDICT, $this->pdo); | ||
$data = ['nickname' => 'updated_nickname']; | ||
$conditions = ['email' => 'email@example.com']; | ||
$update->table(User::class)->set('nickname', 'updated_nickname')->where($conditions); | ||
|
||
$stmt = $this->pdo->prepare($update->getSql()); | ||
$stmt->execute($update->getParameters()); | ||
|
||
$this->assertEquals(1, $stmt->rowCount()); | ||
} | ||
|
||
public function testDeleteIntegration() | ||
{ | ||
$delete = new Delete(Maestro::SQL_NO_PREDICT, $this->pdo); | ||
$conditions = ['email' => 'email@example.com']; | ||
$delete->from(User::class)->where($conditions); | ||
|
||
$stmt = $this->pdo->prepare($delete->getSql()); | ||
$stmt->execute($delete->getParameters()); | ||
|
||
$this->assertEquals(1, $stmt->rowCount()); | ||
} | ||
} | ||
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
Oops, something went wrong.