Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DependencyReadinessCheckTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class DependencyReadinessCheckTest extends \PHPUnit\Framework\TestCase
11 {
15  private $composerJsonFinder;
16 
20  private $directoryList;
21 
25  private $reqUpdDryRunCommand;
26 
30  private $file;
31 
35  private $dependencyReadinessCheck;
36 
37  public function setUp()
38  {
39  $this->composerJsonFinder =
40  $this->createMock(\Magento\Framework\Composer\ComposerJsonFinder::class);
41  $this->composerJsonFinder->expects($this->once())->method('findComposerJson')->willReturn('composer.json');
42  $this->directoryList =
43  $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class);
44  $this->directoryList->expects($this->exactly(2))->method('getPath')->willReturn('var');
45  $this->reqUpdDryRunCommand =
46  $this->createMock(\Magento\Composer\RequireUpdateDryRunCommand::class);
47  $this->file = $this->createMock(\Magento\Framework\Filesystem\Driver\File::class);
48  $this->file->expects($this->once())->method('copy')->with('composer.json', 'var/composer.json');
49  $composerAppFactory = $this->createMock(\Magento\Framework\Composer\MagentoComposerApplicationFactory::class);
50  $composerAppFactory->expects($this->once())
51  ->method('createRequireUpdateDryRunCommand')
52  ->willReturn($this->reqUpdDryRunCommand);
53  $this->dependencyReadinessCheck = new DependencyReadinessCheck(
54  $this->composerJsonFinder,
55  $this->directoryList,
56  $this->file,
57  $composerAppFactory
58  );
59  }
60 
61  public function testRunReadinessCheckFailed()
62  {
63  $this->reqUpdDryRunCommand->expects($this->once())
64  ->method('run')
65  ->with([], 'var')
66  ->willThrowException(new \RuntimeException('Failed' . PHP_EOL . 'dependency readiness check'));
67  $expected = ['success' => false, 'error' => 'Failed<br/>dependency readiness check'];
68  $this->assertEquals($expected, $this->dependencyReadinessCheck->runReadinessCheck([]));
69  }
70 
71  public function testRunReadinessCheck()
72  {
73  $this->reqUpdDryRunCommand->expects($this->once())
74  ->method('run')
75  ->with([], 'var')
76  ->willReturn('Success');
77  $expected = ['success' => true];
78  $this->assertEquals($expected, $this->dependencyReadinessCheck->runReadinessCheck([]));
79  }
80 }