-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configurable base directory for bundles
- Loading branch information
1 parent
b6f820b
commit feb839d
Showing
3 changed files
with
73 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,52 @@ | ||
<?php | ||
|
||
use Nyholm\Psr7\Factory\Psr17Factory; | ||
use Nyholm\Psr7\ServerRequest; | ||
use PHPUnit\Framework\TestCase; | ||
use AssetGatherer\AssetGatherer; | ||
|
||
class AssetGathererTest extends TestCase | ||
{ | ||
private $assetGatherer; | ||
private $baseDirectory; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->assetGatherer = new AssetGatherer(); | ||
$this->baseDirectory = __DIR__ . '/assets'; // Définir un répertoire de base pour les tests | ||
mkdir($this->baseDirectory . '/homepage/images', 0777, true); | ||
file_put_contents($this->baseDirectory . '/homepage/images/test.jpg', 'image content'); | ||
|
||
// Instancier AssetGatherer avec un répertoire de base | ||
$this->assetGatherer = new AssetGatherer($this->baseDirectory); | ||
$this->assetGatherer->loadConfiguration(__DIR__ . '/../config/bundles.yaml'); | ||
} | ||
|
||
public function testGatherAssetsForHomepageRequest(): void | ||
protected function tearDown(): void | ||
{ | ||
$factory = new Psr17Factory(); | ||
$request = new ServerRequest('GET', '/homepage'); | ||
// Nettoyer les fichiers et dossiers de test créés | ||
unlink($this->baseDirectory . '/homepage/images/test.jpg'); | ||
rmdir($this->baseDirectory . '/homepage/images'); | ||
rmdir($this->baseDirectory . '/homepage'); | ||
} | ||
|
||
public function testGatherAssetsWithBaseDirectory(): void | ||
{ | ||
$request = new ServerRequest('GET', '/homepage'); | ||
$this->assetGatherer->gatherAssetsForRequest($request); | ||
$assets = $this->assetGatherer->getAssets('homepage'); | ||
|
||
$assets = $this->assetGatherer->getAssets('homepage'); | ||
|
||
// Vérifier que le fichier est collecté en utilisant le répertoire de base | ||
$this->assertArrayHasKey('images', $assets); | ||
$this->assertCount(1, $assets['images']); | ||
$this->assertStringContainsString('test.jpg', $assets['images'][0]); | ||
} | ||
|
||
public function testNoAssetsForNonMatchingRequest(): void | ||
{ | ||
$factory = new Psr17Factory(); | ||
$request = new ServerRequest('GET', '/unknown'); | ||
|
||
$request = new ServerRequest('GET', '/nonexistent'); | ||
$this->assetGatherer->gatherAssetsForRequest($request); | ||
$assets = $this->assetGatherer->getAssets(); | ||
|
||
$assets = $this->assetGatherer->getAssets(); | ||
$this->assertEmpty($assets); | ||
} | ||
} |