@@ -55,6 +55,24 @@ public function inputCommandToOutputFilesProvider()
55
55
return array_map (null , glob ($ baseDir .'/command/command_*.php ' ), glob ($ baseDir .'/output/output_*.txt ' ));
56
56
}
57
57
58
+ /**
59
+ * @dataProvider inputInteractiveCommandToOutputFilesProvider
60
+ */
61
+ public function testInteractiveOutputs ($ inputCommandFilepath , $ outputFilepath )
62
+ {
63
+ $ code = require $ inputCommandFilepath ;
64
+ $ this ->command ->setCode ($ code );
65
+ $ this ->tester ->execute (array ());
66
+ $ this ->assertStringEqualsFile ($ outputFilepath , $ this ->tester ->getDisplay (true ));
67
+ }
68
+
69
+ public function inputInteractiveCommandToOutputFilesProvider ()
70
+ {
71
+ $ baseDir = __DIR__ .'/../Fixtures/Style/SymfonyStyle ' ;
72
+
73
+ return array_map (null , glob ($ baseDir .'/command/interactive_command_*.php ' ), glob ($ baseDir .'/output/interactive_output_*.txt ' ));
74
+ }
75
+
58
76
public function testLongWordsBlockWrapping ()
59
77
{
60
78
$ word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygovgollhjvhvljfezefeqifzeiqgiqzhrsdgihqzridghqridghqirshdghdghieridgheirhsdgehrsdvhqrsidhqshdgihrsidvqhneriqsdvjzergetsrfhgrstsfhsetsfhesrhdgtesfhbzrtfbrztvetbsdfbrsdfbrn ' ;
@@ -70,6 +88,28 @@ public function testLongWordsBlockWrapping()
70
88
$ expectedCount = (int ) ceil ($ wordLength / ($ maxLineLength )) + (int ) ($ wordLength > $ maxLineLength - 5 );
71
89
$ this ->assertSame ($ expectedCount , substr_count ($ this ->tester ->getDisplay (true ), ' § ' ));
72
90
}
91
+
92
+ public function testSetInputStream ()
93
+ {
94
+ $ command = $ this ->command ;
95
+ $ inputs = ['Foo ' , 'Bar ' , 'Baz ' ];
96
+ $ stream = fopen ('php://memory ' , 'r+ ' , false );
97
+
98
+ fputs ($ stream , implode (PHP_EOL , $ inputs ));
99
+ rewind ($ stream );
100
+
101
+ $ command ->setCode (function ($ input , $ output ) use ($ command , $ stream ) {
102
+ $ sfStyle = new SymfonyStyle ($ input , $ output );
103
+
104
+ $ sfStyle ->setInputStream ($ stream );
105
+ $ sfStyle ->ask ('What \'s your name? ' );
106
+ $ sfStyle ->ask ('How are you? ' );
107
+ $ sfStyle ->ask ('Where do you come from? ' );
108
+ });
109
+
110
+ $ this ->tester ->execute (array ());
111
+ $ this ->assertSame (0 , $ this ->tester ->getStatusCode ());
112
+ }
73
113
}
74
114
75
115
/**
0 commit comments