You are here

class FileTest in YAML Content 8

Same name in this branch
  1. 8 tests/src/Functional/Plugin/yaml_content/process/FileTest.php \Drupal\Tests\yaml_content\Functional\Plugin\yaml_content\process\FileTest
  2. 8 tests/src/Unit/Plugin/yaml_content/process/FileTest.php \Drupal\Tests\yaml_content\Unit\Plugin\yaml_content\process\FileTest

Test file processing.

Note: This only tests failures because to test passes would require writing to the file system.

@group yaml_content

@coversDefaultClass \Drupal\yaml_content\Plugin\yaml_content\process\File

Hierarchy

Expanded class hierarchy of FileTest

File

tests/src/Unit/Plugin/yaml_content/process/FileTest.php, line 22

Namespace

Drupal\Tests\yaml_content\Unit\Plugin\yaml_content\process
View source
class FileTest extends UnitTestCase {
  use LoadFixturesTrait;

  /**
   * The file process plugin being tested.
   *
   * @var \Drupal\yaml_content\Plugin\yaml_content\process\File
   */
  protected $filePlugin;

  /**
   * Setup the file process plugin for all tests.
   */
  public function setUp() {
    parent::setUp();
    $args = [
      'my_entity',
      [
        'filename' => 'test_file.txt',
      ],
    ];
    $this->filePlugin = new File($args, '', []);
  }

  /**
   * @covers ::process
   */
  public function testProcessMissingLoader() {
    $context = new ProcessingContext();
    $data = [];
    $this
      ->expectException(\Exception::class);
    $this
      ->expectExceptionMessage('Missing content loader context.');
    $this->filePlugin
      ->process($context, $data);
  }

  /**
   * @covers ::process
   */
  public function testProcessMissingField() {
    $context = new ProcessingContext();
    $context
      ->setContentLoader(new ContentLoader($this
      ->prophesize(ContainerInterface::class)
      ->reveal()));
    $context
      ->getContentLoader()
      ->setContentPath(realpath($this
      ->getFixturePath() . '/../../'));
    $data = [];
    $this
      ->expectException(\Exception::class);
    $this
      ->expectExceptionMessage('Missing field context.');
    $this->filePlugin
      ->process($context, $data);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileTest::$filePlugin protected property The file process plugin being tested.
FileTest::setUp public function Setup the file process plugin for all tests. Overrides UnitTestCase::setUp
FileTest::testProcessMissingField public function @covers ::process
FileTest::testProcessMissingLoader public function @covers ::process
LoadFixturesTrait::getFixturePath protected function Get the base path for fixture content.
LoadFixturesTrait::loadFixtureContent protected function Load content from a fixture file.
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.