<commit_before><?php
namespace Elchristo\Calendar\Test;

use Elchristo\Calendar\Service\Config\Config;
use Elchristo\Calendar\Model\Event\Collection;
use Elchristo\Calendar\Model\Source\SourceInterface;
use Elchristo\Calendar\Service\Builder\SourceBuilderFactory;

class SourceBuilderTest extends TestCase
{
    private function getConfigProvider()
    {
        return new Config(self::getConfig()['elchristo']['calendar']);
    }

    /**
     * Test to build source by its name in configuration
     */
    public function testBuildSourceByConfig()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $sourceName = 'TestSource'; // stub class unit\Stub\TestSource
        $sourceInterface = SourceInterface::class;

        // when
        $source = $builder->build($sourceName);

        // then
        $this->assertInstanceOf($sourceInterface, $source, 'Cannot create source by name (in config).');
    }

    /**
     * Test to build source by classname
     */
    public function testBuildSourceByClassname()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $sourceName = unit\Stub\TestSource::class;
        $sourceInterface = SourceInterface::class;

        // when
        $source = $builder->build($sourceName);

        // then
        $this->assertInstanceOf($sourceInterface, $source, 'Cannot create source by classname.');
    }

        /**
     * Test to retrieve event collection from source
     */
    public function testCanRetrieveEventsCollection()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $source = $builder->build('TestSource'); // stub class unit\Stub\TestSource
        $expected = Collection::class;

        // when
        $eventsCollection = $source->getEvents();
<commit_msg>Add unit tests for source identifier generation<commit_after><?php
namespace Elchristo\Calendar\Test;

use Elchristo\Calendar\Service\Config\Config;
use Elchristo\Calendar\Model\Event\Collection;
use Elchristo\Calendar\Model\Source\SourceInterface;
use Elchristo\Calendar\Service\Builder\SourceBuilderFactory;

class SourceBuilderTest extends TestCase
{
    private function getConfigProvider()
    {
        return new Config(self::getConfig()['elchristo']['calendar']);
    }

    /**
     * Test to build source by its name in configuration
     */
    public function testBuildSourceByConfig()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $sourceName = 'TestSource'; // stub class unit\Stub\TestSource
        $sourceInterface = SourceInterface::class;

        // when
        $source = $builder->build($sourceName);

        // then
        $this->assertInstanceOf($sourceInterface, $source, 'Cannot create source by name (in config).');
    }

    /**
     * Test to build source by classname
     */
    public function testBuildSourceByClassname()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $sourceName = unit\Stub\TestSource::class;
        $sourceInterface = SourceInterface::class;

        // when
        $source = $builder->build($sourceName);

        // then
        $this->assertInstanceOf($sourceInterface, $source, 'Cannot create source by classname.');
    }

    /**
     * Test to initialize source identifier by configured name
     */
    public function testBuildSourceIdentifierWithPassedName()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $sourceName = 'TestSource';
        $expectedName = 'testsource';

        // when
        $source = $builder->build($sourceName);

        // then
        $this->assertEquals($expectedName, $source->getIdentifier());
    }

    /**
     * Test to initialize source identifier by configured name
     */
    public function testBuildSourceIdentifierWithSourceClassname()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $sourceName = unit\Stub\TestSource::class;
        $expectedName = 'elchristocalendartestunitstubtestsource';

        // when
        $source = $builder->build($sourceName);

        // then
        $this->assertEquals($expectedName, $source->getIdentifier());
    }

        /**
     * Test to retrieve event collection from source
     */
    public function testCanRetrieveEventsCollection()
    {
        // given
        $builder = SourceBuilderFactory::create($this->getConfigProvider());
        $source = $builder->build('TestSource'); // stub class unit\Stub\TestSource
        $expected = Collection::class;

        // when
        $eventsCollection = $source->getEvents();

{'fraction_non_alphanumeric': 0.12004153686396678, 'fraction_numerical': 0.0, 'mean_word_length': 2.7891424075531077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '4870659', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1213, 'n_words': 270}