library behat-extension-driver-locator
        Driver locator tool for behat extensions
    
            
                
                    
                    
                    
                    
                        
                            
    
        
        
            bex/behat-extension-driver-locator
            Driver locator tool for behat extensions
         
     
    
        
            -  Thursday, December 17, 2015
 
                                -  by tkotosz
 
                            -  Repository
 
            -  1 Watchers
 
            -  7 Stars
 
            -  384,360 Installations
 
        
     
    
        
                            - PHP
 
            
            -  3 Dependents
 
            -  0 Suggesters
 
            -  0 Forks
 
            -  0 Open issues
 
            -  4 Versions
 
            -  19 % Grown
 
        
     
 
    
        
            
    
    
    
Behat-ExtensionDriverLocator
, (*1)
Behat-ExtensionDriverLocator helps you load external drivers/services (like image uploaders, output formatters, etc) dinamically.
The DriverLocator can find you a service in a preconfigured namespace by a given driverkey.
- It validates that the class implements the DriverInterface or your specific interface.
- It will call the configure method of the driver to get the config tree of the driver specific configurations
- It will validate the loaded config against the provided config tree.
- It will pass the valid config and the DI container to the load method of the driver in order to get a properly loaded service.
The package also provide a Driver Node Builder which can create the drivers node for your behat extension. (see usage below), (*2)
Installation
Install by adding to your composer.json:, (*3)
composer require --dev bex/behat-extension-driver-locator
Usage
- 
In your behat extension's configure method use the Driver Node Builder to build the drivers configuration node:, (*4)
    $driverNodeBuilder = DriverNodeBuilder::getInstance($driverNamespace, $driverParent);
    $driverNodeBuilder->buildDriverNodes($builder, $activeDriversNodeName, $driversCofigurationNodeName, $defaultDriverKeys);
where:, (*5)
- the 
$driverNamespace is the namespace where the DriverNodeBuilder should look for the drivers when validating a given driver key
e.g.: My\\Awesome\\BehatExtension\\Driver
 
- the 
$driverParent is the parent class/interface which should be implemented by all driver
e.g.: My\\Awesome\\BehatExtension\\Driver\\MyAwesomeDriverInterface
(note that all driver need to implement the Bex\Behat\ExtensionDriverLocator\DriverInterface) 
- the 
$builder is an Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition instance which you get in your behat extension's configure method as a parameter, the DriverNodeBuilder will add the drivers node to this builder. 
- the 
$activeDriversNodeName is the name of the node where the user will be able to specify which driver should be used for your extension
e.g.: active_my_awesome_drivers
 
- the 
driversCofigurationNodeName is the name of the drivers node, the additional configuration of all driver will be under this node
e.g.: my_awesome_drivers
 
- the 
$defaultDriverKeys is the driverkey of the default driver(s) which will be used when the config is empty in the behat.yml
e.g.: first_awesomeness
 
- Note: The driverkey is always the lowercased and underlined version of the driver's classname.
e.g. FirstAwesomeness -> first_awesomeness
e.g. First -> first
 
With the example configurations a valid config would look like this:, (*6)
default:
  extensions:
   My\\Awesome\\BehatExtension: ~
or, (*7)
default:
  extensions:
   My\\Awesome\\BehatExtension:
     active_my_awesome_drivers: first_awesomeness
     my_awesome_drivers:
       first_awesomeness:
         # ... all driver specific configuration goes here ...
 
- 
In your behat extension's load method use the Driver Locator to load the active driver(s):
Note that it will validate the driver specific configs automatically., (*8)
    $driverLocator = DriverLocator::getInstance($driverNamespace, $driverParent);
    $drivers = $driverLocator->findDrivers($container, $activeDrivers, $driverConfigs);
where:, (*9)
- the 
$driverNamespace is the namespace where the DriverLocator should look for the drivers
e.g.: My\\Awesome\\BehatExtension\\Driver
 
- the 
$driverParent is the parent class/interface which should be implemented by all driver
e.g.: My\\Awesome\\BehatExtension\\Driver\\MyAwesomeDriverInterface
 
- the 
$container is an Symfony\Component\DependencyInjection\ContainerBuilder instance which you get in your behat extension's load method as a parameter, the DriverLocator will pass this container to the load method of each driver 
- the 
$activeDrivers are the active image drivers from the $config param which you get in the load method
e.g.: $config['active_my_awesome_drivers'] 
- the 
$driverConfigs are the driver specific configuration values from the $config param
e.g.: $config['my_awesome_drivers']