You are here

public function ContentLoaderTest::testEmptyContentFile in YAML Content 8

Tests the correct return value when parsing an empty file.

When parsing an empty file an empty array should be returned.

File

tests/src/Unit/ContentLoader/ContentLoaderTest.php, line 66

Class

ContentLoaderTest
Test generic functionality of the ContentLoader class.

Namespace

Drupal\Tests\yaml_content\Unit\ContentLoader

Code

public function testEmptyContentFile() {

  // Prepare an empty content file for parsing.
  $test_file = 'emptyFile.content.yml';
  $this
    ->createContentTestFile($test_file, '');

  // Get the mock content loader.
  $this->contentLoader = $this
    ->getContentLoaderMock([
    'getEventDispatcher',
  ]);

  // Stub event dispatching.
  $event_dispatcher_mock = $this
    ->createMock(ContainerAwareEventDispatcher::class);
  $this->contentLoader
    ->method('getEventDispatcher')
    ->willReturn($event_dispatcher_mock);

  // Prepare and parse the empty content file.
  $this->contentLoader
    ->setContentPath($this->root
    ->url());
  $parsed_content = $this->contentLoader
    ->parseContent($test_file);

  // Confirm an empty array was returned.
  $this
    ->assertArrayEquals([], $parsed_content, 'Empty content files return an empty array.');
}