<commit_before><?php
namespace Oro\Bundle\SegmentBundle\Tests\Unit\Entity;

use Oro\Bundle\SegmentBundle\Entity\Segment;

class SegmentTest extends \PHPUnit_Framework_TestCase
{
    /** @var Segment */
    protected $entity;

    public function setUp()
    {
        $this->entity = new Segment();
    }

    public function tearDown()
    {
        unset($this->entity);
    }

    public function testSettersAndGetters()
    {
        $this->assertNull($this->entity->getId());
        $this->assertNull($this->entity->getName());
        $this->assertNull($this->entity->getDefinition());
        $this->assertNull($this->entity->getDescription());
        $this->assertNull($this->entity->getType());
        $this->assertNull($this->entity->getEntity());
        $this->assertNull($this->entity->getOwner());
        $this->assertNull($this->entity->getCreatedAt());
        $this->assertNull($this->entity->getUpdatedAt());
        $this->assertNull($this->entity->getLastRun());

        $testData = uniqid('name');
        $this->entity->setName($testData);
        $this->assertEquals($testData, $this->entity->getName());

        $testData = uniqid('definition');
        $this->entity->setDefinition($testData);
        $this->assertEquals($testData, $this->entity->getDefinition());

        $testData = uniqid('description');
        $this->entity->setDescription($testData);
        $this->assertEquals($testData, $this->entity->getDescription());

        $testData = $this->getMock('Oro\Bundle\SegmentBundle\Entity\SegmentType', [], ['testTypeName']);
        $this->entity->setType($testData);
        $this->assertSame($testData, $this->entity->getType());

        $testData = $this->getMock('Oro\Bundle\OrganizationBundle\Entity\BusinessUnit');
        $this->entity->setOwner($testData);
        $this->assertSame($testData, $this->entity->getOwner());

        $testData = uniqid('entity');
        $this->entity->setEntity($testData);
        $this->assertEquals($testData, $this->entity->getEntity());

        $testData = new \DateTime();
        $this->entity->setCreatedAt($testData);
        $this->assertSame($testData, $this->entity->getCreatedAt());

        $testData = new \DateTime();
        $this->entity->setUpdatedAt($testData);
        $this->assertSame($testData, $this->entity->getUpdatedAt());

        $testData = new \DateTime();
        $this->entity->setLastRun($testData);
        $this->assertSame($testData, $this->entity->getLastRun());
    }

    public function testLifecycleCallbacks()
    {
        $segment = new Segment();

        $segment->beforeSave();
        $this->assertNotNull($segment->getCreatedAt());
        $this->assertNotNull($segment->getUpdatedAt());
        $this->assertEquals($segment->getCreatedAt(), $segment->getUpdatedAt());

        $segment = new Segment();
        $segment->doUpdate();
        $this->assertNull($segment->getCreatedAt());
        $this->assertNotNull($segment->getUpdatedAt());
        $this->assertNotEquals($segment->getCreatedAt(), $segment->getUpdatedAt());
    }
}<commit_msg>BAP-3391: Segments CRUD - fix unit tests<commit_after><?php
namespace Oro\Bundle\SegmentBundle\Tests\Unit\Entity;

use Oro\Bundle\SegmentBundle\Entity\Segment;

class SegmentTest extends \PHPUnit_Framework_TestCase
{
    /** @var Segment */
    protected $entity;

    public function setUp()
    {
        $this->entity = new Segment();
    }

    public function tearDown()
    {
        unset($this->entity);
    }

    public function testSettersAndGetters()
    {
        $this->assertNull($this->entity->getId());
        $this->assertNull($this->entity->getName());
        $this->assertNull($this->entity->getDefinition());
        $this->assertNull($this->entity->getDescription());
        $this->assertNull($this->entity->getType());
        $this->assertNull($this->entity->getEntity());
        $this->assertNull($this->entity->getOwner());
        $this->assertNull($this->entity->getCreatedAt());
        $this->assertNull($this->entity->getUpdatedAt());
        $this->assertNull($this->entity->getLastRun());

        $testData = uniqid('name');
        $this->entity->setName($testData);
        $this->assertEquals($testData, $this->entity->getName());

        $testData = uniqid('definition');
        $this->entity->setDefinition($testData);
        $this->assertEquals($testData, $this->entity->getDefinition());

        $testData = uniqid('description');
        $this->entity->setDescription($testData);
        $this->assertEquals($testData, $this->entity->getDescription());

        $testData = $this->getMock('Oro\Bundle\SegmentBundle\Entity\SegmentType', [], ['testTypeName']);
        $this->entity->setType($testData);
        $this->assertSame($testData, $this->entity->getType());

        $testData = $this->getMock('Oro\Bundle\OrganizationBundle\Entity\BusinessUnit');
        $this->entity->setOwner($testData);
        $this->assertSame($testData, $this->entity->getOwner());

        $testData = uniqid('entity');
        $this->entity->setEntity($testData);
        $this->assertEquals($testData, $this->entity->getEntity());

        $testData = new \DateTime();
        $this->entity->setCreatedAt($testData);
        $this->assertSame($testData, $this->entity->getCreatedAt());

        $testData = new \DateTime();
        $this->entity->setUpdatedAt($testData);
        $this->assertSame($testData, $this->entity->getUpdatedAt());

        $testData = new \DateTime();
        $this->entity->setLastRun($testData);
        $this->assertSame($testData, $this->entity->getLastRun());
    }

    public function testLifecycleCallbacks()
    {
        $segment = new Segment();

        $segment->beforeSave();
        $this->assertInstanceOf('\DateTime', $segment->getCreatedAt());
        $this->assertInstanceOf('\DateTime', $segment->getUpdatedAt());
        $this->assertEquals($segment->getCreatedAt(), $segment->getUpdatedAt());

        $segment = new Segment();
        $segment->doUpdate();
        $this->assertEmpty($segment->getCreatedAt());
        $this->assertInstanceOf('\DateTime', $segment->getUpdatedAt());
    }
}
{'fraction_non_alphanumeric': 0.18928571428571428, 'fraction_numerical': 0.0006493506493506494, 'mean_word_length': 3.326544943820225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 190, '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': '2767979', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1725, 'n_words': 214}