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
|
|
|
|
17
|
|
|
class SonataDoctrinePHPCRAdminExtensionTest extends AbstractExtensionTestCase |
18
|
|
|
{ |
19
|
|
|
public function getContainerExtensions() |
20
|
|
|
{ |
21
|
|
|
return array( |
22
|
|
|
new SonataDoctrinePHPCRAdminExtension(), |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testDocumentTreeDefaultValues() |
27
|
|
|
{ |
28
|
|
|
$this->container->setParameter( |
29
|
|
|
'kernel.bundles', |
30
|
|
|
array() |
31
|
|
|
); |
32
|
|
|
$this->load(array('document_tree' => array())); |
33
|
|
|
|
34
|
|
|
$this->assertContainerBuilderHasParameter( |
35
|
|
|
'sonata_admin_doctrine_phpcr.tree_block.configuration', |
36
|
|
|
array( |
37
|
|
|
'routing_defaults' => array(), |
38
|
|
|
'repository_name' => null, |
39
|
|
|
'sortable_by' => 'position', |
40
|
|
|
'move' => true, |
41
|
|
|
'reorder' => true, |
42
|
|
|
) |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testPrependDefaultRepositoryName() |
47
|
|
|
{ |
48
|
|
|
$this->container->setParameter('kernel.bundles', array('CmfResourceBundle')); |
49
|
|
|
$this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
50
|
|
|
$this->container->prependExtensionConfig('sonata_doctrine_phpcr_admin', array('document_tree' => array())); |
51
|
|
|
$this->container->prependExtensionConfig('cmf_resource', array('default_repository' => 'default')); |
52
|
|
|
|
53
|
|
|
$this->container->getExtension('sonata_doctrine_phpcr_admin')->prepend($this->container); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$config = $this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
56
|
|
|
$expectedConfig = array( |
57
|
|
|
'routing_defaults' => array(), |
58
|
|
|
'repository_name' => 'default', |
59
|
|
|
'sortable_by' => 'position', |
60
|
|
|
'enabled' => true, |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$this->assertEquals($expectedConfig, $config[0]['document_tree']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
68
|
|
|
*/ |
69
|
|
|
public function testPrependDefaultRepositoryNameThrowsOnNonExistingResourceBundle() |
70
|
|
|
{ |
71
|
|
|
$this->container->setParameter('kernel.bundles', array()); |
72
|
|
|
$this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
73
|
|
|
$this->container->prependExtensionConfig('sonata_doctrine_phpcr_admin', array('document_tree' => array())); |
74
|
|
|
$this->container->prependExtensionConfig('cmf_resource', array('default_repository' => 'default')); |
75
|
|
|
|
76
|
|
|
$this->container->getExtension('sonata_doctrine_phpcr_admin')->prepend($this->container); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testPrependDefaultRepositoryNameKeepsCustomNames() |
80
|
|
|
{ |
81
|
|
|
$this->container->setParameter('kernel.bundles', array('CmfResourceBundle')); |
82
|
|
|
$this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
83
|
|
|
$this->container->prependExtensionConfig( |
84
|
|
|
'sonata_doctrine_phpcr_admin', |
85
|
|
|
array('document_tree' => array('repository_name' => 'custom')) |
86
|
|
|
); |
87
|
|
|
$this->container->prependExtensionConfig('cmf_resource', array('default_repository' => 'default')); |
88
|
|
|
|
89
|
|
|
$this->container->getExtension('sonata_doctrine_phpcr_admin')->prepend($this->container); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$config = $this->container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
92
|
|
|
$expectedConfig = array('repository_name' => 'custom'); |
93
|
|
|
|
94
|
|
|
$this->assertEquals($expectedConfig, $config[0]['document_tree']); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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: