-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix #27523: throw informative errors in setup:db:generate-patch #27579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 10 commits into
magento:2.4-develop
from
korostii:korostii-patch-27523
Sep 2, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1e8e825
Fix #27523: throw informative error if the requested module does not …
korostii 1dd5290
Fix #27523: add tests for GeneratePatchCommand
korostii c1d8fef
Fix #27523: fix tests for phpunit8 and code style
korostii a74f8fe
Merge branch '2.4-develop' into korostii-patch-27523
slavvka f48cd50
Merge branch '2.4-develop' into korostii-patch-27523
slavvka 2bc691a
Merge branch '2.4-develop' into korostii-patch-27523
engcom-Kilo 8991733
Merge branch '2.4-develop' into korostii-patch-27523
slavvka 347602f
Merge branch '2.4-develop' into korostii-patch-27523
korostii 75bb2c3
Fix #27523: fix tests for phpunit9 and php7.4
korostii 7d316d4
Merge branch '2.4-develop' into korostii-patch-27523
engcom-Kilo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
app/code/Magento/Developer/Test/Unit/Console/Command/GeneratePatchCommandTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Developer\Test\Unit\Console\Command; | ||
|
||
use Magento\Developer\Console\Command\GeneratePatchCommand; | ||
use Magento\Framework\Component\ComponentRegistrar; | ||
use Magento\Framework\Filesystem\Directory\Read; | ||
use Magento\Framework\Filesystem\Directory\ReadFactory; | ||
use Magento\Framework\Filesystem\Directory\Write; | ||
use Magento\Framework\Filesystem\Directory\WriteFactory; | ||
use Magento\Framework\Filesystem\DirectoryList; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class GeneratePatchCommandTest extends TestCase | ||
{ | ||
/** | ||
* @var ComponentRegistrar|MockObject | ||
*/ | ||
private $componentRegistrarMock; | ||
|
||
/** | ||
* @var DirectoryList|MockObject | ||
*/ | ||
private $directoryListMock; | ||
|
||
/** | ||
* @var ReadFactory|MockObject | ||
*/ | ||
private $readFactoryMock; | ||
|
||
/** | ||
* @var WriteFactory|MockObject | ||
*/ | ||
private $writeFactoryMock; | ||
|
||
/** | ||
* @var GeneratePatchCommand|MockObject | ||
*/ | ||
private $command; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->componentRegistrarMock = $this->createMock(ComponentRegistrar::class); | ||
$this->directoryListMock = $this->createMock(DirectoryList::class); | ||
$this->readFactoryMock = $this->createMock(ReadFactory::class); | ||
$this->writeFactoryMock = $this->createMock(WriteFactory::class); | ||
|
||
$this->command = new GeneratePatchCommand( | ||
$this->componentRegistrarMock, | ||
$this->directoryListMock, | ||
$this->readFactoryMock, | ||
$this->writeFactoryMock | ||
); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$this->componentRegistrarMock->expects($this->once()) | ||
->method('getPath') | ||
->with('module', 'Vendor_Module') | ||
->willReturn('/long/path/to/Vendor/Module'); | ||
|
||
$read = $this->createMock(Read::class); | ||
$read->expects($this->at(0)) | ||
->method('readFile') | ||
->with('patch_template.php.dist') | ||
->willReturn('something'); | ||
$this->readFactoryMock->method('create')->willReturn($read); | ||
|
||
$write = $this->createMock(Write::class); | ||
$write->expects($this->once())->method('writeFile'); | ||
$this->writeFactoryMock->method('create')->willReturn($write); | ||
|
||
$this->directoryListMock->expects($this->once())->method('getRoot')->willReturn('/some/path'); | ||
|
||
$commandTester = new CommandTester($this->command); | ||
$commandTester->execute( | ||
[ | ||
GeneratePatchCommand::MODULE_NAME => 'Vendor_Module', | ||
GeneratePatchCommand::INPUT_KEY_PATCH_NAME => 'SomePatch' | ||
] | ||
); | ||
$this->assertStringContainsString('successfully generated', $commandTester->getDisplay()); | ||
} | ||
|
||
public function testWrongParameter() | ||
{ | ||
$this->expectExceptionMessage('Not enough arguments'); | ||
$this->expectException(\RuntimeException::class); | ||
|
||
$commandTester = new CommandTester($this->command); | ||
$commandTester->execute([]); | ||
} | ||
|
||
public function testBadModule() | ||
{ | ||
$this->componentRegistrarMock->expects($this->once()) | ||
->method('getPath') | ||
->with('module', 'Fake_Module') | ||
->willReturn(null); | ||
|
||
$this->expectExceptionMessage('Cannot find a registered module with name "Fake_Module"'); | ||
$this->expectException(\InvalidArgumentException::class); | ||
|
||
$commandTester = new CommandTester($this->command); | ||
$commandTester->execute( | ||
[ | ||
GeneratePatchCommand::MODULE_NAME => 'Fake_Module', | ||
GeneratePatchCommand::INPUT_KEY_PATCH_NAME => 'SomePatch' | ||
] | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @korostii. Thank you for fixing the issues mentioned earlier. There was a comment from me regarding suffixing mock properties with Mock suffix. The same applies to the variables. This suffix improves code readability by letting know straight away what object we are working on mock or a real instance.
Just a recommendation for the future 😉