Skip to content

integration test created for cache warmer #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DependencyInjection/WebpackEncoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function load(array $configs, ContainerBuilder $container)
];
foreach ($config['builds'] as $name => $path) {
$factories[$name] = $this->entrypointFactory($container, $name, $path, $config['cache']);
$cacheKeys[rawurlencode($name)] = $path;
$cacheKeys[rawurlencode($name)] = $path.'/entrypoints.json';
}

$container->getDefinition('webpack_encore.entrypoint_lookup.cache_warmer')
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<argument type="service" id="cache.webpack_encore" />
</service>

<service id="Symfony\WebpackEncoreBundle\CacheWarmer\EntrypointCacheWarmer" alias="webpack_encore.entrypoint_lookup.cache_warmer" />

<service id="webpack_encore.cache" class="Symfony\Component\Cache\Adapter\PhpArrayAdapter">
<factory class="Symfony\Component\Cache\Adapter\PhpArrayAdapter" method="create" />
<argument>%kernel.cache_dir%/webpack_encore.cache.php</argument>
Expand Down
33 changes: 32 additions & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Symfony\WebpackEncoreBundle\Tests;

use Symfony\WebpackEncoreBundle\CacheWarmer\EntrypointCacheWarmer;
use Symfony\WebpackEncoreBundle\WebpackEncoreBundle;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
Expand Down Expand Up @@ -77,6 +78,19 @@ public function testEntriesAreNotRepeteadWhenAlreadyOutputIntegration()
$html2
);
}

public function testCacheWarmer()
{
$kernal = new WebpackEncoreIntegrationTestKernel(true);
$kernal->boot();
$container = $kernal->getContainer();

$cacheWarmer = $container->get(CacheWarmerTester::class);

$cacheWarmer->warmCache($kernal->getCacheDir());

$this->assertTrue(true, 'Cache warmer has successfully filled that cache and went without exceptions');
}
}

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

$container->loadFromExtension('webpack_encore', [
'output_path' => __DIR__.'/fixtures/build',
'cache' => false,
'cache' => true,
'builds' => [
'different_build' => __DIR__.'/fixtures/different_build'
]
]);

$container->autowire(CacheWarmerTester::class)->setPublic(true);
});
}

Expand All @@ -135,3 +151,18 @@ public function getLogDir()
return sys_get_temp_dir().'/logs'.spl_object_hash($this);
}
}

class CacheWarmerTester
{
private $entrypointCacheWarmer;

public function __construct(EntrypointCacheWarmer $entrypointCacheWarmer)
{
$this->entrypointCacheWarmer = $entrypointCacheWarmer;
}

public function warmCache(string $cacheDir)
{
$this->entrypointCacheWarmer->warmUp($cacheDir);
}
}