Skip to content
Snippets Groups Projects

Issue #2699565: Replace \Drupal:: with $this->container->get() in test classes of Basic Auth module

Open Issue #2699565: Replace \Drupal:: with $this->container->get() in test classes of Basic Auth module
4 unresolved threads
Open Alvaro Hurtado requested to merge issue/drupal-2699565:11.x into 11.x
4 unresolved threads
Files
4
@@ -4,16 +4,32 @@
namespace Drupal\basic_auth_test;
use Drupal\Core\PageCache\ResponsePolicyInterface;
use Drupal\Core\State\StateInterface;
/**
* Provides routes for HTTP Basic Authentication testing.
*/
class BasicAuthTestController {
/**
* Constructs a new BasicAuthTestController object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state storage service.
* @param \Drupal\Core\PageCache\ResponsePolicy\ResponsePolicyInterface $pageCacheKillSwitch
* The page cache kill switch service.
*/
    • Comment on lines +15 to +22
      Suggested change
      15 /**
      16 * Constructs a new BasicAuthTestController object.
      17 *
      18 * @param \Drupal\Core\State\StateInterface $state
      19 * The state storage service.
      20 * @param \Drupal\Core\PageCache\ResponsePolicy\ResponsePolicyInterface $pageCacheKillSwitch
      21 * The page cache kill switch service.
      22 */

      Constructor documentation is no longer necessary.

Please register or sign in to reply
public function __construct(
private StateInterface $state,
private ResponsePolicyInterface $pageCacheKillSwitch,
) {}
/**
* @see \Drupal\basic_auth\Tests\Authentication\BasicAuthTest::testControllerNotCalledBeforeAuth()
*/
public function modifyState() {
\Drupal::state()->set('basic_auth_test.state.controller_executed', TRUE);
$this->state->set('basic_auth_test.state.controller_executed', TRUE);
return ['#markup' => 'Done'];
}
@@ -22,10 +38,10 @@ public function modifyState() {
*/
public function readState() {
// Mark this page as being uncacheable.
\Drupal::service('page_cache_kill_switch')->trigger();
$this->pageCacheKillSwitch->trigger();
return [
'#markup' => \Drupal::state()->get('basic_auth_test.state.controller_executed') ? 'yep' : 'nope',
'#markup' => $this->state->get('basic_auth_test.state.controller_executed') ? 'yep' : 'nope',
'#cache' => [
'max-age' => 0,
],
Loading