You are here

class BlueprintManagerTest in Subrequests 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Unit/Blueprint/BlueprintManagerTest.php \Drupal\Tests\subrequests\Unit\Blueprint\BlueprintManagerTest

@coversDefaultClass \Drupal\subrequests\Blueprint\BlueprintManager @group subrequests

Hierarchy

Expanded class hierarchy of BlueprintManagerTest

File

tests/src/Unit/Blueprint/BlueprintManagerTest.php, line 21

Namespace

Drupal\Tests\subrequests\Unit\Blueprint
View source
class BlueprintManagerTest extends UnitTestCase {

  /**
   * @var \Drupal\subrequests\Blueprint\BlueprintManager
   */
  protected $sut;
  protected function setUp() {
    parent::setUp();
    $denormalizer = $this
      ->prophesize(JsonBlueprintDenormalizer::class);
    $denormalizer
      ->denormalize(Argument::type('array'), SubrequestsTree::class, 'json', [])
      ->willReturn(new SubrequestsTree());
    $denormalizer
      ->supportsDenormalization(Argument::type('array'), SubrequestsTree::class, 'json')
      ->willReturn([])
      ->willReturn(TRUE);

    // Modern versions of Symfony added an extra parameter.
    $denormalizer
      ->supportsDenormalization(Argument::type('array'), SubrequestsTree::class, 'json', Argument::type('array'))
      ->willReturn([])
      ->willReturn(TRUE);
    $denormalizer
      ->setSerializer(Argument::any())
      ->willReturn(NULL);
    $normalizer = $this
      ->prophesize(MultiresponseNormalizer::class);
    $normalizer
      ->normalize(Argument::type('array'), 'multipart-related', Argument::type('array'))
      ->willReturn([
      'content' => 'Booh!',
      'headers' => [
        'head' => 'Ha!',
      ],
    ]);
    $normalizer
      ->supportsNormalization(Argument::type('array'), 'multipart-related')
      ->willReturn([])
      ->willReturn(TRUE);
    $normalizer
      ->supportsNormalization(Argument::type('array'), 'multipart-related', Argument::type('array'))
      ->willReturn([])
      ->willReturn(TRUE);
    $serializer = new Serializer([
      $denormalizer
        ->reveal(),
      $normalizer
        ->reveal(),
    ], [
      new JsonDecode(),
    ]);
    $this->sut = new BlueprintManager($serializer);
  }

  /**
   * @covers ::parse
   */
  public function testParse() {
    $parsed = $this->sut
      ->parse('[]', Request::create('foo'));
    $this
      ->assertInstanceOf(SubrequestsTree::class, $parsed);
    $this
      ->assertSame('/foo', $parsed
      ->getMasterRequest()
      ->getPathInfo());
  }

  /**
   * @covers ::combineResponses
   */
  public function testCombineResponses() {
    $responses = [
      Response::create('foo', 200, [
        'lorem' => 'ipsum',
        'Content-Type' => 'sparrow',
      ]),
      Response::create('bar', 201, [
        'dolor' => 'sid',
        'Content-Type' => 'sparrow',
      ]),
    ];
    $combined = $this->sut
      ->combineResponses($responses, 'multipart-related');
    $this
      ->assertInstanceOf(CacheableResponse::class, $combined);
    $this
      ->assertSame('Ha!', $combined->headers
      ->get('head'));
    $this
      ->assertSame('Booh!', $combined
      ->getContent());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlueprintManagerTest::$sut protected property
BlueprintManagerTest::setUp protected function Overrides UnitTestCase::setUp
BlueprintManagerTest::testCombineResponses public function @covers ::combineResponses
BlueprintManagerTest::testParse public function @covers ::parse
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.
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.