|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the CLI-SYNTAX package. |
| 5 | + * |
| 6 | + * (c) Jitendra Adhikari <jiten.adhikary@gmail.com> |
| 7 | + * <https://github.com/adhocore> |
| 8 | + * |
| 9 | + * Licensed under MIT license. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Ahc\CliSyntax\Test; |
| 13 | + |
| 14 | +use Ahc\CliSyntax\Exporter; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +class ExporterTest extends TestCase |
| 18 | +{ |
| 19 | + protected $out = __DIR__ . '/export.png'; |
| 20 | + protected $ref = __DIR__ . '/../example.png'; |
| 21 | + |
| 22 | + public function setUp() |
| 23 | + { |
| 24 | + if (\is_file($this->out)) { |
| 25 | + @unlink($this->out); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + public function testExport() |
| 30 | + { |
| 31 | + Exporter::for(__DIR__ . '/../example.php')->export($this->out); |
| 32 | + |
| 33 | + $this->assertFileExists($this->out, 'It should exports to given output path'); |
| 34 | + $this->assertSame(\file_get_contents($this->ref), \file_get_contents($this->out)); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @expectedException \InvalidArgumentException |
| 39 | + * @expectedExceptionMessage The output path doesnot exist. |
| 40 | + */ |
| 41 | + public function testExportThrows() |
| 42 | + { |
| 43 | + Exporter::for(__DIR__ . '/../example.php')->export(__DIR__ . '/no/dir/file.png'); |
| 44 | + } |
| 45 | + |
| 46 | + public function testSetOptions() |
| 47 | + { |
| 48 | + Exporter::for(__DIR__ . '/../example.php')->export($this->out, ['font' => 'ubuntu', 'size' => 16]); |
| 49 | + |
| 50 | + $this->assertSame(\file_get_contents($this->ref), \file_get_contents($this->out)); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @expectedException \InvalidArgumentException |
| 55 | + * @expectedExceptionMessage The given font doesnot exist. |
| 56 | + */ |
| 57 | + public function testSetOptionsThrows() |
| 58 | + { |
| 59 | + Exporter::for(__DIR__ . '/../example.php')->export($this->out, ['font' => 'invalid']); |
| 60 | + } |
| 61 | +} |
0 commit comments