MyAwesomeExtension.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @file
  4. * MyAwesomeExtension.php
  5. *
  6. * @author: marand
  7. *
  8. * @copyright (c) 2014 Ouest Systèmes Informatiques (OSInet).
  9. *
  10. * @license General Public License version 2 or later
  11. */
  12. use Behat\Behat\Context\BehatContext;
  13. use Behat\Behat\Context\ClassGuesser\ClassGuesserInterface;
  14. use Behat\Behat\Context\ContextInterface;
  15. use Behat\Behat\Context\Initializer\InitializerInterface;
  16. use Behat\Behat\Extension\Extension;
  17. use Behat\Mink\Mink;
  18. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  19. use Symfony\Component\Config\FileLocator;
  20. use Symfony\Component\DependencyInjection\ContainerBuilder;
  21. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  22. class MyAwesomeExtension extends Extension {
  23. public function load(array $config, ContainerBuilder $container) {
  24. print_r($config);
  25. $loader = new XmlFileLoader($container, new FileLocator(__DIR__));
  26. $loader->load('services.xml');
  27. }
  28. }
  29. class YourCustomContext extends BehatContext {
  30. /**
  31. * @beforeSuite
  32. */
  33. public static function bS() {
  34. echo __METHOD__ . "\n";
  35. }
  36. }
  37. class MinkAwareInitializer implements InitializerInterface {
  38. private $mink;
  39. public function __construct(Mink $mink) {
  40. $this->mink = $mink;
  41. }
  42. public function supports(ContextInterface $context) {
  43. // in real life you should use interface for that
  44. return method_exists($context, 'setMink');
  45. }
  46. public function initialize(ContextInterface $context) {
  47. $context->setMink($this->mink);
  48. }
  49. }
  50. class MinkContextClassGuesser implements ClassGuesserInterface {
  51. public function guess() {
  52. return "YourCustomContext";
  53. }
  54. }
  55. #return new MyAwesomeExtension();