diff --git a/composer.json b/composer.json index a905b3b..9e1d021 100644 --- a/composer.json +++ b/composer.json @@ -5,14 +5,14 @@ "license": "MIT", "authors": [ { - "name": "Ivo Verberk" + "version":"0.8.1-alpha1427726533","name": "Ivo Verberk" } ], "require": { "php": ">=5.4.0", - "illuminate/support": "~4.2", - "illuminate/database": "~4.2", - "illuminate/console": "~4.2", + "illuminate/support": "~4.2|~5.0", + "illuminate/database": "~4.2|~5.0", + "illuminate/console": "~4.2|~5.0", "doctrine/dbal": "~2.3", "elasticsearch/elasticsearch": "~1.0", "nikic/php-parser": "*" diff --git a/src/Iverberk/Larasearch/Commands/PathsCommand.php b/src/Iverberk/Larasearch/Commands/PathsCommand.php index 904293f..b595b3a 100644 --- a/src/Iverberk/Larasearch/Commands/PathsCommand.php +++ b/src/Iverberk/Larasearch/Commands/PathsCommand.php @@ -310,21 +310,40 @@ private function writeConfig() { if ($this->option('write-config')) { - $configDir = app_path() . '/config/packages/iverberk/larasearch'; + if (version_compare(constant('Illuminate\\Foundation\\Application::VERSION'), '5.0.0', '>=')) + { + $configFile = config_path() . '/larasearch.php'; - if (!File::exists($configDir)) - { - if ($this->confirm('It appears that you have not yet published the larasearch config. Would you like to do this now?', false)) - { - $this->call('config:publish', ['package' => 'iverberk/larasearch']); - } - else - { - return; - } + if (!File::exists($configFile)) + { + if ($this->confirm('It appears that you have not yet published the larasearch config. Would you like to do this now?', false)) + { + $this->call('vendor:publish', ['--provider' => 'Iverberk\\Larasearch\\Providers\\L5ServiceProvider', '--tag' => 'config' ]); + } + else + { + return; + } + } + } + else + { + $configFile = app_path() . '/config/packages/iverberk/larasearch/config.php'; + + if (!File::exists($configFile)) + { + if ($this->confirm('It appears that you have not yet published the larasearch config. Would you like to do this now?', false)) + { + $this->call('config:publish', ['package' => 'iverberk/larasearch']); + } + else + { + return; + } + } } - File::put("${configDir}/paths.json", json_encode(['paths' => $this->paths, 'reversedPaths' => $this->reversedPaths], JSON_PRETTY_PRINT)); + File::put(dirname($configFile) . "/paths.json", json_encode(['paths' => $this->paths, 'reversedPaths' => $this->reversedPaths], JSON_PRETTY_PRINT)); $this->info('Paths file written to local package configuration'); } diff --git a/src/Iverberk/Larasearch/Config.php b/src/Iverberk/Larasearch/Config.php new file mode 100644 index 0000000..a677975 --- /dev/null +++ b/src/Iverberk/Larasearch/Config.php @@ -0,0 +1,59 @@ +config = $config; + $this->setPackageName($packageName); + + if (version_compare(constant('Illuminate\\Foundation\\Application::VERSION'), '5.0.0', '<')) $this->delimiter = '::'; + } + + public function setPackageName($packageName) + { + if ($packageName) + { + $this->packageName = (string) $packageName; + } + } + + public function getPackageName() + { + return $this->packageName; + } + + public function get($name, $default = null) + { + return $this->config->get("{$this->packageName}{$this->delimiter}{$name}", $default); + } + + public function set($name, $value = null) + { + return $this->config->set("{$this->packageName}{$this->delimiter}{$name}", $value); + } + +} diff --git a/src/Iverberk/Larasearch/Index.php b/src/Iverberk/Larasearch/Index.php index d104b4b..939ca6b 100644 --- a/src/Iverberk/Larasearch/Index.php +++ b/src/Iverberk/Larasearch/Index.php @@ -2,7 +2,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Str; use Iverberk\Larasearch\Exceptions\ImportException; @@ -22,6 +21,13 @@ class Index { */ private static $client; + /** + * Laravel config repository abstraction + * + * @var \Iverberk\Larasearch\Config + */ + private static $config; + /** * Index parameters * @@ -54,11 +60,17 @@ private static function getClient() public function __construct(Proxy $proxy, $name = '') { self::$client = App::make('Elasticsearch'); + self::$config = App::make('iverberk.larasearch.config'); $this->setProxy($proxy); $this->setName($name ?: $proxy->getModel()->getTable()); } + protected static function getConfig() + { + return self::$config; + } + /** * Import an Eloquent * @@ -120,7 +132,7 @@ public function import(Model $model, $relations = [], $batchSize = 750, Callable */ public function setName($name) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = self::getConfig()->get('elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($name, $index_prefix)) $name = $index_prefix . $name; $this->name = $name; @@ -200,7 +212,7 @@ public function exists() */ public function aliasExists($alias) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = self::getConfig()->get('elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($alias, $index_prefix)) $alias = $index_prefix . $alias; return self::getClient()->indices()->existsAlias(['name' => $alias]); @@ -311,7 +323,7 @@ public function bulk($records) */ public static function clean($name) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = self::getConfig()->get('elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($name, $index_prefix)) $name = $index_prefix . $name; $indices = self::getClient()->indices()->getAliases(); @@ -332,7 +344,7 @@ public static function clean($name) */ public static function getAlias($name) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = self::getConfig()->get('elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($name, $index_prefix)) $name = $index_prefix . $name; return self::getClient()->indices()->getAlias(['name' => $name]); @@ -344,7 +356,7 @@ public static function getAlias($name) */ public static function updateAliases(array $actions) { - if (isset($actions['actions']) && ($index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''))) + if (isset($actions['actions']) && ($index_prefix = self::getConfig()->get('elasticsearch.index_prefix', ''))) { foreach ($actions['actions'] as &$action) { @@ -365,7 +377,7 @@ public static function updateAliases(array $actions) */ public static function refresh($index) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = self::getConfig()->get('elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($index, $index_prefix)) $index = $index_prefix . $index; return self::getClient()->indices()->refresh(['index' => $index]); @@ -378,8 +390,8 @@ public static function refresh($index) */ private function getDefaultIndexParams() { - $analyzers = Config::get('larasearch::elasticsearch.analyzers'); - $params = Config::get('larasearch::elasticsearch.defaults.index'); + $analyzers = self::getConfig()->get('elasticsearch.analyzers'); + $params = self::getConfig()->get('elasticsearch.defaults.index'); $mapping = []; $mapping_options = array_combine( diff --git a/src/Iverberk/Larasearch/Jobs/DeleteJob.php b/src/Iverberk/Larasearch/Jobs/DeleteJob.php index a6b2e06..404b2fe 100644 --- a/src/Iverberk/Larasearch/Jobs/DeleteJob.php +++ b/src/Iverberk/Larasearch/Jobs/DeleteJob.php @@ -1,6 +1,6 @@ app = $app; $this->config = $config; @@ -37,7 +37,7 @@ public function __construct(Application $app, Repository $config) */ public function fire(Job $job, $models) { - $loggerContainerBinding = $this->config->get('larasearch::logger', 'iverberk.larasearch.logger'); + $loggerContainerBinding = $this->config->get('logger', 'iverberk.larasearch.logger'); $logger = $this->app->make($loggerContainerBinding); foreach ($models as $model) diff --git a/src/Iverberk/Larasearch/Jobs/ReindexJob.php b/src/Iverberk/Larasearch/Jobs/ReindexJob.php index 13a4177..ee8a6af 100644 --- a/src/Iverberk/Larasearch/Jobs/ReindexJob.php +++ b/src/Iverberk/Larasearch/Jobs/ReindexJob.php @@ -1,6 +1,6 @@ app = $app; $this->config = $config; @@ -34,7 +34,7 @@ public function __construct(Application $app, Repository $config) public function fire(Job $job, $models) { - $loggerContainerBinding = $this->config->get('larasearch::logger', 'iverberk.larasearch.logger'); + $loggerContainerBinding = $this->config->get('logger', 'iverberk.larasearch.logger'); $logger = $this->app->make($loggerContainerBinding); foreach ($models as $model) diff --git a/src/Iverberk/Larasearch/LarasearchServiceProvider.php b/src/Iverberk/Larasearch/LarasearchServiceProvider.php index 8cf82f3..774d077 100644 --- a/src/Iverberk/Larasearch/LarasearchServiceProvider.php +++ b/src/Iverberk/Larasearch/LarasearchServiceProvider.php @@ -1,151 +1,5 @@ package('iverberk/larasearch'); - - $this->bootContainerBindings(); - } - - /** - * Boot the container bindings. - * - * @return void - */ - public function bootContainerBindings() - { - $this->bindElasticsearch(); - $this->bindLogger(); - $this->bindIndex(); - $this->bindQuery(); - $this->bindProxy(); - $this->bindResult(); - } - - /** - * Bind a Larasearch log handler to the container - */ - protected function bindLogger() - { - $this->app->singleton('iverberk.larasearch.logger', function ($app) - { - return new Logger('larasearch', [ new NullHandler() ]); - }); - } - - /** - * Bind the Elasticsearch client to the container - */ - protected function bindElasticsearch() - { - $this->app->singleton('Elasticsearch', function ($app) - { - return new Client($app->make('config')->get('larasearch::elasticsearch.params')); - }); - } - - /** - * Bind the Larasearch index to the container - */ - protected function bindIndex() - { - $this->app->bind('iverberk.larasearch.index', function ($app, $params) - { - $name = isset($params['name']) ? $params['name'] : ''; - - return new Index($params['proxy'], $name); - }); - } - - /** - * Bind the Larasearch Query to the container - */ - protected function bindQuery() - { - $this->app->bind('iverberk.larasearch.query', function ($app, $params) - { - return new Query($params['proxy'], $params['term'], $params['options']); - }); - } - - /** - * Bind the Larasearch proxy to the container - */ - protected function bindProxy() - { - $this->app->bind('iverberk.larasearch.proxy', function ($app, $model) - { - return new Proxy($model); - }); - } - - /** - * Bind the Larasearch result to the container - */ - protected function bindResult() - { - $this->app->bind('iverberk.larasearch.response.result', function ($app, array $hit) - { - return new Result($hit); - }); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->registerCommands(); - } - - /** - * Register the commands. - * - * @return void - */ - protected function registerCommands() - { - $this->app['iverberk.larasearch.commands.reindex'] = $this->app->share(function ($app) - { - return new ReindexCommand(); - }); - - $this->app['iverberk.larasearch.commands.paths'] = $this->app->share(function ($app) - { - return new PathsCommand(); - }); - - $this->commands('iverberk.larasearch.commands.reindex'); - $this->commands('iverberk.larasearch.commands.paths'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } +class LarasearchServiceProvider extends Providers\L4ServiceProvider { } diff --git a/src/Iverberk/Larasearch/Observer.php b/src/Iverberk/Larasearch/Observer.php index 2c8e96b..b982dc3 100644 --- a/src/Iverberk/Larasearch/Observer.php +++ b/src/Iverberk/Larasearch/Observer.php @@ -2,7 +2,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Queue; class Observer { @@ -45,7 +45,7 @@ private function findAffectedModels(Model $model, $excludeCurrent = false) // Temporary array to store affected models $affectedModels = []; - $paths = Config::get('larasearch::reversedPaths.' . get_class($model), []); + $paths = App::make('iverberk.larasearch.config')->get('reversedPaths.' . get_class($model), []); foreach ((array)$paths as $path) { diff --git a/src/Iverberk/Larasearch/Providers/L4ServiceProvider.php b/src/Iverberk/Larasearch/Providers/L4ServiceProvider.php new file mode 100644 index 0000000..0708cab --- /dev/null +++ b/src/Iverberk/Larasearch/Providers/L4ServiceProvider.php @@ -0,0 +1,21 @@ +package('iverberk/larasearch'); + + parent::boot(); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerCommands(); + } +} diff --git a/src/Iverberk/Larasearch/Providers/L5ServiceProvider.php b/src/Iverberk/Larasearch/Providers/L5ServiceProvider.php new file mode 100644 index 0000000..d504174 --- /dev/null +++ b/src/Iverberk/Larasearch/Providers/L5ServiceProvider.php @@ -0,0 +1,27 @@ +publishes([ + __DIR__ . '/../../../config/config.php' => config_path('larasearch.php'), + ], 'config'); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerCommands(); + + $this->mergeConfigFrom( + __DIR__ . '/../../../config/config.php', 'larasearch' + ); + } +} diff --git a/src/Iverberk/Larasearch/Providers/ServiceProvider.php b/src/Iverberk/Larasearch/Providers/ServiceProvider.php new file mode 100644 index 0000000..ce8b886 --- /dev/null +++ b/src/Iverberk/Larasearch/Providers/ServiceProvider.php @@ -0,0 +1,153 @@ +bootContainerBindings(); + } + + /** + * Boot the container bindings. + * + * @return void + */ + public function bootContainerBindings() + { + $this->bindConfig(); + $this->bindElasticsearch(); + $this->bindLogger(); + $this->bindIndex(); + $this->bindQuery(); + $this->bindProxy(); + $this->bindResult(); + } + + /** + * Bind a Larasearch config repository to the container + */ + protected function bindConfig() + { + $this->app->singleton('Iverberk\\Larasearch\\Config'); + $this->app->alias('Iverberk\\Larasearch\\Config', 'iverberk.larasearch.config'); + } + + /** + * Bind a Larasearch log handler to the container + */ + protected function bindLogger() + { + $this->app->singleton('iverberk.larasearch.logger', function ($app) + { + return new Logger('larasearch', [ new NullHandler() ]); + }); + } + + /** + * Bind the Elasticsearch client to the container + */ + protected function bindElasticsearch() + { + $this->app->singleton('Elasticsearch', function ($app) + { + return new Client($app->make('iverberk.larasearch.config')->get('elasticsearch.params')); + }); + } + + /** + * Bind the Larasearch index to the container + */ + protected function bindIndex() + { + $this->app->bind('iverberk.larasearch.index', function ($app, $params) + { + $name = isset($params['name']) ? $params['name'] : ''; + + return new Index($params['proxy'], $name); + }); + } + + /** + * Bind the Larasearch Query to the container + */ + protected function bindQuery() + { + $this->app->bind('iverberk.larasearch.query', function ($app, $params) + { + return new Query($params['proxy'], $params['term'], $params['options']); + }); + } + + /** + * Bind the Larasearch proxy to the container + */ + protected function bindProxy() + { + $this->app->bind('iverberk.larasearch.proxy', function ($app, $model) + { + return new Proxy($model); + }); + } + + /** + * Bind the Larasearch result to the container + */ + protected function bindResult() + { + $this->app->bind('iverberk.larasearch.response.result', function ($app, array $hit) + { + return new Result($hit); + }); + } + + /** + * Register the commands. + * + * @return void + */ + protected function registerCommands() + { + $this->app['iverberk.larasearch.commands.reindex'] = $this->app->share(function ($app) + { + return new ReindexCommand(); + }); + + $this->app['iverberk.larasearch.commands.paths'] = $this->app->share(function ($app) + { + return new PathsCommand(); + }); + + $this->commands('iverberk.larasearch.commands.reindex'); + $this->commands('iverberk.larasearch.commands.paths'); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } + +} diff --git a/src/Iverberk/Larasearch/Proxy.php b/src/Iverberk/Larasearch/Proxy.php index b84fb9f..7604717 100644 --- a/src/Iverberk/Larasearch/Proxy.php +++ b/src/Iverberk/Larasearch/Proxy.php @@ -2,7 +2,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Config; class Proxy { @@ -125,7 +124,7 @@ public function reindex($relations = false, $batchSize = 750, $mapping = [], Cal $name = $this->config['index']->getName(); $newName = $name . '_' . date("YmdHis"); - $relations = $relations ? Config::get('larasearch::paths.' . get_class($model)) : []; + $relations = $relations ? App::make('iverberk.larasearch.config')->get('paths.' . get_class($model)) : []; Index::clean($name); diff --git a/src/Iverberk/Larasearch/Response/Result.php b/src/Iverberk/Larasearch/Response/Result.php index 30874c3..a495f6e 100644 --- a/src/Iverberk/Larasearch/Response/Result.php +++ b/src/Iverberk/Larasearch/Response/Result.php @@ -1,8 +1,8 @@ hit['fields']) ? $this->hit['fields'] : $this->hit['_source']; } -} \ No newline at end of file +} diff --git a/src/Iverberk/Larasearch/Traits/TransformableTrait.php b/src/Iverberk/Larasearch/Traits/TransformableTrait.php index fe6f6af..0d69b41 100644 --- a/src/Iverberk/Larasearch/Traits/TransformableTrait.php +++ b/src/Iverberk/Larasearch/Traits/TransformableTrait.php @@ -1,6 +1,6 @@ get('paths.' . get_class($this)) : []; $doc = $this->load($relations)->toArray(); diff --git a/tests/Iverberk/Larasearch/Commands/PathsCommandTest.php b/tests/Iverberk/Larasearch/Commands/PathsCommandTest.php index ee3514c..23a69c0 100644 --- a/tests/Iverberk/Larasearch/Commands/PathsCommandTest.php +++ b/tests/Iverberk/Larasearch/Commands/PathsCommandTest.php @@ -14,6 +14,15 @@ function app_path() return PathsCommandTest::$functions->app_path(); } +function constant($const) +{ + return PathsCommandTest::$functions->constant($const); +} +function config_path() +{ + return PathsCommandTest::$functions->config_path(); +} + /** * Class PathsCommandTest * @package Iverberk\Larasearch\Commands @@ -112,7 +121,8 @@ public function it_should_fire_with_models_and_config() App::shouldReceive('make')->andReturn(true); - self::$functions->shouldReceive('app_path')->once()->andReturn(''); + self::$functions->shouldReceive('config_path')->once()->andReturn(''); + self::$functions->shouldReceive('constant')->with('Illuminate\\Foundation\\Application::VERSION')->once()->andReturn('5.0.0'); /** * @@ -291,7 +301,8 @@ public function it_should_fire_with_config_confirmed() App::shouldReceive('make')->andReturn(true); - self::$functions->shouldReceive('app_path')->once()->andReturn(''); + self::$functions->shouldReceive('config_path')->once()->andReturn(''); + self::$functions->shouldReceive('constant')->with('Illuminate\\Foundation\\Application::VERSION')->once()->andReturn('5.0.0'); /** * @@ -346,7 +357,8 @@ public function it_should_fire_with_config_not_confirmed() App::shouldReceive('make')->andReturn(true); - self::$functions->shouldReceive('app_path')->once()->andReturn(''); + self::$functions->shouldReceive('config_path')->once()->andReturn(''); + self::$functions->shouldReceive('constant')->with('Illuminate\\Foundation\\Application::VERSION')->once()->andReturn('5.0.0'); /** * Expectation diff --git a/tests/Iverberk/Larasearch/ConfigTest.php b/tests/Iverberk/Larasearch/ConfigTest.php new file mode 100644 index 0000000..a6a5169 --- /dev/null +++ b/tests/Iverberk/Larasearch/ConfigTest.php @@ -0,0 +1,141 @@ +constant($const); +} + +class ConfigTest extends \PHPUnit_Framework_TestCase { + + public static $functions; + + protected function setup() + { + self::$functions = m::mock(); + } + + protected function tearDown() + { + m::close(); + } + + /** + * @test + */ + public function it_should_constructL4() + { + $this->forL4(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $config = new Config($laravel_config); + } + + /** + * @test + */ + public function it_should_constructL5() + { + $this->forL5(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $config = new Config($laravel_config); + } + + /** + * @test + */ + public function it_should_construct_with_package_name() + { + $this->forL4(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $config = new Config($laravel_config, 'foobarbaz'); + } + + /** + * @test + */ + public function it_should_get_l4_style() + { + $this->forL4(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $laravel_config->shouldReceive('get') + ->with('larasearch::myconfigsetting', null) + ->andReturn('myconfigvalue'); + $config = new Config($laravel_config); + + $this->assertEquals($config->get('myconfigsetting'), 'myconfigvalue'); + } + + /** + * @test + */ + public function it_should_get_l5_style() + { + $this->forL5(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $laravel_config->shouldReceive('get') + ->with('larasearch.myconfigsetting', null) + ->andReturn('myconfigvalue'); + $config = new Config($laravel_config); + + $this->assertEquals($config->get('myconfigsetting'), 'myconfigvalue'); + } + + /** + * @test + */ + public function it_should_set_l4_style() + { + $this->forL4(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $laravel_config->shouldReceive('set') + ->with('larasearch::myconfigsetting', 'myconfigvalue') + ->andReturn(null); + $config = new Config($laravel_config); + + $this->assertEquals($config->set('myconfigsetting', 'myconfigvalue'), null); + } + + /** + * @test + */ + public function it_should_set_l5_style() + { + $this->forL5(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $laravel_config->shouldReceive('set') + ->with('larasearch.myconfigsetting', 'myconfigvalue') + ->andReturn(); + $config = new Config($laravel_config); + + $this->assertEquals($config->set('myconfigsetting', 'myconfigvalue'), null); + } + + /** + * @test + */ + public function it_should_get_and_set_package_name() + { + $this->forL5(); + $laravel_config = m::mock('Illuminate\\Config\\Repository'); + $config = new Config($laravel_config); + + $config->setPackageName($name = 'foo' . microtime(true)); + $this->assertEquals($name, $config->getPackageName()); + } + + protected function forL4() + { + self::$functions->shouldReceive('constant') + ->with('Illuminate\\Foundation\\Application::VERSION') + ->andReturn('4.2.17'); + } + + protected function forL5() + { + self::$functions->shouldReceive('constant') + ->with('Illuminate\\Foundation\\Application::VERSION') + ->andReturn('5.0.0'); + } + +} diff --git a/tests/Iverberk/Larasearch/IndexTest.php b/tests/Iverberk/Larasearch/IndexTest.php index 495d36f..0e5e97f 100644 --- a/tests/Iverberk/Larasearch/IndexTest.php +++ b/tests/Iverberk/Larasearch/IndexTest.php @@ -1,7 +1,6 @@ getMocks(); + list($index, $proxy, $client, $config) = $this->getMocks(); $test = $this; /** @@ -149,8 +148,8 @@ public function it_should_create_an_index() * Expectation * */ - Config::shouldReceive('get') - ->with('larasearch::elasticsearch.analyzers') + $config->shouldReceive('get') + ->with('elasticsearch.analyzers') ->andReturn([ 'autocomplete', 'suggest', @@ -162,8 +161,8 @@ public function it_should_create_an_index() 'word_end' ]); - Config::shouldReceive('get') - ->with('larasearch::elasticsearch.defaults.index') + $config->shouldReceive('get') + ->with('elasticsearch.defaults.index') ->andReturn([ 'settings' => [ 'number_of_shards' => 1, @@ -635,7 +634,7 @@ public function it_should_create_an_index_with_a_prefix() * @var \Mockery\Mock $proxy * @var \Mockery\Mock $client */ - list($index, $proxy, $client) = $this->getMocks('bar_'); + list($index, $proxy, $client, $config) = $this->getMocks('bar_'); $test = $this; /** @@ -643,8 +642,8 @@ public function it_should_create_an_index_with_a_prefix() * Expectation * */ - Config::shouldReceive('get') - ->with('larasearch::elasticsearch.analyzers') + $config->shouldReceive('get') + ->with('elasticsearch.analyzers') ->andReturn([ 'autocomplete', 'suggest', @@ -656,8 +655,8 @@ public function it_should_create_an_index_with_a_prefix() 'word_end' ]); - Config::shouldReceive('get') - ->with('larasearch::elasticsearch.defaults.index') + $config->shouldReceive('get') + ->with('elasticsearch.defaults.index') ->andReturn([ 'settings' => [ 'number_of_shards' => 1, @@ -2116,10 +2115,10 @@ public function it_should_get_aliases_with_an_index_prefix() * @var \Mockery\Mock $proxy * @var \Mockery\Mock $client */ - list($index, $proxy, $client) = $this->getMocks('bar_'); + list($index, $proxy, $client, $config) = $this->getMocks('bar_'); // Mock the self::$client variable - am::double('Iverberk\Larasearch\Index', ['self::$client' => $client]); + am::double('Iverberk\Larasearch\Index', ['self::$client' => $client, 'self::$config' => $config]); /** * @@ -2154,10 +2153,10 @@ public function it_should_refresh() * @var \Mockery\Mock $proxy * @var \Mockery\Mock $client */ - list($index, $proxy, $client) = $this->getMocks(); + list($index, $proxy, $client, $config) = $this->getMocks(); // Mock the self::$client variable - am::double('Iverberk\Larasearch\Index', ['self::$client' => $client]); + am::double('Iverberk\Larasearch\Index', ['self::$client' => $client, 'self::$config' => $config]); /** * @@ -2190,10 +2189,10 @@ public function it_should_refresh_with_an_index_prefix() * @var \Mockery\Mock $proxy * @var \Mockery\Mock $client */ - list($index, $proxy, $client) = $this->getMocks('bar_'); + list($index, $proxy, $client, $config) = $this->getMocks('bar_'); // Mock the self::$client variable - am::double('Iverberk\Larasearch\Index', ['self::$client' => $client]); + am::double('Iverberk\Larasearch\Index', ['self::$client' => $client, 'self::$config' => $config]); /** * @@ -2228,9 +2227,6 @@ private function getMocks($index_prefix = null) * */ Facade::clearResolvedInstances(); - Config::shouldReceive('get') - ->with('larasearch::elasticsearch.index_prefix', '') - ->andReturn($index_prefix); $client = m::mock('Elasticsearch\Client'); @@ -2238,13 +2234,22 @@ private function getMocks($index_prefix = null) ->with('Elasticsearch') ->andReturn($client); + $config = m::mock('Iverberk\\Larasearch\\Config'); + $config->shouldReceive('get') + ->with('elasticsearch.index_prefix', '') + ->andReturn($index_prefix); + + App::shouldReceive('make') + ->with('iverberk.larasearch.config') + ->andReturn($config); + $proxy = m::mock('Iverberk\Larasearch\Proxy'); $proxy->shouldReceive('getModel->getTable') ->andReturn('Husband'); $index = m::mock('Iverberk\Larasearch\Index', [$proxy], [ m::BLOCKS => ['setName', 'setProxy']])->makePartial(); - return [$index, $proxy, $client]; + return [$index, $proxy, $client, $config]; } } \ No newline at end of file diff --git a/tests/Iverberk/Larasearch/Jobs/DeleteJobTest.php b/tests/Iverberk/Larasearch/Jobs/DeleteJobTest.php index 9648b25..9b90f53 100644 --- a/tests/Iverberk/Larasearch/Jobs/DeleteJobTest.php +++ b/tests/Iverberk/Larasearch/Jobs/DeleteJobTest.php @@ -22,7 +22,7 @@ public function it_should_fire_job() * */ $app = m::mock('Illuminate\Foundation\Application'); - $config = m::mock('Illuminate\Config\Repository'); + $config = m::mock('Iverberk\Larasearch\Config'); $logger = m::mock('Monolog\Logger'); $husband = am::double('Husband', ['deleteDoc' => true]); @@ -37,7 +37,7 @@ public function it_should_fire_job() * */ $logger->shouldReceive('info')->with('Deleting Husband with ID: 999 from Elasticsearch'); - $config->shouldReceive('get')->with('larasearch::logger', 'iverberk.larasearch.logger')->andReturn('iverberk.larasearch.logger'); + $config->shouldReceive('get')->with('logger', 'iverberk.larasearch.logger')->andReturn('iverberk.larasearch.logger'); $app->shouldReceive('make')->with('iverberk.larasearch.logger')->andReturn($logger); $job->shouldReceive('delete')->once(); diff --git a/tests/Iverberk/Larasearch/Jobs/ReindexJobTest.php b/tests/Iverberk/Larasearch/Jobs/ReindexJobTest.php index 0f7e237..da86302 100644 --- a/tests/Iverberk/Larasearch/Jobs/ReindexJobTest.php +++ b/tests/Iverberk/Larasearch/Jobs/ReindexJobTest.php @@ -22,7 +22,7 @@ public function it_should_fire_job_with_unresolvable_models() * */ $app = m::mock('Illuminate\Foundation\Application'); - $config = m::mock('Illuminate\Config\Repository'); + $config = m::mock('Iverberk\\Larasearch\\Config'); $logger = m::mock('Monolog\Logger'); $job = m::mock('Illuminate\Queue\Jobs\Job'); $models = [ @@ -36,7 +36,7 @@ public function it_should_fire_job_with_unresolvable_models() */ $logger->shouldReceive('info')->with('Indexing Husband with ID: 99999'); $logger->shouldReceive('error')->with('Indexing Husband with ID: 99999 failed: No query results for model [Husband].'); - $config->shouldReceive('get')->with('larasearch::logger', 'iverberk.larasearch.logger')->andReturn('iverberk.larasearch.logger'); + $config->shouldReceive('get')->with('logger', 'iverberk.larasearch.logger')->andReturn('iverberk.larasearch.logger'); $app->shouldReceive('make')->with('iverberk.larasearch.logger')->andReturn($logger); $job->shouldReceive('delete')->once(); $job->shouldReceive('release')->with(60)->once(); @@ -60,7 +60,7 @@ public function it_should_fire_job_with_resolvable_models() * */ $app = m::mock('Illuminate\Foundation\Application'); - $config = m::mock('Illuminate\Config\Repository'); + $config = m::mock('Iverberk\Larasearch\Config'); $logger = m::mock('Monolog\Logger'); $model = m::mock('Husband'); $model->shouldReceive('refreshDoc')->with($model)->once(); @@ -75,7 +75,7 @@ public function it_should_fire_job_with_resolvable_models() * */ $logger->shouldReceive('info')->with('Indexing Husband with ID: 999'); - $config->shouldReceive('get')->with('larasearch::logger', 'iverberk.larasearch.logger')->andReturn('iverberk.larasearch.logger'); + $config->shouldReceive('get')->with('logger', 'iverberk.larasearch.logger')->andReturn('iverberk.larasearch.logger'); $app->shouldReceive('make')->with('iverberk.larasearch.logger')->andReturn($logger); $job = m::mock('Illuminate\Queue\Jobs\Job'); $job->shouldReceive('delete')->once(); diff --git a/tests/Iverberk/Larasearch/ObserverTest.php b/tests/Iverberk/Larasearch/ObserverTest.php index c837c81..4999d0a 100644 --- a/tests/Iverberk/Larasearch/ObserverTest.php +++ b/tests/Iverberk/Larasearch/ObserverTest.php @@ -2,7 +2,6 @@ use Husband; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Facade; use Illuminate\Support\Facades\Queue; use Mockery as m; @@ -54,19 +53,23 @@ public function it_should_reindex_on_model_save() */ Facade::clearResolvedInstances(); - $proxy = m::mock('Iverberk\Larasearch\Proxy'); + $proxy = m::mock('Iverberk\Larasearch\Proxy'); $proxy->shouldReceive('shouldIndex')->andReturn(true); App::shouldReceive('make') ->with('iverberk.larasearch.proxy', m::type('Illuminate\Database\Eloquent\Model')) ->andReturn($proxy); - Config::shouldReceive('get') - ->with('/^larasearch::reversedPaths\.Husband$/', array()) + $config = m::mock('Iverberk\Larasearch\Config'); + $config->shouldReceive('get') + ->with('reversedPaths.Husband', []) ->once() ->andReturn(['', 'wife', 'children', 'children.toys']); + App::shouldReceive('make') + ->with('iverberk.larasearch.config') + ->andReturn($config); - Queue::shouldReceive('push') + Queue::shouldReceive('push') ->with('Iverberk\Larasearch\Jobs\ReindexJob', [ 'Husband:2', 'Wife:2', @@ -98,10 +101,13 @@ public function it_should_reindex_on_model_save() ->with('iverberk.larasearch.proxy', m::type('Illuminate\Database\Eloquent\Model')) ->andReturn($proxy); - Config::shouldReceive('get') - ->with('/^larasearch::reversedPaths\.Toy$/', array()) + $config->shouldReceive('get') + ->with('reversedPaths.Toy', []) ->once() ->andReturn(['', 'children', 'children.mother.husband', 'children.mother']); + App::shouldReceive('make') + ->with('iverberk.larasearch.config') + ->andReturn($config); Queue::shouldReceive('push') ->with('Iverberk\Larasearch\Jobs\ReindexJob', [ @@ -126,9 +132,9 @@ public function it_should_reindex_on_model_save() } /** - * + * @test */ - public function it_shoud_reindex_on_model_delete() + public function it_should_reindex_on_model_delete() { /** * @@ -145,11 +151,14 @@ public function it_shoud_reindex_on_model_delete() ->with('Iverberk\Larasearch\Jobs\ReindexJob', [ 'Wife:2', 'Child:2', 'Toy:2' ]) ->once(); - Config::shouldReceive('get') - ->with('/^larasearch::reversedPaths\..*$/', array()) + $config = m::mock('Iverberk\\Larasearch\\Config'); + $config->shouldReceive('get') + ->with('/^reversedPaths\..*$/', []) ->once() ->andReturn(['', 'wife', 'children', 'children.toys']); - + App::shouldReceive('make') + ->with('iverberk.larasearch.config') + ->andReturn($config); $husband = \Husband::find(2); with(new Observer)->deleted($husband); diff --git a/tests/Iverberk/Larasearch/LarasearchServiceProviderTest.php b/tests/Iverberk/Larasearch/Providers/L4ServiceProviderTest.php similarity index 81% rename from tests/Iverberk/Larasearch/LarasearchServiceProviderTest.php rename to tests/Iverberk/Larasearch/Providers/L4ServiceProviderTest.php index f104dad..7b53313 100644 --- a/tests/Iverberk/Larasearch/LarasearchServiceProviderTest.php +++ b/tests/Iverberk/Larasearch/Providers/L4ServiceProviderTest.php @@ -1,14 +1,14 @@ shouldAllowMockingProtectedMethods(); @@ -51,13 +51,14 @@ public function it_should_boot_container_bindings() /** * Set */ - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[' . - 'bindProxy, bindIndex, bindLogger, bindElasticsearch, bindQuery, bindResult]', ['something']); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[' . + 'bindProxy, bindConfig, bindIndex, bindLogger, bindElasticsearch, bindQuery, bindResult]', ['something']); $sp->shouldAllowMockingProtectedMethods(); /** * Expectation */ + $sp->shouldReceive('bindConfig')->once()->andReturn(true); $sp->shouldReceive('bindElasticsearch')->once()->andReturn(true); $sp->shouldReceive('bindLogger')->once()->andReturn(true); $sp->shouldReceive('bindProxy')->once()->andReturn(true); @@ -81,18 +82,18 @@ public function it_should_bind_elasticsearch() */ $config = m::mock(); $app = m::mock('LaravelApp'); - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[bindElasticsearch]', [$app]); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[bindElasticsearch]', [$app]); /** * Expectation */ $config->shouldReceive('get') - ->with('larasearch::elasticsearch.params') + ->with('elasticsearch.params') ->once() ->andReturn([]); $app->shouldReceive('make') - ->with('config') + ->with('iverberk.larasearch.config') ->once() ->andReturn($config); @@ -118,7 +119,7 @@ public function it_should_bind_logger() * Set */ $app = m::mock('LaravelApp'); - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[bindLogger]', [$app]); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[bindLogger]', [$app]); /** * Expectation @@ -144,6 +145,14 @@ public function it_should_bind_index() /** * Set */ + App::clearResolvedInstances(); + $config = m::mock('Iverberk\Larasearch\Config'); + $config->shouldReceive('get') + ->with('elasticsearch.index_prefix', '') + ->andReturn(''); + App::shouldReceive('make') + ->with('iverberk.larasearch.config') + ->andReturn($config); App::shouldReceive('make') ->with('iverberk.larasearch.index', Mockery::any()) ->once() @@ -160,7 +169,7 @@ public function it_should_bind_index() ->andReturn('mockType'); $app = m::mock('LaravelApp'); $proxy = m::mock('Iverberk\Larasearch\Proxy', [$model]); - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[bindIndex]', [$app]); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[bindIndex]', [$app]); /** * Expectation @@ -197,7 +206,7 @@ public function it_should_bind_query() ->andReturn('mockType'); $app = m::mock('LaravelApp'); $proxy = m::mock('Iverberk\Larasearch\Proxy', [$model]); - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[bindQuery]', [$app]); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[bindQuery]', [$app]); /** * Expectation @@ -232,7 +241,7 @@ public function it_should_bind_proxy() ->once() ->andReturn('mockType'); $app = m::mock('LaravelApp'); - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[bindProxy]', [$app]); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[bindProxy]', [$app]); /** * Expectation @@ -264,7 +273,7 @@ public function it_should_bind_result() * Set */ $app = m::mock('LaravelApp'); - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[bindResult]', [$app]); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[bindResult]', [$app]); /** * Expectation @@ -295,7 +304,7 @@ public function it_should_register_commands() * Set */ $app = m::mock('Illuminate\Container\Container'); - $sp = m::mock('Iverberk\Larasearch\LarasearchServiceProvider[registerCommands, commands]', [$app]); + $sp = m::mock('Iverberk\Larasearch\Providers\L4ServiceProvider[registerCommands, commands]', [$app]); /** * Expectation @@ -346,8 +355,8 @@ public function it_should_provide_services() /** * Assertion */ - $sp = new Iverberk\Larasearch\LarasearchServiceProvider($app); + $sp = new Iverberk\Larasearch\Providers\L4ServiceProvider($app); assertEquals([], $sp->provides()); } -} \ No newline at end of file +} diff --git a/tests/Iverberk/Larasearch/Providers/L5ServiceProviderTest.php b/tests/Iverberk/Larasearch/Providers/L5ServiceProviderTest.php new file mode 100644 index 0000000..29bc77c --- /dev/null +++ b/tests/Iverberk/Larasearch/Providers/L5ServiceProviderTest.php @@ -0,0 +1,383 @@ +config_path($path); +} + +/** + * Class L5ServiceProviderTest + */ +class L5ServiceProviderTest extends \PHPUnit_Framework_TestCase { + + public static $functions; + protected static $providers_real_path; + + protected function setup() + { + self::$functions = m::mock(); + self::$functions->shouldReceive('config_path')->andReturn(''); + self::$providers_real_path = realpath(__DIR__ . '/../../../../src/Iverberk/Larasearch/Providers'); + } + + protected function tearDown() + { + m::close(); + } + + /** + * @test + */ + public function it_should_boot() + { + /** + * Set + */ + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[package, bootContainerBindings]', ['something']); + + $sp->shouldAllowMockingProtectedMethods(); + + /** + * Expectation + */ + $sp->shouldReceive('publishes') + ->with([ + self::$providers_real_path . '/../../../onfig/config.php' => config_path('larasearch.php'), + ], 'config') + ->once(); + + $sp->shouldReceive('bootContainerBindings') + ->once(); + + /** + * Assertion + */ + $sp->boot(); + } + + /** + * @test + */ + public function it_should_boot_container_bindings() + { + /** + * Set + */ + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[' . + 'bindProxy, bindConfig, bindIndex, bindLogger, bindElasticsearch, bindQuery, bindResult]', ['something']); + $sp->shouldAllowMockingProtectedMethods(); + + /** + * Expectation + */ + $sp->shouldReceive('bindConfig')->once()->andReturn(true); + $sp->shouldReceive('bindElasticsearch')->once()->andReturn(true); + $sp->shouldReceive('bindLogger')->once()->andReturn(true); + $sp->shouldReceive('bindProxy')->once()->andReturn(true); + $sp->shouldReceive('bindIndex')->once()->andReturn(true); + $sp->shouldReceive('bindQuery')->once()->andReturn(true); + $sp->shouldReceive('bindResult')->once()->andReturn(true); + + /** + * Assertions + */ + $sp->bootContainerBindings(); + } + + /** + * @test + */ + public function it_should_bind_elasticsearch() + { + /** + * Set + */ + $config = m::mock(); + $app = m::mock('LaravelApp'); + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[bindElasticsearch]', [$app]); + + /** + * Expectation + */ + $config->shouldReceive('get') + ->with('elasticsearch.params') + ->once() + ->andReturn([]); + + $app->shouldReceive('make') + ->with('iverberk.larasearch.config') + ->once() + ->andReturn($config); + + $app->shouldReceive('singleton') + ->once() + ->andReturnUsing( + function ($name, $closure) use ($app) + { + assertEquals('Elasticsearch', $name); + assertInstanceOf('Elasticsearch\Client', $closure($app)); + } + ); + + $sp->bindElasticsearch(); + } + + /** + * @test + */ + public function it_should_bind_logger() + { + /** + * Set + */ + $app = m::mock('LaravelApp'); + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[bindLogger]', [$app]); + + /** + * Expectation + */ + $app->shouldReceive('singleton') + ->once() + ->andReturnUsing( + function ($name, $closure) use ($app) + { + assertEquals('iverberk.larasearch.logger', $name); + assertInstanceOf('Monolog\Logger', $closure($app)); + } + ); + + $sp->bindLogger(); + } + + /** + * @test + */ + public function it_should_bind_index() + { + /** + * Set + */ + App::clearResolvedInstances(); + $config = m::mock('Iverberk\Larasearch\Config'); + $config->shouldReceive('get') + ->with('elasticsearch.index_prefix', '') + ->andReturn(''); + App::shouldReceive('make') + ->with('iverberk.larasearch.config') + ->andReturn($config); + App::shouldReceive('make') + ->with('iverberk.larasearch.index', m::any()) + ->once() + ->andReturn('mock'); + + App::shouldReceive('make') + ->with('Elasticsearch') + ->twice() + ->andReturn('mock'); + + $model = m::mock('Illuminate\Database\Eloquent\Model'); + $model->shouldReceive('getTable') + ->once() + ->andReturn('mockType'); + $app = m::mock('LaravelApp'); + $proxy = m::mock('Iverberk\Larasearch\Proxy', [$model]); + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[bindIndex]', [$app]); + + /** + * Expectation + */ + $app->shouldReceive('bind') + ->once() + ->andReturnUsing( + function ($name, $closure) use ($app, $proxy) + { + assertEquals('iverberk.larasearch.index', $name); + assertInstanceOf('Iverberk\Larasearch\Index', + $closure($app, ['proxy' => $proxy, 'name' => 'name'])); + } + ); + + + /** + * Assertion + */ + $sp->bindIndex(); + } + + /** + * @test + */ + public function it_should_bind_query() + { + /** + * Set + */ + $model = m::mock('Illuminate\Database\Eloquent\Model'); + $model->shouldReceive('getTable') + ->once() + ->andReturn('mockType'); + $app = m::mock('LaravelApp'); + $proxy = m::mock('Iverberk\Larasearch\Proxy', [$model]); + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[bindQuery]', [$app]); + + /** + * Expectation + */ + $app->shouldReceive('bind') + ->once() + ->andReturnUsing( + function ($name, $closure) use ($app, $proxy) + { + assertEquals('iverberk.larasearch.query', $name); + assertInstanceOf('Iverberk\Larasearch\Query', + $closure($app, ['proxy' => $proxy, 'term' => 'term', 'options' => []])); + } + ); + + /** + * Assertion + */ + $sp->bindQuery(); + } + + /** + * @test + */ + public function it_should_bind_proxy() + { + /** + * Set + */ + $model = m::mock('Illuminate\Database\Eloquent\Model'); + $model->shouldReceive('getTable') + ->once() + ->andReturn('mockType'); + $app = m::mock('LaravelApp'); + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[bindProxy]', [$app]); + + /** + * Expectation + */ + $app->shouldReceive('bind') + ->once() + ->andReturnUsing( + function ($name, $closure) use ($app, $model) + { + assertEquals('iverberk.larasearch.proxy', $name); + assertInstanceOf('Iverberk\Larasearch\Proxy', + $closure($app, $model)); + } + ); + + + /** + * Assertion + */ + $sp->bindProxy(); + } + + /** + * @test + */ + public function it_should_bind_result() + { + /** + * Set + */ + $app = m::mock('LaravelApp'); + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[bindResult]', [$app]); + + /** + * Expectation + */ + $app->shouldReceive('bind') + ->once() + ->andReturnUsing( + function ($name, $closure) use ($app) + { + assertEquals('iverberk.larasearch.response.result', $name); + assertInstanceOf('Iverberk\Larasearch\Response\Result', + $closure($app, [])); + } + ); + + /** + * Assertion + */ + $sp->bindResult(); + } + + /** + * @test + */ + public function it_should_register_commands() + { + /** + * Set + */ + $app = m::mock('Illuminate\Container\Container'); + $sp = m::mock('Iverberk\Larasearch\Providers\L5ServiceProvider[registerCommands, commands]', [$app]); + + /** + * Expectation + */ + $app->shouldReceive('offsetSet')->andReturn(true); + $app->shouldReceive('offsetGet')->andReturn(true); + + $app->shouldReceive('share') + ->once() + ->andReturnUsing(function ($closure) use ($app) + { + assertInstanceOf('Iverberk\Larasearch\Commands\ReindexCommand', $closure($app)); + }); + + $app->shouldReceive('share') + ->once() + ->andReturnUsing(function ($closure) use ($app) + { + assertInstanceOf('Iverberk\Larasearch\Commands\PathsCommand', $closure($app)); + }); + + $sp->shouldReceive('commands') + ->with('iverberk.larasearch.commands.reindex') + ->once() + ->andReturn(true); + + $sp->shouldReceive('commands') + ->with('iverberk.larasearch.commands.paths') + ->once() + ->andReturn(true); + + $sp->shouldReceive('mergeConfigFrom') + ->with(self::$providers_real_path . '/../../../config/config.php', 'larasearch') + ->once(); + /** + * Assertion + */ + $sp->register(); + } + + /** + * @test + */ + public function it_should_provide_services() + { + /** + * Set + */ + $app = m::mock('LaravelApp'); + + /** + * Assertion + */ + $sp = new L5ServiceProvider($app); + assertEquals([], $sp->provides()); + } + +} diff --git a/tests/Iverberk/Larasearch/Traits/TransformableTraitTest.php b/tests/Iverberk/Larasearch/Traits/TransformableTraitTest.php index d411e9d..fcf95ad 100644 --- a/tests/Iverberk/Larasearch/Traits/TransformableTraitTest.php +++ b/tests/Iverberk/Larasearch/Traits/TransformableTraitTest.php @@ -1,6 +1,6 @@ shouldReceive('load->toArray')->once()->andReturn('mock'); - Config::clearResolvedInstance('config'); - Config::shouldReceive('get')->with('/larasearch::paths\..*/')->once(); + $config = m::mock('Iverberk\\Larasearch\\Config'); + $config->shouldReceive('get')->with('/paths\..*/')->once(); + App::shouldReceive('make') + ->with('iverberk.larasearch.config') + ->once() + ->andReturn($config); /** *