@@ 1120-1139 (lines=20) @@ | ||
1117 | * @return Assert |
|
1118 | * @throws AssertionFailedException |
|
1119 | */ |
|
1120 | public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
|
1121 | { |
|
1122 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1123 | { |
|
1124 | return $this; |
|
1125 | } |
|
1126 | $this->string($message, $propertyPath); |
|
1127 | if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
|
1128 | { |
|
1129 | $message = $message ?: $this->overrideError; |
|
1130 | $message = sprintf( |
|
1131 | $message ?: 'Value "%s" does not start with "%s".', |
|
1132 | $this->stringify($this->value), |
|
1133 | $this->stringify($needle) |
|
1134 | ); |
|
1135 | $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1136 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints); |
|
1137 | } |
|
1138 | return $this; |
|
1139 | } |
|
1140 | ||
1141 | /** |
|
1142 | * Assert that string ends with a sequence of chars. |
|
@@ 1183-1202 (lines=20) @@ | ||
1180 | * @return Assert |
|
1181 | * @throws AssertionFailedException |
|
1182 | */ |
|
1183 | public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
|
1184 | { |
|
1185 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1186 | { |
|
1187 | return $this; |
|
1188 | } |
|
1189 | $this->string($message, $propertyPath); |
|
1190 | if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
|
1191 | { |
|
1192 | $message = $message ?: $this->overrideError; |
|
1193 | $message = sprintf( |
|
1194 | $message ?: 'Value "%s" does not contain "%s".', |
|
1195 | $this->stringify($this->value), |
|
1196 | $this->stringify($needle) |
|
1197 | ); |
|
1198 | $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1199 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
|
1200 | } |
|
1201 | return $this; |
|
1202 | } |
|
1203 | ||
1204 | /** |
|
1205 | * Assert that value is in array of choices. |