class YamlDiscoveryTest in Zircon Profile 8
Same name in this branch
- 8 core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDiscoveryTest
- 8 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryTest
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDiscoveryTest
YamlDiscovery component unit tests.
@group Discovery
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Component\Discovery\YamlDiscoveryTest
Expanded class hierarchy of YamlDiscoveryTest
File
- core/
tests/ Drupal/ Tests/ Component/ Discovery/ YamlDiscoveryTest.php, line 21 - Contains \Drupal\Tests\Component\Discovery\YamlDiscoveryTest.
Namespace
Drupal\Tests\Component\DiscoveryView source
class YamlDiscoveryTest extends UnitTestCase {
/**
* Tests the YAML file discovery.
*/
public function testDiscovery() {
vfsStreamWrapper::register();
$root = new vfsStreamDirectory('modules');
vfsStreamWrapper::setRoot($root);
$url = vfsStream::url('modules');
mkdir($url . '/test_1');
file_put_contents($url . '/test_1/test_1.test.yml', 'name: test');
file_put_contents($url . '/test_1/test_2.test.yml', 'name: test');
mkdir($url . '/test_2');
file_put_contents($url . '/test_2/test_3.test.yml', 'name: test');
// Write an empty YAML file.
file_put_contents($url . '/test_2/test_4.test.yml', '');
// Set up the directories to search.
$directories = array(
'test_1' => $url . '/test_1',
'test_2' => $url . '/test_1',
'test_3' => $url . '/test_2',
'test_4' => $url . '/test_2',
);
$discovery = new YamlDiscovery('test', $directories);
$data = $discovery
->findAll();
$this
->assertEquals(count($data), count($directories));
$this
->assertArrayHasKey('test_1', $data);
$this
->assertArrayHasKey('test_2', $data);
$this
->assertArrayHasKey('test_3', $data);
$this
->assertArrayHasKey('test_4', $data);
foreach (array(
'test_1',
'test_2',
'test_3',
) as $key) {
$this
->assertArrayHasKey('name', $data[$key]);
$this
->assertEquals($data[$key]['name'], 'test');
}
$this
->assertSame(array(), $data['test_4']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. | |
UnitTestCase:: |
protected | function | 259 | |
YamlDiscoveryTest:: |
public | function | Tests the YAML file discovery. |