22
33namespace Tests \Unit ;
44
5- use FamilyTree365 \LaravelGedcom \Commands \GedcomExporterHelpers ;
6- use Orchestra \ Testbench \TestCase ;
5+ use FamilyTree365 \LaravelGedcom \Commands \GedcomExporter ;
6+ use Tests \TestCase ;
77use Illuminate \Support \Facades \Storage ;
88use Illuminate \Support \Facades \DB ;
99use Mockery ;
@@ -13,38 +13,28 @@ class GedcomExporterHelpersTest extends TestCase
1313 protected function setUp (): void
1414 {
1515 parent ::setUp ();
16-
1716 Storage::fake ('local ' );
18-
19- DB ::shouldReceive ('table ' )
20- ->andReturnSelf ()
21- ->shouldReceive ('join ' )
22- ->andReturnSelf ()
23- ->shouldReceive ('select ' )
24- ->andReturnSelf ()
25- ->shouldReceive ('get ' )
26- ->andReturn (collect ([]));
27- }
28-
29- protected function getPackageProviders ($ app )
30- {
31- return ['FamilyTree365\LaravelGedcom\ServiceProvider ' ];
3217 }
3318
3419 public function testCreateDirectory ()
3520 {
36- GedcomExporterHelpers ::createDirectory ('test-dir ' );
21+ GedcomExporter ::createDirectory ('test-dir ' );
3722 Storage::disk ('local ' )->assertExists ('test-dir ' );
3823 }
3924
4025 public function testFetchDatabaseData ()
4126 {
42- $ data = GedcomExporterHelpers::fetchDatabaseData ();
43- $ this ->assertCount (0 , $ data );
27+ DB ::shouldReceive ('table ' )
28+ ->with ('submissions ' )
29+ ->andReturnSelf ()
30+ ->shouldReceive ('join ' )
31+ ->andReturnSelf ()
32+ ->shouldReceive ('select ' )
33+ ->andReturnSelf ()
34+ ->shouldReceive ('get ' )
35+ ->andReturn (collect ([]));
4436
45- // No records found
46- DB ::shouldReceive ('get ' )->andReturn (collect ([]));
47- $ data = GedcomExporterHelpers::fetchDatabaseData ();
37+ $ data = GedcomExporter::fetchDatabaseData ();
4838 $ this ->assertCount (0 , $ data );
4939 }
5040
@@ -53,31 +43,29 @@ public function testPrepareDataForView()
5343 $ submissions = ['submission1 ' , 'submission2 ' ];
5444 $ people = ['person1 ' , 'person2 ' ];
5545
56- $ result = GedcomExporterHelpers ::prepareDataForView ($ submissions , $ people );
46+ $ result = GedcomExporter ::prepareDataForView ($ submissions , $ people );
5747 $ this ->assertEquals (['submissions ' => $ submissions , 'people ' => $ people ], $ result );
5848 }
5949
6050 public function testCreateGedcomDocumentString ()
6151 {
6252 $ source = "0 @I1@ INDI \n1 NAME John Doe " ;
6353 $ expectedResult = "HEAD \nGEDC \nVERS 5.5.5 \nFORM LINEAGE-LINKED \nVERS 5.5.5 \nCHAR UTF-8 \nSOUR GS \nVERS 5.5.5 \nCORP gedcom.org \n" . $ source ;
64- $ result = GedcomExporterHelpers ::createGedcomDocumentString ($ source );
54+ $ result = GedcomExporter ::createGedcomDocumentString ($ source );
6555 $ this ->assertEquals ($ expectedResult , $ result );
6656 }
6757
6858 public function testWriteToFile ()
6959 {
70- $ filename = ' testFile .txt ' ;
60+ $ filename = sys_get_temp_dir () . ' /gedcom_test_ ' . uniqid () . ' .txt ' ;
7161 $ content = 'Test content ' ;
7262
73- GedcomExporterHelpers::writeToFile (storage_path ('app/public/ ' . $ filename ), $ content );
74- Storage::disk ('local ' )->assertExists ('public/ ' . $ filename );
75- $ this ->assertEquals ($ content , Storage::disk ('local ' )->get ('public/ ' . $ filename ));
63+ GedcomExporter::writeToFile ($ filename , $ content );
64+
65+ $ this ->assertFileExists ($ filename );
66+ $ this ->assertEquals ($ content , file_get_contents ($ filename ));
7667
77- // Simulate file write error
78- Storage::shouldReceive ('put ' )->andThrow (new \Exception ('Failed to write to file ' ));
79- $ this ->expectException (\Exception::class);
80- GedcomExporterHelpers::writeToFile (storage_path ('app/public/errorFile.txt ' ), 'Error content ' );
68+ unlink ($ filename );
8169 }
8270
8371 protected function tearDown (): void
0 commit comments