Skip to content

Commit c1d8fef

Browse files
committed
Fix #27523: fix tests for phpunit8 and code style
1 parent 1dd5290 commit c1d8fef

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

app/code/Magento/Developer/Test/Unit/Console/Command/GeneratePatchCommandTest.php

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,76 @@
88

99
use Magento\Developer\Console\Command\GeneratePatchCommand;
1010
use Magento\Framework\Component\ComponentRegistrar;
11+
use Magento\Framework\Filesystem\Directory\Read;
1112
use Magento\Framework\Filesystem\Directory\ReadFactory;
13+
use Magento\Framework\Filesystem\Directory\Write;
1214
use Magento\Framework\Filesystem\Directory\WriteFactory;
1315
use Magento\Framework\Filesystem\DirectoryList;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
1418
use Symfony\Component\Console\Tester\CommandTester;
1519

16-
class GeneratePatchCommandTest extends \PHPUnit\Framework\TestCase
20+
class GeneratePatchCommandTest extends TestCase
1721
{
1822
/**
19-
* @var ComponentRegistrar
23+
* @var ComponentRegistrar|MockObject
2024
*/
21-
private $componentRegistrar;
25+
private $componentRegistrarMock;
2226

2327
/**
24-
* @var DirectoryList
28+
* @var DirectoryList|MockObject
2529
*/
26-
private $directoryList;
30+
private $directoryListMock;
2731

2832
/**
29-
* @var ReadFactory
33+
* @var ReadFactory|MockObject
3034
*/
31-
private $readFactory;
35+
private $readFactoryMock;
3236

3337
/**
34-
* @var WriteFactory
38+
* @var WriteFactory|MockObject
3539
*/
36-
private $writeFactory;
40+
private $writeFactoryMock;
3741

3842
/**
39-
* @var GeneratePatchCommand
43+
* @var GeneratePatchCommand|MockObject
4044
*/
4145
private $command;
4246

4347
protected function setUp()
4448
{
45-
$this->componentRegistrar = $this->createMock(ComponentRegistrar::class);
46-
$this->directoryList = $this->createMock(DirectoryList::class);
47-
$this->readFactory = $this->createMock(ReadFactory::class);
48-
$this->writeFactory = $this->createMock(WriteFactory::class);
49+
$this->componentRegistrarMock = $this->createMock(ComponentRegistrar::class);
50+
$this->directoryListMock = $this->createMock(DirectoryList::class);
51+
$this->readFactoryMock = $this->createMock(ReadFactory::class);
52+
$this->writeFactoryMock = $this->createMock(WriteFactory::class);
4953

5054
$this->command = new GeneratePatchCommand(
51-
$this->componentRegistrar,
52-
$this->directoryList,
53-
$this->readFactory,
54-
$this->writeFactory
55+
$this->componentRegistrarMock,
56+
$this->directoryListMock,
57+
$this->readFactoryMock,
58+
$this->writeFactoryMock
5559
);
5660
}
5761

5862
public function testExecute()
5963
{
60-
$this->componentRegistrar->expects($this->once())
64+
$this->componentRegistrarMock->expects($this->once())
6165
->method('getPath')
6266
->with('module', 'Vendor_Module')
6367
->willReturn('/long/path/to/Vendor/Module');
6468

65-
$read = $this->createMock(\Magento\Framework\Filesystem\Directory\Read::class);
69+
$read = $this->createMock(Read::class);
6670
$read->expects($this->at(0))
6771
->method('readFile')
6872
->with('patch_template.php.dist')
6973
->willReturn('something');
70-
$this->readFactory->method('create')->willReturn($read);
74+
$this->readFactoryMock->method('create')->willReturn($read);
7175

72-
$write = $this->createMock(\Magento\Framework\Filesystem\Directory\Write::class);
76+
$write = $this->createMock(Write::class);
7377
$write->expects($this->once())->method('writeFile');
74-
$this->writeFactory->method('create')->willReturn($write);
78+
$this->writeFactoryMock->method('create')->willReturn($write);
7579

76-
$this->directoryList->expects($this->once())->method('getRoot')->willReturn('/some/path');
80+
$this->directoryListMock->expects($this->once())->method('getRoot')->willReturn('/some/path');
7781

7882
$commandTester = new CommandTester($this->command);
7983
$commandTester->execute(
@@ -85,34 +89,31 @@ public function testExecute()
8589
$this->assertContains('successfully generated', $commandTester->getDisplay());
8690
}
8791

88-
/**
89-
* @expectedException \RuntimeException
90-
* @expectedExceptionMessage Not enough arguments
91-
*/
9292
public function testWrongParameter()
9393
{
94+
$this->expectExceptionMessage('Not enough arguments');
95+
$this->expectException(\RuntimeException::class);
96+
9497
$commandTester = new CommandTester($this->command);
9598
$commandTester->execute([]);
9699
}
97100

98-
/**
99-
* @expectedException \InvalidArgumentException
100-
* @expectedExceptionMessage Cannot find a registered module with name "Fake_Module"
101-
*/
102101
public function testBadModule()
103102
{
104-
$this->componentRegistrar->expects($this->once())
103+
$this->componentRegistrarMock->expects($this->once())
105104
->method('getPath')
106105
->with('module', 'Fake_Module')
107106
->willReturn(null);
108107

108+
$this->expectExceptionMessage('Cannot find a registered module with name "Fake_Module"');
109+
$this->expectException(\InvalidArgumentException::class);
110+
109111
$commandTester = new CommandTester($this->command);
110112
$commandTester->execute(
111113
[
112114
GeneratePatchCommand::MODULE_NAME => 'Fake_Module',
113115
GeneratePatchCommand::INPUT_KEY_PATCH_NAME => 'SomePatch'
114116
]
115117
);
116-
$this->assertContains('successfully generated', $commandTester->getDisplay());
117118
}
118119
}

0 commit comments

Comments
 (0)