Skip to content
Closed
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
1 change: 1 addition & 0 deletions UPGRADE-7.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Serializer
* Make `AttributeMetadata` and `ClassMetadata` final
* Deprecate class aliases in the `Annotation` namespace, use attributes instead
* Deprecate getters in attribute classes in favor of public properties
* Deprecate XML configuration format, use YAML or attributes instead

String
------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Cache\Adapter\NullAdapter;
Expand Down Expand Up @@ -39,8 +41,26 @@ private function getArrayPool(string $file): PhpArrayAdapter
return $this->arrayPool = new PhpArrayAdapter($file, new NullAdapter());
}

#[DataProvider('loaderProvider')]
public function testWarmUp(array $loaders)
#[DataProvider('yamlLoaderProvider')]
public function testYamlWarmUp(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);

$warmer = new SerializerCacheWarmer($loaders, $file);
$warmer->warmUp(\dirname($file), \dirname($file));

$this->assertFileExists($file);

$arrayPool = new PhpArrayAdapter($file, new NullAdapter());

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

#[IgnoreDeprecations]
#[Group('legacy')]
#[DataProvider('xmlLoaderProvider')]
public function testXmlWarmUp(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);
Expand All @@ -53,11 +73,31 @@ public function testWarmUp(array $loaders)
$arrayPool = $this->getArrayPool($file);

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
}

#[DataProvider('yamlLoaderProvider')]
public function testYamlWarmUpAbsoluteFilePath(array $loaders)
{
$file = sys_get_temp_dir().'/0/cache-serializer.php';
@unlink($file);

$cacheDir = sys_get_temp_dir().'/1';

$warmer = new SerializerCacheWarmer($loaders, $file);
$warmer->warmUp($cacheDir, $cacheDir);

$this->assertFileExists($file);
$this->assertFileDoesNotExist($cacheDir.'/cache-serializer.php');

$arrayPool = new PhpArrayAdapter($file, new NullAdapter());

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

#[DataProvider('loaderProvider')]
public function testWarmUpAbsoluteFilePath(array $loaders)
#[IgnoreDeprecations]
#[Group('legacy')]
#[DataProvider('xmlLoaderProvider')]
public function testXmlWarmUpAbsoluteFilePath(array $loaders)
{
$file = sys_get_temp_dir().'/0/cache-serializer.php';
@unlink($file);
Expand All @@ -73,11 +113,10 @@ public function testWarmUpAbsoluteFilePath(array $loaders)
$arrayPool = $this->getArrayPool($file);

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

#[DataProvider('loaderProvider')]
public function testWarmUpWithoutBuildDir(array $loaders)
#[DataProvider('yamlLoaderProvider')]
public function testYamlWarmUpWithoutBuildDir(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);
Expand All @@ -89,30 +128,63 @@ public function testWarmUpWithoutBuildDir(array $loaders)

$arrayPool = $this->getArrayPool($file);

$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

public static function loaderProvider(): array
#[IgnoreDeprecations]
#[Group('legacy')]
#[DataProvider('xmlLoaderProvider')]
public function testXmlWarmUpWithoutBuildDir(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);

$warmer = new SerializerCacheWarmer($loaders, $file);
$warmer->warmUp(\dirname($file));

$this->assertFileDoesNotExist($file);

$arrayPool = new PhpArrayAdapter($file, new NullAdapter());

$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
}

public static function yamlLoaderProvider(): array
{
return [
[
[
new LoaderChain([
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
]),
],
],
[
[
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
],
],
];
}

public static function xmlLoaderProvider(): array
{
return [
[
[
new LoaderChain([
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
]),
],
],
[
[
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
],
],
];
}

public function testWarmUpWithoutLoader()
{
$file = sys_get_temp_dir().'/cache-serializer-without-loader.php';
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CHANGELOG
* Make `AttributeMetadata` and `ClassMetadata` final
* Deprecate class aliases in the `Annotation` namespace, use attributes instead
* Deprecate getters in attribute classes in favor of public properties
* Deprecate XML configuration format, use YAML or attributes instead

7.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Loads XML mapping files.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @deprecated since Symfony 7.4, use another loader instead
*/
class XmlFileLoader extends FileLoader
{
Expand All @@ -42,6 +44,8 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
$attributesMetadata = $classMetadata->getAttributesMetadata();

if (isset($this->classes[$classMetadata->getName()])) {
trigger_deprecation('symfony/serializer', '7.4', 'XML configuration format is deprecated, use YAML or attributes instead.');

$xml = $this->classes[$classMetadata->getName()];

foreach ($xml->attribute as $attribute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Serializer\Tests\Mapping\Loader;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
Expand All @@ -32,6 +34,8 @@
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[IgnoreDeprecations]
#[Group('legacy')]
class XmlFileLoaderTest extends TestCase
{
use ContextMappingTestTrait;
Expand Down
Loading