Completed
Push — master ( 2308db...df4497 )
by Massimiliano
03:56
created

testWritelnListPackage()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Bowerphp package.
5
 *
6
 * (c) Mauro D'Alatri <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bowerphp\Test\Output;
13
14
use Bowerphp\Output\BowerphpConsoleOutput;
15
use Mockery;
16
use PHPUnit\Framework\TestCase;
17
18
class BowerphpConsoleOutputTest extends TestCase
19
{
20
    protected function tearDown()
21
    {
22
        // this is to make Mockery assertion count as PHPUnit assertion, avoiding "risky"
23
        if (!is_null($container = Mockery::getContainer())) {
24
            $this->addToAssertionCount($container->mockery_getExpectationCount());
25
        }
26
        Mockery::close();
27
    }
28
29
    public function testWritelnInfoPackage()
30
    {
31
        $output = Mockery::mock('Symfony\Component\Console\Output\OutputInterface');
32
        $package = Mockery::mock('Bowerphp\Package\PackageInterface');
33
34
        $package
35
            ->shouldReceive('getVersion')->andReturn('2.1')
36
            ->shouldReceive('getName')->andReturn('jquery')
37
            ->shouldReceive('getRequiredVersion')->andReturn('2.1')
38
        ;
39
40
        $output
41
            ->shouldReceive('writeln')->with('bower <info>jquery#2.1           </info> <fg=cyan>          </fg=cyan> ')
42
        ;
43
44
        $bConsoleOutput = new BowerphpConsoleOutput($output);
45
        $bConsoleOutput->writelnInfoPackage($package);
46
    }
47
48
    public function testWritelnInstalledPackage()
49
    {
50
        $output = Mockery::mock('Symfony\Component\Console\Output\OutputInterface');
51
        $package = Mockery::mock('Bowerphp\Package\PackageInterface');
52
53
        $package
54
            ->shouldReceive('getVersion')->andReturn('2.1')
55
            ->shouldReceive('getName')->andReturn('jquery')
56
        ;
57
58
        $output
59
            ->shouldReceive('writeln')->with('bower <info>jquery#2.1           </info> <fg=cyan>   install</fg=cyan>')
60
        ;
61
62
        $bConsoleOutput = new BowerphpConsoleOutput($output);
63
        $bConsoleOutput->writelnInstalledPackage($package);
64
    }
65
66
    public function testWritelnNoBowerJsonFile()
67
    {
68
        $output = Mockery::mock('Symfony\Component\Console\Output\OutputInterface');
69
70
        $output
71
            ->shouldReceive('writeln')->with('bower <info>                     </info> <fg=yellow>   no-json</fg=yellow> No bower.json file to save to, use bower init to create one')
72
        ;
73
74
        $bConsoleOutput = new BowerphpConsoleOutput($output);
75
        $bConsoleOutput->writelnNoBowerJsonFile();
76
    }
77
78
    public function testWritelnJson()
79
    {
80
        $output = Mockery::mock('Symfony\Component\Console\Output\OutputInterface');
81
82
        $output
83
            ->shouldReceive('writeln')->with('{<info>name</info>: <fg=cyan>\'foo\'</fg=cyan>}')
84
        ;
85
86
        $bConsoleOutput = new BowerphpConsoleOutput($output);
87
        $bConsoleOutput->writelnJson('{"name": "foo"}');
88
    }
89
90
    public function testWritelnJsonText()
91
    {
92
        $output = Mockery::mock('Symfony\Component\Console\Output\OutputInterface');
93
94
        $output
95
            ->shouldReceive('writeln')->with('<fg=cyan>"name"</fg=cyan>')
96
        ;
97
98
        $bConsoleOutput = new BowerphpConsoleOutput($output);
99
        $bConsoleOutput->writelnJsonText('name');
100
    }
101
102
    public function testWritelnListPackage()
103
    {
104
        $output = Mockery::mock('Symfony\Component\Console\Output\OutputInterface');
105
        $package = Mockery::mock('Bowerphp\Package\PackageInterface');
106
        $bowerphp = Mockery::mock('Bowerphp\Bowerphp');
107
108
        $package
109
            ->shouldReceive('getName')->andReturn('jquery', 'fonts.css')
110
            ->shouldReceive('getVersion')->andReturn('1.2', '1.0.0')
111
        ;
112
113
        $bowerphp
114
            ->shouldReceive('isPackageExtraneous')->with($package)->andReturn(true, false)
115
        ;
116
117
        $output
118
            ->shouldReceive('writeln')->with('jquery#1.2<info> extraneous</info>')
119
            ->shouldReceive('writeln')->with('fonts.css#1.0.0<info></info>')
120
        ;
121
122
        $bConsoleOutput = new BowerphpConsoleOutput($output);
123
        $bConsoleOutput->writelnListPackage($package, $bowerphp);
124
        $bConsoleOutput->writelnListPackage($package, $bowerphp);
125
    }
126
127
    public function testWritelnSearchOrLookup()
128
    {
129
        $output = Mockery::mock('Symfony\Component\Console\Output\OutputInterface');
130
131
        $output
132
            ->shouldReceive('writeln')->with('<fg=cyan>foo</fg=cyan> bar')
133
            ->shouldReceive('writeln')->with('   <fg=cyan>foo</fg=cyan> bar')
134
        ;
135
136
        $bConsoleOutput = new BowerphpConsoleOutput($output);
137
        $bConsoleOutput->writelnSearchOrLookup('foo', 'bar');
138
        $bConsoleOutput->writelnSearchOrLookup('foo', 'bar', 3);
139
    }
140
}
141