File tree Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ trait CacheTrait
88{
99 public function withCacheTtl (?int $ ttl ): static
1010 {
11- $ clone = deep_copy ($ this );
11+ $ clone = deep_copy ($ this , true );
1212 $ clone ->api ->getCacheBuilder ()?->setTtl($ ttl );
1313
1414 return $ clone ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function withLanguage(string $language): static
1616 {
1717 $ this ->validateLanguage ($ language );
1818
19- $ clone = deep_copy ($ this );
19+ $ clone = deep_copy ($ this , true );
2020 $ clone ->api ->addQueryDefault ('lang ' , $ language );
2121
2222 return $ clone ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function withUnitSystem(string $unitSystem): static
1616 {
1717 $ this ->validateUnitSystem ($ unitSystem );
1818
19- $ clone = deep_copy ($ this );
19+ $ clone = deep_copy ($ this , true );
2020 $ clone ->api ->addQueryDefault ('units ' , $ unitSystem );
2121
2222 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