<commit_before><?php

namespace LeanlinkBundle\Tests\Service;

use AppBundle\Entity\ConnectionRequest;
use AppBundle\Entity\MusicCategory;
use AppBundle\Entity\User;
use AppBundle\Validator\Constraints\UserHasMusicCategories;
use AppBundle\Validator\Constraints\UserHasMusicCategoriesValidator;
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;

class UserHasMusicCategoriesValidatorTest extends AbstractConstraintValidatorTest
{
    protected function createValidator()
    {
        return new UserHasMusicCategoriesValidator();
    }

    /**
     * @test
     */
    public function nonMusicConnectionRequestIsValid()
    {
        $connectionRequestMock = $this->getMock(ConnectionRequest::class);
        $connectionRequestMock->expects($this->once())->method('isMusicFriend')->willReturn(false);
        $connectionRequestMock->expects($this->never())->method('getUser');
        $this->validator->validate($connectionRequestMock, new UserHasMusicCategories());
        $this->assertNoViolation();
    }

    /**
     * @test
     */
    public function musicConnectionRequestWithMusicCategoriesIsValid()
    {
        $userMock = $this->getMock(User::class);
        $userMock->expects($this->once())->method('getMusicCategories')->willReturn([$this->getMock(MusicCategory::class)]);
        $connectionRequestMock = $this->getMock(ConnectionRequest::class);
        $connectionRequestMock->expects($this->once())->method('getUser')->willReturn($userMock);
        $connectionRequestMock->expects($this->once())->method('isMusicFriend')->willReturn(true);
        $this->validator->validate($connectionRequestMock, new UserHasMusicCategories());
        $this->assertNoViolation();
    }

    /**
     * @test
     */
    public function musicConnectionRequestWithoutMusicCategoriesIsNotValid()
    {
        $userMock = $this->getMock(User::class);
        $userMock->expects($this->once())->method('getMusiCCategories')->willReturn([]);
        $connectionRequestMock = $this->getMock(ConnectionRequest::class);
        $connectionRequestMock->expects($this->once())->method('getUser')->willReturn($userMock);
        $connectionRequestMock->expects($this->once())->method('isMusicFriend')->willReturn(true);
        $this->validator->validate($connectionRequestMock, new UserHasMusicCategories());
        $this->buildViolation('För att vara musikompis måste du ha anget några musikkategorier på din profil.')->assertRaised();
    }<commit_msg>php 5.4 syntax<commit_after><?php

namespace LeanlinkBundle\Tests\Service;

use AppBundle\Entity\ConnectionRequest;
use AppBundle\Entity\MusicCategory;
use AppBundle\Entity\User;
use AppBundle\Validator\Constraints\UserHasMusicCategories;
use AppBundle\Validator\Constraints\UserHasMusicCategoriesValidator;
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;

class UserHasMusicCategoriesValidatorTest extends AbstractConstraintValidatorTest
{
    protected function createValidator()
    {
        return new UserHasMusicCategoriesValidator();
    }

    /**
     * @test
     */
    public function nonMusicConnectionRequestIsValid()
    {
        $connectionRequestMock = $this->getMock('AppBundle\Entity\ConnectionRequest');
        $connectionRequestMock->expects($this->once())->method('isMusicFriend')->willReturn(false);
        $connectionRequestMock->expects($this->never())->method('getUser');
        $this->validator->validate($connectionRequestMock, new UserHasMusicCategories());
        $this->assertNoViolation();
    }

    /**
     * @test
     */
    public function musicConnectionRequestWithMusicCategoriesIsValid()
    {
        $userMock = $this->getMock('AppBundle\Entity\User');
        $userMock->expects($this->once())->method('getMusicCategories')->willReturn([$this->getMock('AppBundle\Entity\MusicCategory')]);
        $connectionRequestMock = $this->getMock('AppBundle\Entity\ConnectionRequest');
        $connectionRequestMock->expects($this->once())->method('getUser')->willReturn($userMock);
        $connectionRequestMock->expects($this->once())->method('isMusicFriend')->willReturn(true);
        $this->validator->validate($connectionRequestMock, new UserHasMusicCategories());
        $this->assertNoViolation();
    }

    /**
     * @test
     */
    public function musicConnectionRequestWithoutMusicCategoriesIsNotValid()
    {
        $userMock = $this->getMock('AppBundle\Entity\User');
        $userMock->expects($this->once())->method('getMusiCCategories')->willReturn([]);
        $connectionRequestMock = $this->getMock('AppBundle\Entity\ConnectionRequest');
        $connectionRequestMock->expects($this->once())->method('getUser')->willReturn($userMock);
        $connectionRequestMock->expects($this->once())->method('isMusicFriend')->willReturn(true);
        $this->validator->validate($connectionRequestMock, new UserHasMusicCategories());
        $this->buildViolation('För att vara musikompis måste du ha anget några musikkategorier på din profil.')->assertRaised();
    }
{'fraction_non_alphanumeric': 0.14517726282432164, 'fraction_numerical': 0.0003961180431768667, 'mean_word_length': 4.764840182648402, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 97, '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': '6275757', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1313, 'n_words': 160}