Visualphpunit\Core\Test::getTests PHP Method

getTests() public static method

Get test per day between dates
public static getTests ( Doctrine\DBAL\Connection $connection, DateTime $start, DateTime $end, String $unit ) : mixed[]
$connection Doctrine\DBAL\Connection
$start DateTime
$end DateTime
$unit String
return mixed[]
    public static function getTests(Connection $connection, DateTime $start, DateTime $end, $unit)
    {
        $sql = "\n            SELECT\n            strftime('%Y-%m-%d %H:%M:%S', executed) as datetime,\n            ltrim(strftime('" . $unit . "', executed), '0') as unit,\n            COUNT() as number,\n            status\n            FROM tests\n            WHERE executed BETWEEN datetime(?) AND datetime(?)\n            AND status = 'passed'\n            GROUP BY strftime('" . $unit . "', executed)\n            UNION\n            SELECT\n            strftime('%Y-%m-%d %H:%M:%S', executed) as datetime,\n            ltrim(strftime('" . $unit . "', executed), '0') as unit,\n            COUNT() as number,\n            status\n            FROM tests\n            WHERE executed BETWEEN datetime(?) AND datetime(?)\n            AND status = 'failed'\n            GROUP BY strftime('" . $unit . "', executed)\n            UNION\n            SELECT\n            strftime('%Y-%m-%d %H:%M:%S', executed) as datetime,\n            ltrim(strftime('" . $unit . "', executed), '0') as unit,\n            COUNT() as number,\n            status\n            FROM tests\n            WHERE executed BETWEEN datetime(?) AND datetime(?)\n            AND status = 'notImplemented'\n            GROUP BY strftime('" . $unit . "', executed)\n            UNION\n            SELECT\n            strftime('%Y-%m-%d %H:%M:%S', executed) as datetime,\n            ltrim(strftime('" . $unit . "', executed), '0') as unit,\n            COUNT() as number,\n            status\n            FROM tests\n            WHERE executed BETWEEN datetime(?) AND datetime(?)\n            AND status = 'skipped'\n            GROUP BY strftime('" . $unit . "', executed)\n            UNION\n            SELECT\n            strftime('%Y-%m-%d %H:%M:%S', executed) as datetime,\n            ltrim(strftime('" . $unit . "', executed), '0') as unit,\n            COUNT() as number,\n            status\n            FROM tests\n            WHERE executed BETWEEN datetime(?) AND datetime(?)\n            AND status = 'error'\n            GROUP BY strftime('" . $unit . "', executed)\n            ORDER BY status";
        $stmt = $connection->prepare($sql);
        $stmt->bindValue(1, $start->format('Y-m-d H:i:s'));
        $stmt->bindValue(2, $end->format('Y-m-d H:i:s'));
        $stmt->bindValue(3, $start->format('Y-m-d H:i:s'));
        $stmt->bindValue(4, $end->format('Y-m-d H:i:s'));
        $stmt->bindValue(5, $start->format('Y-m-d H:i:s'));
        $stmt->bindValue(6, $end->format('Y-m-d H:i:s'));
        $stmt->bindValue(7, $start->format('Y-m-d H:i:s'));
        $stmt->bindValue(8, $end->format('Y-m-d H:i:s'));
        $stmt->bindValue(9, $start->format('Y-m-d H:i:s'));
        $stmt->bindValue(10, $end->format('Y-m-d H:i:s'));
        $stmt->execute();
        return $stmt->fetchAll();
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Get graph data
  *
  * Get graph data from test resuts
  *
  * @param string $unit
  * @param string $start
  * @param string $end
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \Silex\Application $app
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function index($unit, $start, $end, Request $request, Application $app)
 {
     $start = DateTime::createFromFormat('Y-m-d', $start);
     $start->setTime(0, 0, 0);
     $end = DateTime::createFromFormat('Y-m-d', $end);
     $end->setTime(23, 59, 59);
     $data = null;
     switch ($unit) {
         case 'h':
             $data = Test::getTests($app['db'], $start, $end, Test::GROUP_BY_HOUR);
             break;
         case 'd':
             $data = Test::getTests($app['db'], $start, $end, Test::GROUP_BY_DAY);
             break;
         case 'm':
             $data = Test::getTests($app['db'], $start, $end, Test::GROUP_BY_MONTH);
             break;
         case 'y':
             $data = Test::getTests($app['db'], $start, $end, Test::GROUP_BY_YEAR);
             break;
         default:
             break;
     }
     $data = static::explodeTests($data);
     return $this->ok($data);
 }