Commit 69ceca47 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2911230 by borisson_: Clean up usage of classnames as strings by using ::class

parent feebf73a
......@@ -7,6 +7,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\facets_summary\Annotation\SummaryProcessor;
/**
* Manages processor plugins.
......@@ -24,7 +25,7 @@ class ProcessorPluginManager extends DefaultPluginManager {
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, TranslationInterface $translation) {
parent::__construct('Plugin/facets_summary/processor', $namespaces, $module_handler, 'Drupal\facets_summary\Processor\ProcessorInterface', 'Drupal\facets_summary\Annotation\SummaryProcessor');
parent::__construct('Plugin/facets_summary/processor', $namespaces, $module_handler, ProcessorInterface::class, SummaryProcessor::class);
$this->setCacheBackend($cache_backend, 'facets_summary_processors');
$this->setStringTranslation($translation);
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\facets_summary\Kernel;
use Drupal\facets_summary\Entity\FacetsSummary;
use Drupal\facets_summary\Plugin\facets_summary\processor\HideWhenNotRenderedProcessor;
use Drupal\facets_summary\Processor\ProcessorInterface;
use Drupal\KernelTests\KernelTestBase;
......@@ -106,7 +107,7 @@ class SummaryEntityTest extends KernelTestBase {
$this->assertNotEmpty($entity->getProcessorsByStage(ProcessorInterface::STAGE_BUILD));
$processors = $entity->getProcessors();
$this->assertArrayHasKey($id, $processors);
$this->assertInstanceOf('\Drupal\facets_summary\Plugin\facets_summary\processor\HideWhenNotRenderedProcessor', $processors[$id]);
$this->assertInstanceOf(HideWhenNotRenderedProcessor::class, $processors[$id]);
$entity->removeProcessor($id);
$this->assertEmpty($entity->getProcessorsByStage(ProcessorInterface::STAGE_BUILD));
......
......@@ -3,6 +3,7 @@
namespace Drupal\facets\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\facets\Form\FacetSourceEditForm;
/**
* Provides route responses for facet source configuration.
......@@ -20,7 +21,7 @@ class FacetSourceController extends ControllerBase {
*/
public function facetSourceConfigForm($facets_facet_source) {
// Returns the render array of the FacetSourceConfigForm.
return $this->formBuilder()->getForm('\Drupal\facets\Form\FacetSourceEditForm');
return $this->formBuilder()->getForm(FacetSourceEditForm::class);
}
}
......@@ -6,6 +6,7 @@ use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\facets\Annotation\FacetsFacetSource;
/**
* Manages facet source plugins.
......@@ -20,7 +21,7 @@ class FacetSourcePluginManager extends DefaultPluginManager {
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facets/facet_source', $namespaces, $module_handler, 'Drupal\facets\FacetSource\FacetSourcePluginInterface', 'Drupal\facets\Annotation\FacetsFacetSource');
parent::__construct('Plugin/facets/facet_source', $namespaces, $module_handler, FacetSourcePluginInterface::class, FacetsFacetSource::class);
}
/**
......
......@@ -6,6 +6,7 @@ use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\facets\Annotation\FacetsHierarchy;
/**
* Manages Hierarchy plugins.
......@@ -22,7 +23,7 @@ class HierarchyPluginManager extends DefaultPluginManager {
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facets/hierarchy', $namespaces, $module_handler, 'Drupal\facets\Hierarchy\HierarchyInterface', 'Drupal\facets\Annotation\FacetsHierarchy');
parent::__construct('Plugin/facets/hierarchy', $namespaces, $module_handler, HierarchyInterface::class, FacetsHierarchy::class);
$this->setCacheBackend($cache_backend, 'facets_hierarchy');
}
......
......@@ -7,6 +7,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\facets\Annotation\FacetsProcessor;
/**
* Manages processor plugins.
......@@ -24,7 +25,7 @@ class ProcessorPluginManager extends DefaultPluginManager {
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, TranslationInterface $translation) {
parent::__construct('Plugin/facets/processor', $namespaces, $module_handler, 'Drupal\facets\Processor\ProcessorInterface', 'Drupal\facets\Annotation\FacetsProcessor');
parent::__construct('Plugin/facets/processor', $namespaces, $module_handler, ProcessorInterface::class, FacetsProcessor::class);
$this->setCacheBackend($cache_backend, 'facets_processors');
$this->setStringTranslation($translation);
}
......
......@@ -5,6 +5,7 @@ namespace Drupal\facets\QueryType;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\facets\Annotation\FacetsQueryType;
/**
* Defines a plugin manager for query types.
......@@ -15,7 +16,7 @@ class QueryTypePluginManager extends DefaultPluginManager {
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facets/query_type', $namespaces, $module_handler, 'Drupal\facets\QueryType\QueryTypeInterface', 'Drupal\facets\Annotation\FacetsQueryType');
parent::__construct('Plugin/facets/query_type', $namespaces, $module_handler, QueryTypeInterface::class, FacetsQueryType::class);
}
}
......@@ -6,6 +6,7 @@ use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\facets\Annotation\FacetsUrlProcessor;
/**
* Manages URL processor plugins.
......@@ -23,7 +24,7 @@ class UrlProcessorPluginManager extends DefaultPluginManager {
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facets/url_processor', $namespaces, $module_handler, 'Drupal\facets\UrlProcessor\UrlProcessorInterface', 'Drupal\facets\Annotation\FacetsUrlProcessor');
parent::__construct('Plugin/facets/url_processor', $namespaces, $module_handler, UrlProcessorInterface::class, FacetsUrlProcessor::class);
$this->setCacheBackend($cache_backend, 'facets_url_processors');
}
......
......@@ -113,7 +113,7 @@ class FacetFacetSourceTest extends EntityKernelTestBase {
$entity->setWidget('links');
$entity->setFacetSourceId('search_api:views_page__search_api_test_view__page_1');
$this->setExpectedException('Drupal\facets\Exception\InvalidQueryTypeException');
$this->setExpectedException(InvalidQueryTypeException::class);
$entity->getQueryType();
}
......
......@@ -4,8 +4,11 @@ namespace Drupal\Tests\facets\Kernel\Entity;
use Drupal\Core\Plugin\PluginBase;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Exception\Exception;
use Drupal\facets\Exception\InvalidProcessorException;
use Drupal\facets\Hierarchy\HierarchyPluginManager;
use Drupal\facets\Plugin\facets\hierarchy\Taxonomy;
use Drupal\facets\Plugin\facets\processor\HideNonNarrowingResultProcessor;
use Drupal\facets\Plugin\facets\widget\LinksWidget;
use Drupal\facets\Processor\ProcessorInterface;
use Drupal\facets\Result\Result;
......@@ -75,7 +78,7 @@ class FacetTest extends KernelTestBase {
],
];
$this->assertEquals(['type' => 'links', 'config' => $config], $entity->getWidget());
$this->assertInstanceOf('\Drupal\facets\Plugin\facets\widget\LinksWidget', $entity->getWidgetInstance());
$this->assertInstanceOf(LinksWidget::class, $entity->getWidgetInstance());
$this->assertFalse($entity->getWidgetInstance()->getConfiguration()['show_numbers']);
$config['show_numbers'] = TRUE;
......@@ -132,7 +135,7 @@ class FacetTest extends KernelTestBase {
$this->assertEmpty($entity->getProcessorsByStage(ProcessorInterface::STAGE_SORT));
$processors = $entity->getProcessors();
$this->assertArrayHasKey('hide_non_narrowing_result_processor', $processors);
$this->assertInstanceOf('\Drupal\facets\Plugin\facets\processor\HideNonNarrowingResultProcessor', $processors['hide_non_narrowing_result_processor']);
$this->assertInstanceOf(HideNonNarrowingResultProcessor::class, $processors['hide_non_narrowing_result_processor']);
$entity->removeProcessor($id);
$this->assertEmpty($entity->getProcessorsByStage(ProcessorInterface::STAGE_BUILD));
......@@ -147,7 +150,7 @@ class FacetTest extends KernelTestBase {
public function testGetQueryTypeWithNoFacetSource() {
$entity = new Facet([], 'facets_facet');
$this->setExpectedException('\Drupal\facets\Exception\Exception', 'No facet source defined for facet.');
$this->setExpectedException(Exception::class, 'No facet source defined for facet.');
$entity->getQueryType();
}
......@@ -374,8 +377,7 @@ class FacetTest extends KernelTestBase {
$manager = $entity->getHierarchyManager();
$this->assertInstanceOf(HierarchyPluginManager::class, $manager);
$this->assertInstanceOf('\Drupal\facets\Plugin\facets\hierarchy\Taxonomy', $entity->getHierarchyInstance());
$this->assertInstanceOf(Taxonomy::class, $entity->getHierarchyInstance());
$this->assertEquals(['type' => 'taxonomy', 'config' => []], $entity->getHierarchy());
}
......
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\facets\Kernel\Plugin\query_type;
use Drupal\facets\FacetInterface;
use Drupal\facets\Result\ResultInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\query_type\SearchApiDate;
......@@ -81,13 +83,13 @@ class SearchApiDateTest extends KernelTestBase {
);
$built_facet = $query_type->build();
$this->assertInstanceOf('\Drupal\facets\FacetInterface', $built_facet);
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
foreach ($grouped_results as $k => $result) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $results[$k]);
$this->assertInstanceOf(ResultInterface::class, $results[$k]);
$this->assertEquals($result['count'], $results[$k]->getCount());
$this->assertEquals($result['filter'], $results[$k]->getDisplayValue());
}
......@@ -300,7 +302,7 @@ class SearchApiDateTest extends KernelTestBase {
);
$built_facet = $query_type->build();
$this->assertInstanceOf('\Drupal\facets\FacetInterface', $built_facet);
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
......
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\CountLimitProcessor;
use Drupal\facets\Processor\ProcessorPluginManager;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
......@@ -48,11 +49,11 @@ class CountLimitProcessorTest extends UnitTestCase {
$processor_definitions = [
$processor_id => [
'id' => $processor_id,
'class' => 'Drupal\facets\Plugin\facets\processor\CountLimitProcessor',
'class' => CountLimitProcessor::class,
],
];
$manager = $this->getMockBuilder('Drupal\facets\Processor\ProcessorPluginManager')
$manager = $this->getMockBuilder(ProcessorPluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects($this->any())
......
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\ExcludeSpecifiedItemsProcessor;
use Drupal\facets\Processor\ProcessorPluginManager;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
......@@ -63,11 +64,11 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
$processor_definitions = [
$processor_id => [
'id' => $processor_id,
'class' => 'Drupal\facets\Plugin\facets\processor\ExcludeSpecifiedItemsProcessor',
'class' => ExcludeSpecifiedItemsProcessor::class,
],
];
$manager = $this->getMockBuilder('Drupal\facets\Processor\ProcessorPluginManager')
$manager = $this->getMockBuilder(ProcessorPluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects($this->any())
......
......@@ -3,6 +3,9 @@
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\processor\UidToUserNameCallbackProcessor;
use Drupal\facets\Result\Result;
......@@ -36,8 +39,8 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
* Tests that results were correctly changed.
*/
public function testResultsChanged() {
$user_storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
$entity_manager = $this->getMock('\Drupal\Core\Entity\EntityTypeManagerInterface');
$user_storage = $this->getMock(EntityStorageInterface::class);
$entity_manager = $this->getMock(EntityManagerInterface::class);
$entity_repository = $this->getMock(EntityTypeRepositoryInterface::class);
$entity_repository->expects($this->any())
->method('getEntityTypeFromClass')
......@@ -46,7 +49,7 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
->method('getStorage')
->willReturn($user_storage);
$user1 = $this->getMock('\Drupal\Core\Session\AccountInterface');
$user1 = $this->getMock(AccountInterface::class);
$user1->method('getDisplayName')
->willReturn('Admin');
......@@ -87,8 +90,8 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
* Tests that deleted entity results were correctly handled.
*/
public function testDeletedEntityResults() {
$user_storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
$entity_manager = $this->getMock('\Drupal\Core\Entity\EntityTypeManagerInterface');
$user_storage = $this->getMock(EntityStorageInterface::class);
$entity_manager = $this->getMock(EntityManagerInterface::class);
$entity_repository = $this->getMock(EntityTypeRepositoryInterface::class);
$entity_repository->expects($this->any())
->method('getEntityTypeFromClass')
......
......@@ -3,8 +3,13 @@
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Exception\InvalidProcessorException;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets\Plugin\facets\processor\UrlProcessorHandler;
use Drupal\facets\UrlProcessor\UrlProcessorInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -18,7 +23,7 @@ class UrlProcessorHandlerTest extends UnitTestCase {
* Tests that the processor correctly throws an exception.
*/
public function testEmptyProcessorConfiguration() {
$this->setExpectedException('\Drupal\facets\Exception\InvalidProcessorException', "The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
$this->setExpectedException(InvalidProcessorException::class, "The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
new UrlProcessorHandler([], 'test', []);
}
......@@ -26,7 +31,7 @@ class UrlProcessorHandlerTest extends UnitTestCase {
* Tests that the processor correctly throws an exception.
*/
public function testInvalidProcessorConfiguration() {
$this->setExpectedException('\Drupal\facets\Exception\InvalidProcessorException', "The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
$this->setExpectedException(InvalidProcessorException::class, "The UrlProcessorHandler doesn't have the required 'facet' in the configuration array.");
new UrlProcessorHandler(['facet' => new \stdClass()], 'test', []);
}
......@@ -91,19 +96,19 @@ class UrlProcessorHandlerTest extends UnitTestCase {
* Sets up a container.
*/
protected function createContainer() {
$url_processor = $this->getMockBuilder('\Drupal\facets\UrlProcessor\UrlProcessorInterface')
$url_processor = $this->getMockBuilder(UrlProcessorInterface::class)
->disableOriginalConstructor()
->getMock();
$manager = $this->getMockBuilder('\Drupal\facets\FacetSource\FacetSourcePluginManager')
$manager = $this->getMockBuilder(FacetSourcePluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects($this->exactly(1))
->method('createInstance')
->willReturn($url_processor);
$storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
$em = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeManagerInterface')
$storage = $this->getMock(EntityStorageInterface::class);
$em = $this->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$em->expects($this->exactly(1))
......
......@@ -3,9 +3,12 @@
namespace Drupal\Tests\facets\Unit\Plugin\query_type;
use Drupal\facets\Entity\Facet;
use Drupal\facets\FacetInterface;
use Drupal\facets\Plugin\facets\query_type\SearchApiGranular;
use Drupal\search_api\Backend\BackendInterface;
use Drupal\search_api\IndexInterface;
use Drupal\facets\Result\ResultInterface;
use Drupal\facets\Widget\WidgetPluginInterface;
use Drupal\search_api\Plugin\views\query\SearchApiQuery;
use Drupal\search_api\ServerInterface;
use Drupal\Tests\UnitTestCase;
......@@ -30,12 +33,12 @@ class SearchApiGranularTest extends UnitTestCase {
$query = $this->prophesize(SearchApiQuery::class);
$query->getIndex()->willReturn($index);
$facetReflection = new \ReflectionClass('Drupal\facets\Entity\Facet');
$facet = new Facet(
['query_operator' => 'AND', 'widget' => 'links'],
'facets_facet'
);
$widget = $this->getMockBuilder('Drupal\facets\Widget\WidgetPluginInterface')
$facetReflection = new \ReflectionClass(Facet::class);
$widget = $this->getMockBuilder(WidgetPluginInterface::class)
->disableOriginalConstructor()
->getMock();
$widget->method('getConfiguration')->will($this->returnValue(['granularity' => 10]));
......@@ -68,13 +71,13 @@ class SearchApiGranularTest extends UnitTestCase {
);
$built_facet = $query_type->build();
$this->assertInstanceOf('\Drupal\facets\FacetInterface', $built_facet);
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
foreach ($grouped_results as $k => $result) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $results[$k]);
$this->assertInstanceOf(ResultInterface::class, $results[$k]);
$this->assertEquals($result['count'], $results[$k]->getCount());
$this->assertEquals($result['filter'], $results[$k]->getDisplayValue());
}
......@@ -97,7 +100,7 @@ class SearchApiGranularTest extends UnitTestCase {
);
$built_facet = $query_type->build();
$this->assertInstanceOf('\Drupal\facets\FacetInterface', $built_facet);
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
......
......@@ -3,7 +3,9 @@
namespace Drupal\Tests\facets\Unit\Plugin\query_type;
use Drupal\facets\Entity\Facet;
use Drupal\facets\FacetInterface;
use Drupal\facets\Plugin\facets\query_type\SearchApiString;
use Drupal\facets\Result\ResultInterface;
use Drupal\search_api\Plugin\views\query\SearchApiQuery;
use Drupal\Tests\UnitTestCase;
......@@ -42,13 +44,13 @@ class SearchApiStringTest extends UnitTestCase {
);
$built_facet = $query_type->build();
$this->assertInstanceOf('\Drupal\facets\FacetInterface', $built_facet);
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
foreach ($original_results as $k => $result) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $results[$k]);
$this->assertInstanceOf(ResultInterface::class, $results[$k]);
$this->assertEquals($result['count'], $results[$k]->getCount());
$this->assertEquals($result['filter'], $results[$k]->getDisplayValue());
}
......@@ -83,13 +85,13 @@ class SearchApiStringTest extends UnitTestCase {
);
$built_facet = $query_type->build();
$this->assertInstanceOf('\Drupal\facets\FacetInterface', $built_facet);
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
foreach ($original_results as $k => $result) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $results[$k]);
$this->assertInstanceOf(ResultInterface::class, $results[$k]);
$this->assertEquals($result['count'], $results[$k]->getCount());
$this->assertEquals($result['filter'], $results[$k]->getDisplayValue());
}
......@@ -112,7 +114,7 @@ class SearchApiStringTest extends UnitTestCase {
);
$built_facet = $query_type->build();
$this->assertInstanceOf('\Drupal\facets\FacetInterface', $built_facet);
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
......
......@@ -2,10 +2,18 @@
namespace Drupal\Tests\facets\Unit\Plugin\url_processor;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Entity\FacetSource;
use Drupal\facets\Exception\InvalidProcessorException;
use Drupal\facets\FacetSource\FacetSourcePluginInterface;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets\Plugin\facets\url_processor\QueryString;
use Drupal\facets\Result\Result;
use Drupal\facets\Result\ResultInterface;
use Drupal\Tests\Core\Routing\TestRouterInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\ParameterBag;
......@@ -55,7 +63,7 @@ class QueryStringTest extends UnitTestCase {
* Tests that the processor correctly throws an exception.
*/
public function testEmptyProcessorConfiguration() {
$this->setExpectedException('\Drupal\facets\Exception\InvalidProcessorException', "The url processor doesn't have the required 'facet' in the configuration array.");
$this->setExpectedException(InvalidProcessorException::class, "The url processor doesn't have the required 'facet' in the configuration array.");
new QueryString([], 'test', [], new Request());
}
......@@ -147,7 +155,7 @@ class QueryStringTest extends UnitTestCase {
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $r) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $r);
$this->assertInstanceOf(ResultInterface::class, $r);
$this->assertEquals('route:test?f%5B0%5D=test%3A' . $r->getRawValue(), $r->getUrl()->toUriString());
}
}
......@@ -172,7 +180,7 @@ class QueryStringTest extends UnitTestCase {
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $k => $r) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $r);
$this->assertInstanceOf(ResultInterface::class, $r);
if ($k === 2) {
$this->assertEquals('route:test?f%5B0%5D=king%3Akong', $r->getUrl()->toUriString());
}
......@@ -212,11 +220,11 @@ class QueryStringTest extends UnitTestCase {
$facet_source = new FacetSource(['filter_key' => 'ab'], 'facets_facet_source');
// Override the container with the new facet source.
$storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
$storage = $this->getMock(EntityStorageInterface::class);
$storage->expects($this->once())
->method('load')
->willReturn($facet_source);
$em = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeManagerInterface')
$em = $this->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$em->expects($this->any())
......@@ -240,7 +248,7 @@ class QueryStringTest extends UnitTestCase {
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $r) {
$this->assertInstanceOf('\Drupal\facets\Result\ResultInterface', $r);
$this->assertInstanceOf(ResultInterface::class, $r);
$this->assertEquals('route:test?ab%5B0%5D=test%3A' . $r->getRawValue(), $r->getUrl()->toUriString());
}
......@@ -268,7 +276,7 @@ class QueryStringTest extends UnitTestCase {
*/
public function testContextualFilters() {
// Override router.
$router = $this->getMockBuilder('Drupal\Tests\Core\Routing\TestRouterInterface')
$router = $this->getMockBuilder(TestRouterInterface::class)
->disableOriginalConstructor()
->getMock();
$router->expects($this->any())
......@@ -302,7 +310,7 @@ class QueryStringTest extends UnitTestCase {
* Sets up a container.
*/
protected function setContainer() {
$router = $this->getMockBuilder('Drupal\Tests\Core\Routing\TestRouterInterface')
$router = $this->getMockBuilder(TestRouterInterface::class)
->disableOriginalConstructor()
->getMock();
$router->expects($this->any())
......@@ -312,15 +320,15 @@ class QueryStringTest extends UnitTestCase {
'_route' => 'test',
]);
$validator = $this->getMock('Drupal\Core\Path\PathValidatorInterface');
$validator = $this->getMock(PathValidatorInterface::class);
$fsi = $this->getMockBuilder('\Drupal\facets\FacetSource\FacetSourcePluginInterface')
$fsi = $this->getMockBuilder(FacetSourcePluginInterface::class)
->disableOriginalConstructor()
->getMock();
$fsi->method('getPath')
->willReturn('test');
$manager = $this->getMockBuilder('\Drupal\facets\FacetSource\FacetSourcePluginManager')
$manager = $this->getMockBuilder(FacetSourcePluginManager::class)
->disableOriginalConstructor()
->getMock();
$manager->method('createInstance')
......@@ -329,8 +337,8 @@ class QueryStringTest extends UnitTestCase {
->with('facet_source__dummy')
->willReturn(TRUE);
$storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
$em = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeManagerInterface')
$storage = $this->getMock(EntityStorageInterface::class);
$em = $this->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$em->expects($this->any())
......
......@@ -94,7 +94,7 @@ class ProcessorPluginManagerTest extends UnitTestCase {
public function testConstruct() {
$namespaces = new ArrayObject();
$sut = new ProcessorPluginManager($namespaces, $this->cache, $this->moduleHandler, $this->translator);
$this->assertInstanceOf('\Drupal\facets\Processor\ProcessorPluginManager', $sut);
$this->assertInstanceOf(ProcessorPluginManager::class, $sut);
}
/**
......
......@@ -83,7 +83,7 @@ class QueryTypePluginManagerTest extends UnitTestCase {
public function testConstruct() {
$namespaces = new ArrayObject();
$sut = new QueryTypePluginManager($namespaces, $this->cache, $this->moduleHandler);
$this->assertInstanceOf('\Drupal\facets\QueryType\QueryTypePluginManager', $sut);
$this->assertInstanceOf(QueryTypePluginManager::class, $sut);
}
/**
......
......@@ -93,7 +93,7 @@ class UrlProcessorPluginManagerTest extends UnitTestCase {
public function testConstruct() {
$namespaces = new ArrayObject();
$sut = new UrlProcessorPluginManager($namespaces, $this->cache, $this->moduleHandler, $this->translator);
$this->assertInstanceOf('\Drupal\facets\UrlProcessor\UrlProcessorPluginManager', $sut);
$this->assertInstanceOf(UrlProcessorPluginManager::class, $sut);
}
/**
......
......@@ -4,9 +4,14 @@ namespace Drupal\Tests\facets\Unit\Utility;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\facets\Utility\FacetsDateHandler;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Unit test for Date Handler Service.
......@@ -38,9 +43,9 @@ class FacetsDateHandlerTest extends UnitTestCase {
public function setUp() {
parent::setUp();
$entity_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$entity_storage = $this->getMock(EntityStorageInterface::class);
$em = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$em = $this->getMock(EntityManagerInterface::class);
$em->expects($this->any())
->method('getStorage')
->with('date_format')
......@@ -48,11 +53,11 @@ class FacetsDateHandlerTest extends UnitTestCase {
$language = new Language(['id' => 'en']);
$lm = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$lm = $this->getMock(LanguageManagerInterface::class);
$lm->method('getCurrentLanguage')
->willReturn($language);
$st = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
$rs = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
$st = $this->getMock(TranslationInterface::class);
$rs = $this->getMock(RequestStack::class);
$cf = $this->getConfigFactoryStub();
$config_factory = $this->getConfigFactoryStub([
......
......@@ -93,7 +93,7 @@ class WidgetPluginManagerTest extends UnitTestCase {
public function testConstruct() {
$namespaces = new ArrayObject();
$sut = new WidgetPluginManager($namespaces, $this->cache, $this->moduleHandler, $this->translator);
$this->assertInstanceOf('\Drupal\facets\Widget\WidgetPluginManager', $sut);
$this->assertInstanceOf(WidgetPluginManager::class, $sut);
}
/**
......
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