File tree 4 files changed +42
-3
lines changed
4 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ trait CacheTrait
8
8
{
9
9
public function withCacheTtl (?int $ ttl ): static
10
10
{
11
- $ clone = deep_copy ($ this );
11
+ $ clone = deep_copy ($ this , true );
12
12
$ clone ->api ->getCacheBuilder ()?->setTtl($ ttl );
13
13
14
14
return $ clone ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function withLanguage(string $language): static
16
16
{
17
17
$ this ->validateLanguage ($ language );
18
18
19
- $ clone = deep_copy ($ this );
19
+ $ clone = deep_copy ($ this , true );
20
20
$ clone ->api ->addQueryDefault ('lang ' , $ language );
21
21
22
22
return $ clone ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function withUnitSystem(string $unitSystem): static
16
16
{
17
17
$ this ->validateUnitSystem ($ unitSystem );
18
18
19
- $ clone = deep_copy ($ this );
19
+ $ clone = deep_copy ($ this , true );
20
20
$ clone ->api ->addQueryDefault ('units ' , $ unitSystem );
21
21
22
22
return $ clone ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace ProgrammatorDev \OpenWeatherMap \Test \Integration ;
4
+
5
+ use ProgrammatorDev \Api \Builder \CacheBuilder ;
6
+ use ProgrammatorDev \OpenWeatherMap \Resource \Resource ;
7
+ use ProgrammatorDev \OpenWeatherMap \Resource \Util \CacheTrait ;
8
+ use ProgrammatorDev \OpenWeatherMap \Test \AbstractTest ;
9
+ use Psr \Cache \CacheItemPoolInterface ;
10
+
11
+ class CacheTraitTest extends AbstractTest
12
+ {
13
+ private Resource $ resource ;
14
+
15
+ protected function setUp (): void
16
+ {
17
+ parent ::setUp ();
18
+
19
+ $ pool = $ this ->createMock (CacheItemPoolInterface::class);
20
+ $ cacheBuilder = new CacheBuilder ($ pool );
21
+
22
+ $ this ->api ->setCacheBuilder ($ cacheBuilder );
23
+
24
+ $ this ->resource = new class ($ this ->api ) extends Resource {
25
+ use CacheTrait;
26
+
27
+ public function getCacheTtl (): ?int
28
+ {
29
+ return $ this ->api ->getCacheBuilder ()?->getTtl();
30
+ }
31
+ };
32
+ }
33
+
34
+ public function testMethods (): void
35
+ {
36
+ $ this ->assertSame (600 , $ this ->resource ->withCacheTtl (600 )->getCacheTtl ());
37
+ $ this ->assertSame (60 , $ this ->resource ->getCacheTtl ()); // back to default value
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments