Completed
Push — master ( 2bb842...c59813 )
by Rudie
02:18
created

SimpleFeatureContext   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A aValue() 0 3 1
A valuesAnd() 0 3 1
A valuesAndAnd() 0 3 1
A shouldEqual() 0 5 2
A theDatabaseShouldContain() 0 14 3
1
<?php
2
3
use Behat\Behat\Context\Context;
4
use Behat\Behat\Context\SnippetAcceptingContext;
5
use Behat\Behat\Tester\Exception\PendingException;
6
use Behat\Gherkin\Node\PyStringNode;
7
use Behat\Gherkin\Node\TableNode;
8
use rdx\behatvars\BehatVariablesDatabase;
9
10
class SimpleFeatureContext implements Context, SnippetAcceptingContext {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
12
	/**
13
	 * @Given a value :value
14
	 */
15
	public function aValue($value) {
16
		return $value;
17
	}
18
19
	/**
20
	 * @Given values :value1 and :value2
21
	 */
22
	public function valuesAnd($value1, $value2) {
23
		return [$value1, $value2];
24
	}
25
26
	/**
27
	 * @Given values :value1 and :value2 and :value3
28
	 */
29
	public function valuesAndAnd($value1, $value2, $value3) {
30
		return [$value1, $value2, $value3];
31
	}
32
33
	/**
34
	 * @Then :a should equal :b
35
	 */
36
	public function shouldEqual($a, $b) {
37
		if ($a != $b) {
38
			throw new \Exception("a ($a) does not equal b ($b)");
39
		}
40
	}
41
42
	/**
43
	 * @Then the database should contain:
44
	 */
45
	public function theDatabaseShouldContain(PyStringNode $string) {
46
		// Convert database to TableNode, to compare against test string
47
		$table = array();
48
		foreach (BehatVariablesDatabase::all() as $name => $value) {
49
			$table[] = array($name, $value);
50
		}
51
52
		$table = new TableNode($table);
53
		$table = trim($table);
54
55
		if (trim($string) != $table) {
56
			throw new \Exception("Database contents are wrong:\n$table");
57
		}
58
	}
59
60
}
61