Completed
Push — master ( c3bf1d...4da758 )
by Andrii
02:28
created

SimpleConfigTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * ActiveRecord for API
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart\tests\functional;
12
13
use hiqdev\hiart\curl\Request;
14
use hiqdev\hiart\rest\Connection;
15
use Yii;
16
use yii\console\Application;
17
18
class SimpleConfigTest extends \PHPUnit\Framework\TestCase
19
{
20
    protected $simpleConfig = [
21
        'id' => 'hiart-simple-config',
22
        'basePath' => __DIR__,
23
        'components' => [
24
            'hiart' => [
25
                'class' => Connection::class,
26
                'requestClass' => Request::class,
27
                'baseUri' => 'https://site.com/api/v3/',
28
            ],
29
        ],
30
    ];
31
32
    private $app;
33
    private $container;
34
35
    public function setUp()
36
    {
37
        $this->app = Yii::$app;
38
        $this->container = Yii::$container;
39
        Yii::$app = new Application($this->simpleConfig);
40
        Yii::$container = new yii\di\Container();
41
    }
42
43
    public function tearDown()
44
    {
45
        Yii::$app = $this->app;
46
        Yii::$container = $this->container;
47
    }
48
49
    public function testGetDb()
50
    {
51
        $db = Connection::getDb();
52
        $this->assertInstanceOf(Connection::class, $db);
53
        $this->assertSame(Request::class, $db->requestClass);
0 ignored issues
show
Bug introduced by
Accessing requestClass on the interface hiqdev\hiart\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
54
    }
55
}
56