Skip to content

Commit

Permalink
Added test for handling 400 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rickkuilman committed Oct 23, 2021
1 parent fa9c45d commit 2f48099
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/DigitalHumaniPhpSdkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mockery;
use PHPUnit\Framework\TestCase;
use Rickkuilman\DigitalHumaniPhpSdk\DigitalHumani;
use Rickkuilman\DigitalHumaniPhpSdk\Exceptions\BadRequestException;
use Rickkuilman\DigitalHumaniPhpSdk\Exceptions\ForbiddenException;
use Rickkuilman\DigitalHumaniPhpSdk\Exceptions\NotFoundException;
use Rickkuilman\DigitalHumaniPhpSdk\Exceptions\UnauthorizedException;
Expand Down Expand Up @@ -80,4 +81,27 @@ public function test_handling_403_errors()
$digitalHumani->projects();
}

public function test_handling_400_errors()
{
$this->expectException(BadRequestException::class);

$digitalHumani = new DigitalHumani('abc', '4c6e672d', false, $http = Mockery::mock(Client::class));

$http->shouldReceive('request')
->once()
->with('POST', 'tree', [
'json' => [
'enterpriseId' => '4c6e672d',
'user' => 'rick@example.com',
'treeCount' => 1,
'projectId' => DigitalHumani::DEFAULT_PROJECT_ID,
],
])
->andReturn(
new Response(400)
);

$digitalHumani->plantTree('rick@example.com');
}

}

0 comments on commit 2f48099

Please sign in to comment.