Permalink
Browse files

API use MinkExtension's base_url as framework_host parameter

This change causes SilverStripe extension to be fully dependent
on MinkExtension and it's base_url parameter that cannot be empty now
  • Loading branch information...
1 parent 4ac8551 commit b09f4cf2eb4984163d9da302e1f9cbed229b6649 @michalochman committed Aug 8, 2012
View
@@ -9,7 +9,6 @@ default:
features/extensions/SilverStripeExtension/init.php:
# Behat\SilverStripeExtension\Extension:
framework_path: ../../
- framework_host: http://localhost
Behat\MinkExtension\Extension:
base_url: http://localhost
files_path: %behat.paths.features%/files/
@@ -0,0 +1,44 @@
+<?php
+
+namespace Behat\SilverStripeExtension\Compiler;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder,
+ Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+/*
+ * This file is part of the Behat\SilverStripeExtension
+ *
+ * (c) Michał Ochman <ochman.d.michal@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * Behat\SilverStripe container compilation pass.
+ * Passes Base URL available in MinkExtension config.
+ *
+ * @author Michał Ochman <ochman.d.michal@gmail.com>
+ */
+class MinkExtensionBaseUrlPass implements CompilerPassInterface
+{
+ /**
+ * Passes MinkExtension's base_url parameter
+ *
+ * @param ContainerBuilder $container
+ */
+ public function process(ContainerBuilder $container)
+ {
+ if (!$container->hasDefinition('behat.mink')) {
+ throw new \Exception('MinkExtension not defined');
+ }
+ if (!$container->hasParameter('behat.mink.base_url')) {
+ throw new \Exception('MinkExtension improperly configured. Missing base_url parameter.');
+ }
+ $base_url = $container->getParameter('behat.mink.base_url');
+ if (empty($base_url)) {
+ throw new \Exception('MinkExtension improperly configured. Missing or empty base_url parameter.');
+ }
+ $container->setParameter('behat.silverstripe_extension.framework_host', $base_url);
+ }
+}
@@ -39,11 +39,6 @@ public function load(array $config, ContainerBuilder $container)
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services'));
$loader->load('silverstripe.yml');
- if (!isset($config['framework_host'])) {
- $config['framework_host'] = $container->getParameter('behat.silverstripe_extension.framework_host');
- file_put_contents('php://stderr', 'No `framework_host` parameter for silverstripe_extension provided. Assuming ' . $config['framework_host'] . PHP_EOL);
- }
-
$behat_base_path = $container->getParameter('behat.paths.base');
$config['framework_path'] = realpath(sprintf('%s%s%s',
rtrim($behat_base_path, DIRECTORY_SEPARATOR),
@@ -55,6 +50,17 @@ public function load(array $config, ContainerBuilder $container)
}
$container->setParameter('behat.silverstripe_extension.framework_path', $config['framework_path']);
- $container->setParameter('behat.silverstripe_extension.framework_host', $config['framework_host']);
+ }
+
+ /**
+ * Returns compiler passes used by SilverStripe extension.
+ *
+ * @return array
+ */
+ public function getCompilerPasses()
+ {
+ return array(
+ new Compiler\MinkExtensionBaseUrlPass(),
+ );
}
}
@@ -1,7 +1,6 @@
parameters:
behat.silverstripe_extension.context.initializer.class: Behat\SilverStripeExtension\Context\Initializer\SilverStripeAwareInitializer
behat.silverstripe_extension.framework_path: ~
- behat.silverstripe_extension.framework_host: http://localhost
services:
behat.silverstripe_extension.context.initializer:
class: %behat.silverstripe_extension.context.initializer.class%

0 comments on commit b09f4cf

Please sign in to comment.