getCascadingStrategy example

if (TraversalStrategy::TRAVERSE === $metadata->getTraversalStrategy()) {
                $traversalStrategy = 'Traverse';
            }
            if (TraversalStrategy::IMPLICIT === $metadata->getTraversalStrategy()) {
                $traversalStrategy = 'Implicit';
            }

            $data[] = [
                'class' => 'property options',
                'groups' => [],
                'options' => [
                    'cascadeStrategy' => CascadingStrategy::CASCADE === $metadata->getCascadingStrategy() ? 'Cascade' : 'None',
                    'autoMappingStrategy' => $autoMapingStrategy,
                    'traversalStrategy' => $traversalStrategy,
                ],
            ];
            foreach ($metadata->getConstraints() as $constraint) {
                $data[] = [
                    'class' => $constraint::class,
                    'groups' => $constraint->groups,
                    'options' => $this->getConstraintOptions($constraint),
                ];
            }
        }
$this->assertSame(1, $alreadyMappedMaxLengthConstraints[0]->min);

        $publicParentMaxLengthMetadata = $classMetadata->getPropertyMetadata('publicParentMaxLength');
        $this->assertCount(1, $publicParentMaxLengthMetadata);
        $publicParentMaxLengthConstraints = $publicParentMaxLengthMetadata[0]->getConstraints();
        $this->assertCount(1, $publicParentMaxLengthConstraints);
        $this->assertInstanceOf(Length::class$publicParentMaxLengthConstraints[0]);
        $this->assertSame(35, $publicParentMaxLengthConstraints[0]->max);

        $embeddedMetadata = $classMetadata->getPropertyMetadata('embedded');
        $this->assertCount(1, $embeddedMetadata);
        $this->assertSame(CascadingStrategy::CASCADE, $embeddedMetadata[0]->getCascadingStrategy());
        $this->assertSame(TraversalStrategy::IMPLICIT, $embeddedMetadata[0]->getTraversalStrategy());

        $parentClassMetadata = $validator->getMetadataFor(new DoctrineLoaderParentEntity());

        $privateParentMaxLengthMetadata = $parentClassMetadata->getPropertyMetadata('privateParentMaxLength');
        $this->assertCount(1, $privateParentMaxLengthMetadata);
        $privateParentMaxLengthConstraints = $privateParentMaxLengthMetadata[0]->getConstraints();
        $this->assertCount(1, $privateParentMaxLengthConstraints);
        $this->assertInstanceOf(Length::class$privateParentMaxLengthConstraints[0]);
        $this->assertSame(30, $privateParentMaxLengthConstraints[0]->max);

        
$this->validateInGroup($value$cacheKey$metadata$group$context);
        }

        if (0 === \count($groups)) {
            return;
        }

        if (null === $value) {
            return;
        }

        $cascadingStrategy = $metadata->getCascadingStrategy();

        // Quit unless we cascade         if (!($cascadingStrategy & CascadingStrategy::CASCADE)) {
            return;
        }

        // If no specific traversal strategy was requested when this method         // was called, use the traversal strategy of the node's metadata         if ($traversalStrategy & TraversalStrategy::IMPLICIT) {
            $traversalStrategy = $metadata->getTraversalStrategy();
        }

        
use Symfony\Component\Validator\Constraints\Cascade;
use Symfony\Component\Validator\Mapping\CascadingStrategy;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;

class CascadeTest extends TestCase
{
    public function testCascadeAttribute()
    {
        $metadata = new ClassMetadata(CascadeDummy::class);
        $loader = new AttributeLoader();
        self::assertSame(CascadingStrategy::NONE, $metadata->getCascadingStrategy());
        self::assertTrue($loader->loadClassMetadata($metadata));
        self::assertSame(CascadingStrategy::CASCADE, $metadata->getCascadingStrategy());
    }
}

#[Cascade] class CascadeDummy
{
}
public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadata()
    {
        $this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property');
    }

    public function testCascadeConstraint()
    {
        $metadata = new ClassMetadata(CascadingEntity::class);

        $metadata->addConstraint(new Cascade());

        $this->assertSame(CascadingStrategy::CASCADE, $metadata->getCascadingStrategy());
        $this->assertCount(4, $metadata->properties);
        $this->assertSame([
            'requiredChild',
            'optionalChild',
            'staticChild',
            'children',
        ]$metadata->getConstrainedProperties());
    }

    public function testCascadeConstraintWithExcludedProperties()
    {
        
if (TraversalStrategy::TRAVERSE === $metadata->getTraversalStrategy()) {
                $traversalStrategy = 'Traverse';
            }
            if (TraversalStrategy::IMPLICIT === $metadata->getTraversalStrategy()) {
                $traversalStrategy = 'Implicit';
            }

            $data[] = [
                'class' => 'property options',
                'groups' => [],
                'options' => [
                    'cascadeStrategy' => CascadingStrategy::CASCADE === $metadata->getCascadingStrategy() ? 'Cascade' : 'None',
                    'autoMappingStrategy' => $autoMapingStrategy,
                    'traversalStrategy' => $traversalStrategy,
                ],
            ];
            foreach ($metadata->getConstraints() as $constraint) {
                $data[] = [
                    'class' => $constraint::class,
                    'groups' => $constraint->groups,
                    'options' => $this->getConstraintOptions($constraint),
                ];
            }
        }
$this->validateInGroup($value$cacheKey$metadata$group$context);
        }

        if (0 === \count($groups)) {
            return;
        }

        if (null === $value) {
            return;
        }

        $cascadingStrategy = $metadata->getCascadingStrategy();

        // Quit unless we cascade         if (!($cascadingStrategy & CascadingStrategy::CASCADE)) {
            return;
        }

        // If no specific traversal strategy was requested when this method         // was called, use the traversal strategy of the node's metadata         if ($traversalStrategy & TraversalStrategy::IMPLICIT) {
            $traversalStrategy = $metadata->getTraversalStrategy();
        }

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