Skip to content

Commit

Permalink
Fix tests (#4)
Browse files Browse the repository at this point in the history
* Fix tests

* Update composer.json

* Update composer.json

* Update composer.json

* Update phpunit config

* Update tests workflow
  • Loading branch information
cbaconnier authored May 21, 2024
1 parent 12ecde9 commit 70c6f55
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
coverage: xdebug

- name: Install dependencies
run: |
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
},
"require": {
"php": "^8.1",
"illuminate/contracts": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"league/oauth2-client": "^2.6"
},
"require-dev": {
"brianium/paratest": "^6.2",
"orchestra/testbench": "^7.0",
"phpunit/phpunit": "^9.3",
"nunomaduro/collision": "^6.1",
"brianium/paratest": "^6.2|^7.4",
"orchestra/testbench": "^7.0|^8.20|^9.0",
"phpunit/phpunit": "^9.3|^10.3",
"nunomaduro/collision": "^6.1|^7.0|^8.0",
"spatie/invade": "^1.1",
"friendsofphp/php-cs-fixer": "^3.57"
"friendsofphp/php-cs-fixer": "^3.0"
},
"scripts": {
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
Expand Down
44 changes: 23 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Laravel Zoho Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="DB_CONNECTION" value="testing"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Laravel Zoho Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="DB_CONNECTION" value="testing"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
35 changes: 27 additions & 8 deletions tests/Auth/ZohoAuthProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use MelbaCh\LaravelZoho\Tests\TestCase;
use Mockery\MockInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

class ZohoAuthProviderTest extends TestCase
{
Expand Down Expand Up @@ -62,13 +63,17 @@ public function it_has_a_valid_access_token_url_path(): void
/** @test */
public function it_can_get_the_access_token_on_zoho(): void
{
$response = $this->mock(ResponseInterface::class, static function (MockInterface $response) {
$stream = $this->mock(StreamInterface::class, static function (MockInterface $stream) {
$data = [
'access_token' => 'mock_access_token',
'token_type' => 'bearer',
];

$response->shouldReceive('getBody')->andReturn(json_encode($data));
$stream->shouldReceive('__toString')->andReturn(json_encode($data));
});

$response = $this->mock(ResponseInterface::class, static function (MockInterface $response) use ($stream) {
$response->shouldReceive('getBody')->andReturn($stream);
$response->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
$response->shouldReceive('getStatusCode')->andReturn(200);
});
Expand All @@ -91,6 +96,7 @@ static function (MockInterface $client) use ($response) {

/**
* @test
*
* @throws Exception
*/
public function it_returns_the_crm_owner_data(): void
Expand All @@ -104,22 +110,30 @@ public function it_returns_the_crm_owner_data(): void
],
];

$tokenStream = $this->mock(StreamInterface::class, static function (MockInterface $stream) {
$stream->shouldReceive('__toString')->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token');
});

$tokenResponse = $this->mock(
ResponseInterface::class,
static function (MockInterface $response) {
static function (MockInterface $response) use ($tokenStream) {
$response->shouldReceive('getBody')
->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token');
->andReturn($tokenStream);
$response->shouldReceive('getHeader')
->andReturn(['content-type' => 'application/x-www-form-urlencoded']);
$response->shouldReceive('getStatusCode')
->andReturn(200);
}
);

$ownerStream = $this->mock(StreamInterface::class, static function (MockInterface $stream) use ($data) {
$stream->shouldReceive('__toString')->andReturn(json_encode($data));
});

$ownerResponse = $this->mock(
ResponseInterface::class,
static function (MockInterface $response) use ($data) {
$response->shouldReceive('getBody')->andReturn(json_encode($data));
static function (MockInterface $response) use ($ownerStream) {
$response->shouldReceive('getBody')->andReturn($ownerStream);
$response->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
$response->shouldReceive('getStatusCode')->andReturn(200);
}
Expand All @@ -144,6 +158,7 @@ static function (MockInterface $client) use ($tokenResponse, $ownerResponse) {

/**
* @test
*
* @throws Exception
*/
public function exception_is_thrown_when_error_object_is_received(): void
Expand All @@ -154,10 +169,14 @@ public function exception_is_thrown_when_error_object_is_received(): void
'code' => uniqid('', true),
];

$stream = $this->mock(StreamInterface::class, static function (MockInterface $stream) use ($error) {
$stream->shouldReceive('__toString')->andReturn(json_encode($error));
});

$response = $this->mock(
ResponseInterface::class,
static function (MockInterface $response) use ($status, $error) {
$response->shouldReceive('getBody')->andReturn(json_encode($error));
static function (MockInterface $response) use ($status, $stream) {
$response->shouldReceive('getBody')->andReturn($stream);
$response->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
$response->shouldReceive('getStatusCode')->andReturn($status);
}
Expand Down

0 comments on commit 70c6f55

Please sign in to comment.