Completed
Branch develop (c4bcdd)
by Stephen
06:03
created

TransformerStub::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
1
<?php
2
3
namespace Spinen\Transformers;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Mockery;
7
use Spinen\Transformers\TestCase;
8
use Spinen\Transformers\Transformer;
9
10
class TransformerTest extends TestCase
11
{
12
    /**
13
     * @test
14
     * @group unit
15
     */
16
    public function it_calls_transform_on_the_collection()
17
    {
18
        $model = Mockery::mock(MockedModel::class);
19
20
        $model->shouldReceive('doSomething')
21
              ->once()
22
              ->withNoArgs()
23
              ->andReturn('Ran');
24
25
        $collection = new TransformableCollection([$model]);
26
27
        $transformer = new TransformerStub();
28
29
        $this->assertEquals(['Ran'], $transformer->transformCollection($collection)
30
                                                 ->toArray());
31
    }
32
}
33
34
/**
35
 * Fake model so that we can mock it
36
 *
37
 * Class MockedModel
38
 *
39
 * @package App\Support\Transformation
40
 */
41
class MockedModel extends Model
42
{
43
}
44
45
/**
46
 * Fake transformer so that it can call an asserted method on the model
47
 *
48
 * Class TransformerStub
49
 *
50
 * @package App\Support\Transformation
51
 */
52
Class TransformerStub extends Transformer
53
{
54
    /**
55
     * The method that actually converts the data using the map in the class
56
     *
57
     * @param Model $model
58
     *
59
     * @return mixed
60
     */
61
    public function transform(Model $model)
62
    {
63
        // Mocked out on the model so that we now that transform was called
64
        return $model->doSomething();
65
    }
66
}
67