• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / plugin / 9719022737

27 Jun 2024 12:34PM UTC coverage: 43.355%. Remained the same
9719022737

push

github

twinh
style: php-cs-fixer string_implicit_backslashes

0 of 5 new or added lines in 5 files covered. (0.0%)

1256 of 2897 relevant lines covered (43.36%)

7.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Test/BaseControllerTestCase.php
1
<?php
2

3
namespace Miaoxing\Plugin\Test;
4

5
use Miaoxing\Plugin\Service\Tester;
6
use Miaoxing\Plugin\Service\User;
7

8
/**
9
 * @mixin \AppMixin
10
 */
11
abstract class BaseControllerTestCase extends BaseTestCase
12
{
13
    /**
14
     * 当前控制器名称
15
     *
16
     * @var string
17
     */
18
    protected $controller;
19

20
    /**
21
     * 预期action返回的code
22
     *
23
     * @var array
24
     */
25
    protected $statusCodes = [];
26

27
    public function getController()
28
    {
29
        if (!$this->controller) {
×
NEW
30
            preg_match('/Controller\\\(.+?)ControllerTest/', static::class, $matches);
×
31
            $values = [];
×
32
            foreach (explode('\\', $matches[1]) as $value) {
×
33
                $values[] = lcfirst($value);
×
34
            }
35
            $this->controller = implode('\\', $values);
×
36
        }
37

38
        return $this->controller;
×
39
    }
40

41
    /**
42
     * @param string $controller
43
     * @param string $action
44
     * @return \Exception|\Wei\Res
45
     */
46
    public function dispatch($controller, $action = 'index')
47
    {
48
        User::loginById(1);
×
49

50
        ob_start();
×
51
        try {
52
            $res = $this->app->dispatch($controller, $action);
×
53
        } catch (\Exception $e) {
×
54
            ob_end_clean();
×
55

56
            return $e;
×
57
        }
58

59
        ob_end_clean();
×
60

61
        return $res;
×
62
    }
63

64
    protected function getAction()
65
    {
66
        preg_match('/test(.+?)Action/', $this->getName(), $matches);
×
67
        if (!isset($matches[1])) {
×
68
            throw new \Exception('Invalid test case naming');
×
69
        }
70

71
        return lcfirst($matches[1]);
×
72
    }
73

74
    /**
75
     * @param array $request
76
     * @return Tester
77
     */
78
    protected function visitCurPage(array $request = [])
79
    {
80
        $controller = $this->getController();
×
81
        $action = $this->getAction();
×
82

83
        return wei()->tester($controller, $action)
×
84
            ->request($request);
×
85
    }
86

87
    /**
88
     * 运行任务
89
     *
90
     * @param string $name
91
     * @param array $data
92
     * @return array
93
     */
94
    protected function runJob($name, array $data = [])
95
    {
96
        $parts = explode('/', $name);
×
97
        $action = array_pop($parts);
×
98
        $controller = implode('/', $parts);
×
99

100
        return wei()->tester()
×
101
            ->login(1)
×
102
            ->controller($controller)
×
103
            ->action($action)
×
104
            ->req($data)
×
105
            ->json()
×
106
            ->exec()
×
107
            ->response();
×
108
    }
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc