Unverified Commit 13e93c04 authored by larowlan's avatar larowlan
Browse files

Issue #2866894 by maxocub: Component tests should not use...

Issue #2866894 by maxocub: Component tests should not use Drupal\Tests\UnitTestCase but PHPUnit\Framework\TestCase
parent 2d691d50
......@@ -49,6 +49,8 @@
</listener>
<listener class="\Drupal\Tests\Listeners\DrupalStandardsListener">
</listener>
<listener class="\Drupal\Tests\Listeners\DrupalComponentTestListener">
</listener>
</listeners>
<!-- Filter for coverage reports. -->
<filter>
......
......@@ -6,13 +6,13 @@
use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator;
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
* @group Plugin
*/
class AnnotationBridgeDecoratorTest extends UnitTestCase {
class AnnotationBridgeDecoratorTest extends TestCase {
/**
* @covers ::getDefinitions
......
......@@ -3,14 +3,14 @@
namespace Drupal\Tests\Component\Bridge;
use Drupal\Component\Bridge\ZfExtensionManagerSfContainer;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @coversDefaultClass \Drupal\Component\Bridge\ZfExtensionManagerSfContainer
* @group Bridge
*/
class ZfExtensionManagerSfContainerTest extends UnitTestCase {
class ZfExtensionManagerSfContainerTest extends TestCase {
/**
* @covers ::setContainer
......
......@@ -4,13 +4,13 @@
use Composer\Autoload\ClassLoader;
use Drupal\Component\ClassFinder\ClassFinder;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder
* @group ClassFinder
*/
class ClassFinderTest extends UnitTestCase {
class ClassFinderTest extends TestCase {
/**
* @covers ::findFile
......@@ -20,7 +20,7 @@ public function testFindFile() {
// The full path is returned therefore only tests with
// assertStringEndsWith() so the test is portable.
$this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
$this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
$class = 'Not\\A\\Class';
$this->assertNull($finder->findFile($class));
......@@ -30,7 +30,7 @@ public function testFindFile() {
$loader->register();
$this->assertEquals(__FILE__, $finder->findFile($class));
// This shouldn't prevent us from finding the original file.
$this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
$this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
// Clean up the additional autoloader after the test.
$loader->unregister();
......
......@@ -2,14 +2,14 @@
namespace Drupal\Tests\Component\Datetime;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Datetime\DateTimePlus;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Datetime\DateTimePlus
* @group Datetime
*/
class DateTimePlusTest extends UnitTestCase {
class DateTimePlusTest extends TestCase {
/**
* Test creating dates from string and array input.
......
......@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Datetime;
use Drupal\Component\Datetime\Time;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -15,7 +15,7 @@
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class TimeTest extends UnitTestCase {
class TimeTest extends TestCase {
/**
* The mocked request stack.
......
......@@ -4,8 +4,9 @@
use Drupal\Component\Discovery\DiscoveryException;
use Drupal\Component\Discovery\YamlDirectoryDiscovery;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\FileCache\FileCacheFactory;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* YamlDirectoryDiscoveryTest component unit tests.
......@@ -14,7 +15,15 @@
*
* @group Discovery
*/
class YamlDirectoryDiscoveryTest extends UnitTestCase {
class YamlDirectoryDiscoveryTest extends TestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
// Ensure that FileCacheFactory has a prefix.
FileCacheFactory::setPrefix('prefix');
}
/**
* Tests YAML directory discovery.
......
......@@ -2,18 +2,27 @@
namespace Drupal\Tests\Component\Discovery;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Discovery\YamlDiscovery;
use Drupal\Component\FileCache\FileCacheFactory;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamWrapper;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;
/**
* YamlDiscovery component unit tests.
*
* @group Discovery
*/
class YamlDiscoveryTest extends UnitTestCase {
class YamlDiscoveryTest extends TestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
// Ensure that FileCacheFactory has a prefix.
FileCacheFactory::setPrefix('prefix');
}
/**
* Tests the YAML file discovery.
......
......@@ -2,15 +2,15 @@
namespace Drupal\Tests\Component;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* General tests for \Drupal\Component that can't go anywhere else.
*
* @group Component
*/
class DrupalComponentTest extends UnitTestCase {
class DrupalComponentTest extends TestCase {
/**
* Tests that classes in Component do not use any Core class.
......
......@@ -5,13 +5,14 @@
use Drupal\Component\FileCache\FileCache;
use Drupal\Component\FileCache\NullFileCache;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Random;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\FileCache\FileCacheFactory
* @group FileCache
*/
class FileCacheFactoryTest extends UnitTestCase {
class FileCacheFactoryTest extends TestCase {
/**
* {@inheritdoc}
......@@ -170,7 +171,10 @@ public function testGetSetConfiguration() {
* @covers ::setPrefix
*/
public function testGetSetPrefix() {
$prefix = $this->randomMachineName();
// Random generator.
$random = new Random();
$prefix = $random->name(8, TRUE);
FileCacheFactory::setPrefix($prefix);
$this->assertEquals($prefix, FileCacheFactory::getPrefix());
}
......
......@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\FileCache;
use Drupal\Component\FileCache\FileCache;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\FileCache\FileCache
* @group FileCache
*/
class FileCacheTest extends UnitTestCase {
class FileCacheTest extends TestCase {
/**
* FileCache object used for the tests.
......
......@@ -3,14 +3,14 @@
namespace Drupal\Tests\Component\FileSystem;
use Drupal\Component\FileSystem\RegexDirectoryIterator;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\FileSystem\RegexDirectoryIterator
* @group FileSystem
*/
class RegexDirectoryIteratorTest extends UnitTestCase {
class RegexDirectoryIteratorTest extends TestCase {
/**
* @covers ::accept
......
......@@ -3,7 +3,7 @@
namespace Drupal\Tests\Component\Gettext;
use Drupal\Component\Gettext\PoHeader;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for the Gettext PO file header handling features.
......@@ -12,7 +12,7 @@
*
* @group Gettext
*/
class PoHeaderTest extends UnitTestCase {
class PoHeaderTest extends TestCase {
/**
* Tests that plural expressions are evaluated correctly.
......
......@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Graph;
use Drupal\Component\Graph\Graph;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Graph\Graph
* @group Graph
*/
class GraphTest extends UnitTestCase {
class GraphTest extends TestCase {
/**
* Test depth-first-search features.
......
......@@ -8,7 +8,7 @@
namespace Drupal\Tests\Component\HttpFoundation;
use Drupal\Component\HttpFoundation\SecuredRedirectResponse;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\RedirectResponse;
......@@ -18,7 +18,7 @@
* @group Routing
* @coversDefaultClass \Drupal\Component\HttpFoundation\SecuredRedirectResponse
*/
class SecuredRedirectResponseTest extends UnitTestCase {
class SecuredRedirectResponseTest extends TestCase {
/**
* Test copying of redirect response.
......
......@@ -4,6 +4,7 @@
use Drupal\Component\PhpStorage\FileStorage;
use Drupal\Component\PhpStorage\FileReadOnlyStorage;
use Drupal\Component\Utility\Random;
/**
* @coversDefaultClass \Drupal\Component\PhpStorage\FileReadOnlyStorage
......@@ -48,8 +49,11 @@ protected function setUp() {
* Tests writing with one class and reading with another.
*/
public function testReadOnly() {
// Random generator.
$random = new Random();
$php = new FileStorage($this->standardSettings);
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
$name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
......@@ -85,8 +89,11 @@ public function testWriteable() {
* @covers ::deleteAll
*/
public function testDeleteAll() {
// Random generator.
$random = new Random();
$php = new FileStorage($this->standardSettings);
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
$name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\FileStorage;
use Drupal\Component\Utility\Random;
/**
* @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage
......@@ -55,11 +56,13 @@ public function testWriteable() {
* @covers ::deleteAll
*/
public function testDeleteAll() {
// Random generator.
$random_generator = new Random();
// Write out some files.
$php = new FileStorage($this->standardSettings);
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
$name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Random;
/**
* Base test class for MTime protected storage.
......@@ -36,7 +37,10 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
protected function setUp() {
parent::setUp();
$this->secret = $this->randomMachineName();
// Random generator.
$random = new Random();
$this->secret = $random->name(8, TRUE);
$this->settings = [
'directory' => $this->directory,
......
......@@ -3,13 +3,14 @@
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\PhpStorageInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Random;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
/**
* Base test for PHP storages.
*/
abstract class PhpStorageTestBase extends UnitTestCase {
abstract class PhpStorageTestBase extends TestCase {
/**
* A unique per test class directory path to test php storage.
......@@ -31,7 +32,10 @@ protected function setUp() {
* Assert that a PHP storage's load/save/delete operations work.
*/
public function assertCRUD($php) {
$name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
// Random generator.
$random_generator = new Random();
$name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
// Find a global that doesn't exist.
do {
......
......@@ -3,13 +3,13 @@
namespace Drupal\Tests\Component\Plugin\Context;
use Drupal\Component\Plugin\Context\Context;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Drupal\Component\Plugin\Context\Context
* @group Plugin
*/
class ContextTest extends UnitTestCase {
class ContextTest extends TestCase {
/**
* Data provider for testGetContextValue.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment