/** * @expectedException \RuntimeException * @expectedExceptionMessage No search criteria specified */ public function testFailIfNoCriteria() { $args = self::$findCommand->parseArgs(new StringArgs('')); $this->repo->expects($this->never())->method('find'); $this->discovery->expects($this->never())->method('findByType'); $this->handler->handle($args, $this->io); }
/** * {@inheritdoc} */ public function generateUrl($repositoryPath, $currentUrl = null) { $bindings = $this->discovery->findByPath($repositoryPath, AssetPlugin::BINDING_TYPE); $count = count($bindings); if (0 === $count) { throw new CannotGenerateUrlException(sprintf('No web path mapping exists for path "%s".', $repositoryPath)); } // We can't prevent a resource to be mapped to more than one web path // For now, we'll just take the first one and make the user responsible // for preventing duplicates $url = $this->generateUrlForBinding(reset($bindings), $repositoryPath); if ($currentUrl) { // TODO use Url::makeRelative() once it exists } return $url; }
/** * Finds the resources for a given binding type. * * @param string $typeName The type name. * * @return string[] An array of short resource class names indexed by * the resource path. */ private function findByBindingType($typeName) { $matches = array(); foreach ($this->discovery->findByType($typeName) as $binding) { foreach ($binding->getResources() as $resource) { $matches[$resource->getPath()] = StringUtil::getShortClassName(get_class($resource)); } } ksort($matches); return $matches; }
/** * @expectedException \Puli\AssetPlugin\Api\UrlGenerator\CannotGenerateUrlException * @expectedExceptionMessage foobar */ public function testFailIfTargetNotFound() { $binding = new EagerBinding('/path{,/**/*}', $this->resources, $this->bindingType, array(AssetPlugin::TARGET_PARAMETER => 'foobar', AssetPlugin::PATH_PARAMETER => '/css')); $this->discovery->expects($this->once())->method('findByPath')->with('/path/path/style.css', AssetPlugin::BINDING_TYPE)->willReturn(array($binding)); $this->generator->generateUrl('/path/path/style.css'); }