Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / CheckComposerLockUpToDateTest.php
blob1786668c769973360abc637e787a704c00931d8d
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use CheckComposerLockUpToDate;
7 /**
8 * @internal Only for use by CheckComposerLockUpToDateTest
9 */
10 class SemiMockedCheckComposerLockUpToDate extends CheckComposerLockUpToDate {
12 private string $mockMwInstallPath;
14 /**
15 * Set the a mock MW_INSTALL_PATH value for the test.
17 public function setMockMwInstallPath( string $mockMwInstallPath ) {
18 $this->mockMwInstallPath = $mockMwInstallPath;
21 protected function getMwInstallPath(): string {
22 return $this->mockMwInstallPath;
26 /**
27 * @covers \CheckComposerLockUpToDate
28 * @author Dreamy Jazz
30 class CheckComposerLockUpToDateTest extends MaintenanceBaseTestCase {
32 private const FIXTURE_DIRECTORY = MW_INSTALL_PATH . '/tests/phpunit/data/LockFileChecker';
34 public function getMaintenanceClass() {
35 return SemiMockedCheckComposerLockUpToDate::class;
38 public function testCanExecuteWithoutLocalSettings() {
39 $this->assertTrue( $this->maintenance->canExecuteWithoutLocalSettings() );
42 public function testWhenNoLockFileFound() {
43 // Test that an empty directory as the mediawiki/core install path results in an error.
44 $this->expectCallToFatalError();
45 $this->expectOutputRegex( '/Could not find composer.lock file/' );
46 $testPath = $this->getNewTempDirectory();
47 $this->maintenance->setMockMwInstallPath( $testPath );
48 $this->maintenance->execute();
51 public function testWhenLockFileOkay() {
52 // Get example composer.json and composer.lock files and add them to a fake install directory.
53 $testPath = $this->getNewTempDirectory();
54 copy( self::FIXTURE_DIRECTORY . '/composer-testcase1.json', $testPath . '/composer.json' );
55 copy( self::FIXTURE_DIRECTORY . '/composer-testcase1.lock', $testPath . '/composer.lock' );
56 $this->maintenance->setMockMwInstallPath( $testPath );
57 $this->maintenance->execute();
58 $this->expectOutputRegex( '/Your composer.lock file is up to date with current dependencies/' );
61 public function testWhenLockFileOutdated() {
62 // Get example composer.json and composer.lock files and add them to a fake install directory.
63 $testPath = $this->getNewTempDirectory();
64 copy( self::FIXTURE_DIRECTORY . '/composer-testcase2.json', $testPath . '/composer.json' );
65 copy( self::FIXTURE_DIRECTORY . '/composer-testcase2.lock', $testPath . '/composer.lock' );
66 $this->maintenance->setMockMwInstallPath( $testPath );
67 // Verify that the maintenance script errors out both indicating what is out of date and also
68 // how to fix this.
69 $this->expectCallToFatalError();
70 $this->expectOutputRegex(
71 '/wikimedia\/relpath: 2\.9\.9 installed, 3\.0\.0 required[\s\S]*' .
72 'Error: your composer.lock file is not up to date.*' .
73 'Run "composer update" to install newer dependencies/'
75 $this->maintenance->execute();