Skip to content

Commit

Permalink
Merge pull request #34 from MasonM/fix-request-headers-constraint-sid…
Browse files Browse the repository at this point in the history
…e-effecs

Fix side effects in RequestHeadersConstraint
  • Loading branch information
Maks3w authored Jun 13, 2017
2 parents 3e56d78 + 1cac40b commit a41ec65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/PhpUnit/RequestHeadersConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function __construct($headersParameters, Validator $validator)
// @codeCoverageIgnoreEnd
}

$headerParameter = clone $headerParameter;

$normalizedName = strtolower($headerParameter->name);
unset($headerParameter->name);

Expand Down
13 changes: 11 additions & 2 deletions tests/PhpUnit/RequestHeadersConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class RequestHeadersConstraintTest extends TestCase
* @var Constraint
*/
protected $constraint;
const TEST_SCHEMA = '[{"name":"X-Required-Header","in":"header","description":"Required header","required":true,"type":"string"},{"name":"X-Optional-Header","in":"header","description":"Optional header","type":"string"}]';

protected function setUp()
{
$schema = '[{"name":"X-Required-Header","in":"header","description":"Required header","required":true,"type":"string"},{"name":"X-Optional-Header","in":"header","description":"Optional header","type":"string"}]';
$schema = json_decode($schema);
$schema = json_decode(self::TEST_SCHEMA);

$this->constraint = new RequestHeadersConstraint($schema, new Validator());
}
Expand Down Expand Up @@ -73,4 +73,13 @@ public function testInvalidHeaderType()
);
}
}

public function testSchemaUnchanged()
{
$schema = json_decode(self::TEST_SCHEMA);
new RequestHeadersConstraint($schema, new Validator());

// Make sure there were no side effects ($schema should be unchanged)
self::assertEquals($schema, json_decode(self::TEST_SCHEMA));
}
}

0 comments on commit a41ec65

Please sign in to comment.