File: CheckComposerLockUpToDateTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (77 lines) | stat: -rw-r--r-- 2,791 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

namespace MediaWiki\Tests\Maintenance;

use CheckComposerLockUpToDate;

/**
 * @internal Only for use by CheckComposerLockUpToDateTest
 */
class SemiMockedCheckComposerLockUpToDate extends CheckComposerLockUpToDate {

	private string $mockMwInstallPath;

	/**
	 * Set the a mock MW_INSTALL_PATH value for the test.
	 */
	public function setMockMwInstallPath( string $mockMwInstallPath ) {
		$this->mockMwInstallPath = $mockMwInstallPath;
	}

	protected function getMwInstallPath(): string {
		return $this->mockMwInstallPath;
	}
}

/**
 * @covers \CheckComposerLockUpToDate
 * @author Dreamy Jazz
 */
class CheckComposerLockUpToDateTest extends MaintenanceBaseTestCase {

	private const FIXTURE_DIRECTORY = MW_INSTALL_PATH . '/tests/phpunit/data/LockFileChecker';

	public function getMaintenanceClass() {
		return SemiMockedCheckComposerLockUpToDate::class;
	}

	public function testCanExecuteWithoutLocalSettings() {
		$this->assertTrue( $this->maintenance->canExecuteWithoutLocalSettings() );
	}

	public function testWhenNoLockFileFound() {
		// Test that an empty directory as the mediawiki/core install path results in an error.
		$this->expectCallToFatalError();
		$this->expectOutputRegex( '/Could not find composer.lock file/' );
		$testPath = $this->getNewTempDirectory();
		$this->maintenance->setMockMwInstallPath( $testPath );
		$this->maintenance->execute();
	}

	public function testWhenLockFileOkay() {
		// Get example composer.json and composer.lock files and add them to a fake install directory.
		$testPath = $this->getNewTempDirectory();
		copy( self::FIXTURE_DIRECTORY . '/composer-testcase1.json', $testPath . '/composer.json' );
		copy( self::FIXTURE_DIRECTORY . '/composer-testcase1.lock', $testPath . '/composer.lock' );
		$this->maintenance->setMockMwInstallPath( $testPath );
		$this->maintenance->execute();
		$this->expectOutputRegex( '/Your composer.lock file is up to date with current dependencies/' );
	}

	public function testWhenLockFileOutdated() {
		// Get example composer.json and composer.lock files and add them to a fake install directory.
		$testPath = $this->getNewTempDirectory();
		copy( self::FIXTURE_DIRECTORY . '/composer-testcase2.json', $testPath . '/composer.json' );
		copy( self::FIXTURE_DIRECTORY . '/composer-testcase2.lock', $testPath . '/composer.lock' );
		$this->maintenance->setMockMwInstallPath( $testPath );
		// Verify that the maintenance script errors out both indicating what is out of date and also
		// how to fix this.
		$this->expectCallToFatalError();
		$this->expectOutputRegex(
			'/wikimedia\/relpath: 2\.9\.9 installed, 3\.0\.0 required[\s\S]*' .
			'Error: your composer.lock file is not up to date.*' .
			'Run "composer update" to install newer dependencies/'
		);
		$this->maintenance->execute();
	}
}