Passed
Push — developer ( be0222...346aa7 )
by Mariusz
41:58 queued 06:52
created

01_Integration.php$0 ➔ clearSelf()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
1
<?php
2
/**
3
 * Integration test class.
4
 *
5
 * @copyright YetiForce Sp. z o.o.
6
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
7
 * @author    Michał Lorencik <[email protected]>
8
 */
9
use App\Api;
10
use App\Config;
11
use App\Language;
12
use App\Server;
13
use App\User;
14
use PHPUnit\Framework\TestCase;
15
16
/**
17
 * @covers \Integration::<public>
18
 *
19
 * @internal
20
 */
21
final class Integration extends TestCase
22
{
23
	private const EMAIL = '[email protected]';
24
	private const PASSWORD = 'demo';
25
26
	private static $apiObject;
27
	private static $token;
28
29
	public static function setUpBeforeClass(): void
30
	{
31
		static::$apiObject = new class() extends \App\Api {
0 ignored issues
show
Coding Style introduced by
anonymous//tests/phpunit/01_Integration.php$0 does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility introduced by
Since Integration is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
Bug introduced by
The call to anonymous//tests/phpunit...on.php$0::__construct() misses some required arguments starting with $header.
Loading history...
32
			public static function clearSelf()
33
			{
34
				static::$instance = null;
35
			}
36
		};
37
	}
38
39
	protected function setUp(): void
40
	{
41
		static::$apiObject::clearSelf();
0 ignored issues
show
Comprehensibility introduced by
Since Integration is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
42
		$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
43
		User::getUser()->set('token', static::$token);
0 ignored issues
show
Comprehensibility introduced by
Since Integration is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
44
		User::getUser()->set('logged', true);
45
	}
46
47
	/**
48
	 * Test portal is integrated with crm.
49
	 */
50
	public function testIntegration()
51
	{
52
		$this->expectException(\App\Exceptions\AppException::class);
53
		$response = (new Api())->call('');
0 ignored issues
show
Bug introduced by
The call to Api::__construct() misses some required arguments starting with $header.
Loading history...
54
		$result = (isset($response['code']) && 401 != $response['code']);
55
		static::assertTrue($result);
56
	}
57
58
	public function testLangAfterLogin()
59
	{
60
		$params = [
61
			'version' => Config::$version,
62
			'language' => Language::getLanguage(),
63
			'ip' => Server::getRemoteIp(),
64
			'fromUrl' => Config::$portalUrl
65
		];
66
		$response = Api::getInstance()->call('Users/Login', ['userName' => static::EMAIL, 'password' => static::PASSWORD, 'params' => $params], 'post');
67
		static::assertNotFalse($response);
68
		static::assertTrue($response['logged']);
69
		static::assertSame(Language::getLanguage(), $response['language']);
70
		static::$token = $response['token'];
0 ignored issues
show
Comprehensibility introduced by
Since Integration is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
71
	}
72
73
	public function testModulesLang()
74
	{
75
		$response = (new User())->login(static::EMAIL, static::PASSWORD);
76
		static::assertTrue($response);
77
		$modulesList = Api::getInstance()->call('Modules');
78
		static::assertIsArray($modulesList);
79
		static::assertSame('Contacts', $modulesList['Contacts']);
80
		static::assertSame('Accounts', $modulesList['Accounts']);
81
		static::assertSame('Leads', $modulesList['Leads']);
82
	}
83
84
	/**
85
	 * Test login with default data.
86
	 */
87
	public function testLogin()
88
	{
89
		$response = (new User())->login(static::EMAIL, static::PASSWORD);
90
		static::assertTrue($response);
91
	}
92
93
	/**
94
	 * Test login with bad password.
95
	 */
96
	public function testLoginBadData()
97
	{
98
		$this->expectException(\App\Exceptions\AppException::class);
99
		(new User())->login(static::EMAIL, 'wrongpassword');
100
	}
101
}
102