ClassMetadataFactoryCompiler example

public function testItDumpMetadata()
    {
        $classMetatadataFactory = new ClassMetadataFactory(new AnnotationLoader());

        $dummyMetadata = $classMetatadataFactory->getMetadataFor(Dummy::class);
        $maxDepthDummyMetadata = $classMetatadataFactory->getMetadataFor(MaxDepthDummy::class);
        $serializedNameDummyMetadata = $classMetatadataFactory->getMetadataFor(SerializedNameDummy::class);
        $serializedPathDummyMetadata = $classMetatadataFactory->getMetadataFor(SerializedPathDummy::class);
        $serializedPathInConstructorDummyMetadata = $classMetatadataFactory->getMetadataFor(SerializedPathInConstructorDummy::class);

        $code = (new ClassMetadataFactoryCompiler())->compile([
            $dummyMetadata,
            $maxDepthDummyMetadata,
            $serializedNameDummyMetadata,
            $serializedPathDummyMetadata,
            $serializedPathInConstructorDummyMetadata,
        ]);

        file_put_contents($this->dumpPath, $code);
        $compiledMetadata = require $this->dumpPath;

        $this->assertCount(5, $compiledMetadata);

        
use Symfony\Component\Serializer\CacheWarmer\CompiledClassMetadataCacheWarmer;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryCompiler;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;

final class CompiledClassMetadataCacheWarmerTest extends TestCase
{
    public function testItImplementsCacheWarmerInterface()
    {
        $classMetadataFactory = $this->createMock(ClassMetadataFactoryInterface::class);
        $filesystem = $this->createMock(Filesystem::class);

        $compiledClassMetadataCacheWarmer = new CompiledClassMetadataCacheWarmer([]$classMetadataFactorynew ClassMetadataFactoryCompiler()$filesystem);

        $this->assertInstanceOf(CacheWarmerInterface::class$compiledClassMetadataCacheWarmer);
    }

    public function testItIsAnOptionalCacheWarmer()
    {
        $classMetadataFactory = $this->createMock(ClassMetadataFactoryInterface::class);
        $filesystem = $this->createMock(Filesystem::class);

        $compiledClassMetadataCacheWarmer = new CompiledClassMetadataCacheWarmer([]$classMetadataFactorynew ClassMetadataFactoryCompiler()$filesystem);

        
Home | Imprint | This part of the site doesn't use cookies.