<commit_before><?php

namespace Gendoria\CommandQueue\Tests\RouteDetection;

use Gendoria\CommandQueue\RouteDetection\Detector\CachedRouteDetector;
use Gendoria\CommandQueue\Tests\RouteDetection\Fixtures\DummyChildClass;
use Gendoria\CommandQueue\Tests\RouteDetection\Fixtures\DummyInterface;
use PHPUnit_Framework_TestCase;
use ReflectionObject;

/**
 * Description of RouteDetectorTest.
 *
 * @author <NAME> <<EMAIL>>
 * @group RouteDetection
 */
class CachedRouteDetectorTest extends PHPUnit_Framework_TestCase
{
    public function testAddRouteClear()
    {
        $detector = new CachedRouteDetector();
        $reflectionObject = new ReflectionObject($detector);
        $cache = $reflectionObject->getProperty('cachedRoutes');
        $cache->setAccessible(true);
        $detector->addRoute(DummyInterface::class, 'test');
        $detector->detect(DummyChildClass::class);
        $this->assertEquals(array(DummyChildClass::class => 'test'), $cache->getValue($detector));
        $detector->addRoute(DummyInterface::class, 'test2');
        $this->assertEmpty($cache->getValue($detector));
    }

    public function testAddRouteNoClearOnSame()
    {
        $detector = new CachedRouteDetector();
        $reflectionObject = new ReflectionObject($detector);
        $cache = $reflectionObject->getProperty('cachedRoutes');<commit_msg>Better tests for CachedRouteDetector.<commit_after><?php

namespace Gendoria\CommandQueue\Tests\RouteDetection;

use Gendoria\CommandQueue\RouteDetection\Detector\CachedRouteDetector;
use Gendoria\CommandQueue\Tests\RouteDetection\Fixtures\DummyChildClass;
use Gendoria\CommandQueue\Tests\RouteDetection\Fixtures\DummyInterface;
use PHPUnit_Framework_TestCase;
use ReflectionObject;

/**
 * Description of RouteDetectorTest.
 *
 * @author <NAME> <<EMAIL>>
 * @group RouteDetection
 */
class CachedRouteDetectorTest extends PHPUnit_Framework_TestCase
{
    public function testAddRouteClear()
    {
        $detector = new CachedRouteDetector();
        $reflectionObject = new ReflectionObject($detector);
        $cache = $reflectionObject->getProperty('cachedRoutes');
        $cache->setAccessible(true);
        $detector->addRoute(DummyInterface::class, 'test');
        $detector->detect(DummyChildClass::class);
        $this->assertEquals(array(DummyChildClass::class => 'test'), $cache->getValue($detector));
        $this->assertNotEmpty($cache->getValue($detector));
        //This should go from cache
        $this->assertEquals(array(DummyChildClass::class => 'test'), $cache->getValue($detector));
        $detector->addRoute(DummyInterface::class, 'test2');
        $this->assertEmpty($cache->getValue($detector));
    }

    public function testAddRouteNoClearOnSame()
    {
        $detector = new CachedRouteDetector();
        $reflectionObject = new ReflectionObject($detector);
        $cache = $reflectionObject->getProperty('cachedRoutes');
{'fraction_non_alphanumeric': 0.1258164317634926, 'fraction_numerical': 0.0006875214850464077, 'mean_word_length': 4.808383233532934, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 36, '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': '3525199', 'n_tokens_mistral': 826, 'n_tokens_neox': 828, 'n_words': 125}