File size: 4,033 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
 * pakeTest.php
 * @package gulliver.bin.tasks
 *  
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2011 Colosa Inc.23
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd., 
 * Coral Gables, FL, 33134, USA, or email info@colosa.com.
 * 
 */

 

pake_desc('launch unit tests');
pake_task('test-unit', 'project_exists');

pake_desc('launch functional tests for an application');
pake_task('test-functional', 'project_exists');

pake_desc('launch all tests');
pake_task('test-all', 'project_exists');

   /**
   * Function run_test_all
   * access public
   */

function run_test_all($task, $args)
{
  require_once(sfConfig::get('sf_symfony_lib_dir').'/lime/lime.php');

  $h = new lime_harness(new lime_output_color());
  $h->base_dir = sfConfig::get('sf_test_dir');

  // register all tests
  $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php');
  $h->register($finder->in($h->base_dir));

  $h->run();
}
   
function run_test_functional($task, $args)
{
  if (!count($args))
  {
    throw new Exception('You must provide the app to test.');
  }

  $app = $args[0];

  if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app))
  {
    throw new Exception(sprintf('The app "%s" does not exist.', $app));
  }

  if (isset($args[1]))
  {
    foreach (array_splice($args, 1) as $path)
    {
      $files = pakeFinder::type('file')->ignore_version_control()->follow_link()->name(basename($path).'Test.php')->in(sfConfig::get('sf_test_dir').DIRECTORY_SEPARATOR.'functional'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.dirname($path));
      foreach ($files as $file)
      {
        include($file);
      }
    }
  }
  else
  {
    require_once(sfConfig::get('sf_symfony_lib_dir').'/lime/lime.php');

    $h = new lime_harness(new lime_output_color());
    $h->base_dir = sfConfig::get('sf_test_dir').'/functional/'.$app;

    // register functional tests
    $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php');
    $h->register($finder->in($h->base_dir));

    $h->run();
  }
}

function run_test_unit($task, $args)
{
  $environment  = isset ( $arg[1] ) ? $arg[1] : G_TEST_ENV;
  printf("start test in %s environment\n", pakeColor::colorize( $environment, 'INFO'));
  define ( 'G_ENVIRONMENT', $environment );
  
  if (isset($args[0]))
  {
    foreach ($args as $path)
    {
      $pathUnit = PATH_CORE . 'test' . PATH_SEP . 'unit' . PATH_SEP . dirname($path);
      $files = pakeFinder::type('file')->ignore_version_control()->follow_link()->name(basename($path).'Test.php')->in( $pathUnit );
      foreach ($files as $file)
      {
        $fName = str_replace ( PATH_CORE . 'test' . PATH_SEP . 'unit' . PATH_SEP , '', $file );
        printf("\ntesting %s \n", pakeColor::colorize( $fName, 'INFO'));
        include($file);
      }
    }
  }
  else
  {
    
    require_once( PATH_THIRDPARTY . '/lime/lime.php');
    $h = new lime_harness(new lime_output_color());
    $h->base_dir = $pathUnit = PATH_CORE . 'test' . PATH_SEP . 'unit';
//    $h->base_dir = $pathUnit = PATH_CORE . 'test' . PATH_SEP . 'unit' . PATH_SEP . "processmaker";

    // register unit tests
    $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php');
    $h->register($finder->in($h->base_dir));

    $h->run();
  }
}