<commit_before><?php

namespace BetterReflectionTest\SourceLocator;
use BetterReflection\Identifier\Identifier;
use BetterReflection\Identifier\IdentifierType;
use BetterReflection\SourceLocator\AggregateSourceLocator;
use BetterReflection\SourceLocator\LocatedSource;
use BetterReflection\SourceLocator\SourceLocator;
use BetterReflection\SourceLocator\StringSourceLocator;

/**
 * @covers \BetterReflection\SourceLocator\AggregateSourceLocator
 */
class AggregateSourceLocatorTest extends \PHPUnit_Framework_TestCase
{
    public function testInvokeWillTraverseAllGivenLocatorsAndFailToResolve()
    {
        $locator1   = $this->getMock(SourceLocator::class);
        $locator2   = $this->getMock(SourceLocator::class);
        $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));

        $locator1->expects($this->once())->method('__invoke')->with($identifier);
        $locator2->expects($this->once())->method('__invoke')->with($identifier);

        $this->assertNull((new AggregateSourceLocator([$locator1, $locator2]))->__invoke($identifier));
    }

    public function testInvokeWillTraverseAllGivenLocatorsAndSucceed()
    {
        $locator1   = $this->getMock(SourceLocator::class);
        $locator2   = $this->getMock(SourceLocator::class);
        $locator3   = $this->getMock(SourceLocator::class);
        $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));
        $source     = new LocatedSource('<?php foo', null);

        $locator1->expects($this->once())->method('__invoke')->with($identifier);
        $locator2->expects($this->once())->method('__invoke')->with($identifier)->willReturn($source);
        $locator3->expects($this->never())->method('__invoke');

        $this->assertSame($source, (new AggregateSourceLocator([$locator1, $locator2]))->__invoke($identifier));
    }

    public function testNestedAggregate()
    {
        $this->markTestIncomplete();
        $nestedAggregate = new AggregateSourceLocator([
            new AggregateSourceLocator([
                new StringSourceLocator('<?php level2'),
                new AggregateSourceLocator([
                    new StringSourceLocator('<?php level3'),
                ]),
            ]),
            new StringSourceLocator('<?php level1')
        ]);

        $identifier = new Identifier('Level3', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));

        /** @var \Generator $values */
        $values = $nestedAggregate->__invoke($identifier);

        $values->rewind();
        $this->assertInstanceOf(LocatedSource::class, $values->current());
        $this->assertSame('<?php level2', $values->current()->getSource());

        $values->next();
        $this->assertInstanceOf(LocatedSource::class, $values->current());
        $this->assertSame('<?php level3', $values->current()->getSource());
<commit_msg>An empty resolver list is a valid list<commit_after><?php

namespace BetterReflectionTest\SourceLocator;
use BetterReflection\Identifier\Identifier;
use BetterReflection\Identifier\IdentifierType;
use BetterReflection\SourceLocator\AggregateSourceLocator;
use BetterReflection\SourceLocator\LocatedSource;
use BetterReflection\SourceLocator\SourceLocator;
use BetterReflection\SourceLocator\StringSourceLocator;

/**
 * @covers \BetterReflection\SourceLocator\AggregateSourceLocator
 */
class AggregateSourceLocatorTest extends \PHPUnit_Framework_TestCase
{
    public function testInvokeWillTraverseAllGivenLocatorsAndFailToResolve()
    {
        $locator1   = $this->getMock(SourceLocator::class);
        $locator2   = $this->getMock(SourceLocator::class);
        $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));

        $locator1->expects($this->once())->method('__invoke')->with($identifier);
        $locator2->expects($this->once())->method('__invoke')->with($identifier);

        $this->assertNull((new AggregateSourceLocator([$locator1, $locator2]))->__invoke($identifier));
    }

    public function testInvokeWillTraverseAllGivenLocatorsAndSucceed()
    {
        $locator1   = $this->getMock(SourceLocator::class);
        $locator2   = $this->getMock(SourceLocator::class);
        $locator3   = $this->getMock(SourceLocator::class);
        $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));
        $source     = new LocatedSource('<?php foo', null);

        $locator1->expects($this->once())->method('__invoke')->with($identifier);
        $locator2->expects($this->once())->method('__invoke')->with($identifier)->willReturn($source);
        $locator3->expects($this->never())->method('__invoke');

        $this->assertSame($source, (new AggregateSourceLocator([$locator1, $locator2]))->__invoke($identifier));
    }

    public function testWillNotResolveWithEmptyLocatorsList()
    {
        $this->assertNull(
            (new AggregateSourceLocator([]))
                ->__invoke(new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)))
        );
    }

    public function testNestedAggregate()
    {
        $this->markTestIncomplete();
        $nestedAggregate = new AggregateSourceLocator([
            new AggregateSourceLocator([
                new StringSourceLocator('<?php level2'),
                new AggregateSourceLocator([
                    new StringSourceLocator('<?php level3'),
                ]),
            ]),
            new StringSourceLocator('<?php level1')
        ]);

        $identifier = new Identifier('Level3', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));

        /** @var \Generator $values */
        $values = $nestedAggregate->__invoke($identifier);

        $values->rewind();
        $this->assertInstanceOf(LocatedSource::class, $values->current());
        $this->assertSame('<?php level2', $values->current()->getSource());

        $values->next();
        $this->assertInstanceOf(LocatedSource::class, $values->current());
        $this->assertSame('<?php level3', $values->current()->getSource());

{'fraction_non_alphanumeric': 0.14792316532589067, 'fraction_numerical': 0.006567066163191594, 'mean_word_length': 3.9448051948051948, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 91, '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': '6812120', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1680, 'n_words': 229}