10.1 单体和功能测试

Drupal 8 龦龢龡龟龝龚龘龕龒龑龍龌龋龉龅龡龟龂龁齿龡龟齽龡龟齼齻齺齸龑齶齲齮齫齩龡龟齥齤齠齤齜齛齙齕齒齮齎齍齤齠齌齋齇齆齅龚龢龁齿齽齃齂齩龡龟齎齍齀鼼鼺鼶龡龟齽鼲鼮鼭龢鼪鼦鼤鼣龒龑龍龌龢龡龟齮鼡鼝鼚鼖鼒鼑齒鼣齩龡龟齽

龉龅龡龟龂龁齿龡龟龢龝龚鼎鼍鼪龡龟龢鼉鼈齮龉龅龡龟鼅齥龡龟鼃鼀龢龁齿齽Drupal 8 龦齮黽黼黻黹黵黱黯黮黭黩齻龉龅龡龟齮鼣鼪黦龕黹黵齼黣黟龕黜黩齻鼣黙黹黵龢龁齿鼚黕齮鼣齩黹黵鼝黑黎齺黊齥黉鼼龢 Drupal 黈黆黅齌黂麿黉鼼龢麾麻龂麹麶齽

龁齿龡龟鼪龡龟麴黭麰麮齸麬麨龢龁齿齽麤麣齮麡麟麝齿麜麙齥麖麓龦麒鼼齂黙麏麍齮麉麆麂麀齃齂黙麖麓鹾鹺鼣龑麏鹹齽龚鹵鹳鼣黙鹱齅龚齂黙鹮鹭龢 Drupal 黈黆齽鹱麝鹫鹪麍鹩鼉鼈龢龁齿龡龟齮鼡鹧麟鹤鹠黯鹝齽

本课内容

  • 齕齒龉龅龡龟
  • 麒鼼龉龅龡龟
  • 齕齒龁齿龡龟
  • 麒鼼龁齿龡龟

初期安装

麡麟鹛齇黙鹗鹖鹔 test_example齽

test_example.info.yml

name: Test Example
type: module
description: Example showing how to create tests
core: 8.x
package: Examples
dependencies:
  - user
  - options

创建一个简单服务

黹黵鸴Services鸧鼪齿鸣齀鼼龡龟龢鸠麤鸟齽

test_example.services.yml

services:
  test_example.conversions:
    class: Drupal\pants\TestExampleConversions

src/TestExampleConversions.php 鸌麨龋

<?php
 
/**
 * @file
 * Contains \Drupal\test_example\TestExampleConversions.
 */
 
namespace Drupal\test_example;
 
/**
 * Provide functions for converting measurements.
 *
 * @package Drupal\test_example
 */
class TestExampleConversions {
 
  /**
   * Convert Celsius to Fahrenheit
   *
   * @param $temp
   *
   * @return int
   */
  public function celsiusToFahrenheit($temp) {
    return ($temp * (9/5)) + 32;
  }
 
  /**
   * Convert centimeter to inches.
   *
   * @param $length
   *
   * @return int
   */
  public function centimeterToInch($length) {
    return $length / 2.54;
  }
 
}

评论 (写第一个评论)