33namespace Feature ;
44
55use Tests \TestCase ;
6+ use Typesense \Collection ;
67use Typesense \Exceptions \ObjectNotFound ;
78
89class CollectionsTest extends TestCase
910{
1011 private $ createCollectionRes = null ;
12+ private ?Collection $ testCollection = null ;
1113
1214
1315 protected function setUp (): void
1416 {
1517 parent ::setUp ();
1618
1719 $ schema = $ this ->getSchema ('books ' );
20+
1821 $ this ->createCollectionRes = $ this ->client ()->collections ->create ($ schema );
22+ $ this ->testCollection = $ this ->client ()->collections ['books ' ];
1923 }
2024
2125 public function testCanCreateACollection (): void
@@ -25,7 +29,7 @@ public function testCanCreateACollection(): void
2529
2630 public function testCanRetrieveACollection (): void
2731 {
28- $ response = $ this ->client ()-> collections [ ' books ' ] ->retrieve ();
32+ $ response = $ this ->testCollection ->retrieve ();
2933 $ this ->assertEquals ('books ' , $ response ['name ' ]);
3034 }
3135
@@ -39,25 +43,32 @@ public function testCanUpdateACollection(): void
3943 ]
4044 ]
4145 ];
42- $ response = $ this ->client ()-> collections [ ' books ' ] ->update ($ update_schema );
46+ $ response = $ this ->testCollection ->update ($ update_schema );
4347 $ this ->assertEquals ('isbn ' , $ response ['fields ' ][0 ]['name ' ]);
4448 $ this ->assertArrayHasKey ('drop ' , $ response ['fields ' ][0 ]);
4549
46- $ response = $ this ->client ()-> collections [ ' books ' ] ->retrieve ();
50+ $ response = $ this ->testCollection ->retrieve ();
4751 $ this ->assertEquals (5 , count ($ response ['fields ' ]));
4852 }
4953
5054 public function testCanDeleteACollection (): void
5155 {
52- $ this ->client ()-> collections [ ' books ' ] ->delete ();
56+ $ this ->testCollection ->delete ();
5357
5458 $ this ->expectException (ObjectNotFound::class);
55- $ this ->client ()-> collections [ ' books ' ] ->retrieve ();
59+ $ this ->testCollection ->retrieve ();
5660 }
5761
5862 public function testCanRetrieveAllCollections (): void
5963 {
6064 $ response = $ this ->client ()->collections ->retrieve ();
6165 $ this ->assertCount (1 , $ response );
6266 }
67+
68+ public function testCanCloneACollectionSchema (): void
69+ {
70+ $ response = $ this ->client ()->collections ->create (['name ' => 'books_v2 ' ], ["src_name " => "books " ]);
71+ $ this ->assertEquals ('books_v2 ' , $ response ['name ' ]);
72+ $ this ->assertEquals ($ this ->createCollectionRes ['fields ' ], $ response ['fields ' ]);
73+ }
6374}
0 commit comments