<commit_before><?php

namespace BDBStudios\BreakfastSerializerTests;

use BDBStudios\BreakfastSerializer\Serializer;
use BDBStudios\BreakfastSerializerTest\Fixtures\ComplexClass;

class SerializerTest extends \PHPUnit_Framework_TestCase
{
    /** @var  Serializer */
    protected $instance;

    public function setUp()
    {
        $this->instance =
            \Mockery::mock(
                'BDBStudios\BreakfastSerializer\Serializer',
                array(Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET)
            )
            ->shouldDeferMissing();
    }

    public function testSetup()
    {
        $this->assertTrue($this->instance instanceof Serializer);
    }

    public function testGetSetDepth()
    {
        $expected = 5;

        $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer);
        $this->assertNotEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertEquals($expected, $this->instance->getDepth());
    }

    /**
     * @expectedException \LogicException
     * @expectedExceptionMessage BDBStudios\BreakfastSerializer\Serializer::setDepth expects an int but a string was supplied
     */
    public function testGetSetDepthThrowsExceptionWithString()
    {
        $expected = 'five';
        $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer);
    }

    /**
     * @expectedException \LogicException
     * @expectedExceptionMessage The maximum depth should be non zero, non negative
     */
    public function testSettingDepthToZeroThrowsException()
    {
        $expected = 0;
        $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer);
    }

    public function testIncrementDecrementCurrentDepth()
    {
        $maxDepth = 3;

        $this->instance->setDepth($maxDepth);
        $this->assertEquals($maxDepth, $this->instance->getDepth());
        $this->assertEquals(1, $this->instance->getCurrentDepth());
        $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer);
        $this->assertTrue($this->instance->isWithinBounds());
        $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer);
        $this->assertEquals($maxDepth, $this->instance->getCurrentDepth());
        $this->assertTrue($this->instance->isWithinBounds());
        $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer);
        $this->assertFalse($this->instance->isWithinBounds());
        $this->assertTrue($this->instance->decrementCurrentDepth() instanceof Serializer);
        $this->assertTrue($this->instance->isWithinBounds());

        $this->instance->resetCurrentDepth();
        $this->assertNotEquals($maxDepth, $this->instance->getCurrentDepth());
    }
}
<commit_msg>fixup! Added configuration option<commit_after><?php

namespace BDBStudios\BreakfastSerializerTests;

use BDBStudios\BreakfastSerializer\Serializer;
use BDBStudios\BreakfastSerializerTest\Fixtures\ComplexClass;
use BDBStudios\BreakfastSerializerTest\Fixtures\TypeHandlers\DateTimeType;

class SerializerTest extends \PHPUnit_Framework_TestCase
{
    /** @var  Serializer */
    protected $instance;

    public function setUp()
    {
        $this->instance =
            \Mockery::mock(
                'BDBStudios\BreakfastSerializer\Serializer',
                array(Serializer::FORMAT_JSON, Serializer::MAX_DEPTH_NOT_SET)
            )
                ->shouldDeferMissing();


    }

    public function testSetup()
    {
        $this->assertTrue($this->instance instanceof Serializer);
    }

    public function testGetSetDepth()
    {
        $expected = 5;

        $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer);
        $this->assertNotEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertEquals($expected, $this->instance->getDepth());
    }

    /**
     * @expectedException \LogicException
     * @expectedExceptionMessage BDBStudios\BreakfastSerializer\Serializer::setDepth expects an int but a string was supplied
     */
    public function testGetSetDepthThrowsExceptionWithString()
    {
        $expected = 'five';
        $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer);
    }

    /**
     * @expectedException \LogicException
     * @expectedExceptionMessage The maximum depth should be non zero, non negative
     */
    public function testSettingDepthToZeroThrowsException()
    {
        $expected = 0;
        $this->assertEquals(Serializer::MAX_DEPTH_NOT_SET, $this->instance->getDepth());
        $this->assertTrue($this->instance->setDepth($expected) instanceof Serializer);
    }

    public function testIncrementDecrementCurrentDepth()
    {
        $maxDepth = 3;

        $this->instance->setDepth($maxDepth);
        $this->assertEquals($maxDepth, $this->instance->getDepth());
        $this->assertEquals(1, $this->instance->getCurrentDepth());
        $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer);
        $this->assertTrue($this->instance->isWithinBounds());
        $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer);
        $this->assertEquals($maxDepth, $this->instance->getCurrentDepth());
        $this->assertTrue($this->instance->isWithinBounds());
        $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer);
        $this->assertFalse($this->instance->isWithinBounds());
        $this->assertTrue($this->instance->decrementCurrentDepth() instanceof Serializer);
        $this->assertTrue($this->instance->isWithinBounds());

        $this->instance->resetCurrentDepth();
        $this->assertNotEquals($maxDepth, $this->instance->getCurrentDepth());
    }

    public function testDateIsConvertedToString()
    {
        $testInstance = new DateTimeType();

        $value = $testInstance->__get('dateTime');
        $this->assertTrue($testInstance->isDateTime($value));
        $stringValue = $testInstance->toISO8601Format($value);

        $this->assertTrue(is_string($stringValue));

        $this->assertEquals($value->format(\DateTime::ISO8601), $stringValue);
    }

    public function testDateIsSerializedToString()
    {
        $testInstance = new DateTimeType();

        $value       = $testInstance->__get('dateTime');
        $stringValue = $testInstance->toISO8601Format($value);

        $data = array(
            'dateTime'      => $stringValue,
            'invalidString' => $value->format(\DateTime::COOKIE),
            'className'     => get_class($testInstance)
        );

        $this->instance->shouldReceive('serialize')->withAnyArgs()->andReturn(json_encode($data));

        $serializedData = $this->instance->serialize($testInstance);

        $this->assertContains($stringValue, $serializedData);
    }
}
{'fraction_non_alphanumeric': 0.1386960664216687, 'fraction_numerical': 0.0027221995372260785, 'mean_word_length': 3.5810473815461346, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 159, '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': '6335039', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1921, 'n_words': 280}