Example #1
0
 public function testFilter()
 {
     $this->provider->shouldReceive('fetch')->andReturn(new \ArrayIterator(range(1, 10)));
     $records = $this->porter->import($this->specification->setFilter(function ($record) {
         return $record % 2;
     }));
     self::assertInstanceOf(PorterRecords::class, $records);
     self::assertSame([1, 3, 5, 7, 9], iterator_to_array($records));
     /** @var FilteredRecords $previous */
     self::assertInstanceOf(FilteredRecords::class, $previous = $records->getPreviousCollection());
     self::assertNotSame($previous->getFilter(), $this->specification->getFilter(), 'Filter was not cloned.');
 }
Example #2
0
 private function applyCacheAdvice(Provider $provider, CacheAdvice $cacheAdvice)
 {
     try {
         if (!$provider instanceof CacheToggle) {
             throw CacheUnavailableException::modify();
         }
         switch ("{$cacheAdvice}") {
             case CacheAdvice::MUST_CACHE:
             case CacheAdvice::SHOULD_CACHE:
                 $provider->enableCache();
                 break;
             case CacheAdvice::MUST_NOT_CACHE:
             case CacheAdvice::SHOULD_NOT_CACHE:
                 $provider->disableCache();
         }
     } catch (CacheUnavailableException $exception) {
         if ($cacheAdvice === CacheAdvice::MUST_NOT_CACHE() || $cacheAdvice === CacheAdvice::MUST_CACHE()) {
             throw $exception;
         }
     }
 }