@@ 1142-1161 (lines=20) @@ | ||
1139 | * @return Assert |
|
1140 | * @throws AssertionFailedException |
|
1141 | */ |
|
1142 | public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
|
1143 | { |
|
1144 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1145 | { |
|
1146 | return $this; |
|
1147 | } |
|
1148 | $this->string($message, $propertyPath); |
|
1149 | if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
|
1150 | { |
|
1151 | $message = $message ?: $this->overrideError; |
|
1152 | $message = sprintf( |
|
1153 | $message ?: 'Value "%s" does not start with "%s".', |
|
1154 | $this->stringify($this->value), |
|
1155 | $this->stringify($needle) |
|
1156 | ); |
|
1157 | $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1158 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints); |
|
1159 | } |
|
1160 | return $this; |
|
1161 | } |
|
1162 | ||
1163 | /** |
|
1164 | * Assert that string ends with a sequence of chars. |
|
@@ 1205-1224 (lines=20) @@ | ||
1202 | * @return Assert |
|
1203 | * @throws AssertionFailedException |
|
1204 | */ |
|
1205 | public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
|
1206 | { |
|
1207 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1208 | { |
|
1209 | return $this; |
|
1210 | } |
|
1211 | $this->string($message, $propertyPath); |
|
1212 | if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
|
1213 | { |
|
1214 | $message = $message ?: $this->overrideError; |
|
1215 | $message = sprintf( |
|
1216 | $message ?: 'Value "%s" does not contain "%s".', |
|
1217 | $this->stringify($this->value), |
|
1218 | $this->stringify($needle) |
|
1219 | ); |
|
1220 | $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1221 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
|
1222 | } |
|
1223 | return $this; |
|
1224 | } |
|
1225 | ||
1226 | /** |
|
1227 | * Assert that value is in array of choices. |