Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / Plugin / DMU / Fixer / ImplementTest.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Fixer;
4
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;
10
11 /**
12  * @group DMU.Fixer
13  */
14 class ImplementTest extends TestBase {
15
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]));
20
21     $this
22       ->container
23       ->get('plugin.manager.drupalmoduleupgrader.indexer')
24       ->method('createInstance')
25       ->with('class')
26       ->willReturn($indexer);
27
28     $config = [
29       'definition' => '\Drupal\Core\Block\BlockPluginInterface::blockForm',
30       'target' => 'Foobaz',
31     ];
32     $plugin = new Implement($config, uniqID(), []);
33     $plugin->setTarget($this->target);
34     try {
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.
37       // That's OK, though.
38       $plugin->execute();
39     }
40     catch (IOException $e) {}
41
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());
53   }
54
55 }