getMockBuilder(InstallerRedirectTrait::class) ->setMethods(['isCli']) ->getMockForTrait(); // Make sure that the method thinks we are not using the cli. $trait->expects($this->any()) ->method('isCli') ->willReturn(FALSE); // Un-protect the method using reflection. $method_ref = new \ReflectionMethod($trait, 'shouldRedirectToInstaller'); $method_ref->setAccessible(TRUE); // Mock the database connection info. $db = $this->getMockForAbstractClass(Database::class); $property_ref = new \ReflectionProperty($db, 'databaseInfo'); $property_ref->setAccessible(TRUE); $property_ref->setValue($db, ['default' => $connection_info]); if ($connection) { // Mock the database connection. $connection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->setMethods(['schema']) ->getMockForAbstractClass(); if ($connection_info) { // Mock the database schema class. $schema = $this->getMockBuilder(Schema::class) ->disableOriginalConstructor() ->setMethods(['tableExists']) ->getMockForAbstractClass(); $schema->expects($this->any()) ->method('tableExists') ->with('sessions') ->willReturn($session_table_exists); $connection->expects($this->any()) ->method('schema') ->willReturn($schema); } } else { // Set the database connection if there is none. $connection = NULL; } // Call shouldRedirectToInstaller. $this->assertSame($expected, $method_ref->invoke($trait, $e, $connection)); } } }