You are here

public function DisableTest::test in Drupal 7 to 8/9 Module Upgrader 8

File

tests/src/Unit/Plugin/DMU/Fixer/DisableTest.php, line 16

Class

DisableTest
@group DMU.Fixer

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Fixer

Code

public function test() {
  $code = <<<'END'
<?php

variable_get('foo');
END;
  $this->dir
    ->getChild('foo.module')
    ->setContent(rtrim($code));
  $indexer = new FunctionCalls([], 'function', [
    'exclude' => [],
  ], $this->db, $this->target);
  $indexer
    ->build();
  $this->container
    ->get('plugin.manager.drupalmoduleupgrader.indexer')
    ->method('createInstance')
    ->with('function_call')
    ->willReturn($indexer);
  $config = [
    'type' => 'function_call',
    'id' => 'variable_get',
    'note' => 'This is no longer kosher!',
  ];
  $plugin = new Disable($config, uniqid(), []);
  $plugin
    ->setTarget($this->target);
  $plugin
    ->execute();
  $expected = <<<END
<?php

// This is no longer kosher!
// variable_get('foo');
END;

  // trim() makes the test pass. Go figure.
  $this
    ->assertEquals($expected, trim($this->dir
    ->getChild('foo.module')
    ->getContent()));
}