Skip to content

Commit 8788c08

Browse files
Copilotdkarlovi
andcommitted
Revert to original behavior: return all assets including existing ones for incremental build support
Co-authored-by: dkarlovi <[email protected]>
1 parent c24871b commit 8788c08

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

src/AssetQueue.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public function add(AssetCopy|AssetFetch $specification): void
4141
*/
4242
public function flush(?callable $callable = null): array
4343
{
44-
$processedAssets = [];
45-
4644
foreach ($this->queue as $specification) {
4745
$destination = $this->buildDir.'/'.mb_ltrim($specification->destination, '/');
4846
if (file_exists($destination)) {
@@ -69,18 +67,17 @@ public function flush(?callable $callable = null): array
6967
if ($callable !== null) {
7068
$callable($specification);
7169
}
72-
$processedAssets[] = $specification;
7370
continue;
7471
}
7572

7673
$this->filesystem->copy($specification->source, $destination);
7774
if ($callable !== null) {
7875
$callable($specification);
7976
}
80-
$processedAssets[] = $specification;
8177
}
78+
$queue = array_values($this->queue);
8279
$this->queue = [];
8380

84-
return $processedAssets;
81+
return $queue;
8582
}
8683
}

tests/unit/AssetQueueTest.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)