Skip to content

Commit 8a5cad8

Browse files
Merge branch '4.4' into 5.2
* 4.4: fixed parser Fixed bugs found by psalm [FrameworkBundle] Dont store cache misses on warmup [Cache] skip storing failure-to-save as misses in ArrayAdapter [Validator] Delete obsolete statement in Regex::getHtmlPattern() phpDoc [FrameworkBundle] Remove author comments for configuration and extension [DependencyInjection] Fix "url" env var processor behavior when the url has no path Fixed support for nodes not extending BaseNode add missing queue_name to find(id) in doctrine messenger transport [Serializer] AbstractNormalizer force null for non-optional nullable constructor parameter denormalization when not present in input
2 parents 73ef050 + 815c45f commit 8a5cad8

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Common\Annotations\CachedReader;
1616
use Doctrine\Common\Annotations\Reader;
1717
use Symfony\Component\Cache\Adapter\ArrayAdapter;
18+
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1819
use Symfony\Component\Cache\DoctrineProvider;
1920

2021
/**
@@ -68,6 +69,17 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
6869
return true;
6970
}
7071

72+
/**
73+
* @return string[] A list of classes to preload on PHP 7.4+
74+
*/
75+
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
76+
{
77+
// make sure we don't cache null values
78+
$values = array_filter($values, function ($val) { return null !== $val; });
79+
80+
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values);
81+
}
82+
7183
private function readAllComponents(Reader $reader, string $class)
7284
{
7385
$reflectionClass = new \ReflectionClass($class);

CacheWarmer/ValidatorCacheWarmer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
7474
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
7575
{
7676
// make sure we don't cache null values
77-
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, array_filter($values));
77+
$values = array_filter($values, function ($val) { return null !== $val; });
78+
79+
return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values);
7880
}
7981

8082
/**

DependencyInjection/Configuration.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040

4141
/**
4242
* FrameworkExtension configuration structure.
43-
*
44-
* @author Jeremy Mikola <[email protected]>
45-
* @author Grégoire Pineau <[email protected]>
4643
*/
4744
class Configuration implements ConfigurationInterface
4845
{

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,8 @@
166166
use Symfony\Contracts\Translation\LocaleAwareInterface;
167167

168168
/**
169-
* FrameworkExtension.
170-
*
171-
* @author Fabien Potencier <[email protected]>
172-
* @author Jeremy Mikola <[email protected]>
173-
* @author Kévin Dunglas <[email protected]>
174-
* @author Grégoire Pineau <[email protected]>
169+
* Process the configuration and prepare the dependency injection container with
170+
* parameters and services.
175171
*/
176172
class FrameworkExtension extends Extension
177173
{

Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPUnit\Framework\MockObject\MockObject;
99
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
1010
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
11+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1112
use Symfony\Component\Cache\Adapter\NullAdapter;
1213
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
1314
use Symfony\Component\Cache\DoctrineProvider;
@@ -120,6 +121,35 @@ public function testClassAutoloadExceptionWithUnrelatedException()
120121
spl_autoload_unregister($classLoader);
121122
}
122123

124+
public function testWarmupRemoveCacheMisses()
125+
{
126+
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
127+
$warmer = $this->getMockBuilder(AnnotationsCacheWarmer::class)
128+
->setConstructorArgs([new AnnotationReader(), $cacheFile])
129+
->setMethods(['doWarmUp'])
130+
->getMock();
131+
132+
$warmer->method('doWarmUp')->willReturnCallback(function ($cacheDir, ArrayAdapter $arrayAdapter) {
133+
$arrayAdapter->getItem('foo_miss');
134+
135+
$item = $arrayAdapter->getItem('bar_hit');
136+
$item->set('data');
137+
$arrayAdapter->save($item);
138+
139+
$item = $arrayAdapter->getItem('baz_hit_null');
140+
$item->set(null);
141+
$arrayAdapter->save($item);
142+
143+
return true;
144+
});
145+
146+
$warmer->warmUp($this->cacheDir);
147+
$data = include $cacheFile;
148+
149+
$this->assertCount(1, $data[0]);
150+
$this->assertTrue(isset($data[0]['bar_hit']));
151+
}
152+
123153
/**
124154
* @return MockObject|Reader
125155
*/

0 commit comments

Comments
 (0)