<commit_before><?php

namespace PHPCI\Plugin\Tests\Util;

require_once __DIR__ . "/ExamplePlugins.php";

use PHPCI\Plugin\Util\Executor;
use Prophecy\PhpUnit\ProphecyTestCase;

class ExecutorTest extends ProphecyTestCase
{
    /**
     * @var Executor
     */
    protected $testedExecutor;

    protected $mockBuildLogger;

    protected $mockFactory;

    protected function setUp()
    {
        parent::setUp();
        $this->mockBuildLogger = $this->prophesize('\PHPCI\BuildLogger');
        $this->mockFactory = $this->prophesize('\PHPCI\Plugin\Util\Factory');
        $this->testedExecutor = new Executor($this->mockFactory->reveal(), $this->mockBuildLogger->reveal());
    }

    public function testExecutePlugin_AssumesPHPCINamespaceIfNoneGiven()
    {
        $options = array();
        $pluginName = 'PhpUnit';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)
                          ->shouldBeCalledTimes(1)
                          ->willReturn($this->prophesize('PHPCI\Plugin')->reveal());

        $this->testedExecutor->executePlugin($pluginName, $options);
    }

    public function testExecutePlugin_KeepsCalledNameSpace()
    {
        $options = array();
        $pluginName = 'ExamplePluginFull';
        $pluginNamespace = '\\PHPCI\\Plugin\\Tests\\Util\\';

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)
          ->shouldBeCalledTimes(1)
          ->willReturn($this->prophesize('PHPCI\Plugin')->reveal());

        $this->testedExecutor->executePlugin($pluginNamespace . $pluginName, $options);
    }

    public function testExecutePlugin_CallsExecuteOnFactoryBuildPlugin()
    {
        $options = array();
        $pluginName = 'PhpUnit';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $mockPlugin = $this->prophesize('PHPCI\Plugin');
        $mockPlugin->execute()->shouldBeCalledTimes(1);

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)
          ->shouldBeCalledTimes(1)
          ->willReturn($mockPlugin->reveal());

        $this->testedExecutor->executePlugin($pluginName, $options);
    }

    public function testExecutePlugin_ReturnsPluginSuccess()
    {
        $options = array();
        $pluginName = 'PhpUnit';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $expectedReturnValue = true;

        $mockPlugin = $this->prophesize('PHPCI\Plugin');
        $mockPlugin->execute()->willReturn($expectedReturnValue);

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)->willReturn($mockPlugin->reveal());

        $returnValue = $this->testedExecutor->executePlugin($pluginName, $options);

        $this->assertEquals($expectedReturnValue, $returnValue);
    }

}
 <commit_msg>add tests for plugin executor logging<commit_after><?php

namespace PHPCI\Plugin\Tests\Util;

require_once __DIR__ . "/ExamplePlugins.php";

use PHPCI\Plugin\Util\Executor;
use Prophecy\PhpUnit\ProphecyTestCase;

class ExecutorTest extends ProphecyTestCase
{
    /**
     * @var Executor
     */
    protected $testedExecutor;

    protected $mockBuildLogger;

    protected $mockFactory;

    protected function setUp()
    {
        parent::setUp();
        $this->mockBuildLogger = $this->prophesize('\PHPCI\BuildLogger');
        $this->mockFactory = $this->prophesize('\PHPCI\Plugin\Util\Factory');
        $this->testedExecutor = new Executor($this->mockFactory->reveal(), $this->mockBuildLogger->reveal());
    }

    public function testExecutePlugin_AssumesPHPCINamespaceIfNoneGiven()
    {
        $options = array();
        $pluginName = 'PhpUnit';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)
                          ->shouldBeCalledTimes(1)
                          ->willReturn($this->prophesize('PHPCI\Plugin')->reveal());

        $this->testedExecutor->executePlugin($pluginName, $options);
    }

    public function testExecutePlugin_KeepsCalledNameSpace()
    {
        $options = array();
        $pluginName = 'ExamplePluginFull';
        $pluginNamespace = '\\PHPCI\\Plugin\\Tests\\Util\\';

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)
          ->shouldBeCalledTimes(1)
          ->willReturn($this->prophesize('PHPCI\Plugin')->reveal());

        $this->testedExecutor->executePlugin($pluginNamespace . $pluginName, $options);
    }

    public function testExecutePlugin_CallsExecuteOnFactoryBuildPlugin()
    {
        $options = array();
        $pluginName = 'PhpUnit';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $mockPlugin = $this->prophesize('PHPCI\Plugin');
        $mockPlugin->execute()->shouldBeCalledTimes(1);

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)
          ->shouldBeCalledTimes(1)
          ->willReturn($mockPlugin->reveal());

        $this->testedExecutor->executePlugin($pluginName, $options);
    }

    public function testExecutePlugin_ReturnsPluginSuccess()
    {
        $options = array();
        $pluginName = 'PhpUnit';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $expectedReturnValue = true;

        $mockPlugin = $this->prophesize('PHPCI\Plugin');
        $mockPlugin->execute()->willReturn($expectedReturnValue);

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)->willReturn($mockPlugin->reveal());

        $returnValue = $this->testedExecutor->executePlugin($pluginName, $options);

        $this->assertEquals($expectedReturnValue, $returnValue);
    }

    public function testExecutePlugin_LogsFailureForNonExistentClasses()
    {
        $options = array();
        $pluginName = 'DOESNTEXIST';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $this->mockBuildLogger->logFailure('Plugin does not exist: ' . $pluginName)->shouldBeCalledTimes(1);

        $this->testedExecutor->executePlugin($pluginName, $options);
    }

    public function testExecutePlugin_LogsFailureWhenExceptionsAreThrownByPlugin()
    {
        $options = array();
        $pluginName = 'PhpUnit';
        $pluginNamespace = 'PHPCI\\Plugin\\';

        $expectedException = new \RuntimeException("Generic Error");

        $mockPlugin = $this->prophesize('PHPCI\Plugin');
        $mockPlugin->execute()->willThrow($expectedException);

        $this->mockFactory->buildPlugin($pluginNamespace . $pluginName, $options)->willReturn($mockPlugin->reveal());

        $this->mockBuildLogger->logFailure('EXCEPTION: ' . $expectedException->getMessage(), $expectedException)
                              ->shouldBeCalledTimes(1);

        $this->testedExecutor->executePlugin($pluginName, $options);
    }

}
 
{'fraction_non_alphanumeric': 0.14517078916372203, 'fraction_numerical': 0.0014723203769140165, 'mean_word_length': 3.1370280146163214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 111, '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': '659328', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1854, 'n_words': 262}