RunTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use YdbPlatform\Ydb\Ydb;
  5. use YdbPlatform\Ydb\YdbTable;
  6. class RunTest extends TestCase{
  7. public function testAnonymousConnection(){
  8. $config = [
  9. // Database path
  10. 'database' => '/local',
  11. // Database endpoint
  12. 'endpoint' => 'localhost:2136',
  13. // Auto discovery (dedicated server only)
  14. 'discovery' => false,
  15. // IAM config
  16. 'iam_config' => [
  17. 'anonymous' => true,
  18. 'insecure' => true,
  19. ],
  20. ];
  21. self::assertEquals(
  22. [1, 6, 1, 2, "TBD"],
  23. $this->getYdbResult($config)
  24. );
  25. }
  26. private function getYdbResult(array $config) : array
  27. {
  28. $ydb = new Ydb($config);
  29. $table = $ydb->table();
  30. $session = $table->createSession();
  31. $session->createTable(
  32. 'episodes',
  33. YdbTable::make()
  34. ->addColumn('series_id', 'UINT64')
  35. ->addColumn('title', 'UTF8')
  36. ->addColumn('episode_id', 'UINT64')
  37. ->addColumn('season_id', 'UINT64')
  38. ->primaryKey('series_id')
  39. );
  40. $session->transaction(function($session) {
  41. return $session->query('
  42. UPSERT INTO `episodes` (series_id, season_id, episode_id, title)
  43. VALUES (2, 6, 1, "TBD");');
  44. });
  45. $result = $session->query('select `series_id`, `season_id`, `episode_id`, `title` from `episodes`;');
  46. return [$result->rowCount(), $result->rows()[0]["season_id"],
  47. $result->rows()[0]["episode_id"],
  48. $result->rows()[0]["series_id"],
  49. $result->rows()[0]["title"]];
  50. }
  51. }