Completed
Push — master ( 0a7932...aee286 )
by Maksim
13s
created

testObjUrlOptionsPassedToAmazonOnResolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %
Metric Value
dl 13
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Liip\ImagineBundle\Tests\Imagine\Cache\Resolver;
4
5
use Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver;
6
use Liip\ImagineBundle\Model\Binary;
7
use Liip\ImagineBundle\Tests\AbstractTest;
8
9
/**
10
 * @covers Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver
11
 */
12
class AmazonS3ResolverTest extends AbstractTest
13
{
14
    public function testImplementsResolverInterface()
15
    {
16
        $rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver');
17
18
        $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface'));
19
    }
20
21
    public function testNoDoubleSlashesInObjectUrlOnResolve()
22
    {
23
        $s3 = $this->createAmazonS3Mock();
24
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
25
            ->expects($this->once())
26
            ->method('get_object_url')
27
            ->with('images.example.com', 'thumb/some-folder/path.jpg')
28
        ;
29
30
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 23 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
31
        $resolver->resolve('/some-folder/path.jpg', 'thumb');
32
    }
33
34 View Code Duplication
    public function testObjUrlOptionsPassedToAmazonOnResolve()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $s3 = $this->createAmazonS3Mock();
37
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
38
            ->expects($this->once())
39
            ->method('get_object_url')
40
            ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array('torrent' => true))
41
        ;
42
43
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 36 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
44
        $resolver->setObjectUrlOption('torrent', true);
45
        $resolver->resolve('/some-folder/path.jpg', 'thumb');
46
    }
47
48 View Code Duplication
    public function testThrowsAndLogIfCanNotCreateObjectOnAmazon()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $binary = new Binary('aContent', 'image/jpeg', 'jpeg');
51
52
        $s3 = $this->createAmazonS3Mock();
53
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
54
            ->expects($this->once())
55
            ->method('create_object')
56
            ->will($this->returnValue($this->createCFResponseMock(false)))
57
        ;
58
59
        $logger = $this->getMock('Psr\Log\LoggerInterface');
60
        $logger
61
            ->expects($this->once())
62
            ->method('error')
63
        ;
64
65
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 52 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
66
        $resolver->setLogger($logger);
67
68
        $this->setExpectedException(
69
            'Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotStorableException',
70
            'The object could not be created on Amazon S3.'
71
        );
72
        $resolver->store($binary, 'foobar.jpg', 'thumb');
73
    }
74
75 View Code Duplication
    public function testCreatedObjectOnAmazon()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $binary = new Binary('aContent', 'image/jpeg', 'jpeg');
78
79
        $s3 = $this->createAmazonS3Mock();
80
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
81
            ->expects($this->once())
82
            ->method('create_object')
83
            ->will($this->returnValue($this->createCFResponseMock(true)))
84
        ;
85
86
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 79 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
87
88
        $resolver->store($binary, 'foobar.jpg', 'thumb');
89
    }
90
91 View Code Duplication
    public function testIsStoredChecksObjectExistence()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93
        $s3 = $this->createAmazonS3Mock();
94
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
95
            ->expects($this->once())
96
            ->method('if_object_exists')
97
            ->will($this->returnValue(false))
98
        ;
99
100
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 93 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
101
102
        $this->assertFalse($resolver->isStored('/some-folder/path.jpg', 'thumb'));
103
    }
104
105 View Code Duplication
    public function testReturnResolvedImageUrlOnResolve()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
        $s3 = $this->createAmazonS3Mock();
108
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
109
            ->expects($this->once())
110
            ->method('get_object_url')
111
            ->with('images.example.com', 'thumb/some-folder/path.jpg', 0, array())
112
            ->will($this->returnValue('http://images.example.com/some-folder/path.jpg'))
113
        ;
114
115
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 107 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
116
117
        $this->assertEquals(
118
            'http://images.example.com/some-folder/path.jpg',
119
            $resolver->resolve('/some-folder/path.jpg', 'thumb')
120
        );
121
    }
122
123
    public function testDoNothingIfFiltersAndPathsEmptyOnRemove()
124
    {
125
        $s3 = $this->createAmazonS3Mock();
126
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
            ->expects($this->never())
128
            ->method('if_object_exists')
129
        ;
130
        $s3
131
            ->expects($this->never())
132
            ->method('delete_object')
133
        ;
134
        $s3
135
            ->expects($this->never())
136
            ->method('delete_all_objects')
137
        ;
138
139
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 125 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
140
141
        $resolver->remove(array(), array());
142
    }
143
144
    public function testRemoveCacheForPathAndFilterOnRemove()
145
    {
146
        $s3 = $this->createAmazonS3Mock();
147
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
148
            ->expects($this->once())
149
            ->method('if_object_exists')
150
            ->with('images.example.com', 'thumb/some-folder/path.jpg')
151
            ->will($this->returnValue(true))
152
        ;
153
        $s3
154
            ->expects($this->once())
155
            ->method('delete_object')
156
            ->with('images.example.com', 'thumb/some-folder/path.jpg')
157
            ->will($this->returnValue($this->createCFResponseMock(true)))
158
        ;
159
160
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 146 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
161
162
        $resolver->remove(array('some-folder/path.jpg'), array('thumb'));
163
    }
164
165
    public function testRemoveCacheForSomePathsAndFilterOnRemove()
166
    {
167
        $s3 = $this->createAmazonS3Mock();
168
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
169
            ->expects($this->at(0))
170
            ->method('if_object_exists')
171
            ->with('images.example.com', 'filter/pathOne.jpg')
172
            ->will($this->returnValue(true))
173
        ;
174
        $s3
175
            ->expects($this->at(1))
176
            ->method('delete_object')
177
            ->with('images.example.com', 'filter/pathOne.jpg')
178
            ->will($this->returnValue($this->createCFResponseMock(true)))
179
        ;
180
        $s3
181
            ->expects($this->at(2))
182
            ->method('if_object_exists')
183
            ->with('images.example.com', 'filter/pathTwo.jpg')
184
            ->will($this->returnValue(true))
185
        ;
186
        $s3
187
            ->expects($this->at(3))
188
            ->method('delete_object')
189
            ->with('images.example.com', 'filter/pathTwo.jpg')
190
            ->will($this->returnValue($this->createCFResponseMock(true)))
191
        ;
192
193
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 167 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
194
195
        $resolver->remove(array('pathOne.jpg', 'pathTwo.jpg'), array('filter'));
196
    }
197
198
    public function testRemoveCacheForSomePathsAndSomeFiltersOnRemove()
199
    {
200
        $s3 = $this->createAmazonS3Mock();
201
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
202
            ->expects($this->at(0))
203
            ->method('if_object_exists')
204
            ->with('images.example.com', 'filterOne/pathOne.jpg')
205
            ->will($this->returnValue(true))
206
        ;
207
        $s3
208
            ->expects($this->at(1))
209
            ->method('delete_object')
210
            ->with('images.example.com', 'filterOne/pathOne.jpg')
211
            ->will($this->returnValue($this->createCFResponseMock(true)))
212
        ;
213
        $s3
214
            ->expects($this->at(2))
215
            ->method('if_object_exists')
216
            ->with('images.example.com', 'filterOne/pathTwo.jpg')
217
            ->will($this->returnValue(true))
218
        ;
219
        $s3
220
            ->expects($this->at(3))
221
            ->method('delete_object')
222
            ->with('images.example.com', 'filterOne/pathTwo.jpg')
223
            ->will($this->returnValue($this->createCFResponseMock(true)))
224
        ;
225
        $s3
226
            ->expects($this->at(4))
227
            ->method('if_object_exists')
228
            ->with('images.example.com', 'filterTwo/pathOne.jpg')
229
            ->will($this->returnValue(true))
230
        ;
231
        $s3
232
            ->expects($this->at(5))
233
            ->method('delete_object')
234
            ->with('images.example.com', 'filterTwo/pathOne.jpg')
235
            ->will($this->returnValue($this->createCFResponseMock(true)))
236
        ;
237
        $s3
238
            ->expects($this->at(6))
239
            ->method('if_object_exists')
240
            ->with('images.example.com', 'filterTwo/pathTwo.jpg')
241
            ->will($this->returnValue(true))
242
        ;
243
        $s3
244
            ->expects($this->at(7))
245
            ->method('delete_object')
246
            ->with('images.example.com', 'filterTwo/pathTwo.jpg')
247
            ->will($this->returnValue($this->createCFResponseMock(true)))
248
        ;
249
250
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 200 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
251
252
        $resolver->remove(
253
            array('pathOne.jpg', 'pathTwo.jpg'),
254
            array('filterOne', 'filterTwo')
255
        );
256
    }
257
258
    public function testDoNothingWhenObjectNotExistForPathAndFilterOnRemove()
259
    {
260
        $s3 = $this->createAmazonS3Mock();
261
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
262
            ->expects($this->once())
263
            ->method('if_object_exists')
264
            ->with('images.example.com', 'filter/path.jpg')
265
            ->will($this->returnValue(false))
266
        ;
267
        $s3
268
            ->expects($this->never())
269
            ->method('delete_object')
270
        ;
271
272
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 260 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
273
274
        $resolver->remove(array('path.jpg'), array('filter'));
275
    }
276
277
    public function testLogIfNotDeletedForPathAndFilterOnRemove()
278
    {
279
        $s3 = $this->createAmazonS3Mock();
280
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
281
            ->expects($this->once())
282
            ->method('if_object_exists')
283
            ->with('images.example.com', 'filter/path.jpg')
284
            ->will($this->returnValue(true))
285
        ;
286
        $s3
287
            ->expects($this->once())
288
            ->method('delete_object')
289
            ->will($this->returnValue($this->createCFResponseMock(false)))
290
        ;
291
292
        $logger = $this->getMock('Psr\Log\LoggerInterface');
293
        $logger
294
            ->expects($this->once())
295
            ->method('error')
296
        ;
297
298
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 279 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
299
        $resolver->setLogger($logger);
300
301
        $resolver->remove(array('path.jpg'), array('filter'));
302
    }
303
304 View Code Duplication
    public function testRemoveCacheForFilterOnRemove()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
    {
306
        $s3 = $this->createAmazonS3Mock();
307
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
308
            ->expects($this->once())
309
            ->method('delete_all_objects')
310
            ->with('images.example.com', '/filter/i')
311
            ->will($this->returnValue(true))
312
        ;
313
314
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 306 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
315
316
        $resolver->remove(array(), array('filter'));
317
    }
318
319 View Code Duplication
    public function testRemoveCacheForSomeFiltersOnRemove()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
320
    {
321
        $s3 = $this->createAmazonS3Mock();
322
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
323
            ->expects($this->once())
324
            ->method('delete_all_objects')
325
            ->with('images.example.com', '/filterOne|filterTwo/i')
326
            ->will($this->returnValue(true))
327
        ;
328
329
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 321 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
330
331
        $resolver->remove(array(), array('filterOne', 'filterTwo'));
332
    }
333
334
    public function testLogIfBatchNotDeletedForFilterOnRemove()
335
    {
336
        $s3 = $this->createAmazonS3Mock();
337
        $s3
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in AmazonS3.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
338
            ->expects($this->once())
339
            ->method('delete_all_objects')
340
            ->with('images.example.com', '/filter/i')
341
            ->will($this->returnValue(false))
342
        ;
343
344
        $logger = $this->getMock('Psr\Log\LoggerInterface');
345
        $logger
346
            ->expects($this->once())
347
            ->method('error')
348
        ;
349
350
        $resolver = new AmazonS3Resolver($s3, 'images.example.com');
0 ignored issues
show
Bug introduced by
It seems like $s3 defined by $this->createAmazonS3Mock() on line 336 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...Resolver::__construct() does only seem to accept object<AmazonS3>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
351
        $resolver->setLogger($logger);
352
353
        $resolver->remove(array(), array('filter'));
354
    }
355
356
    /**
357
     * @param bool $ok
358
     *
359
     * @return \PHPUnit_Framework_MockObject_MockObject|\CFResponse
360
     */
361
    protected function createCFResponseMock($ok = true)
362
    {
363
        $s3Response = $this->getMock('CFResponse', array('isOK'), array(), '', false);
364
        $s3Response
365
            ->expects($this->once())
366
            ->method('isOK')
367
            ->will($this->returnValue($ok))
368
        ;
369
370
        return $s3Response;
371
    }
372
373
    /**
374
     * @return \PHPUnit_Framework_MockObject_MockObject|\AmazonS3
375
     */
376
    protected function createAmazonS3Mock()
377
    {
378
        $mockedMethods = array(
379
            'if_object_exists',
380
            'create_object',
381
            'get_object_url',
382
            'delete_object',
383
            'delete_all_objects',
384
            'authenticate',
385
        );
386
387
        return $this->getMock('AmazonS3', $mockedMethods, array(), '', false);
388
    }
389
}
390