Passed
Push — master ( d9b33a...61038f )
by Alexander
05:52 queued 31s
created

OptionsRequestBehaviorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ setMethod() 0 4 1
A hp$1 ➔ send() 0 4 1
A setUp() 0 22 1
A testExit() 0 10 2
A testNotExit() 0 6 1
1
<?php
2
3
namespace Horat1us\Yii\Tests\Behaviors;
4
5
use Horat1us\Yii\Behaviors\OptionsRequestBehavior;
6
use Horat1us\Yii\Tests\AbstractTestCase;
7
use yii\base\ExitException;
8
use yii\web;
9
10
/**
11
 * Class OptionsRequestBehaviorTest
12
 * @package Horat1us\Yii\Tests\Behaviors
13
 */
14
class OptionsRequestBehaviorTest extends AbstractTestCase
15
{
16
    /** @var OptionsRequestBehavior */
17
    protected $behavior;
18
19
    public function setUp()
20
    {
21
        parent::setUp();
22
        $this->behavior = new OptionsRequestBehavior([
23
            'request' => new class extends web\Request
24
            {
25
                public function setMethod(string $method): void
26
                {
27
                    $this->method = $method;
28
                }
29
            },
30
            'response' => new class extends web\Response
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
31
            {
32
                public $triggered = false;
33
34
                public function send(): void
35
                {
36
                    $this->triggered = true;
37
                }
38
            }
39
        ]);
40
    }
41
42
    /**
43
     * @expectedException \yii\base\ExitException
44
     */
45
    public function testExit(): void
46
    {
47
        $this->behavior->request->method = 'OPTIONS';
48
        try {
49
            $this->behavior->check();
50
        } catch (ExitException $exception) {
51
            $this->assertTrue($this->behavior->response->triggered);
52
            throw $exception;
53
        }
54
    }
55
56
    public function testNotExit(): void
57
    {
58
        $this->behavior->request->method = 'GET';
59
        $this->behavior->check();
60
        $this->assertFalse($this->behavior->response->triggered);
61
    }
62
}
63