@@ 1106-1125 (lines=20) @@ | ||
1103 | * @return Assert |
|
1104 | * @throws AssertionFailedException |
|
1105 | */ |
|
1106 | public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
|
1107 | { |
|
1108 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1109 | { |
|
1110 | return $this; |
|
1111 | } |
|
1112 | $this->string($message, $propertyPath); |
|
1113 | if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
|
1114 | { |
|
1115 | $message = $message ?: $this->overrideError; |
|
1116 | $message = sprintf( |
|
1117 | $message ?: 'Value "%s" does not start with "%s".', |
|
1118 | $this->stringify($this->value), |
|
1119 | $this->stringify($needle) |
|
1120 | ); |
|
1121 | $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1122 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints); |
|
1123 | } |
|
1124 | return $this; |
|
1125 | } |
|
1126 | ||
1127 | /** |
|
1128 | * Assert that string ends with a sequence of chars. |
|
@@ 1169-1188 (lines=20) @@ | ||
1166 | * @return Assert |
|
1167 | * @throws AssertionFailedException |
|
1168 | */ |
|
1169 | public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
|
1170 | { |
|
1171 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1172 | { |
|
1173 | return $this; |
|
1174 | } |
|
1175 | $this->string($message, $propertyPath); |
|
1176 | if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
|
1177 | { |
|
1178 | $message = $message ?: $this->overrideError; |
|
1179 | $message = sprintf( |
|
1180 | $message ?: 'Value "%s" does not contain "%s".', |
|
1181 | $this->stringify($this->value), |
|
1182 | $this->stringify($needle) |
|
1183 | ); |
|
1184 | $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1185 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
|
1186 | } |
|
1187 | return $this; |
|
1188 | } |
|
1189 | ||
1190 | /** |
|
1191 | * Assert that value is in array of choices. |