<commit_before><?php

/**
 * This file is part of cloak.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

use cloak\Result;
use cloak\result\LineResult;
use cloak\AnalyzeLifeCycleNotifier;
use cloak\driver\Result as AnalyzeResult;
use cloak\spec\reporter\ReporterFixture;
use PHPExtra\EventManager\EventManagerInterface;
use PHPExtra\EventManager\EventManager;
use \Mockery;
use Prophecy\Prophet;
use Prophecy\Argument;


describe('AnalyzeLifeCycleNotifier', function() {

    describe('#notifyInit', function() {
        beforeEach(function() {
            $this->prophet = new Prophet();

            $reporter = $this->prophet->prophesize('Reporter');
            $reporter->willImplement('cloak\reporter\Initializable');
            $reporter->willImplement('cloak\reporter\ReporterInterface');

            $reporterMock = $reporter->reveal();

            $reporter->registerTo(Argument::that(function(EventManagerInterface $em) use($reporterMock) {
                $em->addListener($reporterMock);
                return true;
            }))->shouldBeCalled();

            $reporter->onInit(Argument::type('\cloak\event\InitEvent'))->shouldBeCalled();
            $reporter->onStop()->shouldNotBeCalled();

            $this->progessNotifier = new AnalyzeLifeCycleNotifier($reporterMock);
            $this->progessNotifier->notifyInit();
        });
        it('should notify the reporter that it has init', function() {
            $this->prophet->checkPredictions();
        });
    });


    describe('#notifyStart', function() {
        beforeEach(function() {
            $this->prophet = new Prophet();

            $reporter = $this->prophet->prophesize('Reporter');
            $reporter->willImplement('cloak\reporter\ReporterInterface');
            $reporter->willImplement('cloak\reporter\StartEventListener');

            $reporterMock = $reporter->reveal();

            $reporter->registerTo(Argument::that(function(EventManagerInterface $em) use($reporterMock) {
                $em->addListener($reporterMock);
                return true;
            }))->shouldBeCalled();

            $reporter->onStart(Argument::type('\cloak\event\StartEvent'))->shouldBeCalled();
            $this->progessNotifier = new AnalyzeLifeCycleNotifier($reporterMock);
            $this->progessNotifier->notifyStart();
        });

        it('should notify the reporter that it has started', function() {
            $this->prophet->checkPredictions();
        });
    });

    describe('#notifyStop', function() {
        beforeEach(function() {
            $rootDirectory = __DIR__ . '/fixtures/src/';
            $coverageResults = [
                $rootDirectory . 'foo.php' => array( 1 => LineResult::EXECUTED )
            ];

            $analyzeResult = AnalyzeResult::fromArray($coverageResults);
            $this->result = Result::fromAnalyzeResult($analyzeResult);

            $subject = $this->subject = new \stdClass();
            $reporter = $this->reporter = Mockery::mock('cloak\reporter\ReporterInterface');

            $reporter->shouldReceive('registerTo')->once()->with(
                Mockery::on(function(EventManager $eventManager) use ($reporter) {
                    $eventManager->addListener($reporter);
                    return true;
                })
            );

            $reporter->shouldReceive('onStop')->once()->with(
                Mockery::on(function($event) use($subject) {
                    $subject->event = $event;
                    return true;
                })
            );

            $this->progessNotifier = new AnalyzeLifeCycleNotifier($reporter);
            $this->progessNotifier->notifyStop($this->result);
        });
        it('should notify the reporter that it has stopped', function() {
            $event = $this->subject->event;
            expect($event)->toBeAnInstanceOf('cloak\event\StopEventInterface');
        });
        it('should include the results', function() {
            $result = $this->subject->event->getResult();
            expect($result)->toEqual($this->result);
            expect(count($result->getFiles()))->toEqual(1);
        });
        it('check mock object expectations', function() {
            Mockery::close();
        });
    });

});<commit_msg>Remove old mock code<commit_after><?php

/**
 * This file is part of cloak.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

use cloak\Result;
use cloak\result\LineResult;
use cloak\AnalyzeLifeCycleNotifier;
use cloak\driver\Result as AnalyzeResult;
use cloak\event\StopEvent;
use PHPExtra\EventManager\EventManagerInterface;
use Prophecy\Prophet;
use Prophecy\Argument;


describe('AnalyzeLifeCycleNotifier', function() {

    describe('#notifyInit', function() {
        beforeEach(function() {
            $this->prophet = new Prophet();

            $reporter = $this->prophet->prophesize('Reporter');
            $reporter->willImplement('cloak\reporter\Initializable');
            $reporter->willImplement('cloak\reporter\ReporterInterface');

            $reporterMock = $reporter->reveal();

            $reporter->registerTo(Argument::that(function(EventManagerInterface $em) use($reporterMock) {
                $em->addListener($reporterMock);
                return true;
            }))->shouldBeCalled();

            $reporter->onInit(Argument::type('\cloak\event\InitEvent'))->shouldBeCalled();
            $reporter->onStop()->shouldNotBeCalled();

            $this->progessNotifier = new AnalyzeLifeCycleNotifier($reporterMock);
            $this->progessNotifier->notifyInit();
        });
        it('should notify the reporter that it has init', function() {
            $this->prophet->checkPredictions();
        });
    });


    describe('#notifyStart', function() {
        beforeEach(function() {
            $this->prophet = new Prophet();

            $reporter = $this->prophet->prophesize('Reporter');
            $reporter->willImplement('cloak\reporter\ReporterInterface');
            $reporter->willImplement('cloak\reporter\StartEventListener');

            $reporterMock = $reporter->reveal();

            $reporter->registerTo(Argument::that(function(EventManagerInterface $em) use($reporterMock) {
                $em->addListener($reporterMock);
                return true;
            }))->shouldBeCalled();

            $reporter->onStart(Argument::type('\cloak\event\StartEvent'))->shouldBeCalled();
            $this->progessNotifier = new AnalyzeLifeCycleNotifier($reporterMock);
            $this->progessNotifier->notifyStart();
        });

        it('should notify the reporter that it has started', function() {
            $this->prophet->checkPredictions();
        });
    });

    describe('#notifyStop', function() {
        beforeEach(function() {
            $rootDirectory = __DIR__ . '/fixtures/src/';
            $coverageResults = [
                $rootDirectory . 'foo.php' => array( 1 => LineResult::EXECUTED )
            ];

            $analyzeResult = AnalyzeResult::fromArray($coverageResults);
            $this->result = Result::fromAnalyzeResult($analyzeResult);


            $this->prophet = new Prophet();

            $reporter = $this->prophet->prophesize('Reporter');
            $reporter->willImplement('cloak\reporter\ReporterInterface');

            $reporterMock = $reporter->reveal();

            $reporter->registerTo(Argument::that(function(EventManagerInterface $em) use($reporterMock) {
                $em->addListener($reporterMock);
                return true;
            }))->shouldBeCalled();

            $reporter->onStop(Argument::that(function(StopEvent $event) {
                $result = $event->getResult();
                expect(count($result->getFiles()))->toEqual(1);
                return true;
            }))->shouldBeCalled();

            $this->progessNotifier = new AnalyzeLifeCycleNotifier($reporterMock);
            $this->progessNotifier->notifyStop($this->result);
        });
        it('should notify the reporter that it has stoped', function() {
            $this->prophet->checkPredictions();
        });
    });
});
{'fraction_non_alphanumeric': 0.14526012255196444, 'fraction_numerical': 0.00048059593896431575, 'mean_word_length': 2.5018931426167437, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 126, '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': '5201949', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2208, 'n_words': 367}