| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use CheckComposerLockUpToDate; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class SemiMockedCheckComposerLockUpToDate extends CheckComposerLockUpToDate { |
| 11 |
|
| 12 |
private string $mockMwInstallPath; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public function setMockMwInstallPath( string $mockMwInstallPath ) { |
| 18 |
$this->mockMwInstallPath = $mockMwInstallPath; |
| 19 |
} |
| 20 |
|
| 21 |
protected function getMwInstallPath(): string { |
| 22 |
return $this->mockMwInstallPath; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class CheckComposerLockUpToDateTest extends MaintenanceBaseTestCase { |
| 31 |
|
| 32 |
private const FIXTURE_DIRECTORY = MW_INSTALL_PATH . '/tests/phpunit/data/LockFileChecker'; |
| 33 |
|
| 34 |
public function getMaintenanceClass() { |
| 35 |
return SemiMockedCheckComposerLockUpToDate::class; |
| 36 |
} |
| 37 |
|
| 38 |
public function testCanExecuteWithoutLocalSettings() { |
| 39 |
$this->assertTrue( $this->maintenance->canExecuteWithoutLocalSettings() ); |
| 40 |
} |
| 41 |
|
| 42 |
public function testWhenNoLockFileFound() { |
| 43 |
|
| 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(); |
| 49 |
} |
| 50 |
|
| 51 |
public function testWhenLockFileOkay() { |
| 52 |
|
| 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/' ); |
| 59 |
} |
| 60 |
|
| 61 |
public function testWhenLockFileOutdated() { |
| 62 |
|
| 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 |
|
| 68 |
|
| 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/' |
| 74 |
); |
| 75 |
$this->maintenance->execute(); |
| 76 |
} |
| 77 |
} |