This repository has been archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
125 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":1,"defects":{"Prem\\ResponseBuilder\\Feature\\ResponseBuilderTest::test_success":3},"times":{"Prem\\ResponseBuilder\\Feature\\ResponseBuilderTest::test_success":0.149,"Prem\\ResponseBuilder\\Feature\\ResponseBuilderTest::test_error":0.01}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Feature"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_KEY" value="base64:9LNymWc/qr+yXLDCC1AFo9b0rLbQSROeC1Em+XgJgtg="/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Prem\ResponseBuilder\Feature; | ||
|
||
use Illuminate\Http\Response; | ||
use Prem\ResponseBuilder\ResponseBuilder; | ||
use Prem\ResponseBuilder\Tests\TestCase; | ||
|
||
class ResponseBuilderTest extends TestCase | ||
{ | ||
public function test_success(): void | ||
{ | ||
$httpOk = Response::HTTP_OK; | ||
|
||
$data = [ | ||
'name' => 'Prem Chand Saini', | ||
'email' => '[email protected]' | ||
]; | ||
|
||
$message = 'Getting the user details'; | ||
|
||
$res = ResponseBuilder::success($data, $message); | ||
|
||
$this->assertEquals($httpOk, $res->status()); | ||
|
||
$res = json_decode($res->getContent()); | ||
|
||
$this->assertObjectHasAttribute('status', $res); | ||
$this->assertIsBool(true, $res->status); | ||
$this->assertObjectHasAttribute('data', $res); | ||
$this->assertEquals($data['name'], $res->data->name); | ||
$this->assertEquals($data['email'], $res->data->email); | ||
$this->assertObjectHasAttribute('message', $res); | ||
$this->assertEquals($message, $res->message); | ||
} | ||
|
||
public function test_error(): void | ||
{ | ||
$message = 'Whoops! Something went wrong please try after some time'; | ||
$code = Response::HTTP_INTERNAL_SERVER_ERROR; | ||
|
||
$res = ResponseBuilder::error($message, $code); | ||
|
||
$this->assertEquals($code, $res->status()); | ||
|
||
$res = json_decode($res->getContent()); | ||
|
||
$this->assertObjectHasAttribute('status', $res); | ||
$this->assertIsBool(false, $res->status); | ||
$this->assertObjectHasAttribute('message', $res); | ||
$this->assertEquals($message, $res->message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Prem\ResponseBuilder\Tests; | ||
|
||
use Prem\ResponseBuilder\ResponseBuilderServiceProvider; | ||
|
||
class TestCase extends \Orchestra\Testbench\TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
// additional setup | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
ResponseBuilderServiceProvider::class, | ||
]; | ||
} | ||
|
||
protected function getEnvironmentSetUp($app) | ||
{ | ||
// perform environment setup | ||
} | ||
} |