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 ); } /** * @return void */ public function testExecute(): void { $this->componentRegistrarMock->expects($this->once()) ->method('getPath') ->with('module', 'Vendor_Module') ->willReturn('/long/path/to/Vendor/Module'); $read = $this->createMock(Read::class); $read ->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()); } /** * @return void */ public function testWrongParameter(): void { $this->expectExceptionMessage('Not enough arguments'); $this->expectException(\RuntimeException::class); $commandTester = new CommandTester($this->command); $commandTester->execute([]); } /** * @return void */ public function testBadModule(): void { $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' ] ); } }