Skip to content

Commit fdd571e

Browse files
committed
Added functional tests for rebuild command.
1 parent 99a7193 commit fdd571e

File tree

5 files changed

+129
-3
lines changed

5 files changed

+129
-3
lines changed

src/Nqxcode/LuceneSearch/Console/RebuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function fire()
3333
$count = $modelRepository->count();
3434

3535
if ($count === 0) {
36-
$this->comment(' No available models found. ');
36+
$this->comment(' No available models found.');
3737
continue;
3838
}
3939

tests/functional/BaseTestCase.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?php
2-
namespace tests\functional;
1+
<?php namespace tests\functional;
32

43
use tests\TestCase;
54
use Config;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php namespace tests\functional\Console;
2+
3+
use Illuminate\Console\Application;
4+
use Symfony\Component\Console\Output\BufferedOutput;
5+
use tests\TestCase;
6+
use Config;
7+
8+
/**
9+
* Class RebuildCommandTest
10+
* @package functional
11+
*/
12+
class RebuildCommandTest extends TestCase
13+
{
14+
/** @var \Illuminate\Foundation\Application|Application $artisan */
15+
private $artisan;
16+
17+
public function setUp()
18+
{
19+
parent::setUp();
20+
21+
$this->artisan = $this->app->make('artisan');
22+
23+
// Call migrations specific to our tests, e.g. to seed the db.
24+
$this->artisan->call('migrate', ['--database' => 'testbench', '--path' => '../tests/migrations']);
25+
26+
Config::set('laravel-lucene-search::index.path', storage_path() . '/lucene-search/index_' . uniqid());
27+
}
28+
29+
/**
30+
* @dataProvider getOutputDataProvider
31+
* @param $expected
32+
* @param $config
33+
*/
34+
public function testRebuildCommand($expected, $config)
35+
{
36+
Config::set('laravel-lucene-search::index.models', $config);
37+
38+
$output = new BufferedOutput();
39+
$this->artisan->call('search:rebuild', ['--verbose' => true], $output);
40+
41+
$this->assertEquals($expected, $output->fetch());
42+
}
43+
44+
public function getOutputDataProvider()
45+
{
46+
return [
47+
[
48+
'Creating index for model: "tests\models\Product"
49+
Creating index for model: "tests\models\Tool"
50+
No available models found.
51+
52+
Operation is fully complete!
53+
',
54+
[
55+
'tests\models\Product' => [
56+
'fields' => ['name', 'description'],
57+
],
58+
59+
'tests\models\Tool' => [
60+
'fields' => ['name', 'description'],
61+
],
62+
]
63+
],
64+
[
65+
'Creating index for model: "tests\models\Tool"
66+
No available models found.
67+
68+
Operation is fully complete!
69+
',
70+
[
71+
'tests\models\Tool' => [
72+
'fields' => ['name', 'description'],
73+
],
74+
]
75+
],
76+
];
77+
}
78+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Carbon\Carbon;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\Schema\Blueprint;
6+
7+
class CreateToolsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('tools', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('name')->nullable();
19+
$table->string('description')->nullable();
20+
21+
$table->timestamps();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
Schema::drop('tools');
33+
}
34+
}

tests/models/Tool.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php namespace tests\models;
2+
3+
use Illuminate\Database\Eloquent\Model;
4+
use Nqxcode\LuceneSearch\Model\SearchTrait;
5+
6+
/**
7+
* Class Tool
8+
* @property string $name
9+
* @property string $description
10+
* @package tests\models
11+
*/
12+
class Tool extends Model
13+
{
14+
use SearchTrait;
15+
}

0 commit comments

Comments
 (0)