class RoutingTransactionNameSubscriberTest in New Relic 8
Same name and namespace in other branches
- 2.x tests/src/Unit/EventListener/RoutingTransactionNameSubscriberTest.php \Drupal\Tests\new_relic_rpm\Unit\EventListener\RoutingTransactionNameSubscriberTest
- 2.0.x tests/src/Unit/EventListener/RoutingTransactionNameSubscriberTest.php \Drupal\Tests\new_relic_rpm\Unit\EventListener\RoutingTransactionNameSubscriberTest
@coversDefaultClass \Drupal\new_relic_rpm\EventSubscriber\RoutingTransactionNameSubscriber @group new_relic_rpm
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\new_relic_rpm\Unit\EventListener\RoutingTransactionNameSubscriberTest
Expanded class hierarchy of RoutingTransactionNameSubscriberTest
File
- tests/
src/ Unit/ EventListener/ RoutingTransactionNameSubscriberTest.php, line 18
Namespace
Drupal\Tests\new_relic_rpm\Unit\EventListenerView source
class RoutingTransactionNameSubscriberTest extends UnitTestCase {
/**
* @covers ::addTransactionNamesToRoutes
*/
public function testSetsTransactionNameForAllRoutes() {
$collection = new RouteCollection();
$collection
->add('foo', new Route('/foo'));
$event = new RouteBuildEvent($collection);
$subscriber = new RoutingTransactionNameSubscriber();
$subscriber
->addTransactionNamesToRoutes($event);
$actualName = $collection
->get('foo')
->getDefault('_transaction_name');
$this
->assertEquals('foo', $actualName);
}
/**
* @covers ::addTransactionNamesToRoutes
*/
public function testSetsTransactionCallbackOnDynamicRoutes() {
$collection = new RouteCollection();
$collection
->add('node.add', new Route('/node/add'));
$event = new RouteBuildEvent($collection);
$subscriber = new RoutingTransactionNameSubscriber();
$subscriber
->addTransactionNamesToRoutes($event);
$actualName = $collection
->get('node.add')
->getDefault('_transaction_name');
$actualCallback = $collection
->get('node.add')
->getDefault('_transaction_name_callback');
$this
->assertEquals('node.add', $actualName);
$this
->assertTrue(is_callable($actualCallback));
}
/**
* @covers ::entityBundleRouteTransactionName
*/
public function testEntityRouteTransactionName() {
$entity = $this
->prophesize(EntityInterface::class);
$entity
->bundle()
->willReturn('bar');
$attributes = [
'_transaction_name' => 'entity.foo.canonical',
'foo' => $entity
->reveal(),
];
$request = new Request([], [], $attributes);
$actualName = RoutingTransactionNameSubscriber::entityBundleRouteTransactionName($request);
$this
->assertEquals('entity.foo.canonical:bar', $actualName);
}
/**
* @covers ::nodeAddTransactionName
*/
public function testNodeAddRouteTransactionName() {
$node_type = $this
->prophesize(NodeTypeInterface::class);
$node_type
->id()
->willReturn('bar');
$attributes = [
'_transaction_name' => 'node.add',
'node_type' => $node_type
->reveal(),
];
$request = new Request([], [], $attributes);
$actualName = RoutingTransactionNameSubscriber::nodeAddTransactionName($request);
$this
->assertEquals('node.add:bar', $actualName);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
RoutingTransactionNameSubscriberTest:: |
public | function | @covers ::entityBundleRouteTransactionName | |
RoutingTransactionNameSubscriberTest:: |
public | function | @covers ::nodeAddTransactionName | |
RoutingTransactionNameSubscriberTest:: |
public | function | @covers ::addTransactionNamesToRoutes | |
RoutingTransactionNameSubscriberTest:: |
public | function | @covers ::addTransactionNamesToRoutes | |
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. | |
UnitTestCase:: |
protected | function | 340 |