/var/www/hkosl.com/imusiccircle/webadmin/libraies/php-console/php-console/tests/Test/Helper.php


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
<?php

namespace PhpConsole\Test;

class 
Helper extends Test {

    
/** @var  \PhpConsole\Connector */
    
protected $connector;
    
/** @var  \PhpConsole\Dispatcher\Debug|\PHPUnit_Framework_MockObject_MockObject */
    
protected $debugDispatcher;

    protected function 
setUp() {
        
$this->connector = \PhpConsole\Connector::getInstance();
        
$this->setProtectedProperty($this->connector'isActiveClient'true);

        
$this->debugDispatcher $this->getMockBuilder('\PhpConsole\Dispatcher\Debug')
            ->
setConstructorArgs(array($this->connector, new \PhpConsole\Dumper()))
            ->
setMethods(array('dispatchDebug'))
            ->
getMock();
        
$this->connector->setDebugDispatcher($this->debugDispatcher);
    }

    public function 
testCallNotRegisteredDebugNotDispatcher() {
        
$this->debugDispatcher->expects($this->never())
            ->
method('dispatchDebug');
        \
PhpConsole\Helper::debug(123);
    }

    
/**
     * @expectedException \Exception
     */
    
public function testGetConnectorBeforeRegisterThrowsException() {
        \
PhpConsole\Helper::getConnector();
    }

    
/**
     * @expectedException \Exception
     */
    
public function testGetHandlerBeforeRegisterThrowsException() {
        \
PhpConsole\Helper::getHandler();
    }

    
/**
     * @expectedException \Exception
     */
    
public function testDoubleRegisterThrowsException() {
        \
PhpConsole\Helper::register();
        \
PhpConsole\Helper::register();
    }

    public function 
testGetDefaultConnector() {
        
$connector = \PhpConsole\Helper::register();
        
$this->assertTrue($connector instanceof \PhpConsole\Connector);
        
$this->assertTrue(\PhpConsole\Helper::getConnector() instanceof \PhpConsole\Connector);
    }

    public function 
testIsRegisteredReturnsFalse() {
        
$this->assertFalse(\PhpConsole\Helper::isRegistered());
    }

    public function 
testIsRegisteredReturnsTrue() {
        \
PhpConsole\Helper::register();
        
$this->assertTrue(\PhpConsole\Helper::isRegistered());
    }

    public function 
testGetCustomConnector() {
        \
PhpConsole\Helper::register($this->connector);
        
$this->assertEquals(spl_object_hash($this->connector), spl_object_hash(\PhpConsole\Helper::getConnector()));
    }

    public function 
testGetDefaultHandler() {
        \
PhpConsole\Helper::register();
        
$this->assertTrue(\PhpConsole\Helper::getHandler() instanceof \PhpConsole\Handler);
    }

    public function 
testGetCustomHandler() {
        
$handler = \PhpConsole\Handler::getInstance();
        \
PhpConsole\Helper::register($this->connector$handler);
        
$this->assertEquals(spl_object_hash($handler), spl_object_hash(\PhpConsole\Helper::getHandler()));
    }

    public function 
testDebug() {
        
$this->debugDispatcher->expects($this->once())
            ->
method('dispatchDebug')
            ->
with($this->equalTo(123), $this->equalTo('db'));

        \
PhpConsole\Helper::register($this->connector);
        
/** @noinspection PhpUndefinedMethodInspection */
        
\PhpConsole\Helper::debug(123'db');
    }

    public function 
testCallStaticDebug() {
        
$this->debugDispatcher->expects($this->once())
            ->
method('dispatchDebug')
            ->
with($this->equalTo(123), $this->equalTo('db'));

        \
PhpConsole\Helper::register($this->connector);
        
/** @noinspection PhpUndefinedMethodInspection */
        
\PhpConsole\Helper::db(123);
    }

    public function 
testShortHelperLoaded() {
        \
PhpConsole\Helper::register($this->connector);
        
$this->assertEquals('PhpConsole\Helper'get_parent_class('PC'));
    }

    public function 
testConstructDisabled() {
        foreach(array(
'PhpConsole\Helper''PC') as $class) {
            
$method = new \ReflectionMethod($class'__construct');
            
$this->assertTrue($method->isProtected() || $method->isPrivate());
        }
    }
}