<commit_before><?php

/*
 * Chill is a software for social workers
 * 
 * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, 
 * <http://www.champs-libres.coop>, <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace Chill\PersonBundle\Tests\Controller;

ini_set('memory_limit', '-1');

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;

/**
 * Test the creation or deletion of accompanying periods
 * 
 * The person on which the test is done has a (current) period opened (and not 
 * closed) starting the 2015-01-05.
 */
class AccompanyingPeriodControllerTest extends WebTestCase
{
    /**
     *
     * @var \Symfony\Component\BrowserKit\Client
     */
    protected $client;
    
    /**
     *
     * @var Person
     */
    protected $person;
    
    /**
     *
     * @var \Doctrine\ORM\EntityManagerInterface
     */
    protected static $em;
    
    const OPENING_INPUT = 'chill_personbundle_accompanyingperiod[openingDate]';
    const CLOSING_INPUT = 'chill_personbundle_accompanyingperiod[closingDate]';
    const CLOSING_MOTIVE_INPUT = 'chill_personbundle_accompanyingperiod[closingMotive]';
    
    /**
     * Setup before the first test of this class (see phpunit doc)
     */
    public static function setUpBeforeClass()
    {
        static::bootKernel();
        static::$em = static::$kernel->getContainer()
              ->get('doctrine.orm.entity_manager');
    }
    
    /**
     * Setup before each test method (see phpunit doc)
     */
    public function setUp()
    {
        $this->client = static::createClient(array(), array(
           'PHP_AUTH_USER' => 'center a_social',
           'PHP_AUTH_PW'   => 'password',
        ));
        
        $center = static::$em->getRepository('ChillMainBundle:Center')
              ->findOneBy(array('name' => 'Center A'));
        
        $this->person = (new Person(new \DateTime('2015-01-05')))
              ->setFirstName('Roland')
              ->setLastName('Gallorime')
              ->setCenter($center)
              ->setGender(Person::MALE_GENDER);

        static::$em->persist($this->person);
        static::$em->flush();
    }
    
     /**
     * TearDown after each test method (see phpunit doc)
     */
    public function tearDown()
    {
       static::$em->refresh($this->person);
       static::$em->remove($this->person);
       
       static::$em->flush();
    }
    
    protected function generatePeriods(array $periods)
    {
        foreach ($periods as $periodDef) {
            $period = new AccompanyingPeriod(new \DateTime($periodDef['openingDate']));
            
            if (array_key_exists('closingDate', $periodDef)) {
                if (!array_key_exists('closingMotive', $periodDef)) {
                    throw new \LogicalException('you must define a closing '
                          . 'motive into your periods fixtures');
                }
                
                $period->setClosingDate(new \DateTime($periodDef['closingDate']))
                      ->setClosingMotive($periodDef['closingMotive']);
            }
             
            $this->person->addAccompanyingPeriod($period);
            
            static::$em->persist($period);
            
        }
        
        static::$em->flush();
    }
    
    protected function getLastValueOnClosingMotive(\Symfony\Component\DomCrawler\Form $form)
    {
        $values = $form->get(self::CLOSING_MOTIVE_INPUT)
              ->availableOptionValues();
        return end($values);
    }
    
    protected function getRandomClosingMotive()
    {
        $motives = static::$em
                ->getRepository('ChillPersonBundle:AccompanyingPeriod\ClosingMotive')
                ->findAll();
        return end($motives);
    }<commit_msg>Refactoring Tests/Controller/AccompanyingPeriodControllerTest.php : indentation and adding doc<commit_after><?php

/*
 * Chill is a software for social workers
 * 
 * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, 
 * <http://www.champs-libres.coop>, <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace Chill\PersonBundle\Tests\Controller;

ini_set('memory_limit', '-1');

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;

/**
 * Test the creation or deletion of accompanying periods
 * 
 * The person on which the test is done has a (current) period opened (and not 
 * closed) starting the 2015-01-05.
 */
class AccompanyingPeriodControllerTest extends WebTestCase
{
    /** @var \Symfony\Component\BrowserKit\Client */
    protected $client;
    
    /** @var Person The person on which the form is applied*/
    protected $person;
    
    /**  @var \Doctrine\ORM\EntityManagerInterface */
    protected static $em;
    
    const OPENING_INPUT = 'chill_personbundle_accompanyingperiod[openingDate]';
    const CLOSING_INPUT = 'chill_personbundle_accompanyingperiod[closingDate]';
    const CLOSING_MOTIVE_INPUT = 'chill_personbundle_accompanyingperiod[closingMotive]';
    
    /**
     * Setup before the first test of this class (see phpunit doc)
     */
    public static function setUpBeforeClass()
    {
        static::bootKernel();
        static::$em = static::$kernel->getContainer()
              ->get('doctrine.orm.entity_manager');
    }
    
    /**
     * Setup before each test method (see phpunit doc)
     */
    public function setUp()
    {
        $this->client = static::createClient(array(), array(
           'PHP_AUTH_USER' => 'center a_social',
           'PHP_AUTH_PW'   => 'password',
        ));
        
        $center = static::$em->getRepository('ChillMainBundle:Center')
            ->findOneBy(array('name' => 'Center A'));
        
        $this->person = (new Person(new \DateTime('2015-01-05')))
            ->setFirstName('Roland')
            ->setLastName('Gallorime')
            ->setCenter($center)
            ->setGender(Person::MALE_GENDER);

        static::$em->persist($this->person);
        static::$em->flush();
    }
    
     /**
     * TearDown after each test method (see phpunit doc)
     */
    public function tearDown()
    {
       static::$em->refresh($this->person);
       static::$em->remove($this->person);
       
       static::$em->flush();
    }
    
    /**
     * Given an array of periods (key openingDate, closingDate (optioal),
     * closingMotive) generate the periods in the db.
     */ 
    protected function generatePeriods(array $periods)
    {
        foreach ($periods as $periodDef) {
            $period = new AccompanyingPeriod(new \DateTime($periodDef['openingDate']));
            
            if (array_key_exists('closingDate', $periodDef)) {
                if (!array_key_exists('closingMotive', $periodDef)) {
                    throw new \LogicalException('you must define a closing '
                          . 'motive into your periods fixtures');
                }
                
                $period->setClosingDate(new \DateTime($periodDef['closingDate']))
                      ->setClosingMotive($periodDef['closingMotive']);
            }
             
            $this->person->addAccompanyingPeriod($period);
            static::$em->persist($period);
        }
        
        static::$em->flush();
    }
    
    /**
     * Get the last value of a closing motive
     * @var \Symfony\Component\DomCrawler\Form The form
     * @return Chill\PersonBundle\Entity\AccompanyingPeriod The last value of closing
     * motive
     */
    protected function getLastValueOnClosingMotive(\Symfony\Component\DomCrawler\Form $form)
    {
        $values = $form->get(self::CLOSING_MOTIVE_INPUT)
            ->availableOptionValues();
        return end($values);
    }
    
    /**
     * Get a random closing motive
     * @return Chill\PersonBundle\Entity\AccompanyingPeriod The last closing motive
     */
    protected function getRandomClosingMotive()
    {
        $motives = static::$em
            ->getRepository('ChillPersonBundle:AccompanyingPeriod\ClosingMotive')
            ->findAll();
        return end($motives);
    }
{'fraction_non_alphanumeric': 0.11429464471764951, 'fraction_numerical': 0.005417795374036257, 'mean_word_length': 2.4918152055292833, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6955820', 'n_tokens_mistral': 2735, 'n_tokens_neox': 2658, 'n_words': 670}