Skip to content

Commit a05a238

Browse files
authored
Merge pull request #333 from driesvints/unify-test-namespaces
[6.0] Unify test namespaces
2 parents f470bbb + 828d9fb commit a05a238

12 files changed

+91
-76
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"autoload-dev": {
4040
"psr-4": {
41-
"Tests\\": "tests/"
41+
"Laravel\\Scout\\Tests\\": "tests/"
4242
}
4343
},
4444
"extra": {

tests/AbstractTestCase.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/AlgoliaEngineTest.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Laravel\Scout\Tests;
44

5-
use Mockery;
5+
use Mockery as m;
66
use Laravel\Scout\Builder;
7-
use Tests\Fixtures\EmptyTestModel;
7+
use PHPUnit\Framework\TestCase;
88
use Laravel\Scout\Engines\AlgoliaEngine;
9-
use Tests\Fixtures\AlgoliaEngineTestModel;
109
use Illuminate\Database\Eloquent\Collection;
11-
use Tests\Fixtures\AlgoliaEngineTestCustomKeyModel;
10+
use Laravel\Scout\Tests\Fixtures\EmptyTestModel;
11+
use Laravel\Scout\Tests\Fixtures\AlgoliaEngineTestModel;
12+
use Laravel\Scout\Tests\Fixtures\AlgoliaEngineTestCustomKeyModel;
1213

13-
class AlgoliaEngineTest extends AbstractTestCase
14+
class AlgoliaEngineTest extends TestCase
1415
{
16+
public function tearDown()
17+
{
18+
m::close();
19+
}
20+
1521
public function test_update_adds_objects_to_index()
1622
{
17-
$client = Mockery::mock('AlgoliaSearch\Client');
18-
$client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass'));
23+
$client = m::mock('AlgoliaSearch\Client');
24+
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass'));
1925
$index->shouldReceive('addObjects')->with([[
2026
'id' => 1,
2127
'objectID' => 1,
@@ -27,8 +33,8 @@ public function test_update_adds_objects_to_index()
2733

2834
public function test_delete_removes_objects_to_index()
2935
{
30-
$client = Mockery::mock('AlgoliaSearch\Client');
31-
$client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass'));
36+
$client = m::mock('AlgoliaSearch\Client');
37+
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass'));
3238
$index->shouldReceive('deleteObjects')->with([1]);
3339

3440
$engine = new AlgoliaEngine($client);
@@ -37,8 +43,8 @@ public function test_delete_removes_objects_to_index()
3743

3844
public function test_search_sends_correct_parameters_to_algolia()
3945
{
40-
$client = Mockery::mock('AlgoliaSearch\Client');
41-
$client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass'));
46+
$client = m::mock('AlgoliaSearch\Client');
47+
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass'));
4248
$index->shouldReceive('search')->with('zonda', [
4349
'numericFilters' => ['foo=1'],
4450
]);
@@ -51,15 +57,15 @@ public function test_search_sends_correct_parameters_to_algolia()
5157

5258
public function test_map_correctly_maps_results_to_models()
5359
{
54-
$client = Mockery::mock('AlgoliaSearch\Client');
60+
$client = m::mock('AlgoliaSearch\Client');
5561
$engine = new AlgoliaEngine($client);
5662

57-
$model = Mockery::mock('StdClass');
63+
$model = m::mock('StdClass');
5864
$model->shouldReceive('newQuery')->andReturn($model);
5965
$model->shouldReceive('getKeyName')->andReturn('id');
6066
$model->shouldReceive('getScoutModelsByIds')->andReturn(Collection::make([new AlgoliaEngineTestModel]));
6167

62-
$builder = Mockery::mock(Builder::class);
68+
$builder = m::mock(Builder::class);
6369

6470
$results = $engine->map($builder, ['nbHits' => 1, 'hits' => [
6571
['objectID' => 1, 'id' => 1],
@@ -70,8 +76,8 @@ public function test_map_correctly_maps_results_to_models()
7076

7177
public function test_a_model_is_indexed_with_a_custom_algolia_key()
7278
{
73-
$client = Mockery::mock('AlgoliaSearch\Client');
74-
$client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass'));
79+
$client = m::mock('AlgoliaSearch\Client');
80+
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass'));
7581
$index->shouldReceive('addObjects')->with([[
7682
'id' => 1,
7783
'objectID' => 'my-algolia-key.1',
@@ -83,8 +89,8 @@ public function test_a_model_is_indexed_with_a_custom_algolia_key()
8389

8490
public function test_a_model_is_removed_with_a_custom_algolia_key()
8591
{
86-
$client = Mockery::mock('AlgoliaSearch\Client');
87-
$client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass'));
92+
$client = m::mock('AlgoliaSearch\Client');
93+
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass'));
8894
$index->shouldReceive('deleteObjects')->with(['my-algolia-key.1']);
8995

9096
$engine = new AlgoliaEngine($client);
@@ -93,8 +99,8 @@ public function test_a_model_is_removed_with_a_custom_algolia_key()
9399

94100
public function test_flush_a_model()
95101
{
96-
$client = Mockery::mock('AlgoliaSearch\Client');
97-
$client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass'));
102+
$client = m::mock('AlgoliaSearch\Client');
103+
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass'));
98104
$index->shouldReceive('clearIndex');
99105

100106
$engine = new AlgoliaEngine($client);
@@ -103,8 +109,8 @@ public function test_flush_a_model()
103109

104110
public function test_update_empty_searchable_array_does_not_add_objects_to_index()
105111
{
106-
$client = Mockery::mock('AlgoliaSearch\Client');
107-
$client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass'));
112+
$client = m::mock('AlgoliaSearch\Client');
113+
$client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass'));
108114
$index->shouldNotReceive('addObjects');
109115

110116
$engine = new AlgoliaEngine($client);

tests/BuilderTest.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Laravel\Scout\Tests;
44

5-
use Mockery;
6-
use StdClass;
5+
use stdClass;
6+
use Mockery as m;
77
use Laravel\Scout\Builder;
8+
use PHPUnit\Framework\TestCase;
89
use Illuminate\Pagination\Paginator;
910
use Illuminate\Database\Eloquent\Collection;
1011

11-
class BuilderTest extends AbstractTestCase
12+
class BuilderTest extends TestCase
1213
{
14+
public function tearDown()
15+
{
16+
m::close();
17+
}
18+
1319
public function test_pagination_correctly_handles_paginated_results()
1420
{
1521
Paginator::currentPageResolver(function () {
@@ -19,12 +25,12 @@ public function test_pagination_correctly_handles_paginated_results()
1925
return 'http://localhost/foo';
2026
});
2127

22-
$builder = new Builder($model = Mockery::mock(), 'zonda');
28+
$builder = new Builder($model = m::mock(), 'zonda');
2329
$model->shouldReceive('getPerPage')->andReturn(15);
24-
$model->shouldReceive('searchableUsing')->andReturn($engine = Mockery::mock());
30+
$model->shouldReceive('searchableUsing')->andReturn($engine = m::mock());
2531

2632
$engine->shouldReceive('paginate');
27-
$engine->shouldReceive('map')->andReturn(Collection::make([new StdClass]));
33+
$engine->shouldReceive('map')->andReturn(Collection::make([new stdClass]));
2834
$engine->shouldReceive('getTotalCount');
2935

3036
$builder->paginate();
@@ -36,22 +42,22 @@ public function test_macroable()
3642
return 'bar';
3743
});
3844

39-
$builder = new Builder($model = Mockery::mock(), 'zonda');
45+
$builder = new Builder($model = m::mock(), 'zonda');
4046
$this->assertEquals(
4147
'bar', $builder->foo()
4248
);
4349
}
4450

4551
public function test_hard_delete_doesnt_set_wheres()
4652
{
47-
$builder = new Builder($model = Mockery::mock(), 'zonda', null, false);
53+
$builder = new Builder($model = m::mock(), 'zonda', null, false);
4854

4955
$this->assertArrayNotHasKey('__soft_deleted', $builder->wheres);
5056
}
5157

5258
public function test_soft_delete_sets_wheres()
5359
{
54-
$builder = new Builder($model = Mockery::mock(), 'zonda', null, true);
60+
$builder = new Builder($model = m::mock(), 'zonda', null, true);
5561

5662
$this->assertEquals(0, $builder->wheres['__soft_deleted']);
5763
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

3-
namespace Tests\Fixtures;
3+
namespace Laravel\Scout\Tests\Fixtures;
44

55
class AlgoliaEngineTestCustomKeyModel extends TestModel
66
{
7-
public function getScoutKey() {
7+
public function getScoutKey()
8+
{
89
return 'my-algolia-key.'.$this->getKey();
910
}
1011
}

tests/Fixtures/AlgoliaEngineTestModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Fixtures;
3+
namespace Laravel\Scout\Tests\Fixtures;
44

55
class AlgoliaEngineTestModel extends TestModel
66
{

tests/Fixtures/EmptyTestModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Fixtures;
3+
namespace Laravel\Scout\Tests\Fixtures;
44

55
class EmptyTestModel extends TestModel
66
{

tests/Fixtures/SearchableTestModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Fixtures;
3+
namespace Laravel\Scout\Tests\Fixtures;
44

55
use Laravel\Scout\Searchable;
66

tests/Fixtures/TestModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tests\Fixtures;
3+
namespace Laravel\Scout\Tests\Fixtures;
44

55
use Illuminate\Database\Eloquent\Model;
66

tests/MakeSearchableTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Laravel\Scout\Tests;
44

5-
use Mockery;
5+
use Mockery as m;
6+
use PHPUnit\Framework\TestCase;
67
use Laravel\Scout\Jobs\MakeSearchable;
78
use Illuminate\Database\Eloquent\Collection;
89

9-
class MakeSearchableTest extends AbstractTestCase
10+
class MakeSearchableTest extends TestCase
1011
{
12+
public function tearDown()
13+
{
14+
m::close();
15+
}
16+
1117
public function test_handle_passes_the_collection_to_engine()
1218
{
1319
$job = new MakeSearchable($collection = Collection::make([
14-
$model = Mockery::mock(),
20+
$model = m::mock(),
1521
]));
1622

1723
$model->shouldReceive('searchableUsing->update')->with($collection);

0 commit comments

Comments
 (0)