class MatcherTest in CRM Core 8.2
Tests the matcher service.
@covers \Drupal\crm_core_match\Matcher
@group crm_core
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\crm_core_match\Unit\MatcherTest
Expanded class hierarchy of MatcherTest
File
- modules/
crm_core_match/ tests/ src/ Unit/ MatcherTest.php, line 20 - Contains \Drupal\Tests\crm_core_match\Unit\MatcherTest.
Namespace
Drupal\Tests\crm_core_match\UnitView source
class MatcherTest extends UnitTestCase {
/**
* The tested matcher.
*
* @var \Drupal\crm_core_match\Entity\Matcher
*/
protected $matcher;
/**
* A set mocked match engines keyed by id.
*
* @var \Drupal\crm_core_match\Matcher\MatcherConfigInterface|\PHPUnit_Framework_MockObject_MockObject[]
*/
protected $engine = array();
/**
* An individual entity used to get matches.
*
* @var \Drupal\crm_core_contact\Entity\Individual
*/
protected $individual;
/**
* A mocked instance of the engine plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pluginManager;
/**
* A mocked instance of the config.
*
* @var \Drupal\Core\Config\Config|\PHPUnit_Framework_MockObject_MockObject
*/
protected $config;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Matcher',
'description' => 'Tests the matcher.',
'group' => 'CRM Core',
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->engine['a'] = $this
->getMock('Drupal\\crm_core_match\\Plugin\\crm_core_match\\engine\\MatchEngineInterface');
$this->engine['b'] = $this
->getMock('Drupal\\crm_core_match\\Plugin\\crm_core_match\\engine\\MatchEngineInterface');
$this->engine['c'] = $this
->getMock('Drupal\\crm_core_match\\Plugin\\crm_core_match\\engine\\MatchEngineInterface');
$this->pluginManager = $this
->getMock('Drupal\\Component\\Plugin\\PluginManagerInterface');
// $this->config = $this->getMockBuilder('\Drupal\Core\Config\Config')
// ->disableOriginalConstructor()
// ->getMock();
// $this->matcher = $this->getMock('Drupal\crm_core_match\Matcher');
$this->individual = $this
->getMockBuilder('Drupal\\crm_core_contact\\Entity\\Individual')
->disableOriginalConstructor()
->getMock();
}
/**
* Tests the sorting of engines.
*/
public function testEngineSort() {
// $engine_config = $this->getMockBuilder('\Drupal\Core\Config\Config')
// ->disableOriginalConstructor()
// ->getMock();
//
// $this->config->expects($this->once())
// ->method('get')
// ->with('engines')
// ->will($this->returnValue($engine_config));
//
// $engine_config->expects($this->exactly(3))
// ->method('get')
// ->will($this->returnValue(TRUE));
//
// $definitions = array(
// 'a' => array('priority' => 5),
// 'b' => array('priority' => 11),
// 'c' => array('priority' => -1),
// );
// $this->pluginManager->expects($this->once())
// ->method('getDefinitions')
// ->will($this->returnValue($definitions));
//
// $this->pluginManager->expects($this->at(1))
// ->method('createInstance')
// ->with('a', $definitions['a'])
// ->will($this->returnValue($this->engine['a']));
//
// $this->pluginManager->expects($this->at(2))
// ->method('createInstance')
// ->with('b', $definitions['b'])
// ->will($this->returnValue($this->engine['b']));
//
// $this->pluginManager->expects($this->at(3))
// ->method('createInstance')
// ->with('c', $definitions['c'])
// ->will($this->returnValue($this->engine['c']));
//
// $engines = $this->matcher->getEngines();
//
// $this->assertTrue(is_array($engines));
// $this->assertTrue(count($engines) == 3);
// $this->assertEquals($this->engine['b'], array_shift($engines));
// $this->assertEquals($this->engine['a'], array_shift($engines));
// $this->assertEquals($this->engine['c'], array_shift($engines));
}
/**
* Tests the execution of match engines.
*/
public function testEngineExecution() {
// $engine_config = $this->getMockBuilder('\Drupal\Core\Config\Config')
// ->disableOriginalConstructor()
// ->getMock();
//
// $this->config->expects($this->once())
// ->method('get')
// ->with('engines')
// ->will($this->returnValue($engine_config));
//
// $engine_config->expects($this->exactly(2))
// ->method('get')
// ->will($this->returnValue(TRUE));
// $definitions = array(
// 'a' => array('priority' => 5),
// 'b' => array('priority' => 11),
// );
// $this->pluginManager->expects($this->once())
// ->method('getDefinitions')
// ->will($this->returnValue($definitions));
//
// $this->pluginManager->expects($this->at(1))
// ->method('createInstance')
// ->with('a', $definitions['a'])
// ->will($this->returnValue($this->engine['a']));
//
// $this->pluginManager->expects($this->at(2))
// ->method('createInstance')
// ->with('b', $definitions['b'])
// ->will($this->returnValue($this->engine['b']));
// $this->engine['a']->expects($this->once())
// ->method('match')
// ->with($this->contact)
// ->will($this->returnValue(array(1, 2, 3, 5, 8, 13)));
//
// $this->engine['b']->expects($this->once())
// ->method('match')
// ->with($this->contact)
// ->will($this->returnValue(array(3, 8, 21, 34)));
// $this->matcher->expects($this->once())
// ->method('match')
// ->with($this->contact)
// ->will($this->)
//
// $ids = $this->matcher->match($this->contact);
// $ids = array_values($ids);
// sort($ids);
// $this->assertEquals(array(1, 2, 3, 5, 8, 13, 21, 34), $ids);
}
/**
* Tests disabled engines are not executed.
*/
public function testDisabledEngines() {
// $engine_config = $this->getMockBuilder('\Drupal\Core\Config\Config')
// ->disableOriginalConstructor()
// ->getMock();
//
// $this->config->expects($this->once())
// ->method('get')
// ->with('engines')
// ->will($this->returnValue($engine_config));
//
// $engine_config->expects($this->exactly(2))
// ->method('get')
// ->will($this->returnValueMap(array(
// array('a.status', TRUE),
// array('b.status', FALSE),
// )));
//
// $definitions = array(
// 'a' => array('priority' => 5),
// 'b' => array('priority' => 11),
// );
// $this->pluginManager->expects($this->once())
// ->method('getDefinitions')
// ->will($this->returnValue($definitions));
//
// $this->pluginManager->expects($this->once())
// ->method('createInstance')
// ->with('a', $definitions['a'])
// ->will($this->returnValue($this->engine['a']));
//
// $this->engine['a']->expects($this->once())
// ->method('match')
// ->with($this->contact)
// ->will($this->returnValue(array()));
//
// $this->engine['b']->expects($this->never())
// ->method('match');
//
// $this->assertEquals(1, count($this->matcher->getEngines()));
//
// $this->matcher->match($this->contact);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MatcherTest:: |
protected | property | A mocked instance of the config. | |
MatcherTest:: |
protected | property | A set mocked match engines keyed by id. | |
MatcherTest:: |
protected | property | An individual entity used to get matches. | |
MatcherTest:: |
protected | property | The tested matcher. | |
MatcherTest:: |
protected | property | A mocked instance of the engine plugin manager. | |
MatcherTest:: |
public static | function | ||
MatcherTest:: |
protected | function |
Overrides UnitTestCase:: |
|
MatcherTest:: |
public | function | Tests disabled engines are not executed. | |
MatcherTest:: |
public | function | Tests the execution of match engines. | |
MatcherTest:: |
public | function | Tests the sorting of engines. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |