<commit_before><?php
/**
 * @package: chapi
 *
 * @author:  msiebeneicher
 * @since:   2015-08-28
 *
 */


namespace unit\Service\JobRepository;


use Chapi\Entity\Chronos\JobEntity;
use Chapi\Service\JobRepository\JobRepository;
use ChapiTest\src\TestTraits\JobEntityTrait;
use Prophecy\Argument;

class JobRepositoryTest extends \PHPUnit_Framework_TestCase
{
    use JobEntityTrait;

    /** @var \Prophecy\Prophecy\ObjectProphecy */
    private $oRepositoryBridge;

    public function setUp()
    {
        $this->oRepositoryBridge = $this->prophesize('Chapi\Service\JobRepository\BridgeInterface');
    }

    public function testGetJobSuccess()
    {
        $this->oRepositoryBridge
            ->getJobs()
            ->willReturn([
                $this->getValidScheduledJobEntity('JobA')
            ])
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $_oJobEntity = $_oJobRepository->getJob('JobA');

        // known job
        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobEntity',
            $_oJobEntity
        );

        $this->assertEquals(
            'JobA',
            $_oJobEntity->name
        );

        // empty job
        $_oJobEntity = $_oJobRepository->getJob('JobZ');

        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobEntity',
            $_oJobEntity
        );

        $this->assertEmpty(
            $_oJobEntity->name
        );
    }

    public function testGetJobsSuccess()
    {
        $this->oRepositoryBridge
            ->getJobs()
            ->willReturn([
                $this->getValidScheduledJobEntity('JobA')
            ])
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $_oJobCollection = $_oJobRepository->getJobs();

        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobCollection',
            $_oJobCollection
        );

        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobEntity',
            $_oJobCollection['JobA']
        );
    }

    public function testAddJobSuccess()
    {
        $_oEntity = $this->getValidScheduledJobEntity('JobA');

        $this->oRepositoryBridge
            ->addJob(Argument::exact($_oEntity))
            ->willReturn(true)
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $this->assertTrue(
            $_oJobRepository->addJob($_oEntity)
        );
    }

    public function testAddJobSuccessWithInitialisedJobCollection()
    {
        $_oEntityA = $this->getValidScheduledJobEntity('JobA');
        $_oEntityB = $this->getValidScheduledJobEntity('JobB');

        $this->oRepositoryBridge
            ->getJobs()
            ->willReturn([$_oEntityA])
            ->shouldBeCalledTimes(1)
        ;

        $this->oRepositoryBridge
            ->addJob(Argument::exact($_oEntityB))
            ->willReturn(true)
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $_oJobEntityResult = $_oJobRepository->getJob('JobA');

        // known job
        $this->assertEquals(
            'JobA',
            $_oEntityA->name
        );

        $this->assertTrue(
            $_oJobRepository->addJob($_oEntityB)
        );
    }

    public function testUpdateJobSuccess()
    {
        $_oEntity = $this->getValidScheduledJobEntity('JobA');

        $this->oRepositoryBridge
            ->updateJob(Argument::exact($_oEntity))
            ->willReturn(true)
            ->shouldBeCalledTimes(1)
        ;
<commit_msg>fix unit test<commit_after><?php
/**
 * @package: chapi
 *
 * @author:  msiebeneicher
 * @since:   2015-08-28
 *
 */


namespace unit\Service\JobRepository;


use Chapi\Entity\Chronos\JobEntity;
use Chapi\Service\JobRepository\JobRepository;
use ChapiTest\src\TestTraits\JobEntityTrait;
use Prophecy\Argument;

class JobRepositoryTest extends \PHPUnit_Framework_TestCase
{
    use JobEntityTrait;

    /** @var \Prophecy\Prophecy\ObjectProphecy */
    private $oRepositoryBridge;

    public function setUp()
    {
        $this->oRepositoryBridge = $this->prophesize('Chapi\Service\JobRepository\BridgeInterface');
    }

    public function testGetJobSuccess()
    {
        $this->oRepositoryBridge
            ->getJobs()
            ->willReturn([
                $this->getValidScheduledJobEntity('JobA')
            ])
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $_oJobEntity = $_oJobRepository->getJob('JobA');

        // known job
        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobEntity',
            $_oJobEntity
        );

        $this->assertEquals(
            'JobA',
            $_oJobEntity->name
        );

        // empty job
        $_oJobEntity = $_oJobRepository->getJob('JobZ');

        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobEntity',
            $_oJobEntity
        );

        $this->assertEmpty(
            $_oJobEntity->name
        );
    }

    public function testGetJobsSuccess()
    {
        $this->oRepositoryBridge
            ->getJobs()
            ->willReturn([
                $this->getValidScheduledJobEntity('JobA')
            ])
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $_oJobCollection = $_oJobRepository->getJobs();

        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobCollection',
            $_oJobCollection
        );

        $this->assertInstanceOf(
            'Chapi\Entity\Chronos\JobEntity',
            $_oJobCollection['JobA']
        );
    }

    public function testAddJobSuccess()
    {
        $_oEntity = $this->getValidScheduledJobEntity('JobA');

        $this->oRepositoryBridge
            ->addJob(Argument::exact($_oEntity))
            ->willReturn(true)
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $this->assertTrue(
            $_oJobRepository->addJob($_oEntity)
        );
    }

    public function testAddJobSuccessWithInitialisedJobCollection()
    {
        $_oEntityA = $this->getValidScheduledJobEntity('JobA');
        $_oEntityB = $this->getValidScheduledJobEntity('JobB');

        $this->oRepositoryBridge
            ->getJobs()
            ->willReturn([$_oEntityA])
            ->shouldBeCalledTimes(1)
        ;

        $this->oRepositoryBridge
            ->addJob(Argument::exact($_oEntityB))
            ->willReturn(true)
            ->shouldBeCalledTimes(1)
        ;

        $_oJobRepository = new JobRepository(
            $this->oRepositoryBridge->reveal()
        );

        $_oJobEntityResult = $_oJobRepository->getJob('JobA');

        // known job
        $this->assertEquals(
            'JobA',
            $_oJobEntityResult->name
        );

        $this->assertTrue(
            $_oJobRepository->addJob($_oEntityB)
        );
    }

    public function testUpdateJobSuccess()
    {
        $_oEntity = $this->getValidScheduledJobEntity('JobA');

        $this->oRepositoryBridge
            ->updateJob(Argument::exact($_oEntity))
            ->willReturn(true)
            ->shouldBeCalledTimes(1)
        ;

{'fraction_non_alphanumeric': 0.12207183758459136, 'fraction_numerical': 0.003643935450286309, 'mean_word_length': 1.9165085388994307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 119, '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': '7585379', 'n_tokens_mistral': 2250, 'n_tokens_neox': 2155, 'n_words': 272}