Completed
Pull Request — master (#1175)
by Grégoire
03:04
created

GalleryControllerTest::testGetGalleriesAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\MediaBundle\Tests\Controller\Api;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Sonata\MediaBundle\Controller\Api\GalleryController;
16
use Sonata\MediaBundle\Model\GalleryItem;
17
use Symfony\Component\HttpFoundation\Request;
18
19
class GalleryTest extends GalleryItem
20
{
21
    private $id;
22
23
    public function __construct()
24
    {
25
        parent::__construct();
26
        $this->id = rand();
27
    }
28
29
    public function getId()
30
    {
31
        return $this->id;
32
    }
33
}
34
35
/**
36
 * @author Hugo Briand <[email protected]>
37
 */
38
class GalleryControllerTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
39
{
40
    public function testGetGalleriesAction()
41
    {
42
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
43
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
44
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
46
        $galleryManager->expects($this->once())->method('getPager')->will($this->returnValue(array()));
47
48
        $gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test');
49
50
        $paramFetcher = $this->getMockBuilder('FOS\RestBundle\Request\ParamFetcher')
51
            ->disableOriginalConstructor()
52
            ->getMock();
53
        $paramFetcher->expects($this->exactly(3))->method('get');
54
        $paramFetcher
55
            ->expects($this->once())
56
            ->method('all')
57
            ->will($this->returnValue(array(
58
                'page' => 1,
59
                'count' => 10,
60
                'orderBy' => array('id' => 'ASC'),
61
            )));
62
63
        $this->assertSame(array(), $gController->getGalleriesAction($paramFetcher));
64
    }
65
66
    public function testGetGalleryAction()
67
    {
68
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
69
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
70
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
71
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
72
73
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
74
75
        $gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test');
76
77
        $this->assertSame($gallery, $gController->getGalleryAction(1));
78
    }
79
80
    /**
81
     * @expectedException        \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
82
     * @expectedExceptionMessage Gallery (42) not found
83
     */
84
    public function testGetGalleryNotFoundAction()
85
    {
86
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
87
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
88
89
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
90
91
        $galleryManager->expects($this->once())->method('findOneBy');
92
93
        $gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test');
94
95
        $gController->getGalleryAction(42);
96
    }
97
98
    public function testGetGalleryGalleryItemsAction()
99
    {
100
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
101
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
102
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
103
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
104
105
        $gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem)));
106
107
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
108
109
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
110
111
        $gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test');
112
113
        $this->assertSame(array($galleryItem), $gController->getGalleryGalleryItemAction(1));
114
    }
115
116
    public function testGetGalleryMediaAction()
117
    {
118
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
119
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
120
121
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
122
        $galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media));
123
124
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
125
        $gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem)));
126
127
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
128
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
129
130
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
131
132
        $gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test');
133
134
        $this->assertSame(array($media), $gController->getGalleryMediasAction(1));
135
    }
136
137
    public function testPostGalleryMediaGalleryItemAction()
138
    {
139
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
140
141
        $media2 = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
142
        $media2->expects($this->any())->method('getId')->will($this->returnValue(1));
143
144
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
145
        $galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media2));
146
147
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
148
        $gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem)));
149
150
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
151
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
152
153
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
154
        $mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media));
155
156
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock();
157
        $form->expects($this->once())->method('handleRequest');
158
        $form->expects($this->once())->method('isValid')->will($this->returnValue(true));
159
        $form->expects($this->once())->method('getData')->will($this->returnValue($galleryItem));
160
161
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
162
        $formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form));
163
164
        $galleryController = new GalleryController(
165
            $galleryManager,
166
            $mediaManager,
167
            $formFactory,
168
            'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest'
169
        );
170
        $view = $galleryController->postGalleryMediaGalleryItemAction(1, 2, new Request());
171
172
        $this->assertInstanceOf('FOS\RestBundle\View\View', $view);
173
        $this->assertSame(200, $view->getResponse()->getStatusCode(), 'Should return 200');
0 ignored issues
show
Bug introduced by
The method getResponse does only exist in FOS\RestBundle\View\View, but not in Symfony\Component\Form\FormInterface.

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...
174
    }
175
176
    public function testPostGalleryMediaGalleryItemInvalidAction()
177
    {
178
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
179
        $media->expects($this->any())->method('getId')->will($this->returnValue(1));
180
181
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
182
        $galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media));
183
184
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
185
        $gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem)));
186
187
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
188
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
189
190
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
191
        $mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media));
192
193
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
194
195
        $galleryController = new GalleryController(
196
            $galleryManager,
197
            $mediaManager,
198
            $formFactory,
199
            'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest'
200
        );
201
        $view = $galleryController->postGalleryMediaGalleryItemAction(1, 1, new Request());
202
203
        $this->assertInstanceOf('FOS\RestBundle\View\View', $view);
204
        $this->assertSame(400, $view->getResponse()->getStatusCode(), 'Should return 400');
0 ignored issues
show
Bug introduced by
The method getResponse does only exist in FOS\RestBundle\View\View, but not in Symfony\Component\Form\FormInterface.

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...
205
    }
206
207
    public function testPutGalleryMediaGalleryItemAction()
208
    {
209
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
210
        $media->expects($this->any())->method('getId')->will($this->returnValue(1));
211
212
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
213
        $galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media));
214
215
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
216
        $gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem)));
217
218
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
219
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
220
221
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
222
        $mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media));
223
224
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock();
225
        $form->expects($this->once())->method('handleRequest');
226
        $form->expects($this->once())->method('isValid')->will($this->returnValue(true));
227
        $form->expects($this->once())->method('getData')->will($this->returnValue($galleryItem));
228
229
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
230
        $formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form));
231
232
        $galleryController = new GalleryController(
233
            $galleryManager,
234
            $mediaManager,
235
            $formFactory,
236
            'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest'
237
        );
238
        $view = $galleryController->putGalleryMediaGalleryItemAction(1, 1, new Request());
239
240
        $this->assertInstanceOf('FOS\RestBundle\View\View', $view);
241
        $this->assertSame(200, $view->getResponse()->getStatusCode(), 'Should return 200');
0 ignored issues
show
Bug introduced by
The method getResponse() does not seem to exist on object<Symfony\Component\Form\FormInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
242
    }
243
244
    public function testPutGalleryMediaGalleryItemInvalidAction()
245
    {
246
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
247
        $media->expects($this->any())->method('getId')->will($this->returnValue(1));
248
249
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
250
        $galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media));
251
252
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
253
        $gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem)));
254
255
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
256
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
257
258
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
259
        $mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media));
260
261
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock();
262
        $form->expects($this->once())->method('handleRequest');
263
        $form->expects($this->once())->method('isValid')->will($this->returnValue(false));
264
265
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
266
        $formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form));
267
268
        $galleryController = new GalleryController(
269
            $galleryManager,
270
            $mediaManager,
271
            $formFactory,
272
            'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest'
273
        );
274
        $view = $galleryController->putGalleryMediaGalleryItemAction(1, 1, new Request());
275
276
        $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $view);
277
    }
278
279
    public function testDeleteGalleryMediaGalleryItemAction()
280
    {
281
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
282
        $media->expects($this->any())->method('getId')->will($this->returnValue(1));
283
284
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
285
        $galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media));
286
287
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
288
        $gallery
289
            ->expects($this->any())
290
            ->method('getGalleryItems')
291
            ->will($this->returnValue(new ArrayCollection(array($galleryItem))));
292
293
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
294
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
295
296
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
297
        $mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media));
298
299
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
300
301
        $galleryController = new GalleryController(
302
            $galleryManager,
303
            $mediaManager,
304
            $formFactory,
305
            'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest'
306
        );
307
        $view = $galleryController->deleteGalleryMediaGalleryItemAction(1, 1);
308
309
        $this->assertSame(array('deleted' => true), $view);
310
    }
311
312
    public function testDeleteGalleryMediaGalleryItemInvalidAction()
313
    {
314
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
315
316
        $media2 = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
317
        $media2->expects($this->any())->method('getId')->will($this->returnValue(2));
318
319
        $galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
320
        $galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media2));
321
322
        $gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
323
        $gallery
324
            ->expects($this->any())
325
            ->method('getGalleryItems')
326
            ->will($this->returnValue(new ArrayCollection(array($galleryItem))));
327
328
        $galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
329
        $galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery));
330
331
        $mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
332
        $mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media));
333
334
        $formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
335
336
        $galleryController = new GalleryController(
337
            $galleryManager,
338
            $mediaManager,
339
            $formFactory,
340
            'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest'
341
        );
342
        $view = $galleryController->deleteGalleryMediaGalleryItemAction(1, 1);
343
344
        $this->assertInstanceOf('FOS\RestBundle\View\View', $view);
345
        $this->assertSame(400, $view->getResponse()->getStatusCode(), 'Should return 400');
346
    }
347
}
348