YamlDiscoveryTest.php

Same filename in this branch
  1. 11.x core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php
  2. 11.x core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php
Same filename in other branches
  1. 9 core/tests/Drupal/Tests/Core/Discovery/YamlDiscoveryTest.php
  2. 9 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php
  3. 9 core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php
  4. 8.9.x core/tests/Drupal/Tests/Core/Discovery/YamlDiscoveryTest.php
  5. 8.9.x core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php
  6. 8.9.x core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php
  7. 10 core/tests/Drupal/Tests/Core/Discovery/YamlDiscoveryTest.php
  8. 10 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php
  9. 10 core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php

Namespace

Drupal\Tests\Core\Discovery

File

core/tests/Drupal/Tests/Core/Discovery/YamlDiscoveryTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\Core\Discovery;

use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Core\Discovery\YamlDiscovery;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use org\bovigo\vfs\vfsStreamWrapper;
use PHPUnit\Framework\TestCase;

/**
 * YamlDiscovery component unit tests.
 *
 * @group Discovery
 */
class YamlDiscoveryTest extends TestCase {
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        // Ensure that FileCacheFactory has a prefix.
        FileCacheFactory::setPrefix('prefix');
    }
    
    /**
     * Tests if filename is output for a broken YAML file.
     */
    public function testFilenameForBrokenYml() : void {
        vfsStreamWrapper::register();
        $root = new vfsStreamDirectory('modules');
        vfsStreamWrapper::setRoot($root);
        $url = vfsStream::url('modules');
        mkdir($url . '/test_broken');
        file_put_contents($url . '/test_broken/test_broken.test.yml', "broken:\n:");
        $this->expectException(InvalidDataTypeException::class);
        $this->expectExceptionMessage('vfs://modules/test_broken/test_broken.test.yml');
        $directories = [
            'test_broken' => $url . '/test_broken',
        ];
        $discovery = new YamlDiscovery('test', $directories);
        $discovery->findAll();
    }

}

Classes

Title Deprecated Summary
YamlDiscoveryTest YamlDiscovery component unit tests.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.