CheckTxSettingsTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use Ydb\Table\OnlineModeSettings;
  5. use Ydb\Table\SnapshotModeSettings;
  6. use Ydb\Table\StaleModeSettings;
  7. class CheckTxSettingsTest extends TestCase
  8. {
  9. public function testCheckParseTxMode()
  10. {
  11. $tests = [
  12. ['mode' => 'stale_read_only', 'result' => ['stale_read_only' => new StaleModeSettings]],
  13. ['mode' => 'stale', 'result' => ['stale_read_only' => new StaleModeSettings]],
  14. ['mode' => 'online_read_only', 'result' => ['online_read_only' => new OnlineModeSettings([
  15. 'allow_inconsistent_reads' => false,
  16. ])]],
  17. ['mode' => 'online', 'result' => ['online_read_only' => new OnlineModeSettings([
  18. 'allow_inconsistent_reads' => false,
  19. ])]],
  20. ['mode' => 'inconsistent_reads', 'result' => ['online_read_only' => new OnlineModeSettings([
  21. 'allow_inconsistent_reads' => true,
  22. ])]],
  23. ['mode' => 'online_inconsistent', 'result' => ['online_read_only' => new OnlineModeSettings([
  24. 'allow_inconsistent_reads' => true,
  25. ])]],
  26. ['mode' => 'online_inconsistent_reads', 'result' => ['online_read_only' => new OnlineModeSettings([
  27. 'allow_inconsistent_reads' => true,
  28. ])]],
  29. ['mode' => 'snapshot', 'result' => ['snapshot_read_only' => new SnapshotModeSettings]],
  30. ['mode' => 'snapshot_read_only', 'result' => ['snapshot_read_only' => new SnapshotModeSettings]],
  31. ];
  32. foreach ($tests as $i => $test){
  33. self::assertEquals($test["result"], Session::parseTxMode($test["mode"]));
  34. }
  35. self::expectException('Exception');
  36. Session::parseTxMode(null);
  37. }
  38. }
  39. class Session extends \YdbPlatform\Ydb\Session {
  40. public static function parseTxMode(string $mode = null): array
  41. {
  42. return parent::parseTxMode($mode);
  43. }
  44. }