<commit_before><?php

/*
 * This file is part of the Symfony CMF package.
 *
 * (c) 2011-2015 Symfony CMF
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Cmf\Component\RoutingAuto\Tests\Unit\Adapter;

use Symfony\Cmf\Component\RoutingAuto\Adapter\EventDispatchingAdapter;
use Symfony\Cmf\Component\RoutingAuto\RoutingAutoEvents;
use Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteCreateEvent;
use Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteMigrateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

class EventDispatchingAdapterTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->realAdapter = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\AdapterInterface');
        $this->dispatcher = new EventDispatcher();
        $this->subscriber = new EventDispatchingAdapterSubscriber();
        $this->dispatcher->addSubscriber($this->subscriber);
        $this->uriContext = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\UriContext');
        $this->autoRoute = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
        $this->autoRoute2 = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
        $this->adapter = new EventDispatchingAdapter(
            $this->realAdapter->reveal(),
            $this->dispatcher
        );
    }

    public function testDispatchCreate()
    {
        $this->realAdapter->createAutoRoute($this->uriContext->reveal(), null, 'fr')->willReturn($this->autoRoute->reveal());
        $this->adapter->createAutoRoute($this->uriContext->reveal(), null, 'fr');
        $this->assertNotNull($this->subscriber->createEvent);
        $this->assertInstanceOf('Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteCreateEvent', $this->subscriber->createEvent);
        $this->assertSame($this->autoRoute->reveal(), $this->subscriber->createEvent->getAutoRoute());
        $this->assertSame($this->uriContext->reveal(), $this->subscriber->createEvent->getUriContext());
    }

    public function testDispatchMigrate()
    {
        $this->adapter->migrateAutoRouteChildren(
            $this->autoRoute->reveal(),
            $this->autoRoute2->reveal()
        );
        $this->assertNotNull($this->subscriber->migrateEvent);
        $this->assertInstanceOf('Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteMigrateEvent', $this->subscriber->migrateEvent);
        $this->assertSame($this->autoRoute->reveal(), $this->subscriber->migrateEvent->getSrcAutoRoute());
        $this->assertSame($this->autoRoute2->reveal(), $this->subscriber->migrateEvent->getDestAutoRoute());
    }
}

class EventDispatchingAdapterSubscriber implements EventSubscriberInterface
{
    public $createEvent;<commit_msg>Added event dispatcher tests<commit_after><?php

/*
 * This file is part of the Symfony CMF package.
 *
 * (c) 2011-2015 Symfony CMF
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Cmf\Component\RoutingAuto\Tests\Unit\Adapter;

use Symfony\Cmf\Component\RoutingAuto\Adapter\EventDispatchingAdapter;
use Symfony\Cmf\Component\RoutingAuto\RoutingAutoEvents;
use Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteCreateEvent;
use Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteMigrateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

class EventDispatchingAdapterTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->realAdapter = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\AdapterInterface');
        $this->dispatcher = new EventDispatcher();
        $this->adapter = new EventDispatchingAdapter(
            $this->realAdapter->reveal(),
            $this->dispatcher
        );

        $this->subscriber = new EventDispatchingAdapterSubscriber();
        $this->dispatcher->addSubscriber($this->subscriber);
        $this->uriContext = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\UriContext');
        $this->autoRoute = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
        $this->autoRoute2 = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
        $this->content = new \stdClass();
    }

    public function testCreateAutoRoute()
    {
        $this->realAdapter->createAutoRoute($this->uriContext->reveal(), null, 'fr')->willReturn($this->autoRoute->reveal());
        $this->adapter->createAutoRoute($this->uriContext->reveal(), null, 'fr');
        $this->assertNotNull($this->subscriber->createEvent);
        $this->assertInstanceOf('Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteCreateEvent', $this->subscriber->createEvent);
        $this->assertSame($this->autoRoute->reveal(), $this->subscriber->createEvent->getAutoRoute());
        $this->assertSame($this->uriContext->reveal(), $this->subscriber->createEvent->getUriContext());
    }

    public function testMigrateAutoRouteChildren()
    {
        $this->adapter->migrateAutoRouteChildren(
            $this->autoRoute->reveal(),
            $this->autoRoute2->reveal()
        );
        $this->assertNotNull($this->subscriber->migrateEvent);
        $this->assertInstanceOf('Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteMigrateEvent', $this->subscriber->migrateEvent);
        $this->assertSame($this->autoRoute->reveal(), $this->subscriber->migrateEvent->getSrcAutoRoute());
        $this->assertSame($this->autoRoute2->reveal(), $this->subscriber->migrateEvent->getDestAutoRoute());
    }

    public function testGetLocales()
    {
        $this->realAdapter->getLocales($this->content)->shouldBeCalled()->willReturn(array('de', 'de_at'));
        $locales = $this->adapter->getLocales($this->content);
        $this->assertEquals(array('de', 'de_at'), $locales);
    }

    public function testTranslateObject()
    {
        $translatedContent = new \stdClass();
        $this->realAdapter->translateObject($this->content, 'en')->shouldBeCalled()->willReturn($translatedContent);
        $content = $this->adapter->translateObject($this->content, 'en');
        $this->assertEquals($translatedContent, $content);
    }

    public function testGenerateAutoRouteTag()
    {
        $this->realAdapter->generateAutoRouteTag($this->uriContext->reveal())->willReturn('hello');
        $tag = $this->adapter->generateAutoRouteTag($this->uriContext->reveal());
        $this->assertEquals('hello', $tag);
    }

    public function testRemoveAutoRoute()
    {
        $this->realAdapter->removeAutoRoute($this->autoRoute->reveal())->shouldBeCalled();
        $this->adapter->removeAutoRoute($this->autoRoute->reveal());
    }

    public function testCreateRedirectRoute()
    {
        $this->realAdapter->createRedirectRoute(
            $this->autoRoute->reveal(),
            $this->autoRoute2->reveal()
        )->shouldBeCalled();

        $this->adapter->createRedirectRoute(
            $this->autoRoute->reveal(),
            $this->autoRoute2->reveal()
        );
    }

    public function testGetRealClassName()
    {
        $this->realAdapter->getRealClassName('foo')->willReturn('bar');

        $className = $this->adapter->getRealClassName('foo');
        $this->assertEquals('bar', $className);
    }

    public function testCompareAutoRouteContent()
    {
        $this->realAdapter->compareAutoRouteContent(
            $this->autoRoute->reveal(),
            $this->content
        )->willReturn(false);

        $this->assertFalse(
            $this->adapter->compareAutoRouteContent(
                $this->autoRoute->reveal(),
                $this->content
            )
        );
    }

    public function testGetReferringAutoRoutes()
    {
        $referrers = array($this->autoRoute->reveal(), $this->autoRoute2->reveal());
        $this->realAdapter->getReferringAutoRoutes(
            $this->content
        )->willReturn($referrers);

        $this->assertEquals($referrers, $this->adapter->getReferringAutoRoutes($this->content));
    }

    public function testFindRouteForUri()
    {
        $routes = array($this->autoRoute->reveal(), $this->autoRoute2->reveal());

        $this->realAdapter->findRouteForUri('uri', $this->uriContext->reveal())->willReturn($routes);

        $this->assertEquals($routes, $this->adapter->findRouteForUri('uri', $this->uriContext->reveal()));
    }
}

class EventDispatchingAdapterSubscriber implements EventSubscriberInterface
{
    public $createEvent;
{'fraction_non_alphanumeric': 0.15022344448264008, 'fraction_numerical': 0.0029792597685344333, 'mean_word_length': 3.8220994475138124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 238, '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': '5038339', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2464, 'n_words': 310}