You are here

class RoutingTransactionNameSubscriberTest in New Relic 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/EventListener/RoutingTransactionNameSubscriberTest.php \Drupal\Tests\new_relic_rpm\Unit\EventListener\RoutingTransactionNameSubscriberTest
  2. 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

Expanded class hierarchy of RoutingTransactionNameSubscriberTest

File

tests/src/Unit/EventListener/RoutingTransactionNameSubscriberTest.php, line 18

Namespace

Drupal\Tests\new_relic_rpm\Unit\EventListener
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RoutingTransactionNameSubscriberTest::testEntityRouteTransactionName public function @covers ::entityBundleRouteTransactionName
RoutingTransactionNameSubscriberTest::testNodeAddRouteTransactionName public function @covers ::nodeAddTransactionName
RoutingTransactionNameSubscriberTest::testSetsTransactionCallbackOnDynamicRoutes public function @covers ::addTransactionNamesToRoutes
RoutingTransactionNameSubscriberTest::testSetsTransactionNameForAllRoutes public function @covers ::addTransactionNamesToRoutes
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340