TYPO3 CMS  TYPO3_6-2
All Classes Namespaces Files Functions Variables Pages
AbstractRecordConstraint.php
Go to the documentation of this file.
1 <?php
3 
18 
22 abstract class AbstractRecordConstraint extends \PHPUnit_Framework_Constraint {
23 
27  protected $sectionFailures = array();
28 
32  protected $table;
33 
37  protected $field;
38 
42  protected $strict = FALSE;
43 
47  protected $values;
48 
49  public function setTable($table) {
50  $this->table = $table;
51  return $this;
52  }
53 
54  public function setField($field) {
55  $this->field = $field;
56  return $this;
57  }
58 
59  public function setValues() {
60  $values = func_get_args();
61  $this->values = $values;
62  return $this;
63  }
64 
65  public function setStrict($strict) {
66  $this->strict = (bool)$strict;
67  return $this;
68  }
69 
77  protected function matches($other) {
78  if (is_array($other)) {
79  $success = NULL;
80  foreach ($other as $item) {
81  $currentSuccess = $this->matchesSection($item);
82  $success = ($success === NULL ? $currentSuccess : $success || $currentSuccess);
83  }
84  return !empty($success);
85  } else {
86  return $this->matchesSection($other);
87  }
88  }
89 
94  abstract protected function matchesSection(ResponseSection $responseSection);
95 
100  protected function getNonMatchingValues(array $records) {
102 
103  foreach ($records as $recordIdentifier => $recordData) {
104  if (strpos($recordIdentifier, $this->table . ':') !== 0) {
105  continue;
106  }
107 
108  if (($foundValueIndex = array_search($recordData[$this->field], $values)) !== FALSE) {
109  unset($values[$foundValueIndex]);
110  }
111  }
112 
113  return $values;
114  }
115 
120  protected function getRemainingRecords(array $records) {
122 
123  foreach ($records as $recordIdentifier => $recordData) {
124  if (strpos($recordIdentifier, $this->table . ':') !== 0) {
125  unset($records[$recordIdentifier]);
126  continue;
127  }
128 
129  if (($foundValueIndex = array_search($recordData[$this->field], $values)) !== FALSE) {
130  unset($values[$foundValueIndex]);
131  unset($records[$recordIdentifier]);
132  }
133  }
134 
135  return $records;
136  }
137 
147  protected function failureDescription($other) {
148  return $this->toString();
149  }
150 
160  protected function additionalFailureDescription($other) {
161  $failureDescription = '';
162  foreach ($this->sectionFailures as $sectionIdentifier => $sectionFailure) {
163  $failureDescription .= '* Section "' . $sectionIdentifier . '": ' . $sectionFailure . LF;
164  }
165  return $failureDescription;
166  }
167 
168 }