You are here

class JsonBlueprintDenormalizerTest in Subrequests 8.2

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

@coversDefaultClass \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer @group subrequests

Hierarchy

Expanded class hierarchy of JsonBlueprintDenormalizerTest

File

tests/src/Unit/Normalizer/JsonBlueprintDenormalizerTest.php, line 15

Namespace

Drupal\Tests\subrequests\Normalizer
View source
class JsonBlueprintDenormalizerTest extends UnitTestCase {

  /**
   * @var \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer
   */
  protected $sut;
  protected function setUp() {
    parent::setUp();
    $logger = $this
      ->prophesize(LoggerInterface::class);
    $this->sut = new JsonBlueprintDenormalizer($logger
      ->reveal());
  }

  /**
   * @dataProvider dataProviderSupportsNormalization
   * @covers ::supportsDenormalization
   */
  public function testSupportsDenormalization($data, $type, $format, $is_supported) {
    $actual = $this->sut
      ->supportsDenormalization($data, $type, $format);
    $this
      ->assertSame($is_supported, $actual);
  }
  public function dataProviderSupportsNormalization() {
    return [
      [
        [
          'a',
          'b',
        ],
        SubrequestsTree::class,
        'json',
        TRUE,
      ],
      [
        'fail',
        SubrequestsTree::class,
        'json',
        FALSE,
      ],
      [
        [
          'a',
          'b',
        ],
        SubrequestsTree::class,
        'fail',
        FALSE,
      ],
      [
        [
          'fail' => 'a',
          'b',
        ],
        SubrequestsTree::class,
        'json',
        FALSE,
      ],
    ];
  }
  public function testDenormalize() {
    $subrequests[] = [
      'uri' => 'lorem',
      'action' => 'view',
      'requestId' => 'foo',
      'body' => '"bar"',
      'headers' => [],
    ];
    $subrequests[] = [
      'uri' => 'ipsum',
      'action' => 'sing',
      'requestId' => 'oop',
      'body' => '[]',
      'waitFor' => [
        'foo',
      ],
    ];
    $subrequests[] = [
      'uri' => 'lorem%3F%7B%7Bipsum%7D%7D',
      // lorem?{{ipsum}}
      'action' => 'create',
      'requestId' => 'oof',
      'body' => '"bar"',
      'waitFor' => [
        'foo',
      ],
    ];
    $actual = $this->sut
      ->denormalize($subrequests, SubrequestsTree::class, 'json', []);
    $tree = new SubrequestsTree();
    $tree
      ->stack([
      new Subrequest([
        'waitFor' => [
          '<ROOT>',
        ],
        '_resolved' => FALSE,
        'body' => 'bar',
      ] + $subrequests[0]),
    ]);
    $tree
      ->stack([
      new Subrequest([
        'headers' => [],
        '_resolved' => FALSE,
        'body' => [],
      ] + $subrequests[1]),
      // Make sure the URL is decoded so we can perform apply regular
      // expressions to it.
      new Subrequest([
        'headers' => [],
        '_resolved' => FALSE,
        'body' => 'bar',
        'uri' => 'lorem?{{ipsum}}',
      ] + $subrequests[2]),
    ]);
    $this
      ->assertEquals($tree, $actual);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsonBlueprintDenormalizerTest::$sut protected property
JsonBlueprintDenormalizerTest::dataProviderSupportsNormalization public function
JsonBlueprintDenormalizerTest::setUp protected function Overrides UnitTestCase::setUp
JsonBlueprintDenormalizerTest::testDenormalize public function
JsonBlueprintDenormalizerTest::testSupportsDenormalization public function @dataProvider dataProviderSupportsNormalization @covers ::supportsDenormalization
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.