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

Commit

Permalink
Change type of statuses returned by getResponseCodes (#26)
Browse files Browse the repository at this point in the history
* Change type of statuses returned by getResponseCodes

* Update CHANGELOG

* Remove allowance to failure on 7.2 on Travis
  • Loading branch information
slavcodev authored Dec 1, 2018
1 parent a2561c5 commit 9e1950b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ matrix:
env:
- EXECUTE_COVERAGE=true
- php: 7.2
allow_failures:
- php: 7.2

notifications:
email: false
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file
using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.4.0] 2018-12-01

### Fixed

- Change type of statuses returned by getResponseCodes from string to int

## [0.3.1] 2018-02-17

### Changed

- Add phpunit 6.0 fallback version

## [0.3.0] 2018-02-17

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/PhpUnit/Asserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ final protected static function assertMethodAllowed(Spec $spec, $template, $meth
final protected static function assertResponseDefined(Spec $spec, $template, $method, $status, $msg = '')
{
Assert::assertTrue(
in_array((string) $status, $spec->getResponseCodes($template, strtolower($method)), true),
in_array((int) $status, $spec->getResponseCodes($template, strtolower($method)), true),
$msg ?: "Operation \"{$method} {$template}\" does not support response code \"{$status}\""
);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ public function getRequestContentTypes($template, $method)
* @param string $template
* @param string $method
*
* @return string[]
* @return int[]
*/
public function getResponseCodes($template, $method)
{
return array_filter(
array_keys((array) $this->fetch($this->schema, 'paths', $template, $method, 'responses')),
'is_numeric'
return array_map(
'intval',
array_filter(
array_keys((array) $this->fetch($this->schema, 'paths', $template, $method, 'responses')),
'is_numeric'
)
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function howToUseSwagger(Schema $spec)
$this->assertSame(['application/json'], $produces);

$statuses = $spec->getResponseCodes($template, 'get');
$this->assertSame(['200'], $statuses);
$this->assertSame([200], $statuses);

$responseHeaders = $spec->getResponseHeaderSchemas($template, 'get', 200);
$this->assertTrue(isset($responseHeaders['Content-Type']));
Expand Down

0 comments on commit 9e1950b

Please sign in to comment.