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;
  }
 
}

评论 (写第一个评论)