9
9
use GrumPHP \Task \TaskInterface ;
10
10
use PhpSpec \ObjectBehavior ;
11
11
use Prophecy \Argument ;
12
+ use Symfony \Component \Console \Formatter \OutputFormatter ;
12
13
use Symfony \Component \Console \Helper \ProgressBar ;
13
14
use Symfony \Component \Console \Output \OutputInterface ;
14
15
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
15
16
16
17
class ProgressSubscriberSpec extends ObjectBehavior
17
18
{
18
- function let (OutputInterface $ output, ProgressBar $ progressBar )
19
+ function let (OutputInterface $ output )
19
20
{
21
+ $ output ->getVerbosity ()->willReturn (OutputInterface::VERBOSITY_NORMAL );
22
+ $ output ->isDecorated ()->willReturn (false );
23
+ $ output ->getFormatter ()->willReturn (new OutputFormatter ());
24
+
25
+ $ progressBar = new ProgressBar ($ output ->getWrappedObject ());
26
+
20
27
$ this ->beConstructedWith ($ output , $ progressBar );
21
28
}
22
29
@@ -35,53 +42,42 @@ function it_should_subscribe_to_events()
35
42
$ this ->getSubscribedEvents ()->shouldBeArray ();
36
43
}
37
44
38
- function it_starts_progress (ProgressBar $ progressBar , RunnerEvent $ event , TasksCollection $ tasks )
45
+ function it_starts_progress (OutputInterface $ output , RunnerEvent $ event , TasksCollection $ tasks )
39
46
{
40
47
$ tasks ->count ()->willReturn (2 );
41
48
$ event ->getTasks ()->willReturn ($ tasks );
42
49
43
- $ progressBar ->setFormat (Argument::type ('string ' ))->shouldBeCalled ();
44
- $ progressBar ->setOverwrite (false )->shouldBeCalled ();
45
- $ progressBar ->setMessage (Argument::type ('string ' ))->shouldBeCalled ();
46
- $ progressBar ->start (2 )->shouldBeCalled ();
50
+ $ output ->write ('<fg=yellow>GrumPHP is sniffing your code!</fg=yellow> ' )->shouldBeCalled ();
47
51
48
52
$ this ->startProgress ($ event );
49
53
}
50
54
51
- function it_should_advance_progress (ProgressBar $ progressBar , TaskEvent $ event , TaskInterface $ task )
55
+ function it_should_advance_progress (OutputInterface $ output , TaskEvent $ event , TaskInterface $ task )
52
56
{
57
+ $ this ->beConstructedWith ($ output , $ progress = new ProgressBar ($ output ->getWrappedObject (), 2 ));
58
+
53
59
$ event ->getTask ()->willReturn ($ task );
54
60
55
- $ progressBar ->setFormat (Argument::type ('string ' ))->shouldBeCalled ();
56
- $ progressBar ->setOverwrite (false )->shouldBeCalled ();
57
- $ progressBar ->setMessage (Argument::type ('string ' ))->shouldBeCalled ();
58
- $ progressBar ->advance ()->shouldBeCalled ();
61
+ $ output ->writeln ('' )->shouldBeCalled ();
62
+ $ output ->write (Argument::containingString ('Running task ' ))->shouldBeCalled ();
63
+ $ output ->write (Argument::containingString ('1/2 ' ))->shouldBeCalled ();
59
64
60
65
$ this ->advanceProgress ($ event );
61
66
}
62
67
63
- function it_finishes_progress (OutputInterface $ output , ProgressBar $ progressBar , RunnerEvent $ event )
68
+ function it_finishes_progress (OutputInterface $ output , RunnerEvent $ event )
64
69
{
65
- $ progressBar ->getProgress ()->willReturn (1 );
66
- $ progressBar ->getMaxSteps ()->willReturn (1 );
70
+ $ this ->beConstructedWith ($ output , $ progress = new ProgressBar ($ output ->getWrappedObject (), 0 ));
67
71
68
- $ progressBar ->setOverwrite (false )->shouldBeCalled ();
69
- $ progressBar ->finish ()->shouldBeCalled ();
70
72
$ output ->writeln ('' )->shouldBeCalled ();
71
73
72
74
$ this ->finishProgress ($ event );
73
75
}
74
76
75
- function it_finishes_progress_early (OutputInterface $ output , ProgressBar $ progressBar , RunnerEvent $ event )
77
+ function it_finishes_progress_early (OutputInterface $ output , RunnerEvent $ event )
76
78
{
77
- $ progressBar ->getProgress ()->willReturn (1 );
78
- $ progressBar ->getMaxSteps ()->willReturn (2 );
79
-
80
- $ progressBar ->setFormat (Argument::type ('string ' ))->shouldBeCalled ();
81
- $ progressBar ->setMessage (Argument::type ('string ' ))->shouldBeCalled ();
82
-
83
- $ progressBar ->setOverwrite (false )->shouldBeCalled ();
84
- $ progressBar ->finish ()->shouldBeCalled ();
79
+ $ this ->beConstructedWith ($ output , $ progress = new ProgressBar ($ output ->getWrappedObject (), 2 ));
80
+ $ output ->write ('<fg=red>Aborted ...</fg=red> ' )->shouldBeCalled ();
85
81
$ output ->writeln ('' )->shouldBeCalled ();
86
82
87
83
$ this ->finishProgress ($ event );
0 commit comments