-
Notifications
You must be signed in to change notification settings - Fork 5
/
PipelineTest.php
87 lines (69 loc) · 2.13 KB
/
PipelineTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Zaengle\Pipeline\Tests;
use Illuminate\Support\Facades\DB;
use Zaengle\Pipeline\Pipeline;
use Zaengle\Pipeline\Tests\Pipes\FailedTestPipe;
use Zaengle\Pipeline\Tests\Pipes\TestPipe;
class PipelineTest extends PipelineTestCase
{
/** @test */
public function it_successfully_process_a_pipeline()
{
$traveler = (new TestTraveler());
$pipes = [
TestPipe::class,
];
$response = app(Pipeline::class)->pipe($traveler, $pipes);
$this->assertEquals('ok', $response->getStatus());
$this->assertEquals('Traveler passed successfully.', $response->getMessage());
$this->assertNull($response->getException());
}
/** @test */
public function it_fails_to_process_a_pipeline()
{
$traveler = (new TestTraveler());
$pipes = [
FailedTestPipe::class,
];
$response = app(Pipeline::class)->pipe($traveler, $pipes);
$this->assertEquals('fail', $response->getStatus());
$this->assertEquals('This Pipe Has Failed!!!', $response->getMessage());
$this->assertNotNull($response->getException());
}
/** @test */
public function it_uses_db_transactions_on_a_successful_run()
{
DB::shouldReceive('beginTransaction')
->once()
->andReturnSelf()
->shouldReceive('commit')
->once();
app(Pipeline::class)->pipe(
new TestTraveler(),
[TestPipe::class],
true
);
}
/** @test */
public function it_uses_db_transactions_on_a_failed_run()
{
DB::shouldReceive('beginTransaction')
->once()
->andReturnSelf()
->shouldReceive('rollback')
->once();
app(Pipeline::class)->pipe(
new TestTraveler(),
[FailedTestPipe::class],
true
);
}
/** @test */
public function it_does_not_work_with_vanilla_travelers()
{
$this->expectException(\TypeError::class);
$traveler = new \stdClass();
$pipes = [TestPipe::class];
$response = app(Pipeline::class)->pipe($traveler, $pipes);
}
}