File tree 2 files changed +18
-8
lines changed
2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public function __construct()
19
19
20
20
public function all ()
21
21
{
22
- return $ this ->printers ;
22
+ return collect ( $ this ->printers ) ;
23
23
}
24
24
25
25
public function get ($ name )
@@ -29,8 +29,12 @@ public function get($name)
29
29
30
30
protected function buildPrinters ()
31
31
{
32
- $ raw = shell_exec ("lpstat -p " );
33
-
32
+ $ raw = shell_exec ("lpstat -p & > /dev/null " );
33
+
34
+ if (gettype ($ raw ) === 'NULL ' ) {
35
+ return $ this ;
36
+ }
37
+
34
38
$ this ->printers = collect (explode ("\n" , $ raw ))
35
39
->reject (function ($ value ) {
36
40
return empty ($ value ) || stripos ($ value , 'unknown ' ) !== false || stripos ($ value , 'looking ' ) !== false ;
Original file line number Diff line number Diff line change 6
6
7
7
use Printing \Printers ;
8
8
use Printing \TestCase ;
9
- use Printing \ Exceptions \ InvalidOptionException ;
9
+ use Tightenco \ Collect \ Support \ Collection ;
10
10
11
11
class PrintersTest extends TestCase
12
12
{
@@ -16,7 +16,7 @@ class PrintersTest extends TestCase
16
16
public function it_returns_all_printers ()
17
17
{
18
18
$ printers = (new Printers )->all ();
19
- $ this ->assertNotEmpty ($ printers );
19
+ $ this ->assertTrue ($ printers instanceof Collection );
20
20
}
21
21
22
22
/**
@@ -25,8 +25,14 @@ public function it_returns_all_printers()
25
25
public function it_can_find_a_printer ()
26
26
{
27
27
$ class = new Printers ;
28
- $ name = $ class ->all ()->first ()['name ' ];
29
-
30
- $ this ->assertNotEmpty ($ class ->get ($ name ));
28
+ $ first = $ class ->all ()->first ();
29
+
30
+ if (is_null ($ first )) {
31
+ $ this ->assertEmpty ($ class ->all ()->toArray ());
32
+ } else {
33
+ $ name = $ first ['name ' ];
34
+
35
+ $ this ->assertNotEmpty ($ class ->get ($ name ));
36
+ }
31
37
}
32
38
}
You can’t perform that action at this time.
0 commit comments