Skip to content

Commit 5b1553f

Browse files
authored
Merge pull request #852 from driehle/docs
Updated docs for caching
2 parents 28eef30 + 4261946 commit 5b1553f

File tree

13 files changed

+187
-115
lines changed

13 files changed

+187
-115
lines changed

docs/en/caching.rst

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,99 @@
11
Caching
22
=======
33

4-
DoctrineModule provides bridging between
5-
`Laminas\Cache <https://github.com/laminas/laminas-cache>`__ and
6-
`Doctrine\Common\Cache <https://github.com/doctrine/common/tree/master/lib/Doctrine/Common/Cache>`__.
7-
This may be useful in case you want to share configured cache instances
8-
across doctrine, symfony and laminas projects.
4+
DoctrineModule provides some pre-configured caches using
5+
`Laminas\Cache <https://github.com/laminas/laminas-cache>`__, which can be utilized
6+
by either Doctrine ORM or Doctrine ODM.
97

10-
You may use ``Laminas\Cache`` within your doctrine-related projects as
11-
following:
8+
The following caches are available by default:
9+
10+
In-Memory
11+
~~~~~~~~~
12+
13+
Provided by ``laminas/laminas-cache-storage-adapter-memory``, you can pull this cache from
14+
the container under the key ``doctrine.cache.array``. It does not really do any caching and
15+
suits merely as a proof of concept or for cases, where you do not want to have caching.
16+
17+
Filesystem
18+
~~~~~~~~~~
19+
20+
Provided by ``laminas/laminas-cache-storage-adapter-filesystem``, you can pull this cache from
21+
the container under the key ``doctrine.cache.filesystem``. To override the location for the
22+
cache storage folder, use the following configuration:
23+
24+
.. code:: php
25+
return [
26+
'caches' => [
27+
'doctrinemodule.cache.filesystem' => [
28+
'options' => [
29+
'cache_dir' => './data/cache/',
30+
],
31+
],
32+
],
33+
];
34+
35+
APCu
36+
~~~~
37+
38+
This cache requires the additional package ``laminas/laminas-cache-storage-adapter-apcu``, which
39+
is not installed by default.
40+
41+
You can pull the cache from the container using the key ``doctrine.cache.apcu``. To pass additional
42+
arguments for configuration, use the following config:
1243

1344
.. code:: php
45+
return [
46+
'caches' => [
47+
'doctrinemodule.cache.apcu' => [
48+
'options' => [
49+
50+
],
51+
],
52+
],
53+
];
1454
15-
$laminasCache = new \Laminas\Cache\Storage\Adapter\Memory(); // any storage adapter is OK here
16-
$doctrineCache = new \DoctrineModule\Cache\LaminasStorageCache($laminasCache);
17-
// now use $doctrineCache as a normal Doctrine\Common\Cache\Cache instance
55+
Memcached
56+
~~~~~~~~~
1857

19-
You may use ``Doctrine\Common\Cache`` within your Laminas projects as
20-
following:
58+
This cache requires the additional package ``laminas/laminas-cache-storage-adapter-memcached``, which
59+
is not installed by default.
60+
61+
You can pull the cache from the container using the key ``doctrine.cache.memcached``. To pass additional
62+
arguments for configuration, use the following config:
2163

2264
.. code:: php
65+
return [
66+
'caches' => [
67+
'doctrinemodule.cache.memcached' => [
68+
'options' => [
69+
'servers' => [
70+
71+
],
72+
],
73+
],
74+
],
75+
];
2376
24-
$doctrineCache = new \Doctrine\Common\Cache\ArrayCache(); // any doctrine cache is OK here
25-
$adapterOptions = new \Laminas\Cache\Storage\Adapter\AdapterOptions();
26-
$laminasCacheStorage = new \DoctrineModule\Cache\DoctrineCacheStorage($adapterOptions, $doctrineCache);
27-
// now use $laminasCacheStorage as a normal Laminas\Cache\Storage\StorageInterface instance.
77+
Redis
78+
~~~~~~~~~
79+
80+
This cache requires the additional package ``laminas/laminas-cache-storage-adapter-redis``, which
81+
is not installed by default.
82+
83+
You can pull the cache from the container using the key ``doctrine.cache.redis``. The default config
84+
will access a Redis server at localhost, port 6379. To pass additional arguments for configuration,
85+
or to change the default config, use the following config:
86+
87+
.. code:: php
88+
return [
89+
'caches' => [
90+
'doctrinemodule.cache.redis' => [
91+
'options' => [
92+
'server' => [
93+
'host' => 'localhost',
94+
'post' => 6379,
95+
],
96+
],
97+
],
98+
],
99+
];

tests/Authentication/Adapter/ObjectRepositoryTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ public function testAuthentication(): void
110110
->expects($this->exactly(2))
111111
->method('findOneBy')
112112
->with($this->equalTo(['username' => 'a username']))
113-
->will($this->returnValue($entity));
113+
->willReturn($entity);
114114

115115
$objectManager = $this->createMock(ObjectManager::class);
116116
$objectManager->expects($this->exactly(2))
117117
->method('getRepository')
118118
->with($this->equalTo(IdentityObject::class))
119-
->will($this->returnValue($objectRepository));
119+
->willReturn($objectRepository);
120120

121121
$adapter = new ObjectRepositoryAdapter();
122122
$adapter->setOptions([
@@ -138,7 +138,7 @@ public function testAuthentication(): void
138138
$result->getIdentity(),
139139
);
140140

141-
$method->will($this->returnValue(null));
141+
$method->willReturn(null);
142142

143143
$result = $adapter->authenticate();
144144

@@ -156,7 +156,7 @@ public function testAuthenticationWithPublicProperties(): void
156156
->expects($this->exactly(2))
157157
->method('findOneBy')
158158
->with($this->equalTo(['username' => 'a username']))
159-
->will($this->returnValue($entity));
159+
->willReturn($entity);
160160

161161
$adapter = new ObjectRepositoryAdapter();
162162
$adapter->setOptions([
@@ -173,7 +173,7 @@ public function testAuthenticationWithPublicProperties(): void
173173

174174
$this->assertTrue($result->isValid());
175175

176-
$method->will($this->returnValue(null));
176+
$method->willReturn(null);
177177

178178
$result = $adapter->authenticate();
179179

@@ -189,7 +189,7 @@ public function testWillRefuseToAuthenticateWithoutGettersOrPublicMethods(): voi
189189
->expects($this->once())
190190
->method('findOneBy')
191191
->with($this->equalTo(['username' => 'a username']))
192-
->will($this->returnValue(new stdClass()));
192+
->willReturn(new stdClass());
193193

194194
$adapter = new ObjectRepositoryAdapter();
195195
$adapter->setOptions([
@@ -216,7 +216,7 @@ public function testCanValidateWithSpecialCrypt(): void
216216
->expects($this->exactly(2))
217217
->method('findOneBy')
218218
->with($this->equalTo(['username' => 'username']))
219-
->will($this->returnValue($entity));
219+
->willReturn($entity);
220220

221221
$adapter = new ObjectRepositoryAdapter();
222222
$adapter->setOptions([
@@ -249,7 +249,7 @@ public function testWillRefuseToAuthenticateWhenInvalidInstanceIsFound(): void
249249
->expects($this->once())
250250
->method('findOneBy')
251251
->with($this->equalTo(['username' => 'a username']))
252-
->will($this->returnValue(new stdClass()));
252+
->willReturn(new stdClass());
253253

254254
$adapter = new ObjectRepositoryAdapter();
255255
$adapter->setOptions([
@@ -283,7 +283,7 @@ public function testWillNotCastAuthCredentialValue(): void
283283
->expects($this->once())
284284
->method('findOneBy')
285285
->with($this->equalTo(['username' => 'a username']))
286-
->will($this->returnValue($entity));
286+
->willReturn($entity);
287287

288288
$this->assertFalse($adapter->authenticate()->isValid());
289289
}

tests/Authentication/Storage/ObjectRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public function testCanRetrieveEntityFromObjectRepositoryStorage(): void
2727
$objectRepository->expects($this->exactly(1))
2828
->method('find')
2929
->with($this->equalTo('a username'))
30-
->will($this->returnValue($entity));
30+
->willReturn($entity);
3131

3232
$metadata = $this->createMock(ClassMetadata::class);
3333
$metadata->expects($this->exactly(1))
3434
->method('getIdentifierValues')
3535
->with($this->equalTo($entity))
36-
->will($this->returnValue($entity->getUsername()));
36+
->willReturn($entity->getUsername());
3737

3838
$storage = new ObjectRepositoryStorage([
3939
'objectRepository' => $objectRepository,

tests/Form/Element/ObjectMultiCheckboxTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr
6363
$proxy = $this->createMock(Proxy::class);
6464
$proxy->expects($this->exactly(2))
6565
->method('getValueOptions')
66-
->will($this->returnValue($options));
66+
->willReturn($options);
6767

6868
$element->expects($this->never())
6969
->method('setValueOptions');
@@ -80,7 +80,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void
8080
$proxy = $this->createMock(Proxy::class);
8181
$proxy->expects($this->once())
8282
->method('getValueOptions')
83-
->will($this->returnValue($options));
83+
->willReturn($options);
8484

8585
$this->setProxyViaReflection($proxy);
8686

tests/Form/Element/ObjectRadioTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr
3737
$proxy = $this->createMock(Proxy::class);
3838
$proxy->expects($this->exactly(2))
3939
->method('getValueOptions')
40-
->will($this->returnValue($options));
40+
->willReturn($options);
4141

4242
$element->expects($this->never())
4343
->method('setValueOptions');
@@ -54,7 +54,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void
5454
$proxy = $this->createMock(Proxy::class);
5555
$proxy->expects($this->once())
5656
->method('getValueOptions')
57-
->will($this->returnValue($options));
57+
->willReturn($options);
5858

5959
$this->setProxyViaReflection($proxy);
6060

tests/Form/Element/ObjectSelectTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArr
8181
$proxy = $this->createMock(Proxy::class);
8282
$proxy->expects($this->exactly(2))
8383
->method('getValueOptions')
84-
->will($this->returnValue($options));
84+
->willReturn($options);
8585

8686
$element->expects($this->never())
8787
->method('setValueOptions');
@@ -98,7 +98,7 @@ public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty(): void
9898
$proxy = $this->createMock(Proxy::class);
9999
$proxy->expects($this->once())
100100
->method('getValueOptions')
101-
->will($this->returnValue($options));
101+
->willReturn($options);
102102

103103
$this->setProxyViaReflection($proxy);
104104

tests/Form/Element/ProxyAwareElementTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ static function () use ($objectOne, $objectTwo) {
7676
$objectRepository = $this->createMock(ObjectRepository::class);
7777
$objectRepository->expects($this->any())
7878
->method('findAll')
79-
->will($this->returnValue($result));
79+
->willReturn($result);
8080

8181
$objectManager = $this->createMock(ObjectManager::class);
8282
$objectManager->expects($this->any())
8383
->method('getClassMetadata')
8484
->with($this->equalTo($objectClass))
85-
->will($this->returnValue($metadata));
85+
->willReturn($metadata);
8686

8787
$objectManager
8888
->expects($this->any())
8989
->method('getRepository')
9090
->with($this->equalTo($objectClass))
91-
->will($this->returnValue($objectRepository));
91+
->willReturn($objectRepository);
9292

9393
if (! method_exists($this->element, 'getProxy')) {
9494
throw new RuntimeException('Element must implement getProxy().');

0 commit comments

Comments
 (0)