1<?php
2
3require(__DIR__ . '/../../vendor/yiisoft/yii/tests/TestApplication.php');
4require(__DIR__ . '/../../vendor/yiisoft/yii/framework/collections/CMap.php');
5
6class TbTestCase extends \Codeception\TestCase\Test
7{
8    /**
9     *
10     */
11    protected function _after()
12    {
13        $this->destroyApplication();
14    }
15
16    /**
17     * @param array $config
18     * @param string $appClass
19     */
20    protected function mockApplication($config = array(), $appClass = 'TestApplication')
21    {
22        $defaultConfig = array(
23            'basePath' => __DIR__,
24            'aliases' => array(
25                'bootstrap' => __DIR__ . '/../..',
26            ),
27        );
28        Yii::createApplication(
29            $appClass,
30            CMap::mergeArray($defaultConfig, $config)
31        );
32    }
33
34    /**
35     *
36     */
37    protected function destroyApplication()
38    {
39        Yii::setApplication(null);
40    }
41
42    /**
43     * @param $widgetClass
44     * @param array $properties
45     * @return string
46     */
47    protected function runWidget($widgetClass, $properties = array())
48    {
49        return $this->mockController()->widget($widgetClass, $properties, true);
50    }
51
52    /**
53     * @param $widgetClass
54     * @param array $properties
55     * @return CWidget
56     */
57    protected function beginWidget($widgetClass, $properties = array())
58    {
59        return $this->mockController()->beginWidget($widgetClass, $properties);
60    }
61
62    /**
63     * @return CController
64     */
65    private function mockController()
66    {
67        return new CController('dummy');
68    }
69}