From 09763f0f7fad4bb119bd9809f49ab1c01f9f409f Mon Sep 17 00:00:00 2001 From: Tom Lingham Date: Sat, 14 May 2016 12:26:40 +1000 Subject: [PATCH] Merge --- .gitattributes | 2 +- .gitignore | 5 +-- .travis.yml | 17 +++++++-- LICENSE | 2 +- composer.json | 13 +++++-- phpunit.xml.dist | 14 ++++++- src/SearchyServiceProvider.php | 83 +++++++++++++++++++++++++----------------- tests/.gitkeep | 0 tests/AbstractTestCase.php | 26 +++++++++++++ tests/Facades/SearchyTest.php | 48 ++++++++++++++++++++++++ tests/ServiceProviderTest.php | 21 +++++++++++ 11 files changed, 182 insertions(+), 49 deletions(-) delete mode 100755 tests/.gitkeep create mode 100644 tests/AbstractTestCase.php create mode 100644 tests/Facades/SearchyTest.php create mode 100644 tests/ServiceProviderTest.php diff --git a/.gitattributes b/.gitattributes index 880a088..7769b44 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,5 +4,5 @@ /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore -/phpunit.xml export-ignore +/phpunit.xml.dist export-ignore /README.md export-ignore diff --git a/.gitignore b/.gitignore index cdb5558..81b9258 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -/vendor -composer.phar composer.lock -.DS_Store -.idea phpunit.xml +vendor diff --git a/.travis.yml b/.travis.yml index 2054605..c3de422 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,21 @@ language: php php: + - 5.5.9 - 5.5 - 5.6 + - 7.0 - hhvm -before_script: - - composer self-update - - composer install --prefer-source --no-interaction --dev +sudo: false -script: vendor/bin/phpspec run +install: + - travis_retry composer install --no-interaction --prefer-source + +script: + - if [ "$TRAVIS_PHP_VERSION" != "5.5.9" ] && [ "$TRAVIS_PHP_VERSION" != "5.5" ] && [ "$TRAVIS_PHP_VERSION" != "5.6" ]; then vendor/bin/phpunit; fi + - if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi + +after_script: + - if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi + - if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi diff --git a/LICENSE b/LICENSE index dc9b5fb..51005dd 100755 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Tom Lingham +Copyright (c) 2014-2016 Tom Lingham Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 305dba9..c355bca 100755 --- a/composer.json +++ b/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" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5beb621..71a80b9 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,28 @@ - ./tests/ + ./tests + + + ./src + + diff --git a/src/SearchyServiceProvider.php b/src/SearchyServiceProvider.php index b2fb6cc..ef51203 100755 --- a/src/SearchyServiceProvider.php +++ b/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 + * @author Vincent Klaiber + */ 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'); } /** - * Loads the configuration file. + * Register the service provider. + * + * @return void */ - public function setupConfig() + public function register() { - $source = realpath(__DIR__.'/../config/searchy.php'); + $this->registerSearchBuilder(); + } - if (class_exists('Illuminate\Foundation\Application', false)) { - $this->publishes([$source => config_path('searchy.php')]); - } + /** + * Register the search builder class. + * + * @return void + */ + public function registerSearchBuilder() + { + $this->app->singleton('searchy', function (Container $app) { + $config = $app['config']; - $this->mergeConfigFrom($source, 'searchy'); + return new SearchBuilder($config); + }); + + $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', + ]; } } diff --git a/tests/.gitkeep b/tests/.gitkeep deleted file mode 100755 index e69de29..0000000 diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php new file mode 100644 index 0000000..01ff1ca --- /dev/null +++ b/tests/AbstractTestCase.php @@ -0,0 +1,26 @@ + + */ +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; + } +} diff --git a/tests/Facades/SearchyTest.php b/tests/Facades/SearchyTest.php new file mode 100644 index 0000000..81a925a --- /dev/null +++ b/tests/Facades/SearchyTest.php @@ -0,0 +1,48 @@ + + */ +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; + } +} diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php new file mode 100644 index 0000000..22e88af --- /dev/null +++ b/tests/ServiceProviderTest.php @@ -0,0 +1,21 @@ + + */ +class ServiceProviderTest extends AbstractTestCase +{ + use ServiceProviderTrait; + + public function testSearchBuilderIsInjectable() + { + $this->assertIsInjectable(SearchBuilder::class); + } +}