Exemple #1
0
 /**
  * Scan child scopes and execute a function against each one passing an
  * accumulator reference along.
  *
  * @param Scope $scope
  * @param callable $fn
  * @param array $accumulator
  * @return array
  */
 protected function scanChildren(Scope $scope, callable $fn, &$accumulator = [])
 {
     if (!empty($accumulator)) {
         return $accumulator;
     }
     $children = $scope->getChildScopes();
     foreach ($children as $childScope) {
         $fn($childScope, $accumulator);
         $this->scanChildren($childScope, $fn, $accumulator);
     }
     return $accumulator;
 }
Exemple #2
0
         });
     });
 });
 context('when calling a mixed in property', function () {
     it('should throw an exception when property not found', function () {
         $exception = null;
         try {
             $this->scope->nope;
         } catch (\Exception $e) {
             $exception = $e;
         }
         assert(!is_null($exception), 'exception should not be null');
     });
     context('and the desired property is on a parent scope', function () {
         it('should look up the property on the scope parent', function () {
             $parent = new Scope();
             $child = new Scope();
             $parent->parentProperty = 'value';
             $parent->mixin($child);
             assert($child->parentProperty === 'value', 'expected child to be able to look at parent scope');
         });
     });
     context("and the desired property is on a child scope's child", function () {
         it("should look up property on the child scope's child", function () {
             $testScope = new TestScope();
             $testScope->mixin(new TestChildScope());
             $this->scope->mixin($testScope);
             $surname = $this->scope->surname;
             assert($surname === "scaturro", "expected scope to look up child scope's child property");
         });
         context("when mixing in multiple scopes, one of which has a child", function () {