Testing_DocTest
[ class tree: Testing_DocTest ] [ index: Testing_DocTest ] [ all elements ]

File: test1.php

Source Location: /Testing_DocTest-0.6.0/docs/test1.php

Classes:

Bar
A class that does nothing.
Foo
Foo class.

Page Details:

This file is part of the PEAR Testing_DocTest package.

PHP version 5

LICENSE: This source file is subject to the MIT license that is available through the world-wide-web at the following URI: http://opensource.org/licenses/mit-license.php

  1.  <?php
  2.  echo "Foo!";
  3.  // expects:
  4.  // Foo!
  5.  ?>


FOO [line 660]

FOO = 'bar'
This is another file level test.

  1.  // doctest: file-level doctest 2
  2.  // setup:
  3.  // $_REQUEST['foo'] = 'bar';
  4.  var_dump(defined('FOO'));
  5.  // expects:
  6.  // bool(true)


[ Top ]



OS_TYPE [line 61]

OS_TYPE = $_ENV['OSTYPE']
This is a file level test.

  1.  // doctest: file-level doctest 1
  2.  // setup:
  3.  // $_ENV['OSTYPE'] = 'linux';
  4.  echo OS_TYPE;
  5.  // expects:
  6.  // linux


[ Top ]



multiply [line 539]

float multiply( mixed $a, mixed $b)

A simple function that multiply two int or float and return a float number.

It throws an exception if arguments given have a wrong type.

Note that the "^M" chars have been intentionally added for tests purpose ;)

  1.  printf("%01.2f\n"multiply(34));
  2.  printf("%01.2f\n"multiply(3.24));
  3.  printf("%01.2f\n"multiply(3.24.2));
  4.  try {
  5.      multiply('foo'4.2);
  6.  catch (Exception $exc{
  7.      echo $exc->getMessage("\n";
  8.  }
  9.  try {
  10.      multiply(3.2'foo');
  11.  catch (Exception $exc{
  12.      echo $exc->getMessage("\n";
  13.  }
  14.  // expects:
  15.  // 12.00
  16.  // 12.80
  17.  // 13.44
  18.  // Wrong type for first argument.
  19.  // Wrong type for second argument.

  • Return: the result of the multiplication
  • Throws: Exception if arguments given have a wrong type


Parameters

mixed   $a   an int or a float
mixed   $b   an int or a float
[ Top ]



multiply2 [line 568]

float multiply2( mixed $a, mixed $b)

A simple function that multiply two int or float and return a float number.

It throws an exception if arguments given have a wrong type.

This example shows the use of an external doctest file.

  1.  // test-file: docs/external_file.doctest

  • Return: the result of the multiplication
  • Throws: Exception if arguments given have a wrong type


Parameters

mixed   $a   an int or a float
mixed   $b   an int or a float
[ Top ]



testArray [line 609]

array testArray( [bool $multi = false])

A simple function that return a simple or multidimensional array.

  1.  // flags:
  2.  print_r(testArray(true));
  3.  // expects:
  4.  // Array
  5.  // (
  6.  //     [foo] => 1
  7.  //     [bar] => 2
  8.  // )

  1.  // note that here we must add a blank line at the end because we are using
  2.  // STRICT_WHITESPACE flag.
  3.  
  4.  // flags: NORMALIZE_WHITESPACE
  5.  // expects:
  6.  // Array([0]=>foo [1]=>bar)

  • Return: multidimensionnal array


Parameters

bool   $multi   return a multidimensional array if set to true.
[ Top ]



testFlags [line 498]

string testFlags( [string $foo = ''])

This little function will explain the usage of flags in doc tests.

At the moment, doc tests can have the following flags:

  • NORMALIZE_WHITESPACE: tells the runner to compare strings ignoring all whitespace differences;
  • CASE_INSENSITIVE: tells the runner to compare strings ignoring case;
  • SKIP: tells the parser to just ignore the test;
  • ELLIPSIS: allow to pass a wildcard pattern: [...] that will match any string in the actual result.
flags syntax: // flags: FLAG_1, FLAG_2 , ... , FLAG_N

or:

// flags: FLAG_1 // FLAG_2 , FLAG_3 // FLAG_N

Here are some examples:

  1.  // flags: NORMALIZE_WHITESPACE
  2.  echo testFlags('   fo  o        ');
  3.  // expects:
  4.  // function says: foo

  1.  // flags: CASE_INSENSITIVE
  2.  echo testFlags('foo');
  3.  // expects:
  4.  // FUNCtion says: Foo

  1.  // flags: SKIP
  2.  echo testFlags('bar');
  3.  // expects:
  4.  // don't care too much...

  1.  // flags: ELLIPSIS
  2.  echo testFlags('bar');
  3.  // expects:
  4.  // function [...]: [...]



Parameters

string   $foo   some string
[ Top ]



testString [line 642]

array testString( )

A simple function that return a string.

  1.  // note that here we must set the ELLIPSIS flag cause we cannot predict
  2.  // exactly the result of the function
  3.  
  4.  // flags: ELLIPSIS
  5.  echo testString();
  6.  // expects:
  7.  // A string that cannot be predicted [...].

  1.  // an example on how we can wrap long text
  2.  
  3.  // flags: ELLIPSIS
  4.  echo testString();
  5.  // expects:
  6.  // A string \
  7.  // that cannot \
  8.  // be predicted [...].

  • Return: multidimensionnal array


[ Top ]



Documentation generated on Mon, 11 Mar 2019 15:52:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.