class JsonBlueprintDenormalizerTest in Subrequests 8.2
Same name and namespace in other branches
- 3.x tests/src/Unit/Normalizer/JsonBlueprintDenormalizerTest.php \Drupal\Tests\subrequests\Normalizer\JsonBlueprintDenormalizerTest
@coversDefaultClass \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer @group subrequests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait- class \Drupal\Tests\subrequests\Normalizer\JsonBlueprintDenormalizerTest
 
Expanded class hierarchy of JsonBlueprintDenormalizerTest
File
- tests/src/ Unit/ Normalizer/ JsonBlueprintDenormalizerTest.php, line 15 
Namespace
Drupal\Tests\subrequests\NormalizerView 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
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| JsonBlueprintDenormalizerTest:: | protected | property | ||
| JsonBlueprintDenormalizerTest:: | public | function | ||
| JsonBlueprintDenormalizerTest:: | protected | function | Overrides UnitTestCase:: | |
| JsonBlueprintDenormalizerTest:: | public | function | ||
| JsonBlueprintDenormalizerTest:: | public | function | @dataProvider dataProviderSupportsNormalization @covers ::supportsDenormalization | |
| 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. | 
