// Test if "bar1" command throw a "CommandNotFoundException" and does not contain
// "foo:bar" as alternative because "bar1" is too far from "foo:bar"
try { $application->
find($commandName = 'bar1'
);
$this->
fail('->find() throws a CommandNotFoundException if command does not exist'
);
} catch (\Exception
$e) { $this->
assertInstanceOf(CommandNotFoundException::
class,
$e, '->find() throws a CommandNotFoundException if command does not exist'
);
$this->
assertSame(['afoobar1', 'foo:bar1'
],
$e->
getAlternatives());
$this->
assertMatchesRegularExpression(sprintf('/Command "%s" is not defined./',
$commandName),
$e->
getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'
);
$this->
assertMatchesRegularExpression('/afoobar1/',
$e->
getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"'
);
$this->
assertMatchesRegularExpression('/foo:bar1/',
$e->
getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"'
);
$this->
assertDoesNotMatchRegularExpression('/foo:bar(?!1)/',
$e->
getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative'
);
} } public function testFindAlternativeCommandsWithAnAlias() { $fooCommand =
new \
FooCommand();
$fooCommand->
setAliases(['foo2'
]);
$application =
new Application();
$application->
setCommandLoader(new FactoryCommandLoader([ 'foo3' =>
static fn () =>
$fooCommand,
]));