Project

General

Profile

Revision 458948d0

ID458948d079d9985d4186c80d008a5d0f27a60201
Parent 2e07d351
Child 778b241c

Added by Andreas Kohlbecker 8 months ago

ref #8771 phpunit improving test suite setup

View differences:

modules/cdm_dataportal/test/phpUnit/phpUnit.xml
4 4
    Configuration for simple unit tests which do not require bootstrapping of drupal
5 5
    The test cases are located in ./src/unit-tests
6 6
-->
7
<phpunit defaultTestSuite="unit">
7
<phpunit>
8 8
    <php>
9 9
        <!--
10 10
            include_path: must point to the folder modules/cdm_dataportal
......
20 20

  
21 21

  
22 22
    <testsuites>
23
        <!--
24
            will add all *Test classes that are found in *Test.php files when the tests directory is
25
            recursively traversed -->
23 26
        <testsuite name="unit">
24 27
            <directory>src/unit/</directory>
25 28
        </testsuite>
......
32 35
             lowUpperBound="35" highLowerBound="70"/>
33 36
        <log type="coverage-clover" target="target/phpunit/clover.xml"/>
34 37
        -->
35
        <log type="junit" target="../../../../target/phpunit/junit-cdm-dataportal.xml" logIncompleteSkipped="false"/>
38
        <log type="junit" target="../../target/phpunit/junit-cdm-dataportal.xml" logIncompleteSkipped="false"/>
36 39
    </logging>
37 40

  
38 41
</phpunit>
modules/cdm_dataportal/test/phpUnit/src/unit/StatisticalValuesTest.php
1
<?php
2

  
3
use PHPUnit\Framework\TestCase;
4

  
5
// these includes require <includePath>../..</includePath> to be set in phpUnit.xml
6
include 'includes/common.inc';
7
include 'cdm_api/commons.php';
8

  
9
/**
10
 * test to test if phpUnit is ok
11
 * @author a.kohlbecker
12
 *
13
 */
14
class StatisticalValuesTest extends TestCase {
15

  
16
  function new_statistical_value($value = null){
17
    $stat_val = new stdClass();
18
    $stat_val->_value = $value;
19
    return $stat_val;
20
  }
21

  
22
  function create_statistical_values($typicalLowerBoundary = null, $typicalUpperrBoundary = null, $average  = null, $sampleSize = null){
23
    $stat_vals = statistical_values_array();
24
    $stat_vals['TypicalLowerBoundary'] = $this->new_statistical_value($typicalLowerBoundary);
25
    $stat_vals['TypicalUpperBoundary'] = $this->new_statistical_value($typicalUpperrBoundary);
26
    $stat_vals['SampleSize'] = $this->new_statistical_value($sampleSize);
27
    $stat_vals['Average'] = $this->new_statistical_value($average);
28
    return $stat_vals;
29
  }
30

  
31
  function html2text($html){
32
    return  html_entity_decode(strip_tags($html), ENT_COMPAT, 'utf-8');
33
  }
34

  
35
  function test_statistical_values() {
36

  
37
    $stat_vals = $this->create_statistical_values(0.123457,  0.123456, 0.123456523847, 5);
38

  
39
    $this->assertEquals('0.123457–0.123456[5;x̄=0.1234565]', $this->html2text(statistical_values($stat_vals)));
40
  }
41

  
42
}
modules/cdm_dataportal/test/phpUnit/src/unit/statistical_values_tests.php
1
<?php
2

  
3
use PHPUnit\Framework\TestCase;
4

  
5
// these includes require <includePath>../..</includePath> to be set in phpUnit.xml
6
include 'includes/common.inc';
7
include 'cdm_api/commons.php';
8

  
9
/**
10
 * test to test if phpUnit is ok
11
 * @author a.kohlbecker
12
 *
13
 */
14
class StatisticalValuesTests extends TestCase {
15

  
16
  function new_statistical_value($value = null){
17
    $stat_val = new stdClass();
18
    $stat_val->_value = $value;
19
    return $stat_val;
20
  }
21

  
22
  function create_statistical_values($typicalLowerBoundary = null, $typicalUpperrBoundary = null, $average  = null, $sampleSize = null){
23
    $stat_vals = statistical_values_array();
24
    $stat_vals['TypicalLowerBoundary'] = $this->new_statistical_value($typicalLowerBoundary);
25
    $stat_vals['TypicalUpperBoundary'] = $this->new_statistical_value($typicalUpperrBoundary);
26
    $stat_vals['SampleSize'] = $this->new_statistical_value($sampleSize);
27
    $stat_vals['Average'] = $this->new_statistical_value($average);
28
    return $stat_vals;
29
  }
30

  
31
  function html2text($html){
32
    return  html_entity_decode(strip_tags($html), ENT_COMPAT, 'utf-8');
33
  }
34

  
35
  function test_statistical_values() {
36

  
37
    $stat_vals = $this->create_statistical_values(0.123457,  0.123456, 0.123456523847, 5);
38

  
39
    $this->assertEquals('0.123457–0.123456[5;x̄=0.1234565]', $this->html2text(statistical_values($stat_vals)));
40
  }
41

  
42
}
modules/cdm_dataportal/test/phpUnit/src/unit/testTest.php
1 1
<?php
2 2

  
3
declare(strict_types=1);
4 3

  
5 4
use PHPUnit\Framework\TestCase;
6 5

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)