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

评论 (写第一个评论)