Skip to content

Commit

Permalink
Adding orchestra testbench for testing integration with Laravel.
Browse files Browse the repository at this point in the history
  • Loading branch information
danvuquoc committed Mar 12, 2018
1 parent af8514a commit 6b7bd1c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 3 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"autoload": {
"psr-4": {
"Danvuquoc\\Kraken\\": "src/"
"Danvuquoc\\Kraken\\": "src/",
"Danvuquoc\\Kraken\\Tests\\": "tests/"
}
},
"extra": {
Expand All @@ -21,5 +22,8 @@
"KrakenIO": "Danvuquoc\\Kraken\\KrakenFacade"
}
}
}
},
"require-dev": {
"orchestra/testbench": "~3.0"
}
}
24 changes: 24 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Laravel Kraken Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
4 changes: 3 additions & 1 deletion src/KrakenServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class KrakenServiceProvider extends ServiceProvider
protected $defer = false;

/**
* Set up the publishing of configuration
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
Expand Down
110 changes: 110 additions & 0 deletions tests/KrakenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: danvuquoc
* Date: 3/12/18
* Time: 10:53 AM
*/

namespace Danvuquoc\Kraken\Tests;

use Danvuquoc\Kraken\KrakenFacade;
use Danvuquoc\Kraken\KrakenServiceProvider;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Orchestra\Testbench\TestCase;
use Kraken;

class KrakenTest extends TestCase
{
/**
* @var string The path to the configuration file.
*/
protected $configPath = 'config/kraken.php';

/**
* @var Local
*/
protected $adapter;

/**
* @var Filesystem
*/
protected $filesystem;

/**
* Set up the testing environment.
*/
public function setUp()
{
parent::setUp();

$this->adapter = new Local(base_path());
$this->filesystem = new Filesystem($this->adapter);

$this->cleanConfiguration();
}

/**
* Tear down the testing environment.
*/
public function tearDown()
{
parent::tearDown();
$this->cleanConfiguration();
}

/**
* Clean up any existing configs.
*/
public function cleanConfiguration()
{
if ($this->filesystem->has($this->configPath)) {
$this->filesystem->delete($this->configPath);
}
}

/**
* Load the provider.
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
{
return [KrakenServiceProvider::class];
}

/**
* Load the facade.
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageAliases($app)
{
return ['KrakenIO' => KrakenFacade::class];
}

/**
* Test to make sure configuration publishing works.
*/
public function testConfigurationPublishing()
{
$exists = $this->filesystem->has($this->configPath);
$this->assertFalse($exists);

$this->artisan('vendor:publish', [
'--provider' => KrakenServiceProvider::class,
]);

$exists = $this->filesystem->has($this->configPath);
$this->assertTrue($exists);
}

/**
* Test to make sure the app singleton exists.
*/
public function testKrakenObject()
{
$this->assertInstanceOf(Kraken::class, $this->app['Kraken']);
}
}

0 comments on commit 6b7bd1c

Please sign in to comment.