3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Fixer;
5 use Drupal\drupalmoduleupgrader\IOException;
6 use Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer\Implement;
7 use Drupal\Tests\drupalmoduleupgrader\Unit\TestBase;
8 use Pharborist\NodeCollection;
9 use Pharborist\Objects\ClassNode;
14 class ImplementTest extends TestBase {
16 public function test() {
17 $class = ClassNode::create('Foobaz');
18 $indexer = $this->getMock('\Drupal\drupalmoduleupgrader\IndexerInterface');
19 $indexer->method('get')->with('Foobaz')->willReturn(new NodeCollection([$class]));
23 ->get('plugin.manager.drupalmoduleupgrader.indexer')
24 ->method('createInstance')
26 ->willReturn($indexer);
29 'definition' => '\Drupal\Core\Block\BlockPluginInterface::blockForm',
32 $plugin = new Implement($config, uniqID(), []);
33 $plugin->setTarget($this->target);
35 // We expect a CodeManagerIOException because we're implementing the
36 // method on a class that is not officially part of the target's code.
40 catch (IOException $e) {}
42 $this->assertTrue($class->hasMethod('blockForm'));
43 $method = $class->getMethod('blockForm');
44 $this->assertInstanceOf('\Pharborist\Objects\ClassMethodNode', $method);
45 $parameters = $method->getParameters();
46 $this->assertCount(2, $parameters);
47 $this->assertEquals($parameters[0]->getName(), 'form');
48 $this->assertNull($parameters[0]->getTypeHint());
49 $this->assertEquals($parameters[1]->getName(), 'form_state');
50 $type = $parameters[1]->getTypeHint();
51 $this->assertInstanceOf('\Pharborist\Namespaces\NameNode', $type);
52 $this->assertEquals('Drupal\Core\Form\FormStateInterface', $type->getText());