Passed
Pull Request — master (#171)
by Corey
05:48
created

ControllerTest::testActions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace common\tests\unit\components;
4
5
use Yii;
6
use common\components\Controller;
7
8
/**
9
 * Controller test
10
 */
11
12
class ControllerTest extends \Codeception\Test\Unit {
13
    use \Codeception\Specify;
14
15
    public function testActions() {
16
      $controller = new Controller('test', 'common');
0 ignored issues
show
Bug introduced by
'common' of type string is incompatible with the type yii\base\Module expected by parameter $module of common\components\Controller::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
      $controller = new Controller('test', /** @scrutinizer ignore-type */ 'common');
Loading history...
17
      expect('actions should return an array of action settings', $this->assertEquals([
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertEquals(arra...$controller->actions()) targeting PHPUnit\Framework\Assert::assertEquals() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
18
        'error' => [
19
          'class' => 'yii\web\ErrorAction',
20
        ],
21
        'captcha' => [
22
          'class' => 'yii\captcha\CaptchaAction',
23
        ],
24
      ], $controller->actions()));
25
    }
26
27
    public function testBeforeAction() {
28
      $controller = new Controller('test', 'common');
0 ignored issues
show
Bug introduced by
'common' of type string is incompatible with the type yii\base\Module expected by parameter $module of common\components\Controller::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
      $controller = new Controller('test', /** @scrutinizer ignore-type */ 'common');
Loading history...
29
      $controller->enableCsrfValidation = true;
30
31
      expect("If CSRF token is valid and parent's beforeAction() returns true, return true", $this->assertTrue($controller->beforeAction('test')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($contr...->beforeAction('test')) targeting PHPUnit\Framework\Assert::assertTrue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
32
33
      // this is a terrible way to test this
34
      // look in common/config/test.php, we are setting the request class to be
35
      // \common\tests\_support\MockRequest
36
      Yii::$app->getRequest()->csrfValidationReturn = false;
37
      expect("If CSRF token is NOT valid and parent's beforeAction() returns true, return false", $this->assertFalse($controller->beforeAction('test')));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($cont...->beforeAction('test')) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
38
39
    }
40
}
41