为什么这个方法在这个特性中可用?
Why is this method available in this trait?
我希望通过在另一个特征中使用它来扩展特征。但是,该特征正在使用一种看起来没有扩展的方法。这个特性有效,所以我想知道如何。
为什么这个 trait 可以访问 markEntityForCleanup
方法?
代码在这个repo for Drupal Test Traits
<?php
namespace weitzman\DrupalTestTraits\Entity;
use Drupal\Tests\node\Traits\NodeCreationTrait as CoreNodeCreationTrait;
/**
* Wraps the node creation trait to track entities for deletion.
*/
trait NodeCreationTrait
{
use CoreNodeCreationTrait {
createNode as coreCreateNode;
}
/**
* Creates a node and marks it for automatic cleanup.
*
* @param array $settings
* @return \Drupal\node\NodeInterface
*/
protected function createNode(array $settings = [])
{
$entity = $this->coreCreateNode($settings);
$this->markEntityForCleanup($entity);
return $entity;
}
}
我发现了问题。
使用 Drupal Test Traits 包时,您应该使用自己的自定义 php-unit bootstrap.php
和 manually load the required packages.
将此行添加到 bootstrap 脚本的底部将获得对 php 中命名空间的访问权限。
// <?php is needed for SO to do the syntax highlighting.
<?php
// Register more namespaces, as needed.
$class_loader->addPsr4('weitzman\DrupalTestTraits\Entity\', "$root/vendor/weitzman\drupal-test-triats\src\Entity");
我希望通过在另一个特征中使用它来扩展特征。但是,该特征正在使用一种看起来没有扩展的方法。这个特性有效,所以我想知道如何。
为什么这个 trait 可以访问 markEntityForCleanup
方法?
代码在这个repo for Drupal Test Traits
<?php
namespace weitzman\DrupalTestTraits\Entity;
use Drupal\Tests\node\Traits\NodeCreationTrait as CoreNodeCreationTrait;
/**
* Wraps the node creation trait to track entities for deletion.
*/
trait NodeCreationTrait
{
use CoreNodeCreationTrait {
createNode as coreCreateNode;
}
/**
* Creates a node and marks it for automatic cleanup.
*
* @param array $settings
* @return \Drupal\node\NodeInterface
*/
protected function createNode(array $settings = [])
{
$entity = $this->coreCreateNode($settings);
$this->markEntityForCleanup($entity);
return $entity;
}
}
我发现了问题。
使用 Drupal Test Traits 包时,您应该使用自己的自定义 php-unit bootstrap.php
和 manually load the required packages.
将此行添加到 bootstrap 脚本的底部将获得对 php 中命名空间的访问权限。
// <?php is needed for SO to do the syntax highlighting.
<?php
// Register more namespaces, as needed.
$class_loader->addPsr4('weitzman\DrupalTestTraits\Entity\', "$root/vendor/weitzman\drupal-test-triats\src\Entity");