@@ -48,7 +48,7 @@ protected function tearDown(): void
4848 }
4949 }
5050
51- public function testFlushDoesNotReturnExistingAssets (): void
51+ public function testFlushReturnsAllAssetsIncludingExisting (): void
5252 {
5353 // Create a temporary source file
5454 $ sourceFile = $ this ->tempDir . '/source.txt ' ;
@@ -78,14 +78,14 @@ public function testFlushDoesNotReturnExistingAssets(): void
7878 $ processedAssets [] = $ asset ;
7979 });
8080
81- // Currently this test will FAIL because the method returns all assets
82- // After the fix, it should only return the new asset
83- $ this ->assertCount ( 1 , $ returnedAssets , 'Should only return newly processed assets, not existing ones ' );
84- $ this ->assertSame ($ newAsset , $ returnedAssets[ 0 ] , 'Should return the new asset ' );
81+ // Should return ALL assets (both existing and new) for incremental build support
82+ $ this -> assertCount ( 2 , $ returnedAssets , ' Should return all assets including existing ones ' );
83+ $ this ->assertContains ( $ existingAsset , $ returnedAssets , 'Should include existing asset in return ' );
84+ $ this ->assertContains ($ newAsset , $ returnedAssets , 'Should include new asset in return ' );
8585
86- // Verify callback was only called for new asset
86+ // Verify callback was only called for new asset (existing assets are skipped from processing)
8787 $ this ->assertCount (1 , $ processedAssets , 'Callback should only be called for newly processed assets ' );
88- $ this ->assertSame ($ newAsset , $ processedAssets [0 ], 'Callback should be called with the new asset ' );
88+ $ this ->assertSame ($ newAsset , $ processedAssets [0 ], 'Callback should be called with the new asset only ' );
8989
9090 // Verify the new asset was actually copied
9191 $ this ->assertFileExists ($ this ->tempDir . $ newDestination , 'New asset should be copied ' );
@@ -131,6 +131,49 @@ public function testFlushWithNoExistingAssets(): void
131131 $ this ->assertFileExists ($ this ->tempDir . '/new/asset2.txt ' );
132132 }
133133
134+ public function testFlushWithAllExistingAssets (): void
135+ {
136+ // Create a temporary source file
137+ $ sourceFile = $ this ->tempDir . '/source.txt ' ;
138+ file_put_contents ($ sourceFile , 'test content ' );
139+
140+ // Create multiple existing destination files
141+ $ existingDestinations = ['/existing1/asset.txt ' , '/existing2/asset.txt ' ];
142+ $ existingAssets = [];
143+
144+ foreach ($ existingDestinations as $ destination ) {
145+ $ path = $ this ->tempDir . $ destination ;
146+ $ this ->filesystem ->mkdir (dirname ($ path ));
147+ file_put_contents ($ path , 'existing content ' );
148+
149+ $ asset = new AssetCopy ($ sourceFile , $ destination );
150+ $ existingAssets [] = $ asset ;
151+ $ this ->assetQueue ->add ($ asset );
152+ }
153+
154+ // Track which assets were processed via callback
155+ $ processedAssets = [];
156+
157+ // Flush the queue
158+ $ returnedAssets = $ this ->assetQueue ->flush (function ($ asset ) use (&$ processedAssets ) {
159+ $ processedAssets [] = $ asset ;
160+ });
161+
162+ // Should return all assets even though they all exist (for incremental build support)
163+ $ this ->assertCount (2 , $ returnedAssets , 'Should return all assets even when they all exist ' );
164+ $ this ->assertContains ($ existingAssets [0 ], $ returnedAssets );
165+ $ this ->assertContains ($ existingAssets [1 ], $ returnedAssets );
166+
167+ // Verify callback was never called since no assets were actually processed
168+ $ this ->assertEmpty ($ processedAssets , 'Callback should not be called when all assets already exist ' );
169+
170+ // Verify all existing files were not modified
171+ foreach ($ existingDestinations as $ destination ) {
172+ $ path = $ this ->tempDir . $ destination ;
173+ $ this ->assertEquals ('existing content ' , file_get_contents ($ path ));
174+ }
175+ }
176+
134177 public function testEmptyQueue (): void
135178 {
136179 $ returnedAssets = $ this ->assetQueue ->flush ();
0 commit comments