<commit_before><?php

namespace Doctrine\ODM\MongoDB\Tests\Functional;

use Documents\Account;
use Documents\BlogPost;
use Documents\CmsArticle;
use Documents\CmsComment;
use Documents\Comment;
use Documents\Developer;
use Documents\Group;
use Documents\Project;
use Documents\User;

class RemoveTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
    public function testRemove()
    {
        $account = new Account();
        $account->setName('Jon Test Account');

        $user = new User();
        $user->setUsername('jon');
        $user->setPassword('<PASSWORD>');
        $user->setAccount($account);

        $this->dm->persist($user);
        $this->dm->flush();

        $this->dm->remove($user);
        $this->dm->flush();

        $account = $this->dm->find('Documents\Account', $account->getId());
        $this->assertNull($account);

        $user = $this->dm->find('Documents\User', $user->getId());
        $this->assertNull($user);
    }

    public function testUnsetFromEmbeddedCollection()
    {
        $user = new User();
        $user->setUsername('jon');
        $user->addGroup(new Group('test group 1'));
        $user->addGroup(new Group('test group 2'));
        $user->addGroup(new Group('test group 3'));

        $this->dm->persist($user);
        $this->dm->flush();
        $this->dm->clear();

        $user = $this->dm->find('Documents\User', $user->getId());

        $groups = $user->getGroups();
        unset($groups[0]);
        $this->assertEquals(2, count($user->getGroups()));

        $this->dm->flush();
        $this->dm->clear();

        $user = $this->dm->getRepository('Documents\User')->findOneBy(array('username' => 'jon'));

        $this->assertEquals(2, count($user->getGroups()));
    }

    public function testUnsetFromReferencedCollectionWithCascade()
    {
        $developerRepository = $this->dm->getRepository('Documents\Developer');
        $projectRepository = $this->dm->getRepository('Documents\Project');

        // Developer owns the one-to-many relationship and cascades
        $developer = new Developer('developer');
        $project1 = new Project('project1');
        $project2 = new Project('project2');

        $developer->getProjects()->add($project1);
        $developer->getProjects()->add($project2);

        $this->dm->persist($developer);
        $this->dm->flush();
        $this->dm->clear();

        $developer = $developerRepository->find($developer->getId());
        $project1 = $projectRepository->find($project1->getId());<commit_msg>Refactor unset embedded test in RemoveTest<commit_after><?php

namespace Doctrine\ODM\MongoDB\Tests\Functional;

use Documents\Account;
use Documents\BlogPost;
use Documents\CmsArticle;
use Documents\CmsComment;
use Documents\Comment;
use Documents\Developer;
use Documents\Group;
use Documents\Project;
use Documents\User;

class RemoveTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
    public function testRemove()
    {
        $account = new Account();
        $account->setName('Jon Test Account');

        $user = new User();
        $user->setUsername('jon');
        $user->setPassword('<PASSWORD>');
        $user->setAccount($account);

        $this->dm->persist($user);
        $this->dm->flush();

        $this->dm->remove($user);
        $this->dm->flush();

        $account = $this->dm->find('Documents\Account', $account->getId());
        $this->assertNull($account);

        $user = $this->dm->find('Documents\User', $user->getId());
        $this->assertNull($user);
    }

    public function testUnsetFromEmbeddedCollection()
    {
        $userRepository = $this->dm->getRepository('Documents\User');

        $user = new User();
        $user->addGroup(new Group('group1'));
        $user->addGroup(new Group('group2'));
        $user->addGroup(new Group('group3'));

        $this->dm->persist($user);
        $this->dm->flush();
        $this->dm->clear();

        $this->assertCount(3, $user->getGroups());

        $user = $userRepository->find($user->getId());
        $user->getGroups()->remove(0);

        $this->dm->flush();
        $this->dm->clear();

        $user = $userRepository->find($user->getId());

        $this->assertCount(2, $user->getGroups());
    }

    public function testUnsetFromReferencedCollectionWithCascade()
    {
        $developerRepository = $this->dm->getRepository('Documents\Developer');
        $projectRepository = $this->dm->getRepository('Documents\Project');

        // Developer owns the one-to-many relationship and cascades
        $developer = new Developer('developer');
        $project1 = new Project('project1');
        $project2 = new Project('project2');

        $developer->getProjects()->add($project1);
        $developer->getProjects()->add($project2);

        $this->dm->persist($developer);
        $this->dm->flush();
        $this->dm->clear();

        $developer = $developerRepository->find($developer->getId());
        $project1 = $projectRepository->find($project1->getId());
{'fraction_non_alphanumeric': 0.18237990831174009, 'fraction_numerical': 0.0055810245166434125, 'mean_word_length': 3.0208333333333335, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2273528', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1418, 'n_words': 237}