Skip to content

Commit

Permalink
Improve tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Apr 3, 2019
1 parent ba99aa0 commit 9b1aaaf
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"autoload-dev": {
"psr-4": {
"Katsana\\TestCase\\": "tests/"
"Katsana\\Tests\\": "tests/"
}
},
"require": {
Expand Down
7 changes: 6 additions & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ protected function createHttpClient(): Client
return $client;
}

public function getDefaultDriver(): string
/**
* Get the default driver name.
*
* @return string
*/
public function getDefaultDriver()
{
return 'laravel';
}
Expand Down
4 changes: 3 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function register()
});

$this->app->singleton('katsana.manager', function (Application $app) {
return new Manager($app, $app->make('config')->get('services.katsana'));
return new Manager(
$app, $app->make('config')->get('services.katsana', ['environment' => 'production'])
);
});

$this->app->singleton('katsana', function (Application $app) {
Expand Down
58 changes: 58 additions & 0 deletions tests/ManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Katsana\Tests;

use Katsana\Manager;

class ManagerTest extends TestCase
{
/** @test */
public function it_has_proper_signature()
{
config(['services.katsana' => [
'environment' => 'carbon',
]]);

$stub = $this->app['katsana.manager'];

$this->assertSame('laravel', $stub->getDefaultDriver());
}

/** @test */
public function it_can_use_laravel_driver()
{
config(['services.katsana' => [
'client_id' => static::CLIENT_ID,
'client_secret' => static::CLIENT_SECRET,
'access_token' => static::ACCESS_TOKEN,
'environment' => 'carbon',
]]);

$stub = $this->app['katsana.manager']->driver('laravel');

$this->assertSame(static::CLIENT_ID, $stub->getClientId());
$this->assertSame(static::CLIENT_SECRET, $stub->getClientSecret());
$this->assertSame(static::ACCESS_TOKEN, $stub->getAccessToken());

$this->assertSame('https://carbon.api.katsana.com', $stub->getApiEndpoint());
}

/** @test */
public function it_can_use_sdk_driver()
{
config(['services.katsana' => [
'client_id' => static::CLIENT_ID,
'client_secret' => static::CLIENT_SECRET,
'access_token' => static::ACCESS_TOKEN,
'environment' => 'carbon',
]]);

$stub = $this->app['katsana.manager']->driver('sdk');

$this->assertNull($stub->getClientId());
$this->assertNull($stub->getClientSecret());
$this->assertNull($stub->getAccessToken());

$this->assertSame('https://carbon.api.katsana.com', $stub->getApiEndpoint());
}
}
2 changes: 1 addition & 1 deletion tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Katsana\TestCase;
namespace Katsana\Tests;

use Katsana\Katsana;
use Katsana\ServiceProvider;
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Katsana\TestCase;
namespace Katsana\Tests;

use Orchestra\Testbench\TestCase as Testbench;

Expand Down

0 comments on commit 9b1aaaf

Please sign in to comment.