/**
  * @test
  * @depends it_uses_default_criteria_when_not_configured_not_to
  */
 function it_reapplies_criteria_only_when_changes_to_criteria_are_made()
 {
     // the idea is that a repository efficiently applies criteria,
     // leaving a query state behind that it can re-use without rebuilding
     // it, unless it MUST be rebuilt.
     // it must be rebuilt when
     //   the first call the the repository is made
     //   new criteria are pushed, criteria are removed or cleared
     //   when criteria are pushed or removed 'once'
     //   when settings have changed on the repository (cache, active, scopes)
     // create spy Criteria to check how many times we apply the criteria
     $mockCriteria = $this->makeMockCriteria($this->exactly(6), 'FirstMockCriteria');
     $this->repository->pushCriteria($mockCriteria);
     // first call, should apply +1
     $this->repository->count();
     // call without changes, should not apply
     $this->repository->count();
     // call after changing setting +1
     $this->repository->disableCache();
     $this->repository->count();
     // call after changing setting +1
     $this->repository->clearScopes();
     $this->repository->count();
     // call after pushing new criteria +1
     $mockCriteriaTwo = $this->makeMockCriteria($this->exactly(2), 'SecondMockCriteria');
     $this->repository->pushCriteria($mockCriteriaTwo, 'MockTwo');
     $this->repository->count();
     // call with once-criteria set +1 (and +1 for mock Two)
     $mockOnce = $this->makeMockCriteria($this->exactly(1), 'OnceMockCriteria');
     $this->repository->pushCriteriaOnce($mockOnce);
     $this->repository->count();
     // call with criteria removed set +1
     // but the oncemock is not-re-applied, so that's still only called 1 time!
     $this->repository->removeCriteria('MockTwo');
     $this->repository->count();
     // call with once-criteria removed if it does not exist should not make a difference
     $this->repository->removeCriteriaOnce('KeyDoesNotExist');
     $this->repository->count();
 }