From 828d9fb6b86ef6116a4486e85930b4a7a37b5892 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 6 Dec 2018 20:48:10 +0100 Subject: [PATCH] Unify test namespaces --- composer.json | 2 +- tests/AbstractTestCase.php | 16 ------ tests/AlgoliaEngineTest.php | 52 +++++++++++-------- tests/BuilderTest.php | 26 ++++++---- .../AlgoliaEngineTestCustomKeyModel.php | 5 +- tests/Fixtures/AlgoliaEngineTestModel.php | 2 +- tests/Fixtures/EmptyTestModel.php | 2 +- tests/Fixtures/SearchableTestModel.php | 2 +- tests/Fixtures/TestModel.php | 2 +- tests/MakeSearchableTest.php | 14 +++-- tests/ModelObserverTest.php | 22 +++++--- tests/SearchableTest.php | 22 +++++--- 12 files changed, 91 insertions(+), 76 deletions(-) delete mode 100644 tests/AbstractTestCase.php diff --git a/composer.json b/composer.json index baed19c0..2e9ef88d 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ }, "autoload-dev": { "psr-4": { - "Tests\\": "tests/" + "Laravel\\Scout\\Tests\\": "tests/" } }, "extra": { diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php deleted file mode 100644 index e7c8b470..00000000 --- a/tests/AbstractTestCase.php +++ /dev/null @@ -1,16 +0,0 @@ -shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass')); + $client = m::mock('AlgoliaSearch\Client'); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass')); $index->shouldReceive('addObjects')->with([[ 'id' => 1, 'objectID' => 1, @@ -27,8 +33,8 @@ public function test_update_adds_objects_to_index() public function test_delete_removes_objects_to_index() { - $client = Mockery::mock('AlgoliaSearch\Client'); - $client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass')); + $client = m::mock('AlgoliaSearch\Client'); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass')); $index->shouldReceive('deleteObjects')->with([1]); $engine = new AlgoliaEngine($client); @@ -37,8 +43,8 @@ public function test_delete_removes_objects_to_index() public function test_search_sends_correct_parameters_to_algolia() { - $client = Mockery::mock('AlgoliaSearch\Client'); - $client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass')); + $client = m::mock('AlgoliaSearch\Client'); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass')); $index->shouldReceive('search')->with('zonda', [ 'numericFilters' => ['foo=1'], ]); @@ -51,15 +57,15 @@ public function test_search_sends_correct_parameters_to_algolia() public function test_map_correctly_maps_results_to_models() { - $client = Mockery::mock('AlgoliaSearch\Client'); + $client = m::mock('AlgoliaSearch\Client'); $engine = new AlgoliaEngine($client); - $model = Mockery::mock('StdClass'); + $model = m::mock('StdClass'); $model->shouldReceive('newQuery')->andReturn($model); $model->shouldReceive('getKeyName')->andReturn('id'); $model->shouldReceive('getScoutModelsByIds')->andReturn(Collection::make([new AlgoliaEngineTestModel])); - $builder = Mockery::mock(Builder::class); + $builder = m::mock(Builder::class); $results = $engine->map($builder, ['nbHits' => 1, 'hits' => [ ['objectID' => 1, 'id' => 1], @@ -70,8 +76,8 @@ public function test_map_correctly_maps_results_to_models() public function test_a_model_is_indexed_with_a_custom_algolia_key() { - $client = Mockery::mock('AlgoliaSearch\Client'); - $client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass')); + $client = m::mock('AlgoliaSearch\Client'); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass')); $index->shouldReceive('addObjects')->with([[ 'id' => 1, 'objectID' => 'my-algolia-key.1', @@ -83,8 +89,8 @@ public function test_a_model_is_indexed_with_a_custom_algolia_key() public function test_a_model_is_removed_with_a_custom_algolia_key() { - $client = Mockery::mock('AlgoliaSearch\Client'); - $client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass')); + $client = m::mock('AlgoliaSearch\Client'); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass')); $index->shouldReceive('deleteObjects')->with(['my-algolia-key.1']); $engine = new AlgoliaEngine($client); @@ -93,8 +99,8 @@ public function test_a_model_is_removed_with_a_custom_algolia_key() public function test_flush_a_model() { - $client = Mockery::mock('AlgoliaSearch\Client'); - $client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass')); + $client = m::mock('AlgoliaSearch\Client'); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass')); $index->shouldReceive('clearIndex'); $engine = new AlgoliaEngine($client); @@ -103,8 +109,8 @@ public function test_flush_a_model() public function test_update_empty_searchable_array_does_not_add_objects_to_index() { - $client = Mockery::mock('AlgoliaSearch\Client'); - $client->shouldReceive('initIndex')->with('table')->andReturn($index = Mockery::mock('StdClass')); + $client = m::mock('AlgoliaSearch\Client'); + $client->shouldReceive('initIndex')->with('table')->andReturn($index = m::mock('StdClass')); $index->shouldNotReceive('addObjects'); $engine = new AlgoliaEngine($client); diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index a23e36a8..7bc16293 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -1,15 +1,21 @@ shouldReceive('getPerPage')->andReturn(15); - $model->shouldReceive('searchableUsing')->andReturn($engine = Mockery::mock()); + $model->shouldReceive('searchableUsing')->andReturn($engine = m::mock()); $engine->shouldReceive('paginate'); - $engine->shouldReceive('map')->andReturn(Collection::make([new StdClass])); + $engine->shouldReceive('map')->andReturn(Collection::make([new stdClass])); $engine->shouldReceive('getTotalCount'); $builder->paginate(); @@ -36,7 +42,7 @@ public function test_macroable() return 'bar'; }); - $builder = new Builder($model = Mockery::mock(), 'zonda'); + $builder = new Builder($model = m::mock(), 'zonda'); $this->assertEquals( 'bar', $builder->foo() ); @@ -44,14 +50,14 @@ public function test_macroable() public function test_hard_delete_doesnt_set_wheres() { - $builder = new Builder($model = Mockery::mock(), 'zonda', null, false); + $builder = new Builder($model = m::mock(), 'zonda', null, false); $this->assertArrayNotHasKey('__soft_deleted', $builder->wheres); } public function test_soft_delete_sets_wheres() { - $builder = new Builder($model = Mockery::mock(), 'zonda', null, true); + $builder = new Builder($model = m::mock(), 'zonda', null, true); $this->assertEquals(0, $builder->wheres['__soft_deleted']); } diff --git a/tests/Fixtures/AlgoliaEngineTestCustomKeyModel.php b/tests/Fixtures/AlgoliaEngineTestCustomKeyModel.php index ce5a535d..8172a756 100644 --- a/tests/Fixtures/AlgoliaEngineTestCustomKeyModel.php +++ b/tests/Fixtures/AlgoliaEngineTestCustomKeyModel.php @@ -1,10 +1,11 @@ getKey(); } } diff --git a/tests/Fixtures/AlgoliaEngineTestModel.php b/tests/Fixtures/AlgoliaEngineTestModel.php index 35698048..2aadf1c0 100644 --- a/tests/Fixtures/AlgoliaEngineTestModel.php +++ b/tests/Fixtures/AlgoliaEngineTestModel.php @@ -1,6 +1,6 @@ shouldReceive('searchableUsing->update')->with($collection); diff --git a/tests/ModelObserverTest.php b/tests/ModelObserverTest.php index 01512f21..b56bee9c 100644 --- a/tests/ModelObserverTest.php +++ b/tests/ModelObserverTest.php @@ -1,16 +1,22 @@ shouldReceive('shouldBeSearchable')->andReturn(true); $model->shouldReceive('searchable'); $observer->saved($model); @@ -19,7 +25,7 @@ public function test_saved_handler_makes_model_searchable() public function test_saved_handler_doesnt_make_model_searchable_when_disabled() { $observer = new ModelObserver; - $model = Mockery::mock(); + $model = m::mock(); $observer->disableSyncingFor(get_class($model)); $model->shouldReceive('searchable')->never(); $observer->saved($model); @@ -28,7 +34,7 @@ public function test_saved_handler_doesnt_make_model_searchable_when_disabled() public function test_saved_handler_makes_model_unsearchable_when_disabled_per_model_rule() { $observer = new ModelObserver; - $model = Mockery::mock(); + $model = m::mock(); $model->shouldReceive('shouldBeSearchable')->andReturn(false); $model->shouldReceive('searchable')->never(); $model->shouldReceive('unsearchable'); @@ -38,7 +44,7 @@ public function test_saved_handler_makes_model_unsearchable_when_disabled_per_mo public function test_deleted_handler_makes_model_unsearchable() { $observer = new ModelObserver; - $model = Mockery::mock(); + $model = m::mock(); $model->shouldReceive('unsearchable'); $observer->deleted($model); } @@ -46,7 +52,7 @@ public function test_deleted_handler_makes_model_unsearchable() public function test_restored_handler_makes_model_searchable() { $observer = new ModelObserver; - $model = Mockery::mock(); + $model = m::mock(); $model->shouldReceive('shouldBeSearchable')->andReturn(true); $model->shouldReceive('searchable'); $observer->restored($model); diff --git a/tests/SearchableTest.php b/tests/SearchableTest.php index 25544241..8e0a202c 100644 --- a/tests/SearchableTest.php +++ b/tests/SearchableTest.php @@ -1,15 +1,21 @@ shouldReceive('isEmpty')->andReturn(false); $collection->shouldReceive('first->searchableUsing->update')->with($collection); @@ -19,7 +25,7 @@ public function test_searchable_using_update_is_called_on_collection() public function test_searchable_using_update_is_not_called_on_empty_collection() { - $collection = Mockery::mock(); + $collection = m::mock(); $collection->shouldReceive('isEmpty')->andReturn(true); $collection->shouldNotReceive('first->searchableUsing->update'); @@ -29,7 +35,7 @@ public function test_searchable_using_update_is_not_called_on_empty_collection() public function test_searchable_using_delete_is_called_on_collection() { - $collection = Mockery::mock(); + $collection = m::mock(); $collection->shouldReceive('isEmpty')->andReturn(false); $collection->shouldReceive('first->searchableUsing->delete')->with($collection); @@ -39,7 +45,7 @@ public function test_searchable_using_delete_is_called_on_collection() public function test_searchable_using_delete_is_not_called_on_empty_collection() { - $collection = Mockery::mock(); + $collection = m::mock(); $collection->shouldReceive('isEmpty')->andReturn(true); $collection->shouldNotReceive('first->searchableUsing->delete');