Server : nginx/1.20.2
System : Linux VM-4-4-centos 3.10.0-1160.66.1.el7.x86_64 #1 SMP Wed May 18 16:02:34 UTC 2022 x86_64
User : www ( 1000)
PHP Version : 5.6.40
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Directory :  /www/wwwroot/greatapp.cn/vendor/topthink/think-testing/src/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : /www/wwwroot/greatapp.cn/vendor/topthink/think-testing/src/AssertionsTrait.php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\testing;

use think\response\View;
use PHPUnit_Framework_Assert as PHPUnit;
use think\Session;
use think\Url;

trait AssertionsTrait
{
    public function assertResponseOk()
    {
        $actual = $this->response->getCode();

        PHPUnit::assertTrue(200 == $actual, "Expected status code 200, got {$actual}.");
    }

    public function assertResponseStatus($code)
    {
        $actual = $this->response->getCode();

        PHPUnit::assertEquals($code, $actual, "Expected status code {$code}, got {$actual}.");
    }

    public function assertViewHas($key, $value = null)
    {
        if (is_array($key)) {
            $this->assertViewHasAll($key);
        } else {
            if (!$this->response instanceof View) {
                PHPUnit::assertTrue(false, 'The response was not a view.');
            } else {
                if (is_null($value)) {
                    PHPUnit::assertArrayHasKey($key, $this->response->getVars());
                } else {
                    PHPUnit::assertEquals($value, $this->response->getVars($key));
                }
            }
        }
    }

    public function assertViewHasAll(array $bindings)
    {
        foreach ($bindings as $key => $value) {
            if (is_int($key)) {
                $this->assertViewHas($value);
            } else {
                $this->assertViewHas($key, $value);
            }
        }
    }

    public function assertViewMissing($key)
    {
        if (!$this->response instanceof View) {
            PHPUnit::assertTrue(false, 'The response was not a view.');
        } else {
            PHPUnit::assertArrayNotHasKey($key, $this->response->getVars());
        }
    }

    public function assertRedirectedTo($uri, $params = [])
    {
        $this->assertInstanceOf('think\response\Redirect', $this->response);

        PHPUnit::assertEquals(Url::build($uri, $params), $this->response->getTargetUrl());
    }

    public function assertSessionHas($key, $value = null)
    {
        if (is_array($key)) {
            $this->assertSessionHasAll($key);
        } else {
            if (is_null($value)) {
                PHPUnit::assertTrue(Session::has($key), "Session missing key: $key");
            } else {
                PHPUnit::assertEquals($value, Session::get($key));
            }
        }
    }

    public function assertSessionHasAll(array $bindings)
    {
        foreach ($bindings as $key => $value) {
            if (is_int($key)) {
                $this->assertSessionHas($value);
            } else {
                $this->assertSessionHas($key, $value);
            }
        }
    }
}