Example #1
0
 /**
  * Save current & reinitialize the Interceptor class.
  */
 beforeAll(function () {
     $this->previous = Interceptor::instance();
     Interceptor::unpatch();
     $cachePath = rtrim(sys_get_temp_dir(), DS) . DS . 'kahlan';
     $include = ['Kahlan\\Spec\\'];
     $interceptor = Interceptor::patch(compact('include', 'cachePath'));
     $interceptor->patchers()->add('quit', new QuitPatcher());
 });
 /**
  * Restore Interceptor class.
  */
 afterAll(function () {
     Interceptor::load($this->previous);
 });
 describe("::enable()", function () {
     it("enables quit statements", function () {
         Quit::disable();
         expect(Quit::enabled())->toBe(false);
         Quit::enable();
         expect(Quit::enabled())->toBe(true);
     });
 });
 describe("::disable()", function () {
     it("disables quit statements", function () {
         Quit::enable();
         expect(Quit::enabled())->toBe(true);
         Quit::disable();
         expect(Quit::enabled())->toBe(false);
Example #2
0
describe("Interceptor", function () {
    beforeAll(function () {
        $this->composer = Interceptor::composer();
        skipIf(!$this->composer);
        $composer = clone $this->composer[0];
        $this->autoloader = new Autoloader($composer);
        spl_autoload_register([$this->autoloader, 'loadClass']);
        spl_autoload_unregister($this->composer);
        $this->cachePath = Dir::tempnam(null, 'cache');
    });
    afterEach(function () {
        Interceptor::unpatch();
    });
    afterAll(function () {
        spl_autoload_register($this->composer);
        spl_autoload_unregister([$this->autoloader, 'loadClass']);
        Dir::remove($this->cachePath);
    });
    describe("::patch()", function () {
        it("patches the composer autoloader by default", function () {
            $interceptor = Interceptor::patch(['cachePath' => $this->cachePath]);
            expect($interceptor->originalInstance())->toBeAnInstanceOf("Composer\\Autoload\\ClassLoader");
        });
        it("throws an exception if the autoloader has already been patched", function () {
            $closure = function () {
                Interceptor::patch(['cachePath' => $this->cachePath]);
                Interceptor::patch(['cachePath' => $this->cachePath]);
            };
            expect($closure)->toThrow(new JitException("An interceptor is already attached."));
        });
        it("throws an exception if the autoloader has already been patched", function () {
Example #3
0
<?php

namespace Kahlan\Spec\Suite;

use stdClass;
use Exception;
use Kahlan\Suite;
use Kahlan\Specification;
use Kahlan\Matcher;
use Kahlan\Plugin\Double;
describe("Specification", function () {
    beforeAll(function () {
        Suite::$PHP = 5;
    });
    afterAll(function () {
        Suite::$PHP = PHP_MAJOR_VERSION;
    });
    beforeEach(function () {
        $this->spec = new Specification(['closure' => function () {
        }]);
    });
    describe("->passed()", function () {
        it("returns the closure return value", function () {
            $this->spec = new Specification(['closure' => function () {
                return 'hello world';
            }]);
            $return = null;
            $this->spec->passed($return);
            expect($return)->toBe('hello world');
        });
        it("fails when an expectation is not verified", function () {
Example #4
0
     it("passes if `beforeEach` has been executed twice", function () {
         expect($this->nb)->toBe(2);
     });
     context("with sub scope", function () {
         it("passes if `beforeEach` has been executed once more", function () {
             expect($this->nb)->toBe(3);
         });
     });
     it("passes if `beforeEach` has been executed once more", function () {
         expect($this->nb)->toBe(4);
     });
 });
 describe("->afterAll()", function () {
     $this->nb = 0;
     afterAll(function () {
         $this->nb++;
     });
     it("passes if `after` has not been executed", function () {
         expect($this->nb)->toBe(0);
     });
 });
 describe("->afterEach()", function () {
     $this->nb = 0;
     afterEach(function () {
         $this->nb++;
     });
     it("passes if `afterEach` has not been executed", function () {
         expect($this->nb)->toBe(0);
     });
     it("passes if `afterEach` has been executed", function () {
         expect($this->nb)->toBe(1);