Skip to content

Commit ff55e2d

Browse files
committed
fix
1 parent 62058f1 commit ff55e2d

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Printers.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct()
1919

2020
public function all()
2121
{
22-
return $this->printers;
22+
return collect($this->printers);
2323
}
2424

2525
public function get($name)
@@ -29,8 +29,12 @@ public function get($name)
2929

3030
protected function buildPrinters()
3131
{
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+
3438
$this->printers = collect(explode("\n", $raw))
3539
->reject(function ($value) {
3640
return empty($value) || stripos($value, 'unknown') !== false || stripos($value, 'looking') !== false;

tests/PrintersTest.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Printing\Printers;
88
use Printing\TestCase;
9-
use Printing\Exceptions\InvalidOptionException;
9+
use Tightenco\Collect\Support\Collection;
1010

1111
class PrintersTest extends TestCase
1212
{
@@ -16,7 +16,7 @@ class PrintersTest extends TestCase
1616
public function it_returns_all_printers()
1717
{
1818
$printers = (new Printers)->all();
19-
$this->assertNotEmpty($printers);
19+
$this->assertTrue($printers instanceof Collection);
2020
}
2121

2222
/**
@@ -25,8 +25,14 @@ public function it_returns_all_printers()
2525
public function it_can_find_a_printer()
2626
{
2727
$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+
}
3137
}
3238
}

0 commit comments

Comments
 (0)