<commit_before><?php

/*
 * This file is part of the Elcodi package.
 *
 * Copyright (c) 2014-2015 Elcodi Networks S.L.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author Elcodi Team <<EMAIL>>
 */

namespace Elcodi\Bundle\NewsletterBundle\Tests\Functional\Service;

use Elcodi\Bundle\TestCommonBundle\Functional\WebTestCase;
use Elcodi\Component\Language\Entity\Interfaces\LanguageInterface;
use Elcodi\Component\Newsletter\Entity\Interfaces\NewsletterSubscriptionInterface;
use Elcodi\Component\Newsletter\Repository\NewsletterSubscriptionRepository;
use Elcodi\Component\Newsletter\Services\NewsletterManager;

/**
 * Class NewsletterManagerTest
 */
class NewsletterManagerTest extends WebTestCase
{
    /**
     * @var NewsletterManager
     *
     * Newsletter manager
     */
    protected $newsletterManager;

    /**
     * @var NewsletterSubscriptionRepository
     *
     * NewsletterSubscription Repository
     */
    protected $newsletterSubscriptionRepository;

    /**
     * Returns the callable name of the service
     *
     * @return string[] service name
     */
    public function getServiceCallableName()
    {
        return ['elcodi.manager.newsletter'];
    }

    /**
     * Load fixtures of these bundles
     *
     * @return array Bundles name where fixtures should be found
     */
    protected function loadFixturesBundles()
    {
        return [
            'ElcodiLanguageBundle',
            'ElcodiNewsletterBundle',
        ];
    }

    /**
     * Set up
     */
    public function setUp()
    {
        parent::setUp();

        $this->newsletterManager = $this
            ->get('elcodi.manager.newsletter');

        $this->newsletterSubscriptionRepository = $this
            ->getRepository('newsletter_subscription');
    }

    /**
     * Test subscribe
     */
    public function testSubscribe()
    {
        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        /**
         * @var LanguageInterface $language
         */
        $language = $this
            ->getRepository('language')
            ->findOneBy([
                'iso' => 'es',
            ]);

        $this
            ->newsletterManager
            ->subscribe('<EMAIL>', $language);

        $this->assertCount(3, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        /**
         * @var NewsletterSubscriptionInterface $newsletterSubscription
         */
        $newsletterSubscription = $this
            ->newsletterSubscriptionRepository
            ->findOneBy([
                'email' => '<EMAIL>',
            ]);

        $this->assertNotEmpty($newsletterSubscription->getHash());
    }

    /**
     * Test subscribe
     */
    public function testSubscribeNoLanguage()
    {
        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        $this
            ->newsletterManager
            ->subscribe('<EMAIL>');

        $this->assertCount(3, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );
    }

    /**
     * Test subscribe
     */
    public function testUnsubscribeExisting()
    {
        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        $this
            ->newsletterManager
            ->unSubscribe('<EMAIL>', '123456789');

        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findAll()
        );

        /**
         * @var LanguageInterface $language
         */
        $language = $this
            ->getRepository('language')
            ->findOneBy([
                'iso' => 'es',
            ]);
<commit_msg>moved setup and teardown before and after class<commit_after><?php

/*
 * This file is part of the Elcodi package.
 *
 * Copyright (c) 2014-2015 Elcodi Networks S.L.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author Elcodi Team <<EMAIL>>
 */

namespace Elcodi\Bundle\NewsletterBundle\Tests\Functional\Service;

use Elcodi\Bundle\TestCommonBundle\Functional\WebTestCase;
use Elcodi\Component\Language\Entity\Interfaces\LanguageInterface;
use Elcodi\Component\Newsletter\Entity\Interfaces\NewsletterSubscriptionInterface;
use Elcodi\Component\Newsletter\Repository\NewsletterSubscriptionRepository;
use Elcodi\Component\Newsletter\Services\NewsletterManager;

/**
 * Class NewsletterManagerTest
 */
class NewsletterManagerTest extends WebTestCase
{
    /**
     * @var NewsletterManager
     *
     * Newsletter manager
     */
    protected $newsletterManager;

    /**
     * @var NewsletterSubscriptionRepository
     *
     * NewsletterSubscription Repository
     */
    protected $newsletterSubscriptionRepository;

    /**
     * Returns the callable name of the service
     *
     * @return string[] service name
     */
    public function getServiceCallableName()
    {
        return ['elcodi.manager.newsletter'];
    }

    /**
     * Load fixtures of these bundles
     *
     * @return array Bundles name where fixtures should be found
     */
    protected static function loadFixturesBundles()
    {
        return [
            'ElcodiLanguageBundle',
            'ElcodiNewsletterBundle',
        ];
    }

    /**
     * Set up
     */
    public function setUp()
    {
        parent::setUp();

        $this->newsletterManager = $this
            ->get('elcodi.manager.newsletter');

        $this->newsletterSubscriptionRepository = $this
            ->getRepository('newsletter_subscription');
    }

    /**
     * Test subscribe
     */
    public function testSubscribe()
    {
        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        /**
         * @var LanguageInterface $language
         */
        $language = $this
            ->getRepository('language')
            ->findOneBy([
                'iso' => 'es',
            ]);

        $this
            ->newsletterManager
            ->subscribe('<EMAIL>', $language);

        $this->assertCount(3, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        /**
         * @var NewsletterSubscriptionInterface $newsletterSubscription
         */
        $newsletterSubscription = $this
            ->newsletterSubscriptionRepository
            ->findOneBy([
                'email' => '<EMAIL>',
            ]);

        $this->assertNotEmpty($newsletterSubscription->getHash());
    }

    /**
     * Test subscribe
     */
    public function testSubscribeNoLanguage()
    {
        static::setUpBeforeClass();
        $this->setUp();

        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        $this
            ->newsletterManager
            ->subscribe('<EMAIL>');

        $this->assertCount(3, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );
    }

    /**
     * Test subscribe
     */
    public function testUnsubscribeExisting()
    {
        static::setUpBeforeClass();
        $this->setUp();

        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findBy([
                    'enabled' => true,
                ])
        );

        $this
            ->newsletterManager
            ->unSubscribe('<EMAIL>', '123456789');

        $this->assertCount(2, $this
                ->newsletterSubscriptionRepository
                ->findAll()
        );

        /**
         * @var LanguageInterface $language
         */
        $language = $this
            ->getRepository('language')
            ->findOneBy([
                'iso' => 'es',
            ]);

{'fraction_non_alphanumeric': 0.11319042758307814, 'fraction_numerical': 0.0052171940569354655, 'mean_word_length': 1.6974609972468644, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 117, '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': '5005801', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2227, 'n_words': 452}