diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-10-17 16:41:55 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-10-17 17:09:14 +0100 |
| commit | 953f11988d09a6cba4eb7cf9a517539ee72ed23c (patch) | |
| tree | c332ea006be1dded99259fbfd0d50a1dd1632cc4 | |
| parent | 7fef921100eb7e3eb34986f37a55753975dad1ba (diff) | |
| download | webtrees-953f11988d09a6cba4eb7cf9a517539ee72ed23c.tar.gz webtrees-953f11988d09a6cba4eb7cf9a517539ee72ed23c.tar.bz2 webtrees-953f11988d09a6cba4eb7cf9a517539ee72ed23c.zip | |
Avoid using the IoC container in unit tests
22 files changed, 36 insertions, 67 deletions
diff --git a/tests/TestCase.php b/tests/TestCase.php index 29dca090ea..352765a537 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -84,11 +84,9 @@ class TestCase extends \PHPUnit\Framework\TestCase // Disable the cache. app()->instance('cache.array', new Repository(new NullStore())); - app()->instance(UserService::class, new UserService()); app()->instance(FilesystemInterface::class, new Filesystem(new MemoryAdapter())); app()->bind(LocaleInterface::class, LocaleEnUs::class); app()->bind(ModuleThemeInterface::class, WebtreesTheme::class); - app()->bind(UserInterface::class, GuestUser::class); // Need the routing table, to generate URLs. app()->instance(RouterContainer::class, new RouterContainer()); diff --git a/tests/app/Http/Middleware/HandleExceptionsTest.php b/tests/app/Http/Middleware/HandleExceptionsTest.php index a2536546ea..a9228c85fd 100644 --- a/tests/app/Http/Middleware/HandleExceptionsTest.php +++ b/tests/app/Http/Middleware/HandleExceptionsTest.php @@ -50,13 +50,6 @@ class HandleExceptionsTest extends TestCase $module_service->method('findByComponent')->willReturn(new Collection([])); app()->instance(ModuleService::class, $module_service); - $user_service = $this->createMock(UserService::class); - app()->instance(UserService::class, $user_service); - - // The error response needs a tree. - //$tree = $this->createMock(Tree::class); - View::share('tree', null); - $request = self::createRequest(); $middleware = new HandleExceptions(); $response = $middleware->process($request, $handler); diff --git a/tests/app/Module/AhnentafelReportModuleTest.php b/tests/app/Module/AhnentafelReportModuleTest.php index 13cde61ba3..61ec633836 100644 --- a/tests/app/Module/AhnentafelReportModuleTest.php +++ b/tests/app/Module/AhnentafelReportModuleTest.php @@ -82,7 +82,6 @@ class AhnentafelReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/ahnentafel_report.xml'; $vars = [ 'pid' => ['id' => 'X1030'], diff --git a/tests/app/Module/BirthDeathMarriageReportModuleTest.php b/tests/app/Module/BirthDeathMarriageReportModuleTest.php index 1b3a6aa219..9f9e0b029a 100644 --- a/tests/app/Module/BirthDeathMarriageReportModuleTest.php +++ b/tests/app/Module/BirthDeathMarriageReportModuleTest.php @@ -76,7 +76,6 @@ class BirthDeathMarriageReportModuleTest extends TestCase public function testReportRunsWithoutError(): void { $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/bdm_report.xml'; $vars = [ 'name' => ['id' => ''], diff --git a/tests/app/Module/BirthReportModuleTest.php b/tests/app/Module/BirthReportModuleTest.php index 71f2f444aa..ea20670070 100644 --- a/tests/app/Module/BirthReportModuleTest.php +++ b/tests/app/Module/BirthReportModuleTest.php @@ -82,7 +82,6 @@ class BirthReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/birth_report.xml'; $vars = [ 'name' => ['id' => ''], diff --git a/tests/app/Module/CemeteryReportModuleTest.php b/tests/app/Module/CemeteryReportModuleTest.php index dc13e07a24..558399fee2 100644 --- a/tests/app/Module/CemeteryReportModuleTest.php +++ b/tests/app/Module/CemeteryReportModuleTest.php @@ -82,7 +82,6 @@ class CemeteryReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/cemetery_report.xml'; $vars = [ 'deathplace' => ['id' => ''], diff --git a/tests/app/Module/ChangeReportModuleTest.php b/tests/app/Module/ChangeReportModuleTest.php index 045b1899b1..cf130d0b63 100644 --- a/tests/app/Module/ChangeReportModuleTest.php +++ b/tests/app/Module/ChangeReportModuleTest.php @@ -83,7 +83,6 @@ class ChangeReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/change_report.xml'; $vars = [ 'changeRangeStart' => ['id' => Carbon::now()->subMonths(1)->format('d M Y')], diff --git a/tests/app/Module/DeathReportModuleTest.php b/tests/app/Module/DeathReportModuleTest.php index 866f3981b7..9f6ab4fc78 100644 --- a/tests/app/Module/DeathReportModuleTest.php +++ b/tests/app/Module/DeathReportModuleTest.php @@ -82,7 +82,6 @@ class DeathReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/death_report.xml'; $vars = [ 'name' => ['id' => ''], diff --git a/tests/app/Module/DescendancyReportModuleTest.php b/tests/app/Module/DescendancyReportModuleTest.php index f0f4d587b0..f156c57e6e 100644 --- a/tests/app/Module/DescendancyReportModuleTest.php +++ b/tests/app/Module/DescendancyReportModuleTest.php @@ -82,7 +82,6 @@ class DescendancyReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/descendancy_report.xml'; $vars = [ 'pid' => ['id' => 'X1030'], diff --git a/tests/app/Module/FactSourcesReportModuleTest.php b/tests/app/Module/FactSourcesReportModuleTest.php index 24b0f66230..a3235b6fd9 100644 --- a/tests/app/Module/FactSourcesReportModuleTest.php +++ b/tests/app/Module/FactSourcesReportModuleTest.php @@ -82,7 +82,6 @@ class FactSourcesReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/fact_sources.xml'; $vars = [ 'id' => ['id' => 's1'], diff --git a/tests/app/Module/FamilyGroupReportModuleTest.php b/tests/app/Module/FamilyGroupReportModuleTest.php index 32b243bc02..2584940949 100644 --- a/tests/app/Module/FamilyGroupReportModuleTest.php +++ b/tests/app/Module/FamilyGroupReportModuleTest.php @@ -82,7 +82,6 @@ class FamilyGroupReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/family_group_report.xml'; $vars = [ 'id' => ['id' => 'f1'], diff --git a/tests/app/Module/IndividualFamiliesReportModuleTest.php b/tests/app/Module/IndividualFamiliesReportModuleTest.php index d6c1902b4b..03827e1e39 100644 --- a/tests/app/Module/IndividualFamiliesReportModuleTest.php +++ b/tests/app/Module/IndividualFamiliesReportModuleTest.php @@ -82,7 +82,6 @@ class IndividualFamiliesReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/individual_ext_report.xml'; $vars = [ 'pid' => ['id' => 'X1030'], diff --git a/tests/app/Module/IndividualReportModuleTest.php b/tests/app/Module/IndividualReportModuleTest.php index d816572452..471c74ffb4 100644 --- a/tests/app/Module/IndividualReportModuleTest.php +++ b/tests/app/Module/IndividualReportModuleTest.php @@ -83,7 +83,6 @@ class IndividualReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/individual_report.xml'; $vars = [ 'id' => ['id' => 'X1030'], diff --git a/tests/app/Module/MarriageReportModuleTest.php b/tests/app/Module/MarriageReportModuleTest.php index 4a796d18e3..c42d88c1f9 100644 --- a/tests/app/Module/MarriageReportModuleTest.php +++ b/tests/app/Module/MarriageReportModuleTest.php @@ -82,7 +82,6 @@ class MarriageReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/marriage_report.xml'; $vars = [ 'name' => ['id' => ''], diff --git a/tests/app/Module/MissingFactsReportModuleTest.php b/tests/app/Module/MissingFactsReportModuleTest.php index 6dccf51a2b..1998ac8e14 100644 --- a/tests/app/Module/MissingFactsReportModuleTest.php +++ b/tests/app/Module/MissingFactsReportModuleTest.php @@ -82,7 +82,6 @@ class MissingFactsReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/missing_facts_report.xml'; $vars = [ 'pid' => ['id' => 'X1030'], diff --git a/tests/app/Module/OccupationReportModuleTest.php b/tests/app/Module/OccupationReportModuleTest.php index 4e402ac4bf..85687c9aab 100644 --- a/tests/app/Module/OccupationReportModuleTest.php +++ b/tests/app/Module/OccupationReportModuleTest.php @@ -82,7 +82,6 @@ class OccupationReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/occupation_report.xml'; $vars = [ 'occupation' => ['id' => 'king'], diff --git a/tests/app/Module/PedigreeReportModuleTest.php b/tests/app/Module/PedigreeReportModuleTest.php index 874039cd05..5432b6c44f 100644 --- a/tests/app/Module/PedigreeReportModuleTest.php +++ b/tests/app/Module/PedigreeReportModuleTest.php @@ -82,7 +82,6 @@ class PedigreeReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/pedigree_report.xml'; $vars = [ 'pid' => ['id' => 'X1030'], diff --git a/tests/app/Module/RelatedIndividualsReportModuleTest.php b/tests/app/Module/RelatedIndividualsReportModuleTest.php index d064f7a30f..d34e8ae2c7 100644 --- a/tests/app/Module/RelatedIndividualsReportModuleTest.php +++ b/tests/app/Module/RelatedIndividualsReportModuleTest.php @@ -82,7 +82,6 @@ class RelatedIndividualsReportModuleTest extends TestCase Auth::login($user); $tree = $this->importTree('demo.ged'); - app()->instance(Tree::class, $tree); $xml = Webtrees::ROOT_DIR . 'resources/xml/reports/relative_ext_report.xml'; $vars = [ 'pid' => ['id' => 'X1030'], diff --git a/tests/app/Services/ModuleServiceTest.php b/tests/app/Services/ModuleServiceTest.php index 29ba1a16cf..a3f86e7257 100644 --- a/tests/app/Services/ModuleServiceTest.php +++ b/tests/app/Services/ModuleServiceTest.php @@ -51,8 +51,6 @@ class ModuleServiceTest extends TestCase */ public function testAll(): void { - app()->instance(Tree::class, Tree::create('name', 'title')); - $module_service = new ModuleService(); $this->assertNotEmpty($module_service->all()); @@ -67,9 +65,7 @@ class ModuleServiceTest extends TestCase */ public function testFindByComponent(): void { - $user_service = new UserService(); - app()->instance(Tree::class, Tree::create('name', 'title')); - + $user_service = new UserService(); $module_service = new ModuleService(); $tree = $this->importTree('demo.ged'); @@ -89,8 +85,6 @@ class ModuleServiceTest extends TestCase */ public function testFindByInterface(): void { - app()->instance(Tree::class, Tree::create('name', 'title')); - $module_service = new ModuleService(); $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class, true)->all()); @@ -114,7 +108,6 @@ class ModuleServiceTest extends TestCase */ public function testOtherModules(): void { - app()->instance(Tree::class, Tree::create('name', 'title')); DB::table('module')->insert(['module_name' => 'not-a-module']); $module_service = new ModuleService(); @@ -128,7 +121,6 @@ class ModuleServiceTest extends TestCase */ public function testDeletedModules(): void { - app()->instance(Tree::class, Tree::create('name', 'title')); DB::table('module')->insert(['module_name' => 'not-a-module']); $module_service = new ModuleService(); diff --git a/tests/feature/EmbeddedVariablesTest.php b/tests/feature/EmbeddedVariablesTest.php index 0d46cdaf5f..e9dd49b0b3 100644 --- a/tests/feature/EmbeddedVariablesTest.php +++ b/tests/feature/EmbeddedVariablesTest.php @@ -74,9 +74,6 @@ class EmbeddedVariablesTest extends TestCase $tree = $this->importTree('demo.ged'); $statistics = new Statistics(new ModuleService(), $tree, new UserService()); - // For Date::display() - app()->instance(Tree::class, $tree); - // As visitor $text = $statistics->embedTags('#getAllTagsTable#'); $this->assertNotEquals('#getAllTagsTable#', $text); @@ -98,9 +95,6 @@ class EmbeddedVariablesTest extends TestCase $tree = Tree::create('name', 'title'); $statistics = new Statistics(new ModuleService(), $tree, new UserService()); - // For Date::display() - app()->instance(Tree::class, $tree); - // As visitor $text = $statistics->embedTags('#getAllTagsTable#'); $this->assertNotEquals('#getAllTagsTable#', $text); diff --git a/tests/feature/IndividualListTest.php b/tests/feature/IndividualListTest.php index c852df8ae4..c001d3cf63 100644 --- a/tests/feature/IndividualListTest.php +++ b/tests/feature/IndividualListTest.php @@ -42,11 +42,8 @@ class IndividualListTest extends TestCase */ public function testIndividualList(): void { - $tree = $this->importTree('demo.ged'); - $user = Auth::user(); - app()->instance(Tree::class, $tree); - app()->instance(User::class, $user); - + $tree = $this->importTree('demo.ged'); + $user = Auth::user(); $list_module = new IndividualListModule(); $localization_service = new LocalizationService(new LocaleEnUs()); $individual_list_service = new IndividualListService($localization_service, $tree); diff --git a/tests/feature/UserAdminTest.php b/tests/feature/UserAdminTest.php index ade8fb8fab..6c0fdda7e9 100644 --- a/tests/feature/UserAdminTest.php +++ b/tests/feature/UserAdminTest.php @@ -19,13 +19,13 @@ declare(strict_types=1); namespace Fisharebest\Webtrees; -use Fig\Http\Message\RequestMethodInterface; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Http\Controllers\Admin\UsersController; +use Fisharebest\Webtrees\Services\DatatablesService; +use Fisharebest\Webtrees\Services\MailService; +use Fisharebest\Webtrees\Services\ModuleService; use Fisharebest\Webtrees\Services\UserService; -use function app; - /** * Test the user administration pages */ @@ -40,12 +40,16 @@ class UserAdminTest extends TestCase */ public function testUserDetailsAreShownOnUserAdminPage(): void { - $user_service = new UserService(); - $admin = $user_service->create('AdminName', 'Administrator', 'admin@example.com', 'secret'); + $datatables_service = new DatatablesService(); + $mail_service = new MailService(); + $module_service = new ModuleService(); + $user_service = new UserService(); + $admin = $user_service->create('AdminName', 'Administrator', 'admin@example.com', 'secret'); $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); - $controller = app(UsersController::class); - $request = self::createRequest(RequestMethodInterface::METHOD_GET, ['length' => '10']) + $controller = new UsersController($datatables_service, $mail_service, $module_service, $user_service); + $request = self::createRequest() + ->withQueryParams(['length' => '10']) ->withAttribute('user', $admin); $response = $controller->data($request); @@ -68,15 +72,17 @@ class UserAdminTest extends TestCase */ public function testFilteringUserAdminPage(): void { - $user_service = new UserService(); - $admin = $user_service->create('AdminName', 'Administrator', 'admin@example.com', 'secret'); + $datatables_service = new DatatablesService(); + $mail_service = new MailService(); + $module_service = new ModuleService(); + $user_service = new UserService(); + $admin = $user_service->create('AdminName', 'Administrator', 'admin@example.com', 'secret'); $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); - $request = self::createRequest() + $controller = new UsersController($datatables_service, $mail_service, $module_service, $user_service); + $request = self::createRequest() ->withQueryParams(['search' => ['value' => 'admin']]) ->withAttribute('user', $admin); - - $controller = app(UsersController::class); $response = $controller->data($request); $this->assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); @@ -98,15 +104,17 @@ class UserAdminTest extends TestCase */ public function testPaginatingUserAdminPage(): void { - $user_service = new UserService(); - $admin = $user_service->create('AdminName', 'Administrator', 'admin@example.com', 'secret'); + $datatables_service = new DatatablesService(); + $mail_service = new MailService(); + $module_service = new ModuleService(); + $user_service = new UserService(); + $admin = $user_service->create('AdminName', 'Administrator', 'admin@example.com', 'secret'); $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); - $request = self::createRequest() + $controller = new UsersController($datatables_service, $mail_service, $module_service, $user_service); + $request = self::createRequest() ->withQueryParams(['length' => 1]) ->withAttribute('user', $admin); - - $controller = app(UsersController::class); $response = $controller->data($request); $this->assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); @@ -124,16 +132,19 @@ class UserAdminTest extends TestCase */ public function testSortingUserAdminPage(): void { - $user_service = new UserService(); + $datatables_service = new DatatablesService(); + $mail_service = new MailService(); + $module_service = new ModuleService(); + $user_service = new UserService(); $admin = $user_service->create('AdminName', 'Administrator', 'admin@example.com', 'secret'); $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); - $request = self::createRequest() + $controller = new UsersController($datatables_service, $mail_service, $module_service, $user_service); + $request = self::createRequest() ->withQueryParams(['column' => 2, 'dir' => 'asc']) ->withAttribute('user', $admin); - - $response = app(UsersController::class)->data($request); + $response = $controller->data($request); $this->assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); $this->assertSame('application/json', $response->getHeaderLine('Content-Type')); @@ -147,7 +158,7 @@ class UserAdminTest extends TestCase ->withQueryParams(['order' => [['column' => 2, 'dir' => 'desc']]]) ->withAttribute('user', $admin); - $controller = app(UsersController::class); + $controller = new UsersController($datatables_service, $mail_service, $module_service, $user_service); $response = $controller->data($request); $this->assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); |
