Completed
Push — 3.2 ( 51a84d...abe3a3 )
by Jonathan
8s
created

ClassGenerator::supportsSuiteAndClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Drupal\DrupalExtension\Context\ContextClass;
4
5
use Behat\Behat\Context\ContextClass\ClassGenerator as BehatClassGenerator;
6
use Behat\Testwork\Suite\Suite;
7
8
/**
9
 * Generates a starting class that extends the RawDrupalContext.
10
 */
11
class ClassGenerator implements BehatClassGenerator {
12
13
  /**
14
   * @var string
15
   */
16
  protected static $template = <<<'PHP'
17
<?php
18
19
{namespace}use Drupal\DrupalExtension\Context\RawDrupalContext;
20
use Behat\Behat\Context\SnippetAcceptingContext;
21
use Behat\Gherkin\Node\PyStringNode;
22
use Behat\Gherkin\Node\TableNode;
23
use Behat\Behat\Tester\Exception\PendingException;
24
25
/**
26
 * Defines application features from the specific context.
27
 */
28
class {className} extends RawDrupalContext implements SnippetAcceptingContext {
29
30
  /**
31
   * Initializes context.
32
   *
33
   * Every scenario gets its own context instance.
34
   * You can also pass arbitrary arguments to the
35
   * context constructor through behat.yml.
36
   */
37
  public function __construct() {
38
  }
39
40
}
41
42
PHP;
43
44
  /**
45
   * {@inheritdoc}
46
   */
47
  public function supportsSuiteAndClass(Suite $suite, $contextClass) {
48
    return TRUE;
49
  }
50
51
  /**
52
   * {@inheritdoc}
53
   */
54
  public function generateClass(Suite $suite, $contextClass) {
55
    $fqn = $contextClass;
56
57
    $namespace = '';
58
    if (false !== $pos = strrpos($fqn, '\\')) {
59
      $namespace = 'namespace ' . substr($fqn, 0, $pos) . ";\n\n";
60
      $contextClass = substr($fqn, $pos + 1);
61
    }
62
63
    return strtr(
64
      static::$template,
65
      array(
66
        '{namespace}' => $namespace,
67
        '{className}' => $contextClass,
68
      )
69
    );
70
  }
71
}
72