Skip to content

Commit 16ddd87

Browse files
Copilotabnegate
andauthored
fix(tests): rewrite skip-index and SETTINGS tests to use builder style
Agent-Logs-Url: https://github.com/utopia-php/query/sessions/6148863a-df07-4bbf-a771-b4721be69f8f Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
1 parent d60af4c commit 16ddd87

1 file changed

Lines changed: 82 additions & 88 deletions

File tree

tests/Query/Schema/ClickHouseTest.php

Lines changed: 82 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,11 @@ public function testColumnLevelTTL(): void
712712
public function testIndexBloomFilter(): void
713713
{
714714
$schema = new Schema();
715-
$result = $schema->create('events', function (Table $table) {
716-
$table->bigInteger('id')->primary();
717-
$table->string('user_id');
718-
$table->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter);
719-
});
715+
$result = $schema->table('events')
716+
->bigInteger('id')->primary()
717+
->string('user_id')
718+
->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter)
719+
->create();
720720
$this->assertBindingCount($result);
721721

722722
$this->assertSame(
@@ -728,13 +728,13 @@ public function testIndexBloomFilter(): void
728728
public function testIndexWithAlgorithmArgs(): void
729729
{
730730
$schema = new Schema();
731-
$result = $schema->create('events', function (Table $table) {
732-
$table->bigInteger('id')->primary();
733-
$table->string('country');
734-
$table->string('text');
735-
$table->index(['country'], algorithm: IndexAlgorithm::Set, algorithmArgs: [100], granularity: 4);
736-
$table->index(['text'], algorithm: IndexAlgorithm::NgramBloomFilter, algorithmArgs: [4, 1024, 3, 0]);
737-
});
731+
$result = $schema->table('events')
732+
->bigInteger('id')->primary()
733+
->string('country')
734+
->string('text')
735+
->index(['country'], algorithm: IndexAlgorithm::Set, algorithmArgs: [100], granularity: 4)
736+
->index(['text'], algorithm: IndexAlgorithm::NgramBloomFilter, algorithmArgs: [4, 1024, 3, 0])
737+
->create();
738738
$this->assertBindingCount($result);
739739

740740
$this->assertSame(
@@ -749,12 +749,12 @@ public function testIndexWithAlgorithmArgs(): void
749749
public function testIndexCompositeColumnsWithAlgorithm(): void
750750
{
751751
$schema = new Schema();
752-
$result = $schema->create('events', function (Table $table) {
753-
$table->bigInteger('id')->primary();
754-
$table->string('user_id');
755-
$table->string('event');
756-
$table->index(['user_id', 'event'], name: 'idx_user_event', algorithm: IndexAlgorithm::BloomFilter);
757-
});
752+
$result = $schema->table('events')
753+
->bigInteger('id')->primary()
754+
->string('user_id')
755+
->string('event')
756+
->index(['user_id', 'event'], name: 'idx_user_event', algorithm: IndexAlgorithm::BloomFilter)
757+
->create();
758758
$this->assertBindingCount($result);
759759

760760
$this->assertSame(
@@ -770,33 +770,31 @@ public function testIndexInvalidGranularityThrows(): void
770770
$this->expectException(ValidationException::class);
771771

772772
$schema = new Schema();
773-
$schema->create('events', function (Table $table) {
774-
$table->bigInteger('id')->primary();
775-
$table->string('user_id');
776-
$table->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter, granularity: 0);
777-
});
773+
$schema->table('events')
774+
->bigInteger('id')->primary()
775+
->string('user_id')
776+
->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter, granularity: 0);
778777
}
779778

780779
public function testIndexEmptyColumnsThrows(): void
781780
{
782781
$this->expectException(ValidationException::class);
783782

784783
$schema = new Schema();
785-
$schema->create('events', function (Table $table) {
786-
$table->bigInteger('id')->primary();
787-
$table->index([]);
788-
});
784+
$schema->table('events')
785+
->bigInteger('id')->primary()
786+
->index([]);
789787
}
790788

791789
public function testIndexNameRegexOnlyEnforcedForClickHouseAlgorithms(): void
792790
{
793791
// No algorithm → permissive name allowed (other dialects quote names)
794792
$schema = new Schema();
795-
$result = $schema->create('events', function (Table $table) {
796-
$table->bigInteger('id')->primary();
797-
$table->string('user_id');
798-
$table->index(['user_id'], name: 'idx-with-hyphens');
799-
});
793+
$result = $schema->table('events')
794+
->bigInteger('id')->primary()
795+
->string('user_id')
796+
->index(['user_id'], name: 'idx-with-hyphens')
797+
->create();
800798
$this->assertBindingCount($result);
801799
$this->assertStringContainsString('INDEX `idx-with-hyphens`', $result->query);
802800
}
@@ -807,22 +805,21 @@ public function testIndexNameRegexEnforcedWhenAlgorithmIsSet(): void
807805
$this->expectExceptionMessage('Invalid index name: idx-with-hyphens');
808806

809807
$schema = new Schema();
810-
$schema->create('events', function (Table $table) {
811-
$table->bigInteger('id')->primary();
812-
$table->string('user_id');
813-
$table->index(['user_id'], name: 'idx-with-hyphens', algorithm: IndexAlgorithm::BloomFilter);
814-
});
808+
$schema->table('events')
809+
->bigInteger('id')->primary()
810+
->string('user_id')
811+
->index(['user_id'], name: 'idx-with-hyphens', algorithm: IndexAlgorithm::BloomFilter);
815812
}
816813

817814
// SETTINGS
818815

819816
public function testTableSettings(): void
820817
{
821818
$schema = new Schema();
822-
$result = $schema->create('events', function (Table $table) {
823-
$table->bigInteger('id')->primary();
824-
$table->settings(['index_granularity' => 8192, 'allow_nullable_key' => true]);
825-
});
819+
$result = $schema->table('events')
820+
->bigInteger('id')->primary()
821+
->settings(['index_granularity' => 8192, 'allow_nullable_key' => true])
822+
->create();
826823
$this->assertBindingCount($result);
827824

828825
$this->assertSame(
@@ -835,12 +832,12 @@ public function testTableSettings(): void
835832
public function testTableSettingsWithTtlOrdering(): void
836833
{
837834
$schema = new Schema();
838-
$result = $schema->create('events', function (Table $table) {
839-
$table->bigInteger('id')->primary();
840-
$table->datetime('created_at');
841-
$table->ttl('`created_at` + INTERVAL 30 DAY');
842-
$table->settings(['index_granularity' => 4096]);
843-
});
835+
$result = $schema->table('events')
836+
->bigInteger('id')->primary()
837+
->datetime('created_at')
838+
->ttl('`created_at` + INTERVAL 30 DAY')
839+
->settings(['index_granularity' => 4096])
840+
->create();
844841
$this->assertBindingCount($result);
845842

846843
$this->assertSame(
@@ -856,30 +853,28 @@ public function testTableSettingsRejectsInvalidKey(): void
856853
$this->expectException(ValidationException::class);
857854

858855
$schema = new Schema();
859-
$schema->create('events', function (Table $table) {
860-
$table->bigInteger('id')->primary();
861-
$table->settings(['1bad-key' => 8192]);
862-
});
856+
$schema->table('events')
857+
->bigInteger('id')->primary()
858+
->settings(['1bad-key' => 8192]);
863859
}
864860

865861
public function testTableSettingsRejectsInvalidValue(): void
866862
{
867863
$this->expectException(ValidationException::class);
868864

869865
$schema = new Schema();
870-
$schema->create('events', function (Table $table) {
871-
$table->bigInteger('id')->primary();
872-
$table->settings(['ok_key' => "evil'; DROP TABLE x; --"]);
873-
});
866+
$schema->table('events')
867+
->bigInteger('id')->primary()
868+
->settings(['ok_key' => "evil'; DROP TABLE x; --"]);
874869
}
875870

876871
public function testTableSettingsFloatAvoidsScientificNotation(): void
877872
{
878873
$schema = new Schema();
879-
$result = $schema->create('events', function (Table $table) {
880-
$table->bigInteger('id')->primary();
881-
$table->settings(['merge_with_ttl_timeout' => 1.0e-5]);
882-
});
874+
$result = $schema->table('events')
875+
->bigInteger('id')->primary()
876+
->settings(['merge_with_ttl_timeout' => 1.0e-5])
877+
->create();
883878
$this->assertBindingCount($result);
884879

885880
$this->assertStringContainsString('SETTINGS merge_with_ttl_timeout = 0.00001', $result->query);
@@ -892,33 +887,31 @@ public function testIndexNoArgAlgorithmRejectsArgs(): void
892887
$this->expectExceptionMessage('minmax does not accept algorithm arguments.');
893888

894889
$schema = new Schema();
895-
$schema->create('events', function (Table $table) {
896-
$table->bigInteger('id')->primary();
897-
$table->integer('score');
898-
$table->index(['score'], algorithm: IndexAlgorithm::MinMax, algorithmArgs: [3]);
899-
});
890+
$schema->table('events')
891+
->bigInteger('id')->primary()
892+
->integer('score')
893+
->index(['score'], algorithm: IndexAlgorithm::MinMax, algorithmArgs: [3]);
900894
}
901895

902896
public function testIndexInvertedRejectsArgs(): void
903897
{
904898
$this->expectException(ValidationException::class);
905899

906900
$schema = new Schema();
907-
$schema->create('events', function (Table $table) {
908-
$table->bigInteger('id')->primary();
909-
$table->string('text');
910-
$table->index(['text'], algorithm: IndexAlgorithm::Inverted, algorithmArgs: [42]);
911-
});
901+
$schema->table('events')
902+
->bigInteger('id')->primary()
903+
->string('text')
904+
->index(['text'], algorithm: IndexAlgorithm::Inverted, algorithmArgs: [42]);
912905
}
913906

914907
public function testIndexAutoNameSanitisesNonIdentifierColumns(): void
915908
{
916909
$schema = new Schema();
917-
$result = $schema->create('events', function (Table $table) {
918-
$table->bigInteger('id')->primary();
919-
$table->string('event-type');
920-
$table->index(['event-type'], algorithm: IndexAlgorithm::BloomFilter);
921-
});
910+
$result = $schema->table('events')
911+
->bigInteger('id')->primary()
912+
->string('event-type')
913+
->index(['event-type'], algorithm: IndexAlgorithm::BloomFilter)
914+
->create();
922915
$this->assertBindingCount($result);
923916

924917
$this->assertSame(
@@ -932,11 +925,11 @@ public function testIndexAutoNameSanitisesNonIdentifierColumns(): void
932925
public function testIndexFloatArgAvoidsScientificNotation(): void
933926
{
934927
$schema = new Schema();
935-
$result = $schema->create('events', function (Table $table) {
936-
$table->bigInteger('id')->primary();
937-
$table->string('user_id');
938-
$table->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter, algorithmArgs: [1.0e-5]);
939-
});
928+
$result = $schema->table('events')
929+
->bigInteger('id')->primary()
930+
->string('user_id')
931+
->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter, algorithmArgs: [1.0e-5])
932+
->create();
940933
$this->assertBindingCount($result);
941934

942935
$this->assertStringContainsString('TYPE bloom_filter(0.00001)', $result->query);
@@ -947,9 +940,9 @@ public function testIndexFloatArgAvoidsScientificNotation(): void
947940
public function testAlterAddIndexWithAlgorithm(): void
948941
{
949942
$schema = new Schema();
950-
$result = $schema->alter('events', function (Table $table) {
951-
$table->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter);
952-
});
943+
$result = $schema->table('events')
944+
->index(['user_id'], algorithm: IndexAlgorithm::BloomFilter)
945+
->alter();
953946
$this->assertBindingCount($result);
954947

955948
$this->assertSame(
@@ -961,9 +954,9 @@ public function testAlterAddIndexWithAlgorithm(): void
961954
public function testAlterAddIndexComposite(): void
962955
{
963956
$schema = new Schema();
964-
$result = $schema->alter('events', function (Table $table) {
965-
$table->index(['user_id', 'event'], name: 'idx_user_event', algorithm: IndexAlgorithm::Set, algorithmArgs: [100], granularity: 4);
966-
});
957+
$result = $schema->table('events')
958+
->index(['user_id', 'event'], name: 'idx_user_event', algorithm: IndexAlgorithm::Set, algorithmArgs: [100], granularity: 4)
959+
->alter();
967960
$this->assertBindingCount($result);
968961

969962
$this->assertSame(
@@ -978,8 +971,9 @@ public function testAlterRejectsSettings(): void
978971
$this->expectExceptionMessage('SETTINGS');
979972

980973
$schema = new Schema();
981-
$schema->alter('events', function (Table $table) {
982-
$table->settings(['index_granularity' => 4096]);
983-
});
974+
$schema->table('events')
975+
->bigInteger('id')->primary()
976+
->settings(['index_granularity' => 4096])
977+
->alter();
984978
}
985979
}

0 commit comments

Comments
 (0)