class PathMatcherTest in Acquia Lift Connector 8
PathMatcher Test.
@coversDefaultClass Drupal\acquia_lift\Service\Helper\PathMatcher @group acquia_lift
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\acquia_lift\Service\Helper\PathMatcherTest
Expanded class hierarchy of PathMatcherTest
File
- tests/
src/ Unit/ Service/ Helper/ PathMatcherTest.php, line 19 - Contains \Drupal\Tests\acquia_lift\Service\Helper\PathMatcherTest.
Namespace
Drupal\Tests\acquia_lift\Service\HelperView source
class PathMatcherTest extends UnitTestCase {
/**
* Alias manager.
*
* @var \Drupal\Core\Path\AliasManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $aliasManager;
/**
* Path matcher.
*
* @var \Drupal\Core\Path\PathMatcherInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $basePathMatcher;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->aliasManager = $this
->getMock('Drupal\\Core\\Path\\AliasManagerInterface');
$this->basePathMatcher = $this
->getMock('Drupal\\Core\\Path\\PathMatcherInterface');
}
/**
* Tests the match() method - no match.
*
* @covers ::match
*/
public function testMatchNoMatch() {
$this->basePathMatcher
->expects($this
->exactly(2))
->method('matchPath')
->willReturn(FALSE);
$pathMatcher = new PathMatcher($this->aliasManager, $this->basePathMatcher);
$is_matched = $pathMatcher
->match('A_PATH', 'A_PATTERN');
$this
->assertFalse($is_matched);
}
/**
* Tests the match() method - path is matched.
*
* @covers ::match
*/
public function testMatchPathMatched() {
$this->basePathMatcher
->expects($this
->once())
->method('matchPath')
->with('a_path', 'a_pattern')
->willReturn(TRUE);
$this->aliasManager
->expects($this
->never())
->method('getAliasByPath');
$pathMatcher = new PathMatcher($this->aliasManager, $this->basePathMatcher);
$is_matched = $pathMatcher
->match('A_PATH', 'A_PATTERN');
$this
->assertTrue($is_matched);
}
/**
* Tests the match() method - path's alias is matched.
*
* @covers ::match
*/
public function testMatchAliasMatched() {
$this->basePathMatcher
->expects($this
->at(0))
->method('matchPath')
->with('a_path', 'a_pattern')
->willReturn(FALSE);
$this->aliasManager
->expects($this
->once())
->method('getAliasByPath')
->with('a_path')
->willReturn('AN_ALIAS');
$this->basePathMatcher
->expects($this
->at(1))
->method('matchPath')
->with('an_alias', 'a_pattern')
->willReturn(TRUE);
$pathMatcher = new PathMatcher($this->aliasManager, $this->basePathMatcher);
$is_matched = $pathMatcher
->match('A_PATH', 'A_PATTERN');
$this
->assertTrue($is_matched);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathMatcherTest:: |
private | property | Alias manager. | |
PathMatcherTest:: |
private | property | Path matcher. | |
PathMatcherTest:: |
public | function |
Overrides UnitTestCase:: |
|
PathMatcherTest:: |
public | function | Tests the match() method - path's alias is matched. | |
PathMatcherTest:: |
public | function | Tests the match() method - no match. | |
PathMatcherTest:: |
public | function | Tests the match() method - path is matched. | |
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. |