-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathApplicationTest.php
More file actions
78 lines (68 loc) · 2.62 KB
/
Copy pathApplicationTest.php
File metadata and controls
78 lines (68 loc) · 2.62 KB
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
78
<?php
/**
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace Test\Console;
use OC\Console\Application;
use Symfony\Component\Console\Command\Command;
use Test\TestCase;
/**
* A minimal, dependency-free console command used as the "valid" command in
* the resilience test. It must be resolvable both via the DI container
* (\OC::$server->query()) and via `new $command()`.
*/
class ValidStubCommand extends Command {
protected function configure() {
$this->setName('test:valid-stub-command');
}
}
/**
* A fake Symfony application that just records the commands it is asked to
* register, so the test can assert which commands survived loading without
* needing a real Symfony Application instance.
*/
class RecordingApplication {
public $registered = [];
public function addCommand($command) {
$this->registered[] = $command;
}
}
/**
* @group DB
*
* Requires the ownCloud test bootstrap (\OC::$server must be available for the
* logger and the DI container). It does NOT require a database connection, but
* is tagged @group DB so it only runs in the bootstrapped suite where
* \OC::$server is wired up.
*/
class ApplicationTest extends TestCase {
/**
* Core guarantee for issue #33895: a single broken app-provided command
* (here an unknown/non-existent class name, which today reaches the
* `throw new \Exception(...)` path) must NOT abort loading or kill occ.
* The broken command is skipped (and logged) while every other valid
* command is still registered.
*/
public function testBrokenCommandDoesNotAbortLoading() {
// Build an Application without running its constructor so we don't need
// a real Symfony Application / OC_Defaults / version string here.
$reflection = new \ReflectionClass(Application::class);
$application = $reflection->newInstanceWithoutConstructor();
// Inject a fake Symfony application that just records added commands.
$symfonyApplication = new RecordingApplication();
self::invokePrivate($application, 'application', [$symfonyApplication]);
$commands = [
// Broken: unknown class -> throws inside the loop. Must be skipped.
'OC\\This\\Command\\Does\\Not\\Exist',
// Valid: must still be registered despite the broken one above.
ValidStubCommand::class,
];
// The method must NOT throw despite the broken command.
self::invokePrivate($application, 'loadCommandsFromInfoXml', [$commands]);
// The valid command was still registered.
$this->assertCount(1, $symfonyApplication->registered);
$this->assertInstanceOf(ValidStubCommand::class, $symfonyApplication->registered[0]);
}
}