Example #1
0
 /**
  * Constructor.
  *
  * @param array $config The Suite config array. Options are:
  *                       -`'closure'` _Closure_ : the closure of the test.
  *                       -`'scope'`   _string_  : supported scope are `'normal'` & `'focus'`.
  *                       -`'matcher'` _object_  : the matcher instance.
  */
 public function __construct($config = [])
 {
     $defaults = ['closure' => null, 'message' => 'passes', 'scope' => 'normal'];
     $config += $defaults;
     $config['message'] = 'it ' . $config['message'];
     parent::__construct($config);
     extract($config);
     $this->_closure = $this->_bind($closure, 'it');
     if ($scope === 'focus') {
         $this->_emitFocus();
     }
 }
Example #2
0
 /**
  * Constructor.
  *
  * @param array $config The Suite config array. Options are:
  *                      -`'closure'` _Closure_ : the closure of the test.
  *                      -`'message'` _string_  : the spec message.
  *                      -`'scope'`   _string_  : supported scope are `'normal'` & `'focus'`.
  */
 public function __construct($config = [])
 {
     $defaults = ['closure' => null, 'message' => 'passes'];
     $config += $defaults;
     $config['message'] = 'it ' . $config['message'];
     parent::__construct($config);
     $config['closure'] = $config['closure'] ?: function () {
     };
     $this->_closure = $this->_bind($config['closure'], 'it');
     if ($this->_type === 'focus') {
         $this->_emitFocus();
     }
 }
Example #3
0
 /**
  * The Constructor.
  *
  * @param array $config The Suite config array. Options are:
  *                      -`'closure'` _Closure_: the closure of the test.
  *                      -`'name'`    _string_ : the type of the suite.
  */
 public function __construct($config = [])
 {
     $defaults = ['closure' => null, 'name' => 'describe'];
     $config += $defaults;
     parent::__construct($config);
     if ($this->_root === $this) {
         return;
     }
     $closure = $this->_bind($config['closure'], $config['name']);
     $this->_closure = $closure;
     if ($this->_type === 'focus') {
         $this->_emitFocus();
     }
 }
Example #4
0
 /**
  * The Constructor.
  *
  * @param array $config The Suite config array. Options are:
  *                       -`'closure'` _Closure_: the closure of the test.
  *                       -`'name'`    _string_ : the type of the suite.
  *                       -`'scope'`   _string_ : supported scope are `'normal'` & `'focus'`.
  */
 public function __construct($config = [])
 {
     $defaults = ['closure' => null, 'name' => 'describe', 'scope' => 'normal'];
     $config += $defaults;
     parent::__construct($config);
     extract($config);
     if ($this->_root === $this) {
         return;
     }
     $closure = $this->_bind($closure, $name);
     $this->_closure = $closure;
     if ($scope === 'focus') {
         $this->_emitFocus();
     }
 }
Example #5
0
 /**
  * Getter.
  *
  * @param  string $key The name of the variable.
  * @return mixed  The value of the variable.
  */
 public function &__get($key)
 {
     if (array_key_exists($key, $this->_data)) {
         return $this->_data[$key];
     }
     if (array_key_exists($key, $this->_given)) {
         $scope = static::current();
         $scope->{$key} = $this->_given[$key]($scope);
         return $scope->__get($key);
     }
     if ($this->_parent !== null) {
         return $this->_parent->__get($key);
     }
     if (in_array($key, static::$blacklist)) {
         if ($key === 'expect') {
             throw new Exception("You can't use expect() inside of describe()");
         }
     }
     throw new Exception("Undefined variable `{$key}`.");
 }
Example #6
0
namespace Kahlan\Spec\Suite;

use Exception;
use Kahlan\SkipException;
use Kahlan\Scope;
use Kahlan\Summary;
use Kahlan\Log;
describe("Scope", function () {
    beforeEach(function () {
        $this->scope = new Scope(['message' => 'it runs a spec']);
    });
    describe("->__construct()", function () {
        it("sets passed options", function () {
            $log = new Log();
            $summary = new Summary();
            $scope = new Scope(['type' => 'focus', 'message' => 'test', 'parent' => null, 'root' => null, 'log' => $log, 'timeout' => 10, 'summary' => $summary]);
            expect($scope->type())->toBe('focus');
            expect($scope->message())->toBe('test');
            expect($scope->parent())->toBe(null);
            expect($scope->log())->toBe($log);
            expect($scope->summary())->toBe($summary);
        });
    });
    describe("->parent()", function () {
        it("returns the parent node", function () {
            $parent = new Scope();
            $this->scope = new Scope(['parent' => $parent]);
            expect($this->scope->parent())->toBe($parent);
        });
    });
    describe("->backtrace()", function () {