Debian Codegraph @

tests/phpunit/unit/includes/shell/CommandFactoryTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Shell\Command;
4 use MediaWiki\Shell\CommandFactory;
5 use MediaWiki\Shell\ShellboxClientFactory;
6 use Psr\Log\NullLogger;
7 use Wikimedia\TestingAccessWrapper;
8
9 /**
10 * @group Shell
11 */
12 class CommandFactoryTest extends MediaWikiUnitTestCase {
13
14 /**
15 * @covers \MediaWiki\Shell\CommandFactory::create
16 */
17 public function testCreate() {
18 $logger = new NullLogger();
19 $cgroup = '/sys/fs/cgroup/memory/mygroup';
20 $limits = [
21 'filesize' => 1000,
22 'memory' => 1000,
23 'time' => 30,
24 'walltime' => 40,
25 ];
26
27 $clientFactory = new class extends ShellboxClientFactory {
28 public function __construct() {
29 }
30
31 public function isEnabled( ?string $service = null ): bool {
32 return false;
33 }
34
35 public function getClient( array $options = [] ) {
36 throw new \LogicException( 'unreachable' );
37 }
38 };
39
40 $factory = new CommandFactory( $clientFactory,
41 $limits, $cgroup, false );
42 $factory->setLogger( $logger );
43 $factory->logStderr();
44 $command = $factory->create();
45 $this->assertInstanceOf( Command::class, $command );
46 $wrapper = TestingAccessWrapper::newFromObject( $command );
47 $this->assertSame( $logger, $wrapper->logger );
48 $this->assertSame( $limits['filesize'] * 1024, $command->getFileSizeLimit() );
49 $this->assertSame( $limits['memory'] * 1024, $command->getMemoryLimit() );
50 $this->assertSame( $limits['time'], $command->getCpuTimeLimit() );
51 $this->assertSame( $limits['walltime'], $command->getWallTimeLimit() );
52 $this->assertTrue( $command->getLogStderr() );
53 }
54 }