Skip to content

Commit 776fcbb

Browse files
authored
Merge pull request #145 from magento-commerce/fix-unit-tests
MCLOUD-10319: Fix unit test failures
2 parents 54b9ab5 + 7c236ab commit 776fcbb

File tree

8 files changed

+43
-33
lines changed

8 files changed

+43
-33
lines changed

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/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/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')

src/Test/Unit/Shell/ProcessFactoryTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
namespace Magento\MagentoCloud\Test\Unit\Shell;
99

10+
use Composer\Repository\LockArrayRepository;
1011
use Magento\MagentoCloud\Shell\Process;
1112
use Magento\MagentoCloud\Shell\ProcessFactory;
1213
use Magento\MagentoCloud\Shell\ProcessInterface;
1314
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
15-
use Magento\MagentoCloud\App\GenericException;
1616
use Composer\Composer;
17-
use Composer\Repository\RepositoryInterface;
1817
use Composer\Package\Locker;
1918
use Composer\Package\PackageInterface;
2019

@@ -24,7 +23,7 @@
2423
class ProcessFactoryTest extends TestCase
2524
{
2625
/**
27-
* @var RepositoryInterface|MockObject
26+
* @var LockArrayRepository|MockObject
2827
*/
2928
private $repositoryMock;
3029

@@ -48,7 +47,7 @@ class ProcessFactoryTest extends TestCase
4847
*/
4948
protected function setUp(): void
5049
{
51-
$this->repositoryMock = $this->getMockForAbstractClass(RepositoryInterface::class);
50+
$this->repositoryMock = $this->createMock(LockArrayRepository::class);
5251
$this->packageMock = $this->getMockForAbstractClass(PackageInterface::class);
5352
$this->composerMock = $this->createMock(Composer::class);
5453

tests/static/phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ parameters:
1717
paths:
1818
- ../../src/Command/BackupRestore.php
1919
- ../../src/Command/DbDump.php
20-
- message: '#Access to private constant#'
21-
path: ../../src/App/Logger/Gelf/TransportFactory.php
2220
- message: '#Property Magento\\MagentoCloud\\App\\Logger\\LineFormatterFactory\:\:\$container is never read, only written\.#'
2321
path: ../../src/App/Logger/LineFormatterFactory.php
2422
- message: '#Property Magento\\MagentoCloud\\Command\\ConfigShow\:\:\$logger is never read, only written\.#'

0 commit comments

Comments
 (0)