<commit_before><commit_msg>Add BundleClassFinder Test Case<commit_after><?php

namespace Darsyn\ClassFinder\Tests;

use Darsyn\ClassFinder\BundleClassFinder;
use Darsyn\ClassFinder\Tests\Fixtures\Bundle\TestBundle;
use Darsyn\ClassFinder\Tests\Fixtures\TestKernel;

/**
 * @author <NAME> <<EMAIL>>
 */
class BundleClassFinderTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Get Booted Kernel
     *
     * @access protected
     * @return \Darsyn\ClassFinder\Tests\Fixtures\TestKernel
     */
    protected function getBootedKernel()
    {
        $kernel = new TestKernel;
        $kernel->boot();
        return $kernel;
    }

    public function testNoKernelInitialisation()
    {
        $finder = new BundleClassFinder;
        $this->assertAttributeInstanceOf('SplObjectStorage', 'bundles', $finder);
        $this->assertAttributeCount(0, 'bundles', $finder);
    }

    public function testKernelInitialisation()
    {
        $finder = new BundleClassFinder($this->getBootedKernel());
        $this->assertAttributeInstanceOf('SplObjectStorage', 'bundles', $finder);
        $this->assertAttributeCount(1, 'bundles', $finder);
    }

    public function testSetAndAddBundles()
    {
        // Test setting the bundles add them to the BundleClassFinder.
        $finder = new BundleClassFinder;
        $finder->setBundles([
            new TestBundle,
        ]);
        $this->assertAttributeCount(1, 'bundles', $finder);
        // Test that adding bundles work.
        $finder->addBundle($bundle = new TestBundle);
        $this->assertAttributeCount(2, 'bundles', $finder);
        // Test that adding the same instance of the bundle does not add duplicates.
        $finder->addBundle($bundle);
        $this->assertAttributeCount(2, 'bundles', $finder);
        // Test that setting bundles resets what's already in BundleClassFinder.
        $finder->setBundles([
            new TestBundle,
        ]);
        $this->assertAttributeCount(1, 'bundles', $finder);
    }

    public function testClassesAreFound()
    {
        $finder = new BundleClassFinder($this->getBootedKernel());
        $this->assertEquals([
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\SecondaryController',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\DefaultController',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\TestBundle',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Entity\\MyEntity',
        ], $finder->findClasses());
    }

    public function testSubDir()
    {
        $finder = new BundleClassFinder($this->getBootedKernel());
        $this->assertEquals([
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\SecondaryController',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\DefaultController',
        ], $finder->findClasses('Controllers'));
        $this->assertEquals([], $finder->findClasses('Controller'));
    }

    public function testSuffix()
    {
        $finder = new BundleClassFinder($this->getBootedKernel());
        $this->assertEquals([
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\SecondaryController',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\DefaultController',
        ], $finder->findClasses(null, 'Controller'));
        $this->assertEquals([], $finder->findClasses(null, 'Controllers'));
    }

    public function testParent()
    {
        $finder = new BundleClassFinder($this->getBootedKernel());
        $this->assertEquals([
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\SecondaryController',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\DefaultController',
        ], $finder->findClasses(
            null,
            null,
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\ControllerInterface'
        ));
    }

    public function testSubDirSuffixAndParent()
    {
        $finder = new BundleClassFinder($this->getBootedKernel());
        $this->assertEquals([
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\SecondaryController',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\Bundle\\Controllers\\DefaultController',
        ], $finder->findClasses(
            'Controllers',
            'Controller',
            'Darsyn\\ClassFinder\\Tests\\Fixtures\\ControllerInterface'
        ));
    }
}
{'fraction_non_alphanumeric': 0.140533212833258, 'fraction_numerical': 0.0013556258472661546, 'mean_word_length': 2.6922435362802335, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, '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': '1341371', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1215, 'n_words': 187}