Skip to content

Commit ef7c34d

Browse files
committed
integration test created for cache warmer
- Created integration test - Created an alias so that cash warmer could be autowired - Fixed a bug where entrypoints.json was not added to the path so the exception would get thrown that entry point was missing
1 parent 436f4d3 commit ef7c34d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/DependencyInjection/WebpackEncoreExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function load(array $configs, ContainerBuilder $container)
3636
];
3737
foreach ($config['builds'] as $name => $path) {
3838
$factories[$name] = $this->entrypointFactory($container, $name, $path, $config['cache']);
39-
$cacheKeys[rawurlencode($name)] = $path;
39+
$cacheKeys[rawurlencode($name)] = $path.'/entrypoints.json';
4040
}
4141

4242
$container->getDefinition('webpack_encore.entrypoint_lookup.cache_warmer')

src/Resources/config/services.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
<argument type="service" id="cache.webpack_encore" />
3737
</service>
3838

39+
<service id="Symfony\WebpackEncoreBundle\CacheWarmer\EntrypointCacheWarmer" alias="webpack_encore.entrypoint_lookup.cache_warmer" />
40+
3941
<service id="webpack_encore.cache" class="Symfony\Component\Cache\Adapter\PhpArrayAdapter">
4042
<factory class="Symfony\Component\Cache\Adapter\PhpArrayAdapter" method="create" />
4143
<argument>%kernel.cache_dir%/webpack_encore.cache.php</argument>

tests/IntegrationTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Symfony\WebpackEncoreBundle\Tests;
44

5+
use Symfony\WebpackEncoreBundle\CacheWarmer\EntrypointCacheWarmer;
56
use Symfony\WebpackEncoreBundle\WebpackEncoreBundle;
67
use PHPUnit\Framework\TestCase;
78
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
@@ -77,6 +78,19 @@ public function testEntriesAreNotRepeteadWhenAlreadyOutputIntegration()
7778
$html2
7879
);
7980
}
81+
82+
public function testCacheWarmer()
83+
{
84+
$kernal = new WebpackEncoreIntegrationTestKernel(true);
85+
$kernal->boot();
86+
$container = $kernal->getContainer();
87+
88+
$cacheWarmer = $container->get(CacheWarmerTester::class);
89+
90+
$cacheWarmer->warmCache($kernal->getCacheDir());
91+
92+
$this->assertTrue(true, 'Cache warmer has successfully filled that cache and went without exceptions');
93+
}
8094
}
8195

8296
class WebpackEncoreIntegrationTestKernel extends Kernel
@@ -117,11 +131,13 @@ public function registerContainerConfiguration(LoaderInterface $loader)
117131

118132
$container->loadFromExtension('webpack_encore', [
119133
'output_path' => __DIR__.'/fixtures/build',
120-
'cache' => false,
134+
'cache' => true,
121135
'builds' => [
122136
'different_build' => __DIR__.'/fixtures/different_build'
123137
]
124138
]);
139+
140+
$container->autowire(CacheWarmerTester::class)->setPublic(true);
125141
});
126142
}
127143

@@ -135,3 +151,18 @@ public function getLogDir()
135151
return sys_get_temp_dir().'/logs'.spl_object_hash($this);
136152
}
137153
}
154+
155+
class CacheWarmerTester
156+
{
157+
private $entrypointCacheWarmer;
158+
159+
public function __construct(EntrypointCacheWarmer $entrypointCacheWarmer)
160+
{
161+
$this->entrypointCacheWarmer = $entrypointCacheWarmer;
162+
}
163+
164+
public function warmCache(string $cacheDir)
165+
{
166+
$this->entrypointCacheWarmer->warmUp($cacheDir);
167+
}
168+
}

0 commit comments

Comments
 (0)