@@ -32,6 +32,7 @@ public static function setUpBeforeClass()
32
32
{
33
33
self ::$ fixturesPath = __DIR__ .'/../Fixtures/ ' ;
34
34
require_once self ::$ fixturesPath .'/TestCommand.php ' ;
35
+ require_once self ::$ fixturesPath .'/TestCommandWithSeparateConfiguration.php ' ;
35
36
}
36
37
37
38
public function testConstructor ()
@@ -336,4 +337,96 @@ public function testInconsistentDefinition()
336
337
{
337
338
new Command ('foo ' , new CommandConfiguration ('bar ' ));
338
339
}
340
+
341
+ public function testThatCommandIsNotLoaded ()
342
+ {
343
+ $ resolver = $ this ->getMockForAbstractClass ('Symfony\Component\Console\Command\Resolver\CommandResolverInterface ' );
344
+
345
+ $ resolver
346
+ ->expects ($ this ->never ())
347
+ ->method ('resolve ' )
348
+ ;
349
+
350
+ $ command = Command::registerLazyLoaded (CommandConfiguration::create ('foo:bar ' ), $ resolver );
351
+
352
+ $ this ->assertSame ('foo:bar ' , $ command ->getName ());
353
+ }
354
+
355
+ public function testCommandWithSeparateConfiguration ()
356
+ {
357
+ $ configuration =
358
+ CommandConfiguration::create ('foo:baz ' )
359
+ ->withDescription ('foo description ' )
360
+ ->withDefinition (
361
+ new InputDefinition (array (
362
+ new InputArgument ('name ' )
363
+ ))
364
+ );
365
+
366
+ $ resolver = $ this ->getMockForAbstractClass ('Symfony\Component\Console\Command\Resolver\CommandResolverInterface ' );
367
+
368
+ $ resolver
369
+ ->expects ($ this ->once ())
370
+ ->method ('resolve ' )
371
+ ->with ('foo:baz ' )
372
+ ->will ($ this ->returnCallback (function () {
373
+ return new \TestCommandWithSeparateConfiguration ();
374
+ }))
375
+ ;
376
+
377
+ $ command = Command::registerLazyLoaded ($ configuration , $ resolver );
378
+ $ command ->setApplication (new Application ());
379
+
380
+ $ tester = new CommandTester ($ command );
381
+ $ tester ->execute (array ('name ' => 'Alice ' ));
382
+
383
+ $ this ->assertSame (
384
+ 'interact called ' .PHP_EOL .'Hello, Alice ' .PHP_EOL .'Command name: foo:baz ' .PHP_EOL .'Description foo description ' .PHP_EOL ,
385
+ $ tester ->getDisplay ()
386
+ );
387
+ }
388
+
389
+ public function testThatResolverIsAllowedToReturnCallable ()
390
+ {
391
+ $ resolver = $ this ->getMockForAbstractClass ('Symfony\Component\Console\Command\Resolver\CommandResolverInterface ' );
392
+
393
+ $ resolver
394
+ ->expects ($ this ->once ())
395
+ ->method ('resolve ' )
396
+ ->will ($ this ->returnValue (function (InputInterface $ input , OutputInterface $ output ) {
397
+ $ output ->writeln ('Hello, world ' );
398
+
399
+ return 42 ;
400
+ }))
401
+ ;
402
+
403
+ $ command = Command::registerLazyLoaded (CommandConfiguration::create ('foo:bar ' ), $ resolver );
404
+
405
+ $ tester = new CommandTester ($ command );
406
+ $ tester ->execute (array (), array ());
407
+
408
+ $ this ->assertSame ('Hello, world ' .PHP_EOL , $ tester ->getDisplay ());
409
+ $ this ->assertSame (42 , $ tester ->getStatusCode ());
410
+ }
411
+
412
+ /**
413
+ * @expectedException \RuntimeException
414
+ * @expectedExceptionMessage Command or callable was expected, string given
415
+ */
416
+ public function testInvalidResolver ()
417
+ {
418
+ $ resolver = $ this ->getMockForAbstractClass ('Symfony\Component\Console\Command\Resolver\CommandResolverInterface ' );
419
+
420
+ $ resolver
421
+ ->expects ($ this ->once ())
422
+ ->method ('resolve ' )
423
+ ->with ('foo:bar ' )
424
+ ->will ($ this ->returnValue ('foo ' ))
425
+ ;
426
+
427
+ $ command = Command::registerLazyLoaded (CommandConfiguration::create ('foo:bar ' ), $ resolver );
428
+
429
+ $ tester = new CommandTester ($ command );
430
+ $ tester ->execute (array ());
431
+ }
339
432
}
0 commit comments