Commit 0414f401 authored by alexpott's avatar alexpott

Issue #2661542 by Mile23, Mixologic: Isolate...

Issue #2661542 by Mile23, Mixologic: Isolate Drupal\Tests\Component\Plugin\DefaultFactoryTest from core test module
parent 15393165
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
use Drupal\Component\Plugin\Definition\PluginDefinitionInterface; use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry; use Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli;
use Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface; use Drupal\Tests\Component\Plugin\Fixtures\vegetable\Corn;
use Drupal\plugin_test\Plugin\plugin_test\fruit\Kale; use Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/** /**
...@@ -22,8 +22,8 @@ class DefaultFactoryTest extends TestCase { ...@@ -22,8 +22,8 @@ class DefaultFactoryTest extends TestCase {
* @covers ::getPluginClass * @covers ::getPluginClass
*/ */
public function testGetPluginClassWithValidArrayPluginDefinition() { public function testGetPluginClassWithValidArrayPluginDefinition() {
$plugin_class = Cherry::class; $plugin_class = Corn::class;
$class = DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class]); $class = DefaultFactory::getPluginClass('corn', ['class' => $plugin_class]);
$this->assertEquals($plugin_class, $class); $this->assertEquals($plugin_class, $class);
} }
...@@ -34,12 +34,12 @@ public function testGetPluginClassWithValidArrayPluginDefinition() { ...@@ -34,12 +34,12 @@ public function testGetPluginClassWithValidArrayPluginDefinition() {
* @covers ::getPluginClass * @covers ::getPluginClass
*/ */
public function testGetPluginClassWithValidObjectPluginDefinition() { public function testGetPluginClassWithValidObjectPluginDefinition() {
$plugin_class = Cherry::class; $plugin_class = Corn::class;
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce()) $plugin_definition->expects($this->atLeastOnce())
->method('getClass') ->method('getClass')
->willReturn($plugin_class); ->willReturn($plugin_class);
$class = DefaultFactory::getPluginClass('cherry', $plugin_definition); $class = DefaultFactory::getPluginClass('corn', $plugin_definition);
$this->assertEquals($plugin_class, $class); $this->assertEquals($plugin_class, $class);
} }
...@@ -52,12 +52,12 @@ public function testGetPluginClassWithValidObjectPluginDefinition() { ...@@ -52,12 +52,12 @@ public function testGetPluginClassWithValidObjectPluginDefinition() {
public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() { public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
if (method_exists($this, 'expectException')) { if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class); $this->expectException(PluginException::class);
$this->expectExceptionMessage('The plugin (cherry) did not specify an instance class.'); $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.');
} }
else { else {
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); $this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.');
} }
DefaultFactory::getPluginClass('cherry', []); DefaultFactory::getPluginClass('corn', []);
} }
/** /**
...@@ -69,12 +69,12 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() { ...@@ -69,12 +69,12 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
if (method_exists($this, 'expectException')) { if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class); $this->expectException(PluginException::class);
$this->expectExceptionMessage('The plugin (cherry) did not specify an instance class.'); $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.');
} }
else { else {
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); $this->setExpectedException(PluginException::class, 'The plugin (corn) did not specify an instance class.');
} }
DefaultFactory::getPluginClass('cherry', $plugin_definition); DefaultFactory::getPluginClass('corn', $plugin_definition);
} }
/** /**
...@@ -85,12 +85,12 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() { ...@@ -85,12 +85,12 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() { public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() {
if (method_exists($this, 'expectException')) { if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class); $this->expectException(PluginException::class);
$this->expectExceptionMessage('Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.'); $this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.');
} }
else { else {
$this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.'); $this->setExpectedException(PluginException::class, 'Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.');
} }
DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']); DefaultFactory::getPluginClass('carrot', ['class' => 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot']);
} }
/** /**
...@@ -99,7 +99,7 @@ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition( ...@@ -99,7 +99,7 @@ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition(
* @covers ::getPluginClass * @covers ::getPluginClass
*/ */
public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() { public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() {
$plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit'; $plugin_class = 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot';
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce()) $plugin_definition->expects($this->atLeastOnce())
->method('getClass') ->method('getClass')
...@@ -110,7 +110,7 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition ...@@ -110,7 +110,7 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition
else { else {
$this->setExpectedException(PluginException::class); $this->setExpectedException(PluginException::class);
} }
DefaultFactory::getPluginClass('kiwifruit', $plugin_definition); DefaultFactory::getPluginClass('carrot', $plugin_definition);
} }
/** /**
...@@ -119,8 +119,8 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition ...@@ -119,8 +119,8 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition
* @covers ::getPluginClass * @covers ::getPluginClass
*/ */
public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() { public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() {
$plugin_class = Cherry::class; $plugin_class = Corn::class;
$class = DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class], FruitInterface::class); $class = DefaultFactory::getPluginClass('corn', ['class' => $plugin_class], VegetableInterface::class);
$this->assertEquals($plugin_class, $class); $this->assertEquals($plugin_class, $class);
} }
...@@ -131,12 +131,12 @@ public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() { ...@@ -131,12 +131,12 @@ public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() {
* @covers ::getPluginClass * @covers ::getPluginClass
*/ */
public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() { public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() {
$plugin_class = Cherry::class; $plugin_class = Corn::class;
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce()) $plugin_definition->expects($this->atLeastOnce())
->method('getClass') ->method('getClass')
->willReturn($plugin_class); ->willReturn($plugin_class);
$class = DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class); $class = DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class);
$this->assertEquals($plugin_class, $class); $this->assertEquals($plugin_class, $class);
} }
...@@ -147,15 +147,14 @@ public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() { ...@@ -147,15 +147,14 @@ public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() {
* @covers ::getPluginClass * @covers ::getPluginClass
*/ */
public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() { public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() {
$plugin_class = Kale::class;
if (method_exists($this, 'expectException')) { if (method_exists($this, 'expectException')) {
$this->expectException(PluginException::class); $this->expectException(PluginException::class);
$this->expectExceptionMessage('Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.'); $this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.');
} }
else { else {
$this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.'); $this->setExpectedException(PluginException::class, 'Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.');
} }
DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class); DefaultFactory::getPluginClass('corn', ['class' => Broccoli::class], VegetableInterface::class);
} }
/** /**
...@@ -164,7 +163,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDef ...@@ -164,7 +163,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDef
* @covers ::getPluginClass * @covers ::getPluginClass
*/ */
public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() { public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() {
$plugin_class = Kale::class; $plugin_class = Broccoli::class;
$plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
$plugin_definition->expects($this->atLeastOnce()) $plugin_definition->expects($this->atLeastOnce())
->method('getClass') ->method('getClass')
...@@ -175,7 +174,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDe ...@@ -175,7 +174,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDe
else { else {
$this->setExpectedException(PluginException::class); $this->setExpectedException(PluginException::class);
} }
DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class); DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class);
} }
} }
<?php
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
/**
* @Plugin(
* id = "broccoli",
* label = "Broccoli",
* color = "green"
* )
*/
class Broccoli {}
<?php
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
/**
* @Plugin(
* id = "corn",
* label = "Corn",
* color = "yellow"
* )
*/
class Corn implements VegetableInterface {}
<?php
namespace Drupal\Tests\Component\Plugin\Fixtures\vegetable;
/**
* Provides an interface for test plugins.
*/
interface VegetableInterface {}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment