12
12
namespace Symfony \Component \VarDumper \Tests \Dumper ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Console \Command \Command ;
16
+ use Symfony \Component \Console \Input \InputInterface ;
17
+ use Symfony \Component \Console \Input \StringInput ;
18
+ use Symfony \Component \Console \Output \ConsoleOutput ;
19
+ use Symfony \Component \Console \Output \OutputInterface ;
15
20
use Symfony \Component \VarDumper \Cloner \VarCloner ;
16
21
use Symfony \Component \VarDumper \Dumper \CliDumper ;
17
22
use Symfony \Component \VarDumper \Dumper \ContextProvider \SourceContextProvider ;
@@ -28,15 +33,14 @@ public function testContextualizedCliDumper(): void
28
33
$ wrappedDumper ->setColors (true );
29
34
30
35
$ var = 'example ' ;
31
- $ href = sprintf ('file://%s#L%s ' , __FILE__ , 37 );
36
+ $ href = sprintf ('file://%s#L%s ' , __FILE__ , 42 );
32
37
$ dumper = new ContextualizedDumper ($ wrappedDumper , [new SourceContextProvider ()]);
33
38
$ cloner = new VarCloner ();
34
39
$ data = $ cloner ->cloneVar ($ var );
35
40
36
41
ob_start ();
37
42
$ dumper ->dump ($ data );
38
- $ out = ob_get_clean ();
39
- $ out = preg_replace ('/[ \t]+$/m ' , '' , $ out );
43
+ $ out = preg_replace ('/[ \t]+$/m ' , '' , ob_get_clean ());
40
44
41
45
$ this ->assertStringMatchesFormat (
42
46
<<<EOTXT
@@ -49,14 +53,27 @@ public function testContextualizedCliDumper(): void
49
53
50
54
public function testContextualizedCliDumperInCommand (): void
51
55
{
56
+ $ command = new class () extends Command {
57
+ public function execute (InputInterface $ input , OutputInterface $ output )
58
+ {
59
+ $ var = 'example ' ;
60
+ $ wrappedDumper = new CliDumper ('php://output ' );
61
+ $ wrappedDumper ->setColors (true );
62
+
63
+ $ dumper = new ContextualizedDumper ($ wrappedDumper , [new SourceContextProvider ()]);
64
+ $ cloner = new VarCloner ();
65
+ $ data = $ cloner ->cloneVar ($ var );
66
+
67
+ $ dumper ->dump ($ data );
68
+ }
69
+ };
70
+
52
71
$ var = 'example ' ;
53
- $ href = 'file://%s/Tests/Fixtures/dumb-console.php#L22 ' ;
72
+ $ href = sprintf ( 'file://%s#L%s ' , __FILE__ , 67 ) ;
54
73
55
- $ dumbConsole = __DIR__ .'/../Fixtures/dumb-console.php ' ;
56
- $ sh = [];
57
- exec ("php {$ dumbConsole }" , $ sh );
58
- $ out = implode (PHP_EOL , $ sh );
59
- $ out = preg_replace ('/[ \t]+$/m ' , '' , $ out );
74
+ ob_start ();
75
+ $ command ->run (new StringInput ('' ), new ConsoleOutput ());
76
+ $ out = preg_replace ('/[ \t]+$/m ' , '' , ob_get_clean ());
60
77
61
78
$ this ->assertStringMatchesFormat (
62
79
<<<EOTXT
0 commit comments