Skip to content

Commit

Permalink
[BUGFIX] Show correct type in exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
brotkrueml committed Apr 2, 2020
1 parent 2f60265 commit 2c69a4f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ jobs:
vendor/bin/psalm --no-progress
- name: Run infection
run: |
vendor/bin/infection --no-progress --min-msi=93 --threads=4
vendor/bin/infection --no-progress --min-msi=94 --threads=4
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"ext-curl": "*",
"ext-json": "*",
"kriswallsmith/buzz": "^1.1",
"nyholm/psr7": "^1.2"
"nyholm/psr7": "^1.2",
"symfony/polyfill-php80": "^1.15"
},
"require-dev": {
"captainhook/captainhook": "^5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Client/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function request(string $method, string $resource, $data = []): ResponseI
throw new RestClientException(
\sprintf(
'data must be an array, "%s" given',
gettype($data)
\get_debug_type($data)
),
1578233543
);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function setProcessTableField(string $name, $value): self
\sprintf(
'value has to be either a string, an integer, a boolean or an instance of %s, "%s" given',
FileInterface::class,
gettype($value)
\get_debug_type($value)
),
1578225863
);
Expand Down
18 changes: 17 additions & 1 deletion tests/Unit/Client/RestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,33 @@ public function formDataIsCorrectlySend(): void
/**
* @test
*/
public function requestWhenDataIsNotAnArrayAnExceptionIsThrown(): void
public function requestWhenDataIsABooleanAnExceptionIsThrown(): void
{
$this->expectException(RestClientException::class);
$this->expectExceptionCode(1578233543);
$this->expectExceptionMessage('data must be an array, "bool" given');

$this->setResponseOfTokensPath();
$restClient = new RestClient(self::$configuration);

$restClient->request('POST', 'some/route', false);
}

/**
* @test
*/
public function requestWhenDataIsAClassAnExceptionIsThrown(): void
{
$this->expectException(RestClientException::class);
$this->expectExceptionCode(1578233543);
$this->expectExceptionMessage('data must be an array, "stdClass" given');

$this->setResponseOfTokensPath();
$restClient = new RestClient(self::$configuration);

$restClient->request('POST', 'some/route', new \stdClass());
}

/**
* @test
*/
Expand Down
16 changes: 15 additions & 1 deletion tests/Unit/Model/IncidentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,28 @@ public function setAndGetProcessTableFieldAreImplementedCorrectlyForAFile(): voi
/**
* @test
*/
public function setProcessTableFieldThrowsExceptionWhenValueTypeIsNotAllowed(): void
public function setProcessTableFieldThrowsExceptionWhenValueTypeIsAClass(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1578225863);
$this->expectExceptionMessage('value has to be either a string, an integer, a boolean or an instance of Brotkrueml\JobRouterClient\Resource\FileInterface, "stdClass" given');

$this->subject->setProcessTableField('some name', new \stdClass());
}

/**
* @test
*/
public function setProcessTableFieldThrowsExceptionWhenValueTypeIsAnArray(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1578225863);
$this->expectExceptionMessage('value has to be either a string, an integer, a boolean or an instance of Brotkrueml\JobRouterClient\Resource\FileInterface, "array" given');

/** @noinspection PhpParamsInspection */
$this->subject->setProcessTableField('some name', ['invalid']);
}

/**
* @test
*/
Expand Down

0 comments on commit 2c69a4f

Please sign in to comment.