thinkphp/tests/thinkphp/library/traits/think/instanceTest.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php
namespace tests\thinkphp\library\traits\think;

use traits\think\Instance;

class instanceTest extends \PHPUnit_Framework_TestCase
{
    public function testInstance()
    {
        $father = InstanceTestFather::instance();
        $this->assertInstanceOf('\tests\thinkphp\library\traits\think\InstanceTestFather', $father);
        $this->assertEquals([], $father->options);

        $son = InstanceTestFather::instance(['son']);
        $this->assertSame($father, $son);
    }

    public function testCallStatic()
    {
        $father = InstanceTestFather::instance();
        $this->assertEquals([], $father->options);

        $this->assertEquals($father::__protectedStaticFunc(['thinkphp']), 'protectedStaticFunc["thinkphp"]');

        try {
            $father::_protectedStaticFunc();
            $this->setExpectedException('\think\Exception');
        } catch (\Exception $e) {
            $this->assertInstanceOf('\think\Exception', $e);
        }
    }

    protected function tearDown()
    {
        call_user_func(\Closure::bind(function () {
            InstanceTestFather::$instance = null;
        }, null, '\tests\thinkphp\library\traits\think\InstanceTestFather'));
    }
}

class InstanceTestFather
{
    use Instance;

    public $options = null;

    public function __construct($options)
    {
        $this->options = $options;
    }

    protected static function _protectedStaticFunc($params)
    {
        return 'protectedStaticFunc' . json_encode($params);
    }
}

class InstanceTestSon extends InstanceTestFather
{
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。