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

Commit d86c2c9

Browse files
committed
Fixed normalizing headers in HeadersConstraint (#15)
* Fixed normalizing headers in HeadersConstraint * Update CHANGELOG
1 parent 55d12e7 commit d86c2c9

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file
33
using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [Unreleased]
7+
8+
### Fixed
9+
- Fixed normalizing headers with scalar value in HeadersConstraint.
10+
611
## [0.1.1] 2016-05-15
712

813
### Added

src/PhpUnit/HeadersConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ private static function normalizeJsonSchema($schema)
118118
*/
119119
private static function normalizeHeaderValue($value)
120120
{
121-
if (is_string($value)) {
121+
if (is_string($value) && strpos($value, ',') !== false) {
122122
return preg_split('#\s*,\s*#', $value, -1, PREG_SPLIT_NO_EMPTY);
123123
} else {
124-
return (array) $value;
124+
return $value;
125125
}
126126
}
127127
}

tests/PhpUnit/HeadersConstraintTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ protected function setUp()
3434
$this->constraint = new HeadersConstraint(
3535
[
3636
'Content-Type' => [
37-
'type' => 'array',
37+
'type' => 'string',
3838
'required' => true,
39-
'minItems' => 1,
40-
'items' => [
41-
'type' => 'string',
42-
],
4339
],
4440
'Allow' => [
4541
'type' => 'array',
@@ -48,6 +44,9 @@ protected function setUp()
4844
'type' => 'string',
4945
],
5046
],
47+
'X-Timestamp' => [
48+
'type' => 'integer',
49+
],
5150
]
5251
);
5352
}
@@ -68,7 +67,11 @@ public function passUnexpectedValue()
6867
*/
6968
public function AssertValidHeaders()
7069
{
71-
$headers = ['Content-Type' => ['application/json'], 'Allow' => 'OPTIONS, HEAD'];
70+
$headers = [
71+
'Content-Type' => 'application/json',
72+
'Allow' => 'OPTIONS, HEAD',
73+
'X-Timestamp' => time(),
74+
];
7275

7376
$this->assertThat($headers, $this->constraint);
7477
}
@@ -104,12 +107,17 @@ public function provideInvalidHeaders()
104107
'Missing required header' => [
105108
[],
106109
],
107-
'[Allow] There must be a minimum of 2 items in the array' => [
110+
'[Allow] String value found, but an array is required' => [
108111
[
109112
'Content-Type' => 'application/json',
110113
'Allow' => 'OPTIONS',
111114
],
112115
],
116+
'[X-Timestamp] String value found, but an integer is required' => [
117+
[
118+
'X-Timestamp' => 'foo',
119+
],
120+
],
113121
];
114122
}
115123
}

0 commit comments

Comments
 (0)