<commit_before><?php

namespace CultuurNet\UDB3;

use UnexpectedValueException;

class CalendarTest extends \PHPUnit_Framework_TestCase
{
    const START_DATE = '2016-03-06T10:00:00';
    const END_DATE = '2016-03-13T12:00:00';

    const TIMESTAMP_1 = '1457254800';
    const TIMESTAMP_1_START_DATE = '2016-03-06T10:00:00';
    const TIMESTAMP_1_END_DATE = '2016-03-06T10:00:00';
    const TIMESTAMP_2 = '1457859600';
    const TIMESTAMP_2_START_DATE = '2016-03-13T10:00:00';
    const TIMESTAMP_2_END_DATE = '2016-03-13T12:00:00';

    /**
     * @var Calendar
     */
    private $calendar;

    /**
     * @var array
     */
    private $calendarAsArray;

    public function setUp()
    {
        $timestamp1 = new Timestamp(
            self::TIMESTAMP_1_START_DATE,
            self::TIMESTAMP_1_END_DATE
        );

        $timestamp2 = new Timestamp(
            self::TIMESTAMP_2_START_DATE,
            self::TIMESTAMP_2_END_DATE
        );

        $this->calendar = new Calendar(
            Calendar::MULTIPLE,
            self::START_DATE,
            self::END_DATE,
            array(
                self::TIMESTAMP_1 => $timestamp1,
                self::TIMESTAMP_2 => $timestamp2
            )
        );

        $this->calendarAsArray = array(
            'type' => Calendar::MULTIPLE,
            'startDate' => self::START_DATE,
            'endDate' => self::END_DATE,
            'timestamps' => array(
                self::TIMESTAMP_1 => array(
                    'startDate' => self::TIMESTAMP_1_START_DATE,
                    'endDate' => self::TIMESTAMP_1_END_DATE,
                ),
                self::TIMESTAMP_2 => array(
                    'startDate' => self::TIMESTAMP_2_START_DATE,
                    'endDate' => self::TIMESTAMP_2_END_DATE,
                )
            ),
            'openingHours' => array()
        );
    }

    /**
     * @test
     * @expectedException UnexpectedValueException
     */
    public function it_validates_calendar_type()
    {
        new Calendar('unknown');
    }

    /**
     * @test
     * @expectedException UnexpectedValueException
     */
    public function it_validates_start_date()
    {
        new Calendar('multiple');
    }

    /**
     * @test
     */
    public function it_serializes()
    {
        $actual = $this->calendar->serialize();

        $this->assertEquals($this->calendarAsArray, $actual);
    }

    /**
     * @test
     */
    public function it_deserializes()
    {
        $calendar = Calendar::deserialize($this->calendarAsArray);

        $this->assertEquals($this->calendar, $calendar);
    }
}<commit_msg>III-827: Simplified the serialization and deserialization test for Calendar.<commit_after><?php

namespace CultuurNet\UDB3;

use UnexpectedValueException;

class CalendarTest extends \PHPUnit_Framework_TestCase
{
    const START_DATE = '2016-03-06T10:00:00';
    const END_DATE = '2016-03-13T12:00:00';

    const TIMESTAMP_1 = '1457254800';
    const TIMESTAMP_1_START_DATE = '2016-03-06T10:00:00';
    const TIMESTAMP_1_END_DATE = '2016-03-06T10:00:00';
    const TIMESTAMP_2 = '1457859600';
    const TIMESTAMP_2_START_DATE = '2016-03-13T10:00:00';
    const TIMESTAMP_2_END_DATE = '2016-03-13T12:00:00';

    /**
     * @var Calendar
     */
    private $calendar;

    public function setUp()
    {
        $timestamp1 = new Timestamp(
            self::TIMESTAMP_1_START_DATE,
            self::TIMESTAMP_1_END_DATE
        );

        $timestamp2 = new Timestamp(
            self::TIMESTAMP_2_START_DATE,
            self::TIMESTAMP_2_END_DATE
        );

        $this->calendar = new Calendar(
            Calendar::MULTIPLE,
            self::START_DATE,
            self::END_DATE,
            array(
                self::TIMESTAMP_1 => $timestamp1,
                self::TIMESTAMP_2 => $timestamp2
            )
        );
    }

    /**
     * @test
     * @expectedException UnexpectedValueException
     */
    public function it_validates_calendar_type()
    {
        new Calendar('unknown');
    }

    /**
     * @test
     * @expectedException UnexpectedValueException
     */
    public function it_validates_start_date()
    {
        new Calendar('multiple');
    }

    /**
     * @test
     */
    public function it_has_the_exact_original_state_after_serialization_and_deserialization()
    {
        $serialized = $this->calendar->serialize();
        $jsonEncoded = json_encode($serialized);

        $jsonDecoded = json_decode($jsonEncoded, true);
        $deserialized = Calendar::deserialize($jsonDecoded);

        $this->assertEquals($this->calendar, $deserialized);
    }
}
{'fraction_non_alphanumeric': 0.11654459284791038, 'fraction_numerical': 0.054071520896165445, 'mean_word_length': 2.135043889264011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '3910729', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1449, 'n_words': 221}