Completed
Push — master ( 16ddfb...0ea243 )
by Henry
09:18
created

tests/unit/Controller/LoginTest.php (4 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Tests\Controller;
3
4
use Redaxscript\Controller;
5
use Redaxscript\Db;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * LoginTest
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 * @author Balázs Szilágyi
17
 *
18
 * @covers Redaxscript\Controller\ControllerAbstract
19
 * @covers Redaxscript\Controller\Login
20
 */
21
22
class LoginTest extends TestCaseAbstract
23
{
24
	/**
25
	 * setUp
26
	 *
27
	 * @since 3.1.0
28
	 */
29
30
	public function setUp() : void
31
	{
32
		parent::setUp();
33
		$optionArray =
34
		[
35
			'adminName' => 'Test',
36
			'adminUser' => 'test',
37
			'adminPassword' => 'test',
38
			'adminEmail' => '[email protected]'
39
		];
40
		$installer = $this->installerFactory();
0 ignored issues
show
The method installerFactory() does not seem to exist on object<Redaxscript\Tests\Controller\LoginTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
		$installer->init();
42
		$installer->rawCreate();
43
		$installer->insertSettings($optionArray);
44
		$installer->insertUsers($optionArray);
45
		$setting = $this->settingFactory();
0 ignored issues
show
The method settingFactory() does not seem to exist on object<Redaxscript\Tests\Controller\LoginTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
		$setting->set('captcha', 1);
47
	}
48
49
	/**
50
	 * tearDown
51
	 *
52
	 * @since 3.1.0
53
	 */
54
55
	public function tearDown() : void
56
	{
57
		$this->dropDatabase();
0 ignored issues
show
The method dropDatabase() does not seem to exist on object<Redaxscript\Tests\Controller\LoginTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
	}
59
60
	/**
61
	 * testProcess
62
	 *
63
	 * @since 3.0.0
64
	 *
65
	 * @param array $postArray
66
	 * @param array $userArray
67
	 * @param string $method
68
	 * @param string $expect
69
	 *
70
	 * @dataProvider providerAutoloader
71
	 */
72
73
	public function testProcess(array $postArray = [], array $userArray = [], string $method = null, string $expect = null) : void
74
	{
75
		/* setup */
76
77
		Db::forTablePrefix('users')
78
			->whereIdIs(1)
79
			->findOne()
80
			->set('status', $userArray['status'])
81
			->save();
82
		$this->_request->set('post', $postArray);
83
		if ($method)
84
		{
85
			$loginController = $this
86
				->getMockBuilder('Redaxscript\Controller\Login')
87
				->setConstructorArgs(
88
				[
89
					$this->_registry,
90
					$this->_request,
91
					$this->_language,
92
					$this->_config
93
				])
94
				->setMethods(
95
				[
96
					$method
97
				])
98
				->getMock();
99
100
			/* override */
101
102
			$loginController
103
				->expects($this->any())
104
				->method($method)
105
				->will($this->returnValue(false));
106
		}
107
		else
108
		{
109
			$loginController = new Controller\Login($this->_registry, $this->_request, $this->_language, $this->_config);
110
		}
111
112
		/* actual */
113
114
		$actual = $loginController->process();
0 ignored issues
show
The method process does only exist in Redaxscript\Controller\Login, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
115
116
		/* compare */
117
118
		$this->assertEquals($expect, $actual);
119
	}
120
}
121