|
3 | 3 | namespace Incenteev\HashedAssetBundle\Tests\Asset;
|
4 | 4 |
|
5 | 5 | use Incenteev\HashedAssetBundle\Asset\HashingVersionStrategy;
|
| 6 | +use Incenteev\HashedAssetBundle\Hashing\AssetHasherInterface; |
6 | 7 | use PHPUnit\Framework\TestCase;
|
7 | 8 |
|
8 | 9 | class HashingVersionStrategyTest extends TestCase
|
9 | 10 | {
|
10 |
| - /** |
11 |
| - * @dataProvider getAssetVersions |
12 |
| - */ |
13 |
| - public function testGetVersion($path, $version) |
| 11 | + public function testGetVersion() |
14 | 12 | {
|
15 |
| - $versionStrategy = new HashingVersionStrategy(__DIR__.'/fixtures'); |
| 13 | + $hasher = $this->prophesize(AssetHasherInterface::class); |
| 14 | + $hasher->computeHash('test')->willReturn('foo'); |
16 | 15 |
|
17 |
| - $this->assertEquals($version, $versionStrategy->getVersion($path)); |
18 |
| - } |
| 16 | + $versionStrategy = new HashingVersionStrategy($hasher->reveal()); |
19 | 17 |
|
20 |
| - public static function getAssetVersions() |
21 |
| - { |
22 |
| - yield ['asset1.txt', 'd0c0575']; |
23 |
| - yield ['asset2.txt', 'c1cf85a']; |
24 |
| - yield ['/asset2.txt', 'c1cf85a']; |
25 |
| - yield ['asset3.txt', '']; |
| 18 | + $this->assertEquals('foo', $versionStrategy->getVersion('test')); |
26 | 19 | }
|
27 | 20 |
|
28 | 21 | /**
|
29 | 22 | * @dataProvider getVersionedAssets
|
30 | 23 | */
|
31 |
| - public function testApplyVersion($path, $expected, $format = null) |
| 24 | + public function testApplyVersion($path, $expected, $hash, $format = null) |
32 | 25 | {
|
33 |
| - $versionStrategy = new HashingVersionStrategy(__DIR__.'/fixtures', $format); |
| 26 | + $hasher = $this->prophesize(AssetHasherInterface::class); |
| 27 | + $hasher->computeHash($path)->willReturn($hash); |
| 28 | + |
| 29 | + $versionStrategy = new HashingVersionStrategy($hasher->reveal(), $format); |
34 | 30 |
|
35 | 31 | $this->assertEquals($expected, $versionStrategy->applyVersion($path));
|
36 | 32 | }
|
37 | 33 |
|
38 | 34 | public static function getVersionedAssets()
|
39 | 35 | {
|
40 |
| - yield ['asset1.txt', 'asset1.txt?d0c0575']; |
41 |
| - yield ['asset2.txt', 'asset2.txt?c1cf85a']; |
42 |
| - yield ['/asset2.txt', '/asset2.txt?c1cf85a']; |
43 |
| - yield ['asset3.txt', 'asset3.txt?']; |
44 |
| - yield ['asset2.txt', 'c1cf85a/asset2.txt', '%2$s/%1$s']; |
45 |
| - yield ['/asset2.txt', '/c1cf85a/asset2.txt', '%2$s/%1$s']; |
46 |
| - yield ['/asset2.txt', '/c1cf85a/asset2.txt', '%2$s/%s']; |
| 36 | + yield ['asset1.txt', 'asset1.txt?d0c0575', 'd0c0575']; |
| 37 | + yield ['asset2.txt', 'asset2.txt?c1cf85a', 'c1cf85a']; |
| 38 | + yield ['/asset2.txt', '/asset2.txt?c1cf85a', 'c1cf85a']; |
| 39 | + yield ['asset3.txt', 'asset3.txt?', '']; |
| 40 | + yield ['asset2.txt', 'c1cf85a/asset2.txt', 'c1cf85a', '%2$s/%1$s']; |
| 41 | + yield ['/asset2.txt', '/c1cf85a/asset2.txt', 'c1cf85a', '%2$s/%1$s']; |
| 42 | + yield ['/asset2.txt', '/c1cf85a/asset2.txt', 'c1cf85a', '%2$s/%s']; |
47 | 43 | }
|
48 | 44 | }
|
0 commit comments