aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/generateRandomImages.php
blob: 4d85862b3548efc56258025f72e24e2b2d703942 (plain) (blame)
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
<?php

namespace MediaWiki\Tests\Api;

use Maintenance;

/**
 * Bootstrapping for test image file generation
 *
 * @file
 */

// Start up MediaWiki in command-line mode
require_once __DIR__ . "/../../../../maintenance/Maintenance.php";
require_once __DIR__ . "/RandomImageGenerator.php";

class GenerateRandomImages extends Maintenance {

	public function getDbType() {
		return Maintenance::DB_NONE;
	}

	public function execute() {
		$getOptSpec = [
			'minWidth::',
			'maxWidth::',
			'minHeight::',
			'maxHeight::',
			'shapesToDraw::',
			'shape::',

			'number::',
			'format::'
		];
		$options = getopt( null, $getOptSpec );

		$format = $options['format'] ?? 'jpg';
		unset( $options['format'] );

		$number = (int)( $options['number'] ?? 10 );
		unset( $options['number'] );

		$randomImageGenerator = new RandomImageGenerator( $options );
		$randomImageGenerator->writeImages( $number, $format );
	}
}

$maintClass = GenerateRandomImages::class;
require_once RUN_MAINTENANCE_IF_MAIN;