Skip to content

Commit 53abcda

Browse files
committed
move complile to dump
1 parent 44a50ac commit 53abcda

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/PTS/SymfonyDiLoader/LoaderContainer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ protected function createContainer(): ContainerInterface
7676

7777
if (!($appContainer instanceof ContainerInterface)) {
7878
$appContainer = $this->getFactory()->create($this->configFiles);
79-
$appContainer->compile(true);
80-
$this->flushContainerToFile($this->cacheFile, $this->classContainer, $appContainer);
79+
$this->dump($this->cacheFile, $this->classContainer, $appContainer);
8180
}
8281

8382
return $appContainer;
@@ -90,8 +89,9 @@ protected function createContainer(): ContainerInterface
9089
*
9190
* @throws EnvParameterException
9291
*/
93-
protected function flushContainerToFile(string $filePath, string $className, ContainerBuilder $container): void
92+
protected function dump(string $filePath, string $className, ContainerBuilder $container): void
9493
{
94+
$container->compile(true);
9595
$dumper = new PhpDumper($container);
9696
file_put_contents($filePath, $dumper->dump([
9797
'class' => $className,

test/unit/LoaderContainerTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ public function testCreateContainerFromCache(): void
201201

202202
/** @var MockObject|LoaderContainer $loader */
203203
$loader = $this->getMockBuilder(LoaderContainer::class)
204-
->setMethods(['getContainerFromCache', 'flushContainerToFile', 'getFactory'])
204+
->setMethods(['getContainerFromCache', 'dump', 'getFactory'])
205205
->setConstructorArgs([$arg1, $arg2, $arg3])
206206
->getMock();
207207
$loader->expects(self::once())->method('getContainerFromCache')->with($arg2, $arg1)->willReturn($container);
208208
$loader->expects(self::never())->method('getFactory');
209-
$loader->expects(self::never())->method('flushContainerToFile');
209+
$loader->expects(self::never())->method('dump');
210210

211211
$createContainer = new \ReflectionMethod(LoaderContainer::class, 'createContainer');
212212
$createContainer->setAccessible(true);
@@ -234,12 +234,12 @@ public function testCreateContainerFromFactory(): void
234234

235235
/** @var MockObject|LoaderContainer $loader */
236236
$loader = $this->getMockBuilder(LoaderContainer::class)
237-
->setMethods(['getContainerFromCache', 'flushContainerToFile', 'getFactory'])
237+
->setMethods(['getContainerFromCache', 'dump', 'getFactory'])
238238
->setConstructorArgs([$arg1, $arg2, $arg3])
239239
->getMock();
240240
$loader->expects(self::once())->method('getContainerFromCache')->with($arg2, $arg1)->willReturn(null);
241241
$loader->expects(self::once())->method('getFactory')->willReturn($factory);
242-
$loader->expects(self::once())->method('flushContainerToFile')->willReturn($arg2);
242+
$loader->expects(self::once())->method('dump')->willReturn($arg2);
243243

244244
$createContainer = new \ReflectionMethod(LoaderContainer::class, 'createContainer');
245245
$createContainer->setAccessible(true);
@@ -251,19 +251,18 @@ public function testCreateContainerFromFactory(): void
251251
/**
252252
* @throws \ReflectionException
253253
*/
254-
public function testFlushContainerToFile(): void
254+
public function testDump(): void
255255
{
256256
$root = vfsStream::setup('/temp');
257257
$filePath = vfsStream::newFile('cache.php')->at($root)->url();
258258

259259
$className = 'AppContainer';
260260
$container = new ContainerBuilder;
261-
$container->compile();
262261

263262
$loader = $this->createMock(LoaderContainer::class);
264-
$flushContainerToFile = new \ReflectionMethod(LoaderContainer::class, 'flushContainerToFile');
265-
$flushContainerToFile->setAccessible(true);
266-
$flushContainerToFile->invoke($loader, $filePath, $className, $container);
263+
$dump = new \ReflectionMethod(LoaderContainer::class, 'dump');
264+
$dump->setAccessible(true);
265+
$dump->invoke($loader, $filePath, $className, $container);
267266

268267
$fileContent = file_get_contents($filePath);
269268
self::assertTrue((bool)\strlen($fileContent));

0 commit comments

Comments
 (0)