<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of the Sonata Project package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\AdminBundle\Tests\Manipulator;

use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Manipulator\ObjectManipulator;

class ObjectManipulatorTest extends TestCase
{
    public function testAddInstance(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBar']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $instance = new \stdClass();
        $object = $this->getMockBuilder(\stdClass::class)->setMethods(['addFooBar'])->getMock();
        $object->expects($this->once())->method('addFooBar')->with($instance);

        ObjectManipulator::addInstance($object, $instance, $fieldDescription);
    }

    public function testAddInstanceWithParentAssociation(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBar']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([['fieldName' => 'parent']]);

        $instance = new \stdClass();

        $object2 = $this->getMockBuilder(\stdClass::class)->setMethods(['addFooBar'])->getMock();
        $object2->expects($this->once())->method('addFooBar')->with($instance);

        $object1 = $this->getMockBuilder(\stdClass::class)->setMethods(['getParent'])->getMock();
        $object1->expects($this->once())->method('getParent')->willReturn($object2);

        ObjectManipulator::addInstance($object1, $instance, $fieldDescription);
    }

    public function testAddInstancePlural(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBars']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $instance = new \stdClass();
        $object = $this->getMockBuilder(\stdClass::class)->setMethods(['addFooBar'])->getMock();
        $object->expects($this->once())->method('addFooBar')->with($instance);

        ObjectManipulator::addInstance($object, $instance, $fieldDescription);
    }

    public function testAddInstanceInflector(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'entries']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $instance = new \stdClass();
        $object = $this->getMockBuilder(\stdClass::class)->setMethods(['addEntry'])->getMock();
        $object->expects($this->once())->method('addEntry')->with($instance);

        ObjectManipulator::addInstance($object, $instance, $fieldDescription);
    }

    public function testSetObject(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['mappedBy' => 'parent']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $object = new \stdClass();
        $instance = $this->getMockBuilder(\stdClass::class)->setMethods(['setParent'])->getMock();
        $instance->expects($this->once())->method('setParent')->with($object);

        ObjectManipulator::setObject($instance, $object, $fieldDescription);
    }

    public function testSetObjectWithParentAssociation(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['mappedBy' => 'fooBar']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([['fieldName' => 'parent']]);

        $object2 = new \stdClass();

        $instance = $this->getMockBuilder(\stdClass::class)->setMethods(['setFooBar'])->getMock();
        $instance->expects($this->once())->method('setFooBar')->with($object2);

        $object1 = $this->getMockBuilder(\stdClass::class)->setMethods(['getParent'])->getMock();
        $object1->expects($this->once())->method('getParent')->willReturn($object2);

        ObjectManipulator::setObject($instance, $object1, $fieldDescription);
    }
}
<commit_msg>Add test<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of the Sonata Project package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\AdminBundle\Tests\Manipulator;

use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Manipulator\ObjectManipulator;

class ObjectManipulatorTest extends TestCase
{
    public function testAddInstance(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBar']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $instance = new \stdClass();
        $object = $this->getMockBuilder(\stdClass::class)->setMethods(['addFooBar'])->getMock();
        $object->expects($this->once())->method('addFooBar')->with($instance);

        ObjectManipulator::addInstance($object, $instance, $fieldDescription);
    }

    public function testAddInstanceWithParentAssociation(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBar']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([['fieldName' => 'parent']]);

        $instance = new \stdClass();

        $object2 = $this->getMockBuilder(\stdClass::class)->setMethods(['addFooBar'])->getMock();
        $object2->expects($this->once())->method('addFooBar')->with($instance);

        $object1 = $this->getMockBuilder(\stdClass::class)->setMethods(['getParent'])->getMock();
        $object1->expects($this->once())->method('getParent')->willReturn($object2);

        ObjectManipulator::addInstance($object1, $instance, $fieldDescription);
    }

    public function testAddInstancePlural(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBars']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $instance = new \stdClass();
        $object = $this->getMockBuilder(\stdClass::class)->setMethods(['addFooBar'])->getMock();
        $object->expects($this->once())->method('addFooBar')->with($instance);

        ObjectManipulator::addInstance($object, $instance, $fieldDescription);
    }

    public function testAddInstanceInflector(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'entries']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $instance = new \stdClass();
        $object = $this->getMockBuilder(\stdClass::class)->setMethods(['addEntry'])->getMock();
        $object->expects($this->once())->method('addEntry')->with($instance);

        ObjectManipulator::addInstance($object, $instance, $fieldDescription);
    }

    public function testSetObject(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['mappedBy' => 'parent']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([]);

        $object = new \stdClass();
        $instance = $this->getMockBuilder(\stdClass::class)->setMethods(['setParent'])->getMock();
        $instance->expects($this->once())->method('setParent')->with($object);

        ObjectManipulator::setObject($instance, $object, $fieldDescription);
    }

    public function testSetObjectWithoutMappedBy(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['mappedBy' => null]);

        ObjectManipulator::setObject(new \stdClass(), new \stdClass(), $fieldDescription);
    }

    public function testSetObjectWithParentAssociation(): void
    {
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['mappedBy' => 'fooBar']);
        $fieldDescription->expects($this->once())->method('getParentAssociationMappings')->willReturn([['fieldName' => 'parent']]);

        $object2 = new \stdClass();

        $instance = $this->getMockBuilder(\stdClass::class)->setMethods(['setFooBar'])->getMock();
        $instance->expects($this->once())->method('setFooBar')->with($object2);

        $object1 = $this->getMockBuilder(\stdClass::class)->setMethods(['getParent'])->getMock();
        $object1->expects($this->once())->method('getParent')->willReturn($object2);

        ObjectManipulator::setObject($instance, $object1, $fieldDescription);
    }
}

{'fraction_non_alphanumeric': 0.18463035019455254, 'fraction_numerical': 0.002529182879377432, 'mean_word_length': 5.012280701754386, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 251, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3007181', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2706, 'n_words': 336}