@@ -78,51 +78,18 @@ public function it_can_count_the_results()
7878 /** @test */
7979 public function it_respects_table_prefixes ()
8080 {
81- $ connection = DB ::connection ();
82- $ originalPrefix = $ connection ->getTablePrefix ();
81+ $ this ->initDatabase ('prefix_ ' );
8382
84- try {
85- // Set prefix FIRST before creating tables
86- $ connection ->setTablePrefix ('prefix_ ' );
87-
88- // Drop existing unprefixed tables
89- $ connection ->setTablePrefix ($ originalPrefix );
90- Schema::dropIfExists ('posts ' );
91- Schema::dropIfExists ('videos ' );
92- Schema::dropIfExists ('comments ' );
93- Schema::dropIfExists ('blogs ' );
94- Schema::dropIfExists ('pages ' );
95-
96- // Set prefix back and create prefixed tables
97- $ connection ->setTablePrefix ('prefix_ ' );
98- include_once __DIR__ . '/create_tables.php ' ;
99- (new \CreateTables )->up ();
100-
101- $ postA = Post::create (['title ' => 'foo ' ]);
102- $ postB = Post::create (['title ' => 'bar ' ]);
103- $ videoA = Video::create (['title ' => 'foo ' ]);
104- $ videoB = Video::create (['title ' => 'bar ' , 'subtitle ' => 'foo ' ]);
105-
106- $ count = Search::add (Post::class, 'title ' )
107- ->add (Video::class, ['title ' , 'subtitle ' ])
108- ->count ('foo ' );
109-
110- $ this ->assertEquals (3 , $ count );
111- } finally {
112- // Always reset prefix and recreate original tables
113- $ connection ->setTablePrefix ($ originalPrefix );
114-
115- // Drop prefixed tables
116- Schema::dropIfExists ('prefix_posts ' );
117- Schema::dropIfExists ('prefix_videos ' );
118- Schema::dropIfExists ('prefix_comments ' );
119- Schema::dropIfExists ('prefix_blogs ' );
120- Schema::dropIfExists ('prefix_pages ' );
121-
122- // Recreate original tables for other tests
123- include_once __DIR__ . '/create_tables.php ' ;
124- (new \CreateTables )->up ();
125- }
83+ $ postA = Post::create (['title ' => 'foo ' ]);
84+ $ postB = Post::create (['title ' => 'bar ' ]);
85+ $ videoA = Video::create (['title ' => 'foo ' ]);
86+ $ videoB = Video::create (['title ' => 'bar ' , 'subtitle ' => 'foo ' ]);
87+
88+ $ count = Search::add (Post::class, 'title ' )
89+ ->add (Video::class, ['title ' , 'subtitle ' ])
90+ ->count ('foo ' );
91+
92+ $ this ->assertEquals (3 , $ count );
12693 }
12794
12895 /** @test */
0 commit comments