Test Failed
Push — master ( 68289f...b25dc9 )
by huang
03:32
created

TestCase::getDataSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @link      https://www.github.com/janhuang
7
 * @link      http://www.fast-d.cn/
8
 */
9
10
namespace FastD\Test;
11
12
13
use FastD\Application;
14
use FastD\Testing\WebTestCase;
15
use PHPUnit_Extensions_Database_DataSet_IDataSet;
16
use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
17
18
/**
19
 * Class TestCase
20
 * @package FastD\Test
21
 */
22
class TestCase extends WebTestCase
23
{
24
    /**
25
     * @var Application
26
     */
27
    protected $app;
28
29
    /**
30
     * Set up unit.
31
     */
32
    public function setUp()
33
    {
34
        $this->app = $this->createApplication();
35
        parent::setUp();
36
    }
37
38
    /**
39
     * @return Application
40
     */
41
    public function createApplication()
42
    {
43
        return new Application(getcwd());
44
    }
45
46
    /**
47
     * Returns the test database connection.
48
     *
49
     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
50
     */
51
    protected function getConnection()
52
    {
53
        $connection = env('connection');
54
        if (!$connection) {
55
            $connection = 'default';
56
        }
57
        return $this->createDefaultDBConnection(database($connection)->pdo);
0 ignored issues
show
Bug introduced by
The property pdo does not seem to exist in Medoo\Medoo.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
It seems like $connection defined by env('connection') on line 53 can also be of type boolean; however, database() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
58
    }
59
60
    /**
61
     * Returns the test dataset.
62
     *
63
     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
64
     */
65
    protected function getDataSet()
66
    {
67
        $path = app()->getPath() . '/database/dataset/*';
68
69
        $composite = new \PHPUnit_Extensions_Database_DataSet_CompositeDataSet();
70
71
        foreach (glob($path) as $file) {
72
            $dataSet = load($file);
73
            $tableName = pathinfo($file, PATHINFO_FILENAME);
74
            $composite->addDataSet(new \PHPUnit_Extensions_Database_DataSet_ArrayDataSet([
75
                $tableName => $dataSet
76
            ]));
77
        }
78
79
        return $composite;
80
    }
81
}