summaryrefslogtreecommitdiff
path: root/vendor/league/glide/tests/Api/ApiTest.php
blob: 1ff7c5bce99b322deb5ef344fbabf4515a1f9803 (plain)
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
<?php

namespace League\Glide\Api;

use Mockery;

class ApiTest extends \PHPUnit_Framework_TestCase
{
    private $output;

    public function setUp()
    {
        $this->api = new Api(Mockery::mock('Intervention\Image\ImageManager'), []);
    }

    public function tearDown()
    {
        Mockery::close();
    }

    public function testCreateInstance()
    {
        $this->assertInstanceOf('League\Glide\Api\Api', $this->api);
    }

    public function testSetImageManager()
    {
        $this->api->setImageManager(Mockery::mock('Intervention\Image\ImageManager'));
        $this->assertInstanceOf('Intervention\Image\ImageManager', $this->api->getImageManager());
    }

    public function testGetImageManager()
    {
        $this->assertInstanceOf('Intervention\Image\ImageManager', $this->api->getImageManager());
    }

    public function testSetManipulators()
    {
        $this->api->setManipulators([Mockery::mock('League\Glide\Manipulators\ManipulatorInterface')]);
        $manipulators = $this->api->getManipulators();
        $this->assertInstanceOf('League\Glide\Manipulators\ManipulatorInterface', $manipulators[0]);
    }

    public function testSetInvalidManipulator()
    {
        $this->setExpectedException('InvalidArgumentException', 'Not a valid manipulator.');

        $this->api->setManipulators([new \StdClass()]);
    }

    public function testGetManipulators()
    {
        $this->assertEquals([], $this->api->getManipulators());
    }

    public function testRun()
    {
        $image = Mockery::mock('Intervention\Image\Image', function ($mock) {
            $mock->shouldReceive('getEncoded')->andReturn('encoded');
        });

        $manager = Mockery::mock('Intervention\Image\ImageManager', function ($mock) use ($image) {
            $mock->shouldReceive('make')->andReturn($image);
        });

        $manipulator = Mockery::mock('League\Glide\Manipulators\ManipulatorInterface', function ($mock) use ($image) {
            $mock->shouldReceive('setParams')->with([]);
            $mock->shouldReceive('run')->andReturn($image);
        });

        $api = new Api($manager, [$manipulator]);

        $this->assertEquals('encoded', $api->run('source', []));
    }
}