Skip to content

Commit b813cbc

Browse files
authored
Merge branch 'develop' into MCLOUD-12166
2 parents 973c708 + 776fcbb commit b813cbc

File tree

13 files changed

+99
-64
lines changed

13 files changed

+99
-64
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"consolidation/robo": "^3.0",
4646
"php-mock/php-mock-phpunit": "^2.0",
4747
"phpmd/phpmd": "@stable",
48-
"phpstan/phpstan": "^0.12",
48+
"phpstan/phpstan": "^1.10",
4949
"phpunit/php-code-coverage": "^7.0 || ^9.2",
5050
"phpunit/phpunit": "^8.5 || ^9.5",
5151
"squizlabs/php_codesniffer": "^3.0",

src/App/Logger/Gelf/TransportFactory.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class TransportFactory
2222
public const TRANSPORT_UDP = 'udp';
2323
public const TRANSPORT_TCP = 'tcp';
2424

25+
private const DEFAULT_HOST = '127.0.0.1';
26+
private const DEFAULT_PORT_HTTP = 12202;
27+
private const DEFAULT_PORT_TCP = 12201;
28+
private const DEFAULT_PORT_UDP = 12201;
29+
private const DEFAULT_PATH_HTTP = '/gelf';
30+
2531
/**
2632
* @param string $type
2733
* @param array $config
@@ -34,27 +40,27 @@ public function create(string $type, array $config): AbstractTransport
3440
switch ($type) {
3541
case self::TRANSPORT_HTTP:
3642
$transport = new HttpTransport(
37-
$config['host'] ?? null,
38-
$config['port'] ?? null,
39-
$config['path'] ?? null
43+
$config['host'] ?? self::DEFAULT_HOST,
44+
$config['port'] ?? self::DEFAULT_PORT_HTTP,
45+
$config['path'] ?? self::DEFAULT_PATH_HTTP
4046
);
4147
if (isset($config['connection_timeout'])) {
4248
$transport->setConnectTimeout($config['connection_timeout']);
4349
}
4450
break;
4551
case self::TRANSPORT_TCP:
4652
$transport = new TcpTransport(
47-
$config['host'] ?? TcpTransport::DEFAULT_HOST,
48-
$config['port'] ?? TcpTransport::DEFAULT_PORT
53+
$config['host'] ?? self::DEFAULT_HOST,
54+
$config['port'] ?? self::DEFAULT_PORT_TCP
4955
);
5056
if (isset($config['connection_timeout'])) {
5157
$transport->setConnectTimeout($config['connection_timeout']);
5258
}
5359
break;
5460
case self::TRANSPORT_UDP:
5561
$transport = new UdpTransport(
56-
$config['host'] ?? UdpTransport::DEFAULT_HOST,
57-
$config['port'] ?? UdpTransport::DEFAULT_PORT,
62+
$config['host'] ?? self::DEFAULT_HOST,
63+
$config['port'] ?? self::DEFAULT_PORT_UDP,
5864
$config['chunk_size'] ?? UdpTransport::CHUNK_SIZE_WAN
5965
);
6066
break;

src/Filesystem/DirectoryList.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public function getPath(string $code, bool $relativePath = false): string
8080
throw new \RuntimeException("Code {$code} is not registered");
8181
}
8282

83-
if (!array_key_exists(static::PATH, $directories[$code])) {
83+
if (!array_key_exists(self::PATH, $directories[$code])) {
8484
throw new \RuntimeException(
85-
sprintf('Config var "%s" does not exists', static::PATH)
85+
sprintf('Config var "%s" does not exists', self::PATH)
8686
);
8787
}
8888

@@ -113,7 +113,7 @@ public function getMagentoRoot(): string
113113
*/
114114
public function getInit(): string
115115
{
116-
return $this->getPath(static::DIR_INIT);
116+
return $this->getPath(self::DIR_INIT);
117117
}
118118

119119
/**
@@ -122,7 +122,7 @@ public function getInit(): string
122122
*/
123123
public function getVar(): string
124124
{
125-
return $this->getPath(static::DIR_VAR);
125+
return $this->getPath(self::DIR_VAR);
126126
}
127127

128128
/**
@@ -131,7 +131,7 @@ public function getVar(): string
131131
*/
132132
public function getLog(): string
133133
{
134-
return $this->getPath(static::DIR_LOG);
134+
return $this->getPath(self::DIR_LOG);
135135
}
136136

137137
/**
@@ -140,7 +140,7 @@ public function getLog(): string
140140
*/
141141
public function getGeneratedCode(): string
142142
{
143-
return $this->getPath(static::DIR_GENERATED_CODE);
143+
return $this->getPath(self::DIR_GENERATED_CODE);
144144
}
145145

146146
/**
@@ -149,7 +149,7 @@ public function getGeneratedCode(): string
149149
*/
150150
public function getGeneratedMetadata(): string
151151
{
152-
return $this->getPath(static::DIR_GENERATED_METADATA);
152+
return $this->getPath(self::DIR_GENERATED_METADATA);
153153
}
154154

155155
/**
@@ -161,15 +161,15 @@ public function getGeneratedMetadata(): string
161161
public function getWritableDirectories(): array
162162
{
163163
$writableDirs = [
164-
static::DIR_ETC,
165-
static::DIR_MEDIA,
166-
static::DIR_LOG,
167-
static::DIR_VIEW_PREPROCESSED,
164+
self::DIR_ETC,
165+
self::DIR_MEDIA,
166+
self::DIR_LOG,
167+
self::DIR_VIEW_PREPROCESSED,
168168
];
169169

170170
if ($this->magentoVersion->satisfies('2.1.*')) {
171-
$writableDirs[] = static::DIR_GENERATED_METADATA;
172-
$writableDirs[] = static::DIR_GENERATED_CODE;
171+
$writableDirs[] = self::DIR_GENERATED_METADATA;
172+
$writableDirs[] = self::DIR_GENERATED_CODE;
173173
}
174174

175175
return array_map(function ($path) {
@@ -186,10 +186,10 @@ public function getWritableDirectories(): array
186186
public function getMountPoints(): array
187187
{
188188
$mountPoints = [
189-
static::DIR_ETC,
190-
static::DIR_VAR,
191-
static::DIR_MEDIA,
192-
static::DIR_STATIC
189+
self::DIR_ETC,
190+
self::DIR_VAR,
191+
self::DIR_MEDIA,
192+
self::DIR_STATIC
193193
];
194194

195195
return array_map(function ($path) {
@@ -203,13 +203,13 @@ public function getMountPoints(): array
203203
private function getDefaultDirectories(): array
204204
{
205205
$config = [
206-
static::DIR_INIT => [static::PATH => 'init'],
207-
static::DIR_VAR => [static::PATH => 'var'],
208-
static::DIR_LOG => [static::PATH => 'var/log'],
209-
static::DIR_ETC => [static::PATH => 'app/etc'],
210-
static::DIR_MEDIA => [static::PATH => 'pub/media'],
211-
static::DIR_STATIC => [static::PATH => 'pub/static'],
212-
static::DIR_VIEW_PREPROCESSED => [static::PATH => 'var/view_preprocessed'],
206+
self::DIR_INIT => [self::PATH => 'init'],
207+
self::DIR_VAR => [self::PATH => 'var'],
208+
self::DIR_LOG => [self::PATH => 'var/log'],
209+
self::DIR_ETC => [self::PATH => 'app/etc'],
210+
self::DIR_MEDIA => [self::PATH => 'pub/media'],
211+
self::DIR_STATIC => [self::PATH => 'pub/static'],
212+
self::DIR_VIEW_PREPROCESSED => [self::PATH => 'var/view_preprocessed'],
213213
];
214214

215215
return $config;
@@ -224,11 +224,11 @@ private function getDefaultVariadicDirectories(): array
224224
$config = [];
225225

226226
if ($this->magentoVersion->satisfies('2.1.*')) {
227-
$config[static::DIR_GENERATED_CODE] = [static::PATH => 'var/generation'];
228-
$config[static::DIR_GENERATED_METADATA] = [static::PATH => 'var/di'];
227+
$config[self::DIR_GENERATED_CODE] = [self::PATH => 'var/generation'];
228+
$config[self::DIR_GENERATED_METADATA] = [self::PATH => 'var/di'];
229229
} else {
230-
$config[static::DIR_GENERATED_CODE] = [static::PATH => 'generated/code'];
231-
$config[static::DIR_GENERATED_METADATA] = [static::PATH => 'generated/metadata'];
230+
$config[self::DIR_GENERATED_CODE] = [self::PATH => 'generated/code'];
231+
$config[self::DIR_GENERATED_METADATA] = [self::PATH => 'generated/metadata'];
232232
}
233233

234234
return $config;

src/Test/Unit/App/Logger/Gelf/MessageFormatterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public function testSetAdditional()
4040
'datetime' => new \DateTime(),
4141
'level' => Logger::INFO,
4242
'extra' => [],
43-
'context' => []
43+
'context' => [],
44+
'channel' => 'some_channel'
4445
]);
4546

4647
$this->assertEquals(
4748
[
48-
'some_key' => 'some_value'
49+
'some_key' => 'some_value',
50+
'facility' => 'some_channel'
4951
],
5052
$message->getAllAdditionals()
5153
);

src/Test/Unit/ApplicationTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
use Composer\Composer;
1111
use Composer\Package\PackageInterface;
12+
use Composer\Package\RootPackageInterface;
1213
use Magento\MagentoCloud\App\ContainerInterface;
1314
use Magento\MagentoCloud\Application;
1415
use Magento\MagentoCloud\Command;
1516
use PHPUnit\Framework\MockObject\MockObject;
1617
use PHPUnit\Framework\TestCase;
18+
use Symfony\Component\Console\Input\InputDefinition;
1719

1820
/**
1921
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -36,10 +38,15 @@ class ApplicationTest extends TestCase
3638
private $composerMock;
3739

3840
/**
39-
* @var PackageInterface|MockObject
41+
* @var RootPackageInterface|MockObject
4042
*/
4143
private $packageMock;
4244

45+
/**
46+
* @var InputDefinition|MockObject
47+
*/
48+
private $inputDefinitionMock;
49+
4350
/**
4451
* @var string
4552
*/
@@ -94,8 +101,9 @@ class ApplicationTest extends TestCase
94101
public function setUp(): void
95102
{
96103
$this->containerMock = $this->getMockForAbstractClass(ContainerInterface::class);
97-
$this->packageMock = $this->getMockForAbstractClass(PackageInterface::class);
104+
$this->packageMock = $this->getMockForAbstractClass(RootPackageInterface::class);
98105
$this->composerMock = $this->createMock(Composer::class);
106+
$this->inputDefinitionMock = $this->createMock(InputDefinition::class);
99107

100108
$map = [
101109
[Composer::class, [], $this->composerMock],
@@ -108,7 +116,7 @@ public function setUp(): void
108116
$mock->method('isEnabled')
109117
->willReturn(true);
110118
$mock->method('getDefinition')
111-
->willReturn([]);
119+
->willReturn($this->inputDefinitionMock);
112120
$mock->method('getAliases')
113121
->willReturn([]);
114122

src/Test/Unit/Config/AdminDataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\MagentoCloud\Config\AdminData;
1111
use Magento\MagentoCloud\Config\EnvironmentDataInterface;
12-
use PHPStan\Testing\TestCase;
1312
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
1414

1515
/**
1616
* @inheritDoc

src/Test/Unit/Config/EnvironmentDataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use Magento\MagentoCloud\Filesystem\Driver\File;
1818
use Magento\MagentoCloud\Filesystem\FileSystemException;
1919
use phpmock\phpunit\PHPMock;
20-
use PHPStan\Testing\TestCase;
2120
use PHPUnit\Framework\MockObject\MockObject;
21+
use PHPUnit\Framework\TestCase;
2222

2323
/**
2424
* @inheritDoc

src/Test/Unit/Config/Validator/Deploy/PhpVersionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\MagentoCloud\Test\Unit\Config\Validator\Deploy;
99

1010
use Composer\Composer;
11+
use Composer\Repository\LockArrayRepository;
1112
use Magento\MagentoCloud\Config\GlobalSection;
1213
use Magento\MagentoCloud\Config\Validator\Deploy\PhpVersion;
1314
use Composer\Package\Version\VersionParser;
@@ -19,7 +20,6 @@
1920
use PHPUnit\Framework\TestCase;
2021
use Magento\MagentoCloud\Config\Validator\ResultInterface;
2122
use Composer\Package\Locker;
22-
use Composer\Repository\RepositoryInterface;
2323
use Composer\Package\PackageInterface;
2424
use Composer\Package\Link;
2525
use Magento\MagentoCloud\Config\Validator\Result\Error;
@@ -175,7 +175,7 @@ public function testValidationSuccessInstallFromComposerVersion(): void
175175
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
176176
->willReturn(null);
177177

178-
$repoMock = $this->getMockForAbstractClass(RepositoryInterface::class);
178+
$repoMock = $this->createMock(LockArrayRepository::class);
179179
$lockerMock = $this->createMock(Locker::class);
180180
$repoMock->method('findPackage')
181181
->with('magento/magento2-base', '*')
@@ -199,7 +199,7 @@ protected function setUpComposerMocks(): void
199199
$constraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
200200
$linkMock = $this->createMock(Link::class);
201201
$packageMock = $this->getMockForAbstractClass(PackageInterface::class);
202-
$repoMock = $this->getMockForAbstractClass(RepositoryInterface::class);
202+
$repoMock = $this->createMock(LockArrayRepository::class);
203203
$lockerMock = $this->createMock(Locker::class);
204204
$this->composerConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
205205
$this->phpConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);

src/Test/Unit/Package/MagentoVersionTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ public function testIsGitInstallationException(): void
305305
->method('get')
306306
->with(GlobalConfig::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
307307
->willReturn(false);
308-
$this->rootPackageMock->method('getPrettyVersion')
309-
->willReturn(null);
310308

311309
self::assertTrue($this->magentoVersion->isGitInstallation());
312310
}

src/Test/Unit/Package/ManagerTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Composer\Composer;
1111
use Composer\Package\Locker;
12-
use Composer\Package\PackageInterface;
13-
use Composer\Repository\RepositoryInterface;
12+
use Composer\Package\RootPackageInterface;
13+
use Composer\Repository\LockArrayRepository;
1414
use Composer\Package\Link;
1515
use Magento\MagentoCloud\App\Error;
1616
use Magento\MagentoCloud\Package\Manager;
@@ -34,12 +34,12 @@ class ManagerTest extends TestCase
3434
private $composerMock;
3535

3636
/**
37-
* @var RepositoryInterface|MockObject
37+
* @var LockArrayRepository|MockObject
3838
*/
3939
private $repositoryMock;
4040

4141
/**
42-
* @var PackageInterface|MockObject
42+
* @var RootPackageInterface|MockObject
4343
*/
4444
private $packageMock;
4545

@@ -49,9 +49,8 @@ class ManagerTest extends TestCase
4949
protected function setUp(): void
5050
{
5151
$this->composerMock = $this->createMock(Composer::class);
52-
$this->repositoryMock = $this->getMockBuilder(RepositoryInterface::class)
53-
->getMockForAbstractClass();
54-
$this->packageMock = $this->getMockForAbstractClass(PackageInterface::class);
52+
$this->repositoryMock = $this->createMock(LockArrayRepository::class);
53+
$this->packageMock = $this->getMockForAbstractClass(RootPackageInterface::class);
5554
$lockerMock = $this->createMock(Locker::class);
5655

5756
$this->composerMock->expects($this->once())
@@ -68,7 +67,7 @@ protected function setUp(): void
6867

6968
public function testGetPrettyInfo(): void
7069
{
71-
$packageOneMock = $this->getMockBuilder(PackageInterface::class)
70+
$packageOneMock = $this->getMockBuilder(RootPackageInterface::class)
7271
->getMockForAbstractClass();
7372
$packageOneMock->expects($this->once())
7473
->method('getPrettyName')
@@ -77,7 +76,7 @@ public function testGetPrettyInfo(): void
7776
->method('getPrettyVersion')
7877
->willReturn('v1.0.0');
7978

80-
$packageTwoMock = $this->getMockBuilder(PackageInterface::class)
79+
$packageTwoMock = $this->getMockBuilder(RootPackageInterface::class)
8180
->getMockForAbstractClass();
8281
$packageTwoMock->expects($this->once())
8382
->method('getPrettyName')
@@ -105,7 +104,7 @@ public function testGetPrettyInfo(): void
105104

106105
public function testGetPrettyInfoWithNotExistPackage(): void
107106
{
108-
$packageOneMock = $this->getMockBuilder(PackageInterface::class)
107+
$packageOneMock = $this->getMockBuilder(RootPackageInterface::class)
109108
->getMockForAbstractClass();
110109
$packageOneMock->expects($this->once())
111110
->method('getPrettyName')

0 commit comments

Comments
 (0)