Browse Source

Add working test suite

master
Vincent Klaiber 9 years ago
parent
commit
04a66d99e9
  1. 13
      composer.json
  2. 81
      src/SearchyServiceProvider.php
  3. 0
      tests/.gitkeep
  4. 26
      tests/AbstractTestCase.php
  5. 48
      tests/Facades/SearchyTest.php
  6. 15
      tests/ServiceProviderTest.php

13
composer.json

@ -10,17 +10,24 @@
}
],
"require": {
"php": ">=5.5.0",
"illuminate/support": "5.*"
"php": "^5.5.9 || ^7.0",
"illuminate/support": "5.1.* || 5.2.*"
},
"require-dev" :{
"phpspec/phpspec": "~2.0"
"graham-campbell/testbench": "^3.1",
"mockery/mockery": "^0.9.4",
"phpunit/phpunit": "^4.8 || ^5.0"
},
"autoload": {
"psr-4": {
"TomLingham\\Searchy\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"TomLingham\\Tests\\Searchy\\": "tests/"
}
},
"config": {
"preferred-install": "dist"
},

81
src/SearchyServiceProvider.php

@ -2,67 +2,82 @@
namespace TomLingham\Searchy;
use Illuminate\Contracts\Container\Container;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;
use Laravel\Lumen\Application as LumenApplication;
/**
* This is the searchy service provider class.
*
* @author Tom Lingham <tjlingham@gmail.com>
* @author Vincent Klaiber <hello@vinkla.com>
*/
class SearchyServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
* Boot the service provider.
*
* @var bool
*/
protected $defer = false;
/**
* Register the service provider.
* @return void
*/
public function register()
public function boot()
{
//
$this->setupConfig();
}
/**
* Registers searchy.
* Setup the config.
*
* @return void
*/
public function registerSearchy()
protected function setupConfig()
{
// Laravel <= 5.1
$closure = function ($app) {
return new SearchBuilder( $app['config'] );
};
$source = realpath(__DIR__.'/../config/searchy.php');
if ( method_exists($this->app, 'bindShared') )
{
$this->app->bindShared('searchy', $closure);
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
$this->publishes([$source => config_path('searchy.php')]);
} elseif ($this->app instanceof LumenApplication) {
$this->app->configure('searchy');
}
// Laravel 5.2 Goodness :)
else {
$this->app->singleton('searchy', $closure);
$this->mergeConfigFrom($source, 'searchy');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerSearchBuilder();
}
/**
* Loads the configuration file.
* Register the search builder class.
*
* @return void
*/
public function setupConfig()
public function registerSearchBuilder()
{
$source = realpath(__DIR__.'/../config/searchy.php');
$this->app->singleton('searchy', function (Container $app) {
$config = $app['config'];
if (class_exists('Illuminate\Foundation\Application', false)) {
$this->publishes([$source => config_path('searchy.php')]);
}
return new SearchBuilder($config);
});
$this->mergeConfigFrom($source, 'searchy');
$this->app->alias('searchy', HashidsFactory::class);
}
/**
* Boot the service provider.
* Get the services provided by the provider.
*
* @return string[]
*/
public function boot()
public function provides()
{
$this->setupConfig();
$this->registerSearchy();
return [
'searchy',
];
}
}

0
tests/.gitkeep

26
tests/AbstractTestCase.php

@ -0,0 +1,26 @@
<?php
namespace TomLingham\Tests\Searchy;
use GrahamCampbell\TestBench\AbstractPackageTestCase;
use TomLingham\Searchy\SearchyServiceProvider;
/**
* This is the abstract test case class.
*
* @author Vincent Klaiber <hello@vinkla.com>
*/
abstract class AbstractTestCase extends AbstractPackageTestCase
{
/**
* Get the service provider class.
*
* @param \Illuminate\Contracts\Foundation\Application $app
*
* @return string
*/
protected function getServiceProviderClass($app)
{
return SearchyServiceProvider::class;
}
}

48
tests/Facades/SearchyTest.php

@ -0,0 +1,48 @@
<?php
namespace TomLingham\Tests\Searchy\Facades;
use GrahamCampbell\TestBenchCore\FacadeTrait;
use TomLingham\Searchy\Facades\Searchy;
use TomLingham\Searchy\SearchBuilder;
use TomLingham\Tests\Searchy\AbstractTestCase;
/**
* This is the searchy facade test class.
*
* @author Vincent Klaiber <hello@vinkla.com>
*/
class SearchyTest extends AbstractTestCase
{
use FacadeTrait;
/**
* Get the facade accessor.
*
* @return string
*/
protected function getFacadeAccessor()
{
return 'searchy';
}
/**
* Get the facade class.
*
* @return string
*/
protected function getFacadeClass()
{
return Searchy::class;
}
/**
* Get the facade root.
*
* @return string
*/
protected function getFacadeRoot()
{
return SearchBuilder::class;
}
}

15
tests/ServiceProviderTest.php

@ -0,0 +1,15 @@
<?php
namespace TomLingham\Tests\Searchy;
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
/**
* This is the service provider test.
*
* @author Vincent Klaiber <hello@vinkla.com>
*/
class ServiceProviderTest extends AbstractTestCase
{
use ServiceProviderTrait;
}
Loading…
Cancel
Save