Blame view

sources/3rdparty/doctrine/dbal/tests/Doctrine/Tests/DbalFunctionalTestCase.php 2.36 KB
31b7f2792   Kload   Upgrade to ownclo...
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
  <?php
  
  namespace Doctrine\Tests;
  
  class DbalFunctionalTestCase extends DbalTestCase
  {
      /**
       * Shared connection when a TestCase is run alone (outside of it's functional suite)
       *
       * @var \Doctrine\DBAL\Connection
       */
      private static $_sharedConn;
  
      /**
       * @var \Doctrine\DBAL\Connection
       */
      protected $_conn;
  
      /**
       * @var \Doctrine\DBAL\Logging\DebugStack
       */
      protected $_sqlLoggerStack;
  
      protected function resetSharedConn()
      {
          if (self::$_sharedConn) {
              self::$_sharedConn->close();
              self::$_sharedConn = null;
          }
      }
  
      protected function setUp()
      {
          if ( ! isset(self::$_sharedConn)) {
              self::$_sharedConn = TestUtil::getConnection();
          }
          $this->_conn = self::$_sharedConn;
  
          $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack();
          $this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
      }
  
      protected function onNotSuccessfulTest(\Exception $e)
      {
          if ($e instanceof \PHPUnit_Framework_AssertionFailedError) {
              throw $e;
          }
  
          if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) {
              $queries = "";
              $i = count($this->_sqlLoggerStack->queries);
              foreach (array_reverse($this->_sqlLoggerStack->queries) AS $query) {
                  $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array());
                  $queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL;
                  $i--;
              }
  
              $trace = $e->getTrace();
              $traceMsg = "";
              foreach($trace AS $part) {
                  if(isset($part['file'])) {
                      if(strpos($part['file'], "PHPUnit/") !== false) {
                          // Beginning with PHPUnit files we don't print the trace anymore.
                          break;
                      }
  
                      $traceMsg .= $part['file'].":".$part['line'].PHP_EOL;
                  }
              }
  
              $message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg;
  
              throw new \Exception($message, (int)$e->getCode(), $e);
          }
          throw $e;
      }
  }