public function testAddCreateUrlGeneratorMethodWithoutTargets()
    {
        $targets = new InstallTargetCollection(array());
        $this->targetManager->expects($this->any())->method('getTargets')->willReturn($targets);
        $class = new Clazz('Puli\\MyFactory');
        $class->addImport(new Import('Puli\\Factory\\PuliFactory'));
        $class->addImplementedInterface('PuliFactory');
        $class->setFilePath($this->tempFile);
        $this->generator->addCreateUrlGeneratorMethod($class);
        $writer = new ClassWriter();
        $writer->writeClass($class);
        $expected = <<<EOF
<?php

namespace Puli;

use Puli\\AssetPlugin\\Api\\Factory\\UrlGeneratorFactory;
use Puli\\AssetPlugin\\Api\\Target\\InstallTargetCollection;
use Puli\\AssetPlugin\\Api\\UrlGenerator\\AssetUrlGenerator;
use Puli\\AssetPlugin\\UrlGenerator\\DiscoveryUrlGenerator;
use Puli\\Discovery\\Api\\ResourceDiscovery;
use Puli\\Factory\\PuliFactory;

class MyFactory implements PuliFactory, UrlGeneratorFactory
{
    /**
     * Creates the URL generator.
     *
     * @param ResourceDiscovery \$discovery The resource discovery to read from.
     *
     * @return AssetUrlGenerator The created URL generator.
     */
    public function createUrlGenerator(ResourceDiscovery \$discovery)
    {
        \$targets = new InstallTargetCollection();
        \$generator = new DiscoveryUrlGenerator(\$discovery, \$targets);

        return \$generator;
    }
}

EOF;
        $this->assertSame($expected, file_get_contents($this->tempFile));
    }
Exemple #2
0
 /**
  * @param GenerateFactoryEvent $event
  *
  * @internal
  */
 public function handleGenerateFactoryEvent(GenerateFactoryEvent $event)
 {
     $generator = new CreateUrlGeneratorMethodGenerator($this->getInstallTargetManager());
     $generator->addCreateUrlGeneratorMethod($event->getFactoryClass());
 }