|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\MediaBundle\Tests\Provider; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
|
19
|
|
|
use Sonata\MediaBundle\Provider\MediaProviderInterface; |
|
20
|
|
|
use Symfony\Component\Form\FormBuilder; |
|
21
|
|
|
use Symfony\Component\Form\FormTypeInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Virgile Vivier <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract class AbstractProviderTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var FormBuilder|MockObject |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $formBuilder; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var FormMapper|MockObject |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $formMapper; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var FormTypeInterface|MockObject |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $formType; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var MediaProviderInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $provider; |
|
47
|
|
|
|
|
48
|
|
|
protected function setUp(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->formMapper = $this->createMock(FormMapper::class); |
|
51
|
|
|
|
|
52
|
|
|
$this->formBuilder = $this->createMock(FormBuilder::class); |
|
53
|
|
|
$this->formBuilder->method('getOption')->willReturn('api'); |
|
54
|
|
|
|
|
55
|
|
|
$this->provider = $this->getProvider(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get the provider which have to be tested. |
|
60
|
|
|
*/ |
|
61
|
|
|
abstract public function getProvider(): MediaProviderInterface; |
|
62
|
|
|
|
|
63
|
|
|
public function testBuildEditForm(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->formMapper |
|
|
|
|
|
|
66
|
|
|
->expects($this->atLeastOnce()) |
|
67
|
|
|
->method('add'); |
|
68
|
|
|
|
|
69
|
|
|
$this->provider->buildEditForm($this->formMapper); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testBuildCreateForm(): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->formMapper |
|
|
|
|
|
|
75
|
|
|
->expects($this->atLeastOnce()) |
|
76
|
|
|
->method('add'); |
|
77
|
|
|
|
|
78
|
|
|
$this->provider->buildCreateForm($this->formMapper); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testBuildMediaType(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->formBuilder |
|
|
|
|
|
|
84
|
|
|
->expects($this->atLeastOnce()) |
|
85
|
|
|
->method('add'); |
|
86
|
|
|
|
|
87
|
|
|
$this->provider->buildMediaType($this->formBuilder); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
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.