Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88c7ef6

Browse files
committed
Functional test for pipeline dev server
1 parent f64e5d3 commit 88c7ef6

12 files changed

+88
-11
lines changed

src/Symfony/Component/Asset/Pipeline/AssetPipelineDevServerSubscriber.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function onKernelRequest(RequestEvent $event): void
4242
throw new NotFoundHttpException(sprintf('Asset "%s" not found.', $assetPath));
4343
}
4444

45-
if ($this->assetPipeline->getDigest($asset->getLogicalPath()) === $digest) {
45+
if ($this->assetPipeline->getDigest($asset->getLogicalPath()) !== $digest) {
4646
throw new NotFoundHttpException(sprintf('Asset "%s" was found but the digest does not match.', $assetPath));
4747
}
4848

@@ -75,6 +75,10 @@ private function extractAssetPathAndDigest(string $fullPath): array
7575
$fullPath = substr($fullPath, \strlen($this->assetPipeline->getPublicPrefix()));
7676
preg_match('/-([0-9a-zA-Z]{7,128}(?:\.digested)?)\.[^.]+\z/', $fullPath, $matches);
7777
$digest = $matches[1] ?? null;
78+
// check for pre-digested assets
79+
if (str_ends_with($digest, '.digested')) {
80+
$digest = null;
81+
}
7882
$path = $digest ? str_replace("-{$digest}", '', $fullPath) : $fullPath;
7983

8084
return [$path, $digest];

src/Symfony/Component/Asset/Tests/Pipeline/AssetPipelineCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Pipeline;
12+
namespace Symfony\Component\Asset\Tests\Pipeline;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Asset\Pipeline\AssetCompilerInterface;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Pipeline;
13+
14+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15+
use Symfony\Component\Asset\Tests\fixtures\pipeline\PipelineTestAppKernel;
16+
17+
class AssetPipelineDevServerSubscriberFunctionalTest extends WebTestCase
18+
{
19+
public function testGettingAssetWorks(): void
20+
{
21+
$client = static::createClient();
22+
23+
$client->request('GET', '/assets/file1-b3445cb7a86a0795a7af7f2004498aef.css');
24+
$response = $client->getResponse();
25+
$this->assertSame(200, $response->getStatusCode());
26+
$this->assertSame(<<<EOF
27+
/* file1.css */
28+
body {}
29+
30+
EOF, $response->getContent());
31+
$this->assertSame('"b3445cb7a86a0795a7af7f2004498aef"', $response->headers->get('ETag'));
32+
$this->assertSame('immutable, public, s-maxage=604800', $response->headers->get('Cache-Control'));
33+
}
34+
35+
public function test404OnUnknownAsset(): void
36+
{
37+
$client = static::createClient();
38+
39+
$client->request('GET', '/assets/unknown.css');
40+
$response = $client->getResponse();
41+
$this->assertSame(404, $response->getStatusCode());
42+
}
43+
44+
public function test404OnInvalidDigest(): void
45+
{
46+
$client = static::createClient();
47+
48+
$client->request('GET', '/assets/file1-fakedigest.css');
49+
$response = $client->getResponse();
50+
$this->assertSame(404, $response->getStatusCode());
51+
$this->assertStringContainsString('Asset &quot;file1.css&quot; was found but the digest does not match.', $response->getContent());
52+
}
53+
54+
public function testPreDigestedAssetIsReturned(): void
55+
{
56+
$client = static::createClient();
57+
58+
$client->request('GET', '/assets/already-abcdefVWXYZ0123456789.digested.css');
59+
$response = $client->getResponse();
60+
$this->assertSame(200, $response->getStatusCode());
61+
$this->assertSame(<<<EOF
62+
/* already-abcdefVWXYZ0123456789.digested.css */
63+
body {}
64+
65+
EOF, $response->getContent());
66+
}
67+
68+
protected static function getKernelClass(): string
69+
{
70+
return PipelineTestAppKernel::class;
71+
}
72+
}

src/Symfony/Component/Asset/Tests/Pipeline/AssetPipelineRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Pipeline;
12+
namespace Symfony\Component\Asset\Tests\Pipeline;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Asset\Pipeline\AssetPipelineRepository;

src/Symfony/Component/Asset/Tests/Pipeline/AssetPipelineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Pipeline;
3+
namespace Symfony\Component\Asset\Tests\Pipeline;
44

55
use Symfony\Bundle\TwigBundle\Tests\TestCase;
66
use Symfony\Component\Asset\Pipeline\AssetCompilerInterface;

src/Symfony/Component/Asset/Tests/Pipeline/Compiler/AssetCompilerPathResolverTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Pipeline\Compiler;
12+
namespace Symfony\Component\Asset\Tests\Pipeline\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Asset\Exception\RuntimeException;

src/Symfony/Component/Asset/Tests/Pipeline/Compiler/JavaScriptImportPathCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Pipeline\Compiler;
12+
namespace Symfony\Component\Asset\Tests\Pipeline\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Asset\Exception\RuntimeException;

src/Symfony/Component/Asset/Tests/Pipeline/Compiler/SourceMappingUrlsCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Pipeline\Compiler;
12+
namespace Symfony\Component\Asset\Tests\Pipeline\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Asset\Pipeline\AssetPipeline;

src/Symfony/Component/Asset/Tests/Pipeline/PipelineAwareAssetPackageIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Pipeline;
3+
namespace Symfony\Component\Asset\Tests\Pipeline;
44

55
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
66
use Symfony\Component\Asset\Packages;

src/Symfony/Component/Asset/Tests/Pipeline/PipelineAwareAssetPackageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Pipeline;
12+
namespace Symfony\Component\Asset\Tests\Pipeline;
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Asset\PackageInterface;

0 commit comments

Comments
 (0)