Skip to content

Commit

Permalink
Temp commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jails committed Oct 28, 2016
1 parent 725cf39 commit 1c82d80
Show file tree
Hide file tree
Showing 23 changed files with 1,605 additions and 1,482 deletions.
4 changes: 2 additions & 2 deletions spec/Fixture/Kahlan/Spec/FailTest.php
@@ -1,7 +1,7 @@
<?php
$suite = $this->suite();
$root = $this->suite()->root();

$suite->describe("Fail", function() {
$root->describe("Fail", function() {

$this->it("fail", function() {

Expand Down
4 changes: 2 additions & 2 deletions spec/Fixture/Kahlan/Spec/PassTest.php
@@ -1,7 +1,7 @@
<?php
$suite = $this->suite();
$root = $this->suite()->root();

$suite->describe("Pass", function() {
$root->describe("Pass", function() {

$this->it("pass", function() {

Expand Down
2 changes: 1 addition & 1 deletion spec/Suite/Analysis/Debugger.spec.php
Expand Up @@ -56,7 +56,7 @@
expect($backtrace)->toBeA('string');

$trace = current(explode("\n", $backtrace));
expect($trace)->toMatch('~src[/|\\\]Specification.php~');
expect($trace)->toMatch('~src[/|\\\]Block.php~');

});

Expand Down
62 changes: 38 additions & 24 deletions spec/Suite/Scope.spec.php → spec/Suite/Block.spec.php
Expand Up @@ -3,40 +3,42 @@

use Exception;
use Kahlan\SkipException;
use Kahlan\Scope;
use Kahlan\Suite;
use Kahlan\Summary;
use Kahlan\Log;
use Kahlan\Plugin\Double;

describe("Scope", function () {
describe("Block", function () {

beforeEach(function () {
$this->block = $block = Double::classname(['extends' => 'Kahlan\Block']);

$this->scope = new Scope(['message' => 'it runs a spec']);

$this->createScope= function ($options = []) use ($block) {
return new $block($options);
};
$this->scope = $this->createScope(['message' => 'it runs a spec']);
});

describe("->__construct()", function () {

it("sets passed options", function () {

$log = new Log();
$summary = new Summary();

$scope = new Scope([
$scope = $this->createScope([
'type' => 'focus',
'message' => 'test',
'parent' => null,
'root' => null,
'log' => $log,
'timeout' => 10,
'summary' => $summary
'timeout' => 10
]);

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);
expect($scope->suite()->summary())->toBe($scope->summary());

});

Expand All @@ -46,8 +48,8 @@

it("returns the parent node", function () {

$parent = new Scope();
$this->scope = new Scope(['parent' => $parent]);
$parent = $this->createScope();
$this->scope = $this->createScope(['parent' => $parent]);
expect($this->scope->parent())->toBe($parent);

});
Expand All @@ -58,8 +60,8 @@

it("returns the backtrace", function () {

$this->scope = new Scope();
expect(basename($this->scope->backtrace()[1]['file']))->toBe('Scope.spec.php');
$this->scope = $this->createScope();
expect(basename($this->scope->backtrace()[1]['file']))->toBe('Block.spec.php');

});

Expand All @@ -82,7 +84,29 @@

it("throw an new exception for reserved keywords", function () {

foreach (Scope::$blacklist as $keyword => $bool) {
foreach ([
'__construct' => true,
'__call' => true,
'__get' => true,
'__set' => true,
'given' => true,
'afterAll' => true,
'afterEach' => true,
'beforeAll' => true,
'beforeEach' => true,
'context' => true,
'describe' => true,
'expect' => true,
'given' => true,
'it' => true,
'fdescribe' => true,
'fcontext' => true,
'fit' => true,
'skipIf' => true,
'xdescribe' => true,
'xcontext' => true,
'xit' => true
] as $keyword => $bool) {
$closure = function () use ($keyword) {
$this->{$keyword} = 'some value';
};
Expand All @@ -101,16 +125,6 @@

});

it("throws properly message on expect() usage inside of describe()", function () {

$closure = function () {
$this->expect;
};

expect($closure)->toThrow(new Exception("You can't use expect() inside of describe()"));

});

context("when nested", function () {

beforeEach(function () {
Expand Down
@@ -1,18 +1,18 @@
<?php
namespace Kahlan\Spec\Suite;
namespace Kahlan\Spec\Suite\Block;

use stdClass;
use Exception;
use Kahlan\Suite;
use Kahlan\Specification;
use Kahlan\Block\Specification;
use Kahlan\Matcher;
use Kahlan\Plugin\Double;

describe("Specification", function () {

beforeEach(function () {

$this->spec = new Specification(['closure' => function () {}]);
$this->spec = new Specification();

});

Expand All @@ -22,7 +22,7 @@

$this->spec = new Specification(['closure' => null]);

expect($this->spec->passed())->toBe(true);
expect($this->spec->process())->toBe(true);

$pending = $this->spec->summary()->pending();
expect($pending)->toBe(1);
Expand Down Expand Up @@ -53,7 +53,7 @@
}
]);

expect($this->spec->passed())->toBe(true);
expect($this->spec->process())->toBe(true);

});

Expand All @@ -71,7 +71,7 @@

});

describe("->passed()", function () {
describe("->process()", function () {

it("returns the closure return value", function () {

Expand All @@ -82,7 +82,7 @@
]);

$return = null;
$this->spec->passed($return);
$this->spec->process($return);
expect($return)->toBe('hello world');

});
Expand All @@ -96,7 +96,7 @@
}
]);

expect($this->spec->passed())->toBe(false);
expect($this->spec->process())->toBe(false);

});

Expand All @@ -111,7 +111,7 @@
}
]);

expect($this->spec->passed())->toBe(true);
expect($this->spec->process())->toBe(true);

$passed = $this->spec->summary()->logs('passed');
expect($passed)->toHaveLength(1);
Expand Down Expand Up @@ -142,7 +142,7 @@
}
]);

expect($this->spec->passed())->toBe(true);
expect($this->spec->process())->toBe(true);

$passes = $this->spec->summary()->logs('passed');
expect($passes)->toHaveLength(1);
Expand Down Expand Up @@ -172,7 +172,7 @@
}
]);

expect($this->spec->passed())->toBe(true);
expect($this->spec->process())->toBe(true);

$passes = $this->spec->summary()->logs('passed');
expect($passes)->toHaveLength(1);
Expand All @@ -186,16 +186,16 @@

it("logs deferred matcher backtrace", function () {

$root = new Suite();
$root->backtraceFocus(['*Spec.php', '*.spec.php']);
$suite = new Suite();
$suite->backtraceFocus(['*Spec.php', '*.spec.php']);
$this->spec = new Specification([
'parent' => $root,
'suite' => $suite,
'closure' => function () {
$this->expect(Double::instance())->not->toReceive('helloWorld');
}
]);

expect($this->spec->passed())->toBe(true);
expect($this->spec->process())->toBe(true);

$passes = $this->spec->summary()->logs('passed');
expect($passes)->toHaveLength(1);
Expand All @@ -217,7 +217,7 @@
}
]);

expect($this->spec->passed())->toBe(true);
expect($this->spec->process())->toBe(true);

$passes = $this->spec->summary()->logs('passed');
expect($passes)->toHaveLength(1);
Expand Down Expand Up @@ -251,7 +251,7 @@
}
]);

expect($this->spec->passed())->toBe(false);
expect($this->spec->process())->toBe(false);

$failed = $this->spec->summary()->logs('failed');
expect($failed)->toHaveLength(1);
Expand Down Expand Up @@ -280,7 +280,7 @@
}
]);

expect($this->spec->passed())->toBe(false);
expect($this->spec->process())->toBe(false);

$failed = $this->spec->summary()->logs('failed');
expect($failed)->toHaveLength(1);
Expand Down Expand Up @@ -309,7 +309,7 @@
}
]);

expect($this->spec->passed())->toBe(false);
expect($this->spec->process())->toBe(false);

$failures = $this->spec->summary()->logs('failed');
expect($failures)->toHaveLength(1);
Expand All @@ -331,7 +331,7 @@
}
]);

expect($this->spec->passed())->toBe(false);
expect($this->spec->process())->toBe(false);

$failures = $this->spec->summary()->logs('failed');
expect($failures)->toHaveLength(1);
Expand All @@ -355,7 +355,7 @@
}
]);

expect($this->spec->passed())->toBe(false);
expect($this->spec->process())->toBe(false);

$failured = $this->spec->summary()->logs('failed');
expect($failured)->toHaveLength(1);
Expand Down Expand Up @@ -387,7 +387,7 @@
}
]);

expect($this->spec->passed())->toBe(false);
expect($this->spec->process())->toBe(false);

$failured = $this->spec->summary()->logs('failed');
expect($failured)->toHaveLength(1);
Expand Down
14 changes: 7 additions & 7 deletions spec/Suite/Expectation.spec.php
Expand Up @@ -5,7 +5,7 @@
use RuntimeException;
use stdClass;
use DateTime;
use Kahlan\Specification;
use Kahlan\Block\Specification;
use Kahlan\Matcher;
use Kahlan\Expectation;
use Kahlan\Plugin\Double;
Expand Down Expand Up @@ -97,11 +97,11 @@ function expectation($actual, $timeout = -1)

});

describe("->passed()", function () {
describe("->process()", function () {

it("verifies the expectation", function () {

$actual = expectation(true)->toBe(true)->passed();
$actual = expectation(true)->toBe(true)->process();
expect($actual)->toBe(true);

});
Expand All @@ -111,7 +111,7 @@ function expectation($actual, $timeout = -1)
$spec = new Specification(['closure' => function () {
return true;
}]);
$actual = expectation($spec)->toBe(true)->passed();
$actual = expectation($spec)->toBe(true)->process();
expect($actual)->toBe(true);

});
Expand All @@ -122,7 +122,7 @@ function expectation($actual, $timeout = -1)
$spec = new Specification(['closure' => function () {
expect(true)->toBe(false);
}]);
$actual = expectation($spec, 0.1)->passed();
$actual = expectation($spec, 0.1)->process();
expect($actual)->toBe(false);
$end = microtime(true);
expect($end - $start)->toBeGreaterThan(0.1);
Expand Down Expand Up @@ -176,7 +176,7 @@ function expectation($actual, $timeout = -1)
]);
expect($expectation->timeout())->toBe(10);
expect($expectation->not())->toBe(true);
expect($expectation->passed())->toBe(true);
expect($expectation->process())->toBe(true);
expect($expectation->logs())->toHaveLength(1);

$expectation->clear();
Expand All @@ -185,7 +185,7 @@ function expectation($actual, $timeout = -1)
expect($expectation->deferred())->toBe(null);
expect($expectation->timeout())->toBe(-1);
expect($expectation->not())->toBe(false);
expect($expectation->passed())->toBe(true);
expect($expectation->process())->toBe(false);
expect($expectation->logs())->toHaveLength(0);

});
Expand Down

0 comments on commit 1c82d80

Please sign in to comment.