|
4 | 4 |
|
5 | 5 | use Mockery;
|
6 | 6 | use Illuminate\Support\Facades\Storage;
|
| 7 | +use Mockery\MockInterface; |
7 | 8 | use ZeroDaHero\LaravelWorkflow\Commands\WorkflowDumpCommand;
|
8 | 9 |
|
9 | 10 | class WorkflowDumpCommandTest extends BaseWorkflowTestCase
|
10 | 11 | {
|
11 | 12 | public function testShouldThrowExceptionForUndefinedWorkflow()
|
12 | 13 | {
|
13 |
| - $command = Mockery::mock(WorkflowDumpCommand::class) |
14 |
| - ->makePartial() |
15 |
| - ->shouldReceive('argument') |
16 |
| - ->with('workflow') |
17 |
| - ->andReturn('fake') |
18 |
| - ->shouldReceive('option') |
19 |
| - ->with('format') |
20 |
| - ->andReturn('png') |
21 |
| - ->shouldReceive('option') |
22 |
| - ->with('class') |
23 |
| - ->andReturn('Tests\Fixtures\TestObject') |
24 |
| - ->shouldReceive('option') |
25 |
| - ->with('disk') |
26 |
| - ->andReturn('local') |
27 |
| - ->shouldReceive('option') |
28 |
| - ->with('path') |
29 |
| - ->andReturn('/') |
30 |
| - ->getMock(); |
| 14 | + $command = $this->getMock(workflow: 'fake'); |
31 | 15 |
|
32 | 16 | $this->expectException(\Exception::class);
|
33 | 17 | $this->expectExceptionMessage('Workflow fake is not configured.');
|
| 18 | + |
34 | 19 | $command->handle();
|
35 | 20 | }
|
36 | 21 |
|
37 | 22 | public function testShouldThrowExceptionForUndefinedClass()
|
38 | 23 | {
|
39 |
| - $command = Mockery::mock(WorkflowDumpCommand::class) |
40 |
| - ->makePartial() |
41 |
| - ->shouldReceive('argument') |
42 |
| - ->with('workflow') |
43 |
| - ->andReturn('straight') |
44 |
| - ->shouldReceive('option') |
45 |
| - ->with('format') |
46 |
| - ->andReturn('png') |
47 |
| - ->shouldReceive('option') |
48 |
| - ->with('class') |
49 |
| - ->andReturn('Tests\Fixtures\FakeObject') |
50 |
| - ->shouldReceive('option') |
51 |
| - ->with('disk') |
52 |
| - ->andReturn('local') |
53 |
| - ->shouldReceive('option') |
54 |
| - ->with('path') |
55 |
| - ->andReturn('/') |
56 |
| - ->getMock(); |
| 24 | + $command = $this->getMock(class: 'Tests\Fixtures\FakeObject'); |
57 | 25 |
|
58 | 26 | $this->expectException(\Exception::class);
|
59 | 27 | $this->expectExceptionMessage('Workflow straight has no support for' .
|
60 | 28 | ' class Tests\Fixtures\FakeObject. Please specify a valid support' .
|
61 | 29 | ' class with the --class option.');
|
| 30 | + |
62 | 31 | $command->handle();
|
63 | 32 | }
|
64 | 33 |
|
65 | 34 | public function testWorkflowCommand()
|
66 | 35 | {
|
67 | 36 | $optionalPath = '/my/path';
|
68 |
| - $disk = 'public'; |
| 37 | + $disk = 'public'; |
69 | 38 |
|
70 | 39 | Storage::fake($disk);
|
71 | 40 |
|
72 | 41 | if (Storage::disk($disk)->exists($optionalPath . '/straight.png')) {
|
73 | 42 | Storage::disk($disk)->delete($optionalPath . '/straight.png');
|
74 | 43 | }
|
75 | 44 |
|
76 |
| - $command = Mockery::mock(WorkflowDumpCommand::class) |
| 45 | + $command = $this->getMock(disk: $disk, path: $optionalPath); |
| 46 | + $command->handle(); |
| 47 | + |
| 48 | + Storage::disk($disk)->assertExists($optionalPath . '/straight.png'); |
| 49 | + } |
| 50 | + |
| 51 | + public function testWorkflowCommandWithMetadata() |
| 52 | + { |
| 53 | + $disk = 'public'; |
| 54 | + |
| 55 | + Storage::fake($disk); |
| 56 | + |
| 57 | + $command = $this->getMock( |
| 58 | + disk: $disk, |
| 59 | + format: 'svg', |
| 60 | + withMetadata: true, |
| 61 | + ); |
| 62 | + |
| 63 | + $command->handle(); |
| 64 | + |
| 65 | + Storage::disk($disk)->assertExists('straight.svg'); |
| 66 | + $svg_file = Storage::disk($disk)->get('straight.svg'); |
| 67 | + $this->assertStringContainsString('metadata_place', $svg_file); |
| 68 | + $this->assertStringContainsString('metadata_exists', $svg_file); |
| 69 | + } |
| 70 | + |
| 71 | + public function testWorkflowCommandWithoutMetadata() |
| 72 | + { |
| 73 | + $disk = 'public'; |
| 74 | + |
| 75 | + Storage::fake($disk); |
| 76 | + |
| 77 | + $command = $this->getMock( |
| 78 | + disk: $disk, |
| 79 | + format: 'svg', |
| 80 | + withMetadata: false, |
| 81 | + ); |
| 82 | + |
| 83 | + $command->handle(); |
| 84 | + |
| 85 | + Storage::disk($disk)->assertExists('straight.svg'); |
| 86 | + $svg_file = Storage::disk($disk)->get('straight.svg'); |
| 87 | + $this->assertStringContainsString('metadata_place', $svg_file); |
| 88 | + $this->assertStringNotContainsString('metadata_exists', $svg_file); |
| 89 | + } |
| 90 | + |
| 91 | + private function getMock( |
| 92 | + string $workflow = 'straight', |
| 93 | + string $format = 'png', |
| 94 | + string $class = 'Tests\Fixtures\TestObject', |
| 95 | + string $disk = 'local', |
| 96 | + string $path = '/', |
| 97 | + bool $withMetadata = false, |
| 98 | + ): MockInterface { |
| 99 | + return Mockery::mock(WorkflowDumpCommand::class) |
77 | 100 | ->makePartial()
|
78 | 101 | ->shouldReceive('argument')
|
79 | 102 | ->with('workflow')
|
80 |
| - ->andReturn('straight') |
| 103 | + ->andReturn($workflow) |
81 | 104 | ->shouldReceive('option')
|
82 | 105 | ->with('format')
|
83 |
| - ->andReturn('png') |
| 106 | + ->andReturn($format) |
84 | 107 | ->shouldReceive('option')
|
85 | 108 | ->with('class')
|
86 |
| - ->andReturn('Tests\Fixtures\TestObject') |
| 109 | + ->andReturn($class) |
87 | 110 | ->shouldReceive('option')
|
88 | 111 | ->with('disk')
|
89 | 112 | ->andReturn($disk)
|
90 | 113 | ->shouldReceive('option')
|
91 | 114 | ->with('path')
|
92 |
| - ->andReturn($optionalPath) |
| 115 | + ->andReturn($path) |
| 116 | + ->shouldReceive('option') |
| 117 | + ->with('with-metadata') |
| 118 | + ->andReturn($withMetadata) |
93 | 119 | ->getMock();
|
94 |
| - |
95 |
| - $command->handle(); |
96 |
| - |
97 |
| - Storage::disk($disk)->assertExists($optionalPath . '/straight.png'); |
98 | 120 | }
|
99 | 121 |
|
100 | 122 | protected function getEnvironmentSetUp($app)
|
101 | 123 | {
|
102 | 124 | $app['config']['workflow'] = [
|
103 | 125 | 'straight' => [
|
104 | 126 | 'supports' => ['Tests\Fixtures\TestObject'],
|
105 |
| - 'places' => ['a', 'b', 'c'], |
| 127 | + 'places' => [ |
| 128 | + 'a', |
| 129 | + 'b', |
| 130 | + 'c', |
| 131 | + 'metadata_place' => [ |
| 132 | + 'metadata' => [ |
| 133 | + 'metadata_exists' => true, |
| 134 | + ], |
| 135 | + ], |
| 136 | + ], |
106 | 137 | 'transitions' => [
|
107 | 138 | 't1' => [
|
108 | 139 | 'from' => 'a',
|
109 |
| - 'to' => 'b', |
| 140 | + 'to' => 'b', |
110 | 141 | ],
|
111 | 142 | 't2' => [
|
112 | 143 | 'from' => 'b',
|
113 |
| - 'to' => 'c', |
| 144 | + 'to' => 'c', |
114 | 145 | ],
|
115 | 146 | ],
|
116 | 147 | ],
|
|
0 commit comments