|
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\DoctrinePHPCRAdminBundle\Tests\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
|
15
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\DependencyInjection\SonataDoctrinePHPCRAdminExtension; |
|
16
|
|
|
use Symfony\Cmf\Bundle\ResourceBundle\DependencyInjection\CmfResourceExtension; |
|
17
|
|
|
|
|
18
|
|
|
class SonataDoctrinePHPCRAdminExtensionTest extends AbstractExtensionTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function getContainerExtensions() |
|
21
|
|
|
{ |
|
22
|
|
|
return array( |
|
23
|
|
|
new SonataDoctrinePHPCRAdminExtension(), |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testDocumentTreeDefaultValues() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->container->setParameter( |
|
30
|
|
|
'kernel.bundles', |
|
31
|
|
|
array() |
|
32
|
|
|
); |
|
33
|
|
|
$this->load(array('document_tree' => array())); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertContainerBuilderHasParameter( |
|
36
|
|
|
'sonata_admin_doctrine_phpcr.tree_block.configuration', |
|
37
|
|
|
array( |
|
38
|
|
|
'routing_defaults' => array(), |
|
39
|
|
|
'repository_name' => null, |
|
40
|
|
|
'sortable_by' => 'position', |
|
41
|
|
|
'move' => true, |
|
42
|
|
|
'reorder' => true, |
|
43
|
|
|
) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testPrependDefaultRepositoryName() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->container->setParameter('kernel.bundles', ['CmfResourceBundle']); |
|
50
|
|
|
$this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
|
51
|
|
|
$this->container->prependExtensionConfig('sonata_doctrine_phpcr_admin', array('document_tree' => array())); |
|
52
|
|
|
$this->container->prependExtensionConfig('cmf_resource', array('default_repository' =>'default')); |
|
53
|
|
|
|
|
54
|
|
|
$this->container->getExtension('sonata_doctrine_phpcr_admin')->prepend($this->container); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$config = $this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
|
57
|
|
|
$expectedConfig = array( |
|
58
|
|
|
'routing_defaults' => array(), |
|
59
|
|
|
'repository_name' => 'default', |
|
60
|
|
|
'sortable_by' => 'position', |
|
61
|
|
|
'enabled' => true, |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertEquals($expectedConfig, $config[0]['document_tree']); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function testPrependDefaultRepositoryNameThrowsOnNonExistingResourceBundle() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
73
|
|
|
$this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
|
74
|
|
|
$this->container->prependExtensionConfig('sonata_doctrine_phpcr_admin', array('document_tree' => array())); |
|
75
|
|
|
$this->container->prependExtensionConfig('cmf_resource', array('default_repository' =>'default')); |
|
76
|
|
|
|
|
77
|
|
|
$this->container->getExtension('sonata_doctrine_phpcr_admin')->prepend($this->container); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testPrependDefaultRepositoryNameKeepsCustomNames() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->container->setParameter('kernel.bundles', ['CmfResourceBundle']); |
|
83
|
|
|
$this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
|
84
|
|
|
$this->container->prependExtensionConfig( |
|
85
|
|
|
'sonata_doctrine_phpcr_admin', |
|
86
|
|
|
array('document_tree' => array('repository_name' => 'custom')) |
|
87
|
|
|
); |
|
88
|
|
|
$this->container->prependExtensionConfig('cmf_resource', array('default_repository' =>'default')); |
|
89
|
|
|
|
|
90
|
|
|
$this->container->getExtension('sonata_doctrine_phpcr_admin')->prepend($this->container); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
$config = $this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
|
93
|
|
|
$expectedConfig = array('repository_name' => 'custom'); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals($expectedConfig, $config[0]['document_tree']); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: