forked from drupal/drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2304461 by sun: Rebase KernelTestBase onto PHPUnit.
Includes various performance optimizations, since ContainerBuilder::compile() is very slow: A precompiled Container is shared across test methods. Each test boots new DrupalKernel that gets the precompiled Container injected. Each test registers itself as a Logger, so as to catch unexpected error log messages, in case functional code fails to use trigger_error(). Various utility methods of the former Simpletest TestBase + KernelTestBase are made available as traits (so as to keep the original code functional).
- Loading branch information
Showing
18 changed files
with
1,755 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
|
||
#before_script: | ||
# - composer self-update | ||
# # @todo Enable APC(u) extension. | ||
|
||
script: | ||
# @todo Re-enable. For now, we know that it works. | ||
#- phpunit -v -c core --testsuite Unit | ||
# Disable XDebug after running unit tests. | ||
- phpenv config-rm xdebug.ini | ||
- php --version | ||
# @todo Update to new stable once all fixes are in upstream. | ||
- ./core/vendor/phpunit/phpunit/phpunit -v -c core --testsuite Kernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Core\Queue\QueueMemoryFactory. | ||
*/ | ||
|
||
namespace Drupal\Core\Queue; | ||
|
||
/** | ||
* Defines the queue factory for the memory backend. | ||
*/ | ||
class QueueMemoryFactory { | ||
|
||
/** | ||
* Constructs a new queue object for a given name. | ||
* | ||
* @param string $name | ||
* The name of the collection holding key and value pairs. | ||
* | ||
* @return \Drupal\Core\Queue\Memory | ||
* A queue implementation for the given $collection. | ||
*/ | ||
public function get($name) { | ||
return new Memory($name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\simpletest\RandomGeneratorTrait. | ||
*/ | ||
|
||
namespace Drupal\simpletest; | ||
|
||
use Drupal\Component\Utility\Random; | ||
|
||
/** | ||
* Provides random generator utility methods. | ||
*/ | ||
trait RandomGeneratorTrait { | ||
|
||
/** | ||
* The random generator. | ||
* | ||
* @var \Drupal\Component\Utility\Random | ||
*/ | ||
protected $randomGenerator; | ||
|
||
/** | ||
* Generates a unique random string of ASCII characters of codes 32 to 126. | ||
* | ||
* Do not use this method when special characters are not possible (e.g., in | ||
* machine or file names that have already been validated); instead, use | ||
* randomName(). | ||
* | ||
* @param int $length | ||
* Length of random string to generate. | ||
* | ||
* @return string | ||
* Randomly generated unique string. | ||
* | ||
* @see \Drupal\Component\Utility\Random::string() | ||
*/ | ||
protected function randomString($length = 8) { | ||
return $this->getRandomGenerator()->string($length, TRUE, array($this, 'randomStringValidate')); | ||
} | ||
|
||
/** | ||
* Callback for random string validation. | ||
* | ||
* @see \Drupal\Component\Utility\Random::string() | ||
* | ||
* @param string $string | ||
* The random string to validate. | ||
* | ||
* @return bool | ||
* TRUE if the random string is valid, FALSE if not. | ||
*/ | ||
protected function randomStringValidate($string) { | ||
// Consecutive spaces causes issues for | ||
// Drupal\simpletest\WebTestBase::assertLink(). | ||
if (preg_match('/\s{2,}/', $string)) { | ||
return FALSE; | ||
} | ||
// Starting with a space means that length might not be what is expected. | ||
// Starting with an @ sign causes CURL to fail if used in conjunction with a | ||
// file upload, see https://drupal.org/node/2174997. | ||
if (preg_match('/^(\s|@)/', $string)) { | ||
return FALSE; | ||
} | ||
// Ending with a space means that length might not be what is expected. | ||
if (preg_match('/\s$/', $string)) { | ||
return FALSE; | ||
} | ||
return TRUE; | ||
} | ||
|
||
/** | ||
* Generates a unique random string containing letters and numbers. | ||
* | ||
* Do not use this method when testing unvalidated user input. Instead, use | ||
* \Drupal\simpletest\TestBase::randomString(). | ||
* | ||
* @param int $length | ||
* Length of random string to generate. | ||
* | ||
* @return string | ||
* Randomly generated unique string. | ||
* | ||
* @see \Drupal\Component\Utility\Random::name() | ||
*/ | ||
protected function randomName($length = 8) { | ||
return $this->getRandomGenerator()->name($length, TRUE); | ||
} | ||
|
||
/** | ||
* Generates a random PHP object. | ||
* | ||
* @param int $size | ||
* The number of random keys to add to the object. | ||
* | ||
* @return \stdClass | ||
* The generated object, with the specified number of random keys. Each key | ||
* has a random string value. | ||
* | ||
* @see \Drupal\Component\Utility\Random::object() | ||
*/ | ||
protected function randomObject($size = 4) { | ||
return $this->getRandomGenerator()->object($size); | ||
} | ||
|
||
/** | ||
* Gets the random generator for the utility methods. | ||
* | ||
* @return \Drupal\Component\Utility\Random | ||
* The random generator. | ||
*/ | ||
protected function getRandomGenerator() { | ||
if (!is_object($this->randomGenerator)) { | ||
$this->randomGenerator = new Random(); | ||
} | ||
return $this->randomGenerator; | ||
} | ||
|
||
} |
Oops, something went wrong.