Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DbStatusCommandTest.php
Go to the documentation of this file.
1 <?php
7 
15 use PHPUnit_Framework_MockObject_MockObject as Mock;
16 use Symfony\Component\Console\Tester\CommandTester;
17 
21 class DbStatusCommandTest extends \PHPUnit\Framework\TestCase
22 {
26  private $dbVersionInfo;
27 
31  private $deploymentConfig;
32 
36  private $command;
37 
41  private $validators;
42 
46  protected function setUp()
47  {
48  $this->dbVersionInfo = $this->getMockBuilder(DbVersionInfo::class)
49  ->disableOriginalConstructor()
50  ->getMock();
52  $objectManagerProvider = $this->getMockBuilder(ObjectManagerProvider::class)
53  ->disableOriginalConstructor()
54  ->getMock();
56  $objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class);
57  $this->deploymentConfig = $this->getMockBuilder(DeploymentConfig::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60  $this->validators = [
61  'declarative_schema' => $this->getMockBuilder(UpToDateValidatorInterface::class)->getMock(),
62  'up_to_date_schema' => $this->getMockBuilder(UpToDateValidatorInterface::class)->getMock(),
63  'up_to_date_data' => $this->getMockBuilder(UpToDateValidatorInterface::class)->getMock(),
64  'old_validator' => $this->getMockBuilder(UpToDateValidatorInterface::class)->getMock(),
65  ];
66 
67  $objectManagerProvider->expects($this->any())
68  ->method('get')
69  ->will($this->returnValue($objectManager));
70  $objectManager->expects(self::exactly(4))
71  ->method('get')
72  ->willReturnOnConsecutiveCalls(
73  $this->validators['declarative_schema'],
74  $this->validators['up_to_date_schema'],
75  $this->validators['up_to_date_data'],
76  $this->validators['old_validator']
77  );
78  $this->command = new DbStatusCommand($objectManagerProvider, $this->deploymentConfig);
79  }
80 
81  public function testExecute()
82  {
83  $this->validators['old_validator']->expects(self::once())
84  ->method('isUpToDate')
85  ->willReturn(true);
86  $this->validators['up_to_date_schema']->expects(self::once())
87  ->method('isUpToDate')
88  ->willReturn(true);
89  $this->validators['up_to_date_data']->expects(self::once())
90  ->method('isUpToDate')
91  ->willReturn(true);
92  $this->validators['declarative_schema']->expects(self::once())
93  ->method('isUpToDate')
94  ->willReturn(true);
95  $this->deploymentConfig->expects($this->once())
96  ->method('isAvailable')
97  ->will($this->returnValue(true));
98  $tester = new CommandTester($this->command);
99  $tester->execute([]);
100  $this->assertStringMatchesFormat('All modules are up to date.', $tester->getDisplay());
101  $this->assertSame(0, $tester->getStatusCode());
102  }
103 
104  public function testExecuteNotInstalled()
105  {
106  $this->deploymentConfig->expects($this->once())
107  ->method('isAvailable')
108  ->will($this->returnValue(false));
109  $tester = new CommandTester($this->command);
110  $tester->execute([]);
111 
112  $this->assertStringMatchesFormat(
113  'No information is available: the Magento application is not installed.%w',
114  $tester->getDisplay()
115  );
116  $this->assertSame(Cli::RETURN_FAILURE, $tester->getStatusCode());
117  }
118 }
$objectManager
Definition: bootstrap.php:17