Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit d9b096a

Browse files
authored
Use multibyte functions (#34)
1 parent 7f6e260 commit d9b096a

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"require": {
1616
"php": "^7.1",
1717
"ext-json": "*",
18+
"ext-mbstring": "*",
1819
"psr/http-message": "^1.0",
1920
"justinrainbow/json-schema": "~5.2",
2021
"phpunit/phpunit": "~7.5"

src/PhpUnit/Asserts.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ final protected static function assertMethodAllowed(Schema $schema, string $path
116116
final protected static function assertResponseDefined(Schema $schema, string $template, string $method, string $status, string $msg = ''): void
117117
{
118118
Assert::assertTrue(
119-
$schema->isResponseDefined($template, strtolower($method), $status),
119+
$schema->isResponseDefined($template, mb_strtolower($method), $status),
120120
$msg ?: "Operation \"{$method} {$template}\" does not support response code \"{$status}\""
121121
);
122122
}
@@ -149,15 +149,15 @@ final protected static function assertRequestHeaders(Schema $schema, string $pat
149149
{
150150
Assert::assertThat(
151151
$headers,
152-
new HeadersConstraint($schema->getRequestHeaderSchemas($path, strtolower($method))),
152+
new HeadersConstraint($schema->getRequestHeaderSchemas($path, mb_strtolower($method))),
153153
$msg
154154
);
155155

156156
if ($schema->isRequestBodyDefined($path, $method) && isset($headers['Content-Type'][0])) {
157157
self::assertRequestContentType(
158158
$schema,
159159
$path,
160-
strtolower($method),
160+
mb_strtolower($method),
161161
$headers['Content-Type'][0],
162162
$msg
163163
);
@@ -169,7 +169,7 @@ final protected static function assertResponseHeaders(Schema $schema, string $pa
169169
Assert::assertThat(
170170
$headers,
171171
new HeadersConstraint(
172-
$schema->getResponseHeaderSchemas($path, strtolower($method), $status)
172+
$schema->getResponseHeaderSchemas($path, mb_strtolower($method), $status)
173173
),
174174
$msg
175175
);
@@ -186,7 +186,7 @@ final protected static function assertResponseHeaders(Schema $schema, string $pa
186186
}
187187

188188
if (isset($headers['Allow'])) {
189-
if (isset($headers['Allow'][0]) && strpos($headers['Allow'][0], ',') !== false) {
189+
if (isset($headers['Allow'][0]) && mb_strpos($headers['Allow'][0], ',') !== false) {
190190
$headers['Allow'] = preg_split('#\s*,\s*#', $headers['Allow'][0], -1, PREG_SPLIT_NO_EMPTY);
191191
}
192192

@@ -200,7 +200,7 @@ final protected static function assertResponseHeaders(Schema $schema, string $pa
200200

201201
final protected static function assertRequestBody(Schema $schema, string $path, string $method, StreamInterface $body = null, string $msg = ''): void
202202
{
203-
$bodySchema = $schema->getRequestBodySchema($path, strtolower($method));
203+
$bodySchema = $schema->getRequestBodySchema($path, mb_strtolower($method));
204204

205205
if ($bodySchema) {
206206
Assert::assertThat(
@@ -215,7 +215,7 @@ final protected static function assertRequestBody(Schema $schema, string $path,
215215

216216
final protected static function assertResponseBody(Schema $schema, string $path, string $method, string $status, StreamInterface $body = null, string $msg = ''): void
217217
{
218-
$bodySchema = $schema->getResponseBodySchema($path, strtolower($method), $status);
218+
$bodySchema = $schema->getResponseBodySchema($path, mb_strtolower($method), $status);
219219

220220
if ($bodySchema) {
221221
Assert::assertThat(

src/PhpUnit/ContentTypeConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public function toString(): string
3939

4040
private static function stripParams(string $type): string
4141
{
42-
return strstr($type, ';', true) ?: $type;
42+
return mb_strstr($type, ';', true) ?: $type;
4343
}
4444
}

src/PhpUnit/MethodsAllowedConstraint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ final class MethodsAllowedConstraint extends Constraint
2222
public function __construct(array $allowedMethods)
2323
{
2424
parent::__construct();
25-
$this->allowedMethods = array_map('strtoupper', $allowedMethods);
25+
$this->allowedMethods = array_map('mb_strtoupper', $allowedMethods);
2626
}
2727

2828
protected function matches($other): bool
2929
{
3030
if (is_string($other)) {
31-
return in_array(strtoupper($other), $this->allowedMethods);
32-
} else {
33-
return empty(array_diff($this->allowedMethods, array_map('strtoupper', $other)));
31+
return in_array(mb_strtoupper($other), $this->allowedMethods);
3432
}
33+
34+
return empty(array_diff($this->allowedMethods, array_map('mb_strtoupper', $other)));
3535
}
3636

3737
public function toString(): string

src/PhpUnit/UriConstraint.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private function assertPathSegment(string $expectedSegment, string $actualSegmen
6161

6262
private function assertPathParam(string $expectedSegment, string $actualSegment)
6363
{
64-
$pathParamSchema = $this->pathParameters[substr($expectedSegment, 1, -1)];
64+
$pathParamSchema = $this->pathParameters[mb_substr($expectedSegment, 1, -1)];
6565

6666
// TODO: Consider to disallow non-string params in path, that make no sense
6767
$actualSegment = $this->normalizeNumericString($actualSegment);
@@ -81,7 +81,7 @@ protected function matches($uri): bool
8181
$baseUrl = null;
8282

8383
foreach ($this->servers as $serverUrl) {
84-
if (strpos((string) $uri, $serverUrl) === 0) {
84+
if (mb_strpos((string) $uri, $serverUrl) === 0) {
8585
$baseUrl = $serverUrl;
8686

8787
continue;
@@ -97,8 +97,8 @@ protected function matches($uri): bool
9797
return false;
9898
}
9999

100-
$pathStart = strlen($baseUrl) - strpos($baseUrl, '/', strpos($baseUrl, '://') + 3);
101-
$path = substr($uri->getPath(), $pathStart + 1);
100+
$pathStart = mb_strlen($baseUrl) - mb_strpos($baseUrl, '/', mb_strpos($baseUrl, '://') + 3);
101+
$path = mb_substr($uri->getPath(), $pathStart + 1);
102102
$actualSegments = $this->splitString('#\/#', $path);
103103
$expectedSegments = $this->splitString('#\/#', $this->path);
104104

@@ -113,7 +113,7 @@ protected function matches($uri): bool
113113

114114
foreach ($expectedSegments as $i => $expectedSegment) {
115115
$actualSegment = $actualSegments[$i];
116-
strpos($expectedSegment, '{') === false
116+
mb_strpos($expectedSegment, '{') === false
117117
? $this->assertPathSegment($expectedSegment, $actualSegment)
118118
: $this->assertPathParam($expectedSegment, $actualSegment);
119119
}

src/Schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class Schema
2525

2626
public function __construct(string $uri)
2727
{
28-
if (strpos($uri, '//') === false) {
28+
if (mb_strpos($uri, '//') === false) {
2929
$uri = "file://{$uri}";
3030
}
3131

@@ -206,7 +206,7 @@ private function encodePath(string $path): string
206206

207207
private function normalizeMethod(string $method): string
208208
{
209-
return strtolower($method);
209+
return mb_strtolower($method);
210210
}
211211

212212
private function getRequestParameters(string $path, string $method, string $location): array

0 commit comments

Comments
 (0)