function it_setups()
 {
     $command = new Command();
     $this->setup($command);
     it($command->isGlobal())->shouldBe(true);
     it($command->isHidden())->shouldBe(true);
 }
Example #2
0
 /**
  * @test
  */
 public function it_provides_five_entry_points()
 {
     $instances = [it(null), this(null), these(null), those(null), that(null)];
     foreach ($instances as $instance) {
         $this->assertInstanceOf("Essence\\Essence", $instance);
     }
 }
Example #3
0
 protected function testBothFunctions($input, $expected)
 {
     $actual = $this->fibonacciProduct($input);
     it(sprintf('computes Fibonacci product for %d as %d -- clear  code', $input, $actual), $actual === $expected);
     $actual = $this->getFunctionOutput(function () use($input) {
         return $this->fbnccPrdct(2, array(__FILE__, $input));
     });
     it(sprintf('computes Fibonacci product for %d as %d -- golfed code', $input, $actual), $actual == $expected);
 }
Example #4
0
 function it_has_valid_masks()
 {
     it(OutputVerbosity::NORMAL & OutputVerbosity::VERBOSE)->shouldBe(OutputVerbosity::NORMAL);
     it(OutputVerbosity::NORMAL & OutputVerbosity::DEBUG)->shouldBe(OutputVerbosity::NORMAL);
     it(OutputVerbosity::VERBOSE & OutputVerbosity::DEBUG)->shouldBe(OutputVerbosity::VERBOSE);
     it(OutputVerbosity::NORMAL & OutputVerbosity::SILENT)->shouldBe(0);
     it(OutputVerbosity::VERBOSE & OutputVerbosity::SILENT)->shouldBe(0);
     it(OutputVerbosity::DEBUG & OutputVerbosity::SILENT)->shouldBe(0);
 }
Example #5
0
 function it_initializes()
 {
     $container = new Container();
     $this->initialize($container);
     it($container->has(TwigLoader::class))->shouldBe(true);
     it($container->has(Twig_Loader_Filesystem::class))->shouldBe(true);
     it($container->has(Twig::class))->shouldBe(true);
     it($container->has(Twig_Environment::class))->shouldBe(true);
 }
 function it_formats_with_ansi_and_styles()
 {
     $this->style('red')->setColor('red')->setBackground('white')->setFormat(['bold', 'dim']);
     $this->style('blue')->allowInheritance(true)->setColor('blue')->setBackground('red')->setFormat('italic');
     $result = $this->format('<style color=red><red>red<blue>blue\\<x><red>red</red></blue>red</red></style>')->getWrappedObject();
     $result = str_replace("", '', $result);
     $expected = '[0;31m[0;31;107;1;2mred[34;41;3mblue<x>[0;31;107;1;2mred[34;41;3m[0;31;107;1;2mred[0;31m[0m';
     it($result)->shouldBe($expected);
 }
Example #7
0
 public function describe(array $data = null)
 {
     if ($data) {
         $this->data = $data;
     }
     $self = $this;
     describe("TOKEN SERVEICE", function () use($self) {
         it("CAN STORE & LOAD EACH DATA", [$self, "testStoreAndLoadData"]);
     });
 }
 function it_initializes()
 {
     $container = new Container();
     $this->beConstructedWith($container);
     $this->initialize($container);
     it($container->has(ISwiftMailerManager::class))->shouldBe(true);
     it($container->has(SwiftMailerManager::class))->shouldBe(true);
     it($container->has(SwiftMailer::class))->shouldBe(true);
     it($container->has(Swift_Mailer::class))->shouldBe(true);
 }
Example #9
0
 protected function testBothMethods($input, $expected)
 {
     // The clean code
     $actual = $this->checkIfPangram($input);
     it(sprintf("thinks '%s' %s a pangram (clear  code).", $input, $actual ? 'is' : 'is not'), $actual == $expected);
     // The golfed code
     $actual = $this->getFunctionOutput(function () use($input) {
         $this->chkPngrm(2, array(__FILE__, $input));
     });
     it(sprintf("thinks '%s' %s a pangram (golfed code).", $input, $actual ? 'is' : 'is not'), $actual == $expected);
 }
 /**
  * Test helper. Test both scripts (plain and golfed version) using the test framework.
  * Check their actual output against the expected output.
  *
  * @param int[]  $delays  the input argument (the number of seconds to wait before pushing the button)
  * @param string $expected the expected program output
  */
 protected function testDoorStatus(array $delays, $expected)
 {
     // Format the input for display
     $input = implode(' ', $delays);
     // Put the script path in front of the arguments; the real program gets its arguments from the command line
     array_unshift($delays, __FILE__);
     // Test the plain-code function
     it(sprintf("turns input '%s' into output '%s' -- clear  version", $input, $expected), $this->getFunctionOutput(function () use($delays) {
         $this->handleDoor($delays);
     }) === $expected);
     // Test the golfed function
     it(sprintf("turns input '%s' into output '%s' -- golfed version", $input, $expected), $this->getFunctionOutput(function () use($delays) {
         $this->hndlDr($delays);
     }) === $expected);
 }
 function testImplementation($implementation)
 {
     it('can boot using given papertrail log host and port', function () use($implementation) {
         $logger = $implementation::boot($this->host, $this->port);
         $message = 'this is a test log message';
         $logger->info($message);
         expect($this->papertrailClient->getLastEvent()->message)->toContain($message);
     });
     it('can boot using given log message prefix', function () use($implementation) {
         $prefix = '@PREFIX@';
         $logger = $implementation::bootWithPrefix($prefix);
         $message = 'this is a test log message';
         $logger->info($message);
         $actualMessage = $this->papertrailClient->getLastEvent()->message;
         expect($actualMessage)->toContain("[{$prefix}]");
         expect($actualMessage)->toContain($message);
     });
 }
Example #12
0
 public static function gensuite($config = array(), $current_depth = 1)
 {
     $config = array_merge(array('befores' => 0, 'before_alls' => 0, 'afters' => 0, 'after_alls' => 0, 'tests' => 1, 'depth' => 0, 'describes' => array('L', 'R'), 'callbacks' => array('it' => function ($ctx) {
         expect(true)->to->eql(true);
     }, 'before' => function ($ctx) {
         $ctx->value = 3;
     }, 'before_all' => function ($ctx) {
         $ctx->value = 5;
     }, 'after' => function ($ctx) {
         $ctx->value = 7;
     }, 'after_all' => function ($ctx) {
         $ctx->value = 11;
     })), $config);
     if ($config['depth'] == 0) {
         return;
     }
     foreach ($config['describes'] as $side) {
         describe("Level {$side}{$current_depth}", function ($ctx) use($config, $current_depth) {
             for ($i = 1; $i <= $config['tests']; $i++) {
                 it("nested {$i}", $config['callbacks']['it']);
             }
             for ($i = 1; $i <= $config['befores']; $i++) {
                 before($config['callbacks']['before']);
             }
             for ($i = 1; $i <= $config['before_alls']; $i++) {
                 before_all($config['callbacks']['before_all']);
             }
             for ($i = 1; $i <= $config['after_alls']; $i++) {
                 after_all($config['callbacks']['after_all']);
             }
             for ($i = 1; $i <= $config['afters']; $i++) {
                 after($config['callbacks']['after']);
             }
             $config['depth']--;
             Util::gensuite($config, $current_depth + 1);
         });
     }
 }
 /**
  * The tester for both methods, the clean code and the golfed code
  *
  * @param int $n
  * @param int $expected
  */
 protected function testAllFunctions($n, $expected)
 {
     // The clean code method 1
     $startTime = microtime(TRUE);
     $result = $this->countLatticePoints1($n) === $expected;
     $runTime = microtime(TRUE) - $startTime;
     it(sprintf('it computes f(%d)=%d -- clean  code #1; time=%f s', $n, $expected, $runTime), $result);
     // The golfed code method 1
     $startTime = microtime(TRUE);
     $result = $this->cntLttcPnts1($n) === $expected;
     $runTime = microtime(TRUE) - $startTime;
     it(sprintf('it computes f(%d)=%d -- golfed code #1; time=%f s', $n, $expected, $runTime), $result);
     // The clean code method 2
     $startTime = microtime(TRUE);
     $result = $this->countLatticePoints2($n) === $expected;
     $runTime = microtime(TRUE) - $startTime;
     it(sprintf('it computes f(%d)=%d -- clean  code #2; time=%f s', $n, $expected, $runTime), $result);
     // The golfed code method 2
     $startTime = microtime(TRUE);
     $result = $this->cntLttcPnts2($n) === $expected;
     $runTime = microtime(TRUE) - $startTime;
     it(sprintf('it computes f(%d)=%d -- golfed code #2; time=%f s', $n, $expected, $runTime), $result);
 }
Example #14
0
        });
        it('throws RuntimeException when the resource is already closed', function () {
            expect(function () {
                $resource = fopen('php://memory', 'r');
                fclose($resource);
                $stream = new Stream($resource);
                $stream->getContents();
            })->toThrow(new RuntimeException());
        });
        it('returns content', function () {
            $resource = fopen('php://memory', 'w+');
            fwrite($resource, 'Hello');
            fseek($resource, 0);
            expect((new Stream($resource))->getContents())->toBe('Hello');
        });
    });
    describe('->getMetadata', function () {
        it('returns null if when there is no resource', function () {
            expect((new Stream(NULL))->getMetadata())->toBeNull();
            expect((new Stream(NULL))->getMetadata('anykey'))->toBeNull();
        });
        it('returns all metadata when no key given', function () {
            $stream = new Stream(fopen('php://memory', 'r'));
            expect($stream->getMetadata())->toBeA('array')->toContainKey('uri');
            expect($stream->getMetadata()['uri'])->toBe('php://memory');
        });
        it('returns value for given key', function () {
            expect((new Stream(fopen('php://memory', 'r')))->getMetadata('uri'))->toBe('php://memory');
        });
    });
});
Example #15
0
            $title = $console->formatter->grey($spec->getTitle());
            expect($afterSpec)->toPrint($title . PHP_EOL);
        });
        it('prints the spec title in red if it failed', function () use(&$console, &$spec) {
            $suite = new Suite('test', function () {
            });
            $spec = new Spec('testspec', function () {
                throw new \Exception('test');
            }, $suite);
            $spec->run();
            $afterSpec = function () use($console, $spec) {
                $reporter = new SpecReporter($console);
                $reporter->afterSpec($spec);
            };
            $specTitle = $console->formatter->red($spec->getTitle());
            expect($afterSpec)->toPrint($specTitle . PHP_EOL);
        });
        it('prints the spec title in cyan if incomplete', function () use(&$console, $spec) {
            $suite = new Suite('test', function () {
            });
            $spec = new Spec('testspec', null, $suite);
            $spec->run();
            $afterSpec = function () use($console, $spec) {
                $reporter = new SpecReporter($console);
                $reporter->afterSpec($spec);
            };
            $specTitle = $console->formatter->cyan($spec->getTitle());
            expect($afterSpec)->toPrint($specTitle . PHP_EOL);
        });
    });
});
<?php

namespace Preview\DSL\BDD;

require_once __DIR__ . '/../ok.php';
shared_example("to share test", function () {
    it("will use the caller's context", function () {
        ok($this->name == "wenjun.yan");
    });
    describe("create a test suite here", function () {
        it("and still have access to vars defined caller", function () {
            ok($this->name == "wenjun.yan");
        });
    });
});
describe("it_behaves_like", function () {
    before_each(function () {
        $this->name = "wenjun.yan";
    });
    /*
     * the following line will be replaced by
     * code defined in shared_exmaple "to share test";
     */
    it_behaves_like("to share test");
});
<?php

use Vnn\Places\Formatter\LatLngFormatter;
describe('Vnn\\Places\\Formatter\\LatLngFormatter', function () {
    describe('__invoke()', function () {
        it('should format a single result', function () {
            $data = ['formatted_address' => '123 main st', 'geometry' => ['location' => ['lat' => 5, 'lng' => 9]]];
            $expected = ['address' => '123 main st', 'lat' => 5, 'lng' => 9];
            $formatter = new LatLngFormatter(true);
            $result = $formatter($data);
            expect($result)->to->equal($expected);
        });
        it('should remove the country on multiple results', function () {
            $data = [['formatted_address' => '123 main st', 'geometry' => ['location' => ['lat' => 5, 'lng' => 9]]], ['formatted_address' => '862 first st', 'geometry' => ['location' => ['lat' => 55, 'lng' => 12]]]];
            $expected = [['address' => '123 main st', 'lat' => 5, 'lng' => 9], ['address' => '862 first st', 'lat' => 55, 'lng' => 12]];
            $formatter = new LatLngFormatter();
            $result = $formatter($data);
            expect($result)->to->equal($expected);
        });
    });
});
Example #18
0
     */
    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);
        });
    });
    describe("::disable()", function () {
        it("throws an exception when an exit statement occurs if not allowed", function () {
            Quit::disable();
            $closure = function () {
                $foo = new Foo();
                $foo->exitStatement(-1);
            };
            expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
        });
    });
});
 * Time: 11:29 PM
 */
use Notes\Domain\Entity\UserGroup\Admin;
use Notes\Domain\ValueObject\Uuid;
use Notes\Domain\Entity\User;
use Notes\Domain\ValueObject\StringLiteral;
use Notes\Domain\Entity\Roles\AdminRole;
describe('Notes\\Domain\\Entity\\Roles\\AdminRole', function () {
    describe('->__construct()', function () {
        it('should return a Admin object', function () {
            $actual = new AdminRole();
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\Roles\\AdminRole');
        });
    });
    // this tests what exists of this class atm im not sure if i will  have to add the other methods to it later or if im on the right track
    describe('->__construct(params)', function () {
        it('should return a AdminRole object', function () {
            $roleID = new Uuid();
            $name = "Full admins";
            $createPermission = true;
            $deletePermission = true;
            $permissions = array("Can Create" => $createPermission, "Can Delete" => $deletePermission);
            $actual = new AdminRole($roleID, $name, $createPermission, $deletePermission);
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\Roles\\AdminRole');
            expect($actual->getID())->equal($roleID->__toString());
            expect($actual->getPermissions())->equal($permissions);
            expect($actual->getName())->equal($name);
        });
    });
});
// end tests
Example #20
0
    describe("::compile()", function () {
        it("compiles a tokens structure", function () {
            $token = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]]');
            $rules = Parser::compile($token);
            expect($rules)->toBe(['/test(?:/([^/]+)(?:/([0-9]+))?)?', ['name' => false, 'id' => false]]);
        });
        it("compiles a tokens structure with repeatable patterns", function () {
            $tokens = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]*]');
            $rules = Parser::compile($tokens);
            expect($rules)->toBe(['/test(?:/([^/]+)((?:/[0-9]+)*))?', ['name' => false, 'id' => '/{id:[0-9]+}']]);
        });
        it("throws an exception when a placeholder is present several time", function () {
            $closure = function () {
                Parser::compile(Parser::tokenize('/test/{var}/{var}'));
            };
            expect($closure)->toThrow(ParserException::duplicatePlaceholder('var'));
        });
        it("throws an exception when a placeholder is present several time through different segments", function () {
            $closure = function () {
                Parser::compile(Parser::tokenize('/test/{var}[/{var}]'));
            };
            expect($closure)->toThrow(ParserException::duplicatePlaceholder('var'));
        });
        it("throws an exception when multiple placeholder are present in repeatable segments", function () {
            $closure = function () {
                Parser::compile(Parser::tokenize('/test[/{var1}/{var2}]*'));
            };
            expect($closure)->toThrow(ParserException::placeholderExceeded());
        });
    });
});
Example #21
0
                    foreach ($suite->specs as $spec) {
                        $this->spec = $spec;
                        $this->formatter->beforeSpec($spec);
                        $spec->run();
                        $this->formatter->afterSpec($spec);
                    }
                    $this->formatter->afterSuite($suite);
                }
                $this->formatter->after();
            }
            */
        });
    });
    describe("run", function () {
        it("should call run on the current runner object", function ($scope, $spec) {
            $oldRunner = pecs\runner();
            $mockRunner = new MockRunner();
            pecs\runner($mockRunner);
            $spec->expect($mockRunner->runCalls)->to_be_empty();
            $formatter = new pecs\Formatter();
            pecs\run($formatter);
            pecs\run($formatter);
            $spec->expect($mockRunner->runCalls)->to_have_count(2);
            $spec->expect($mockRunner->runCalls[0])->to_have_count(1);
            $spec->expect($mockRunner->runCalls[1])->to_have_count(1);
            $spec->expect($mockRunner->runCalls[0][0])->to_be($formatter);
            $spec->expect($mockRunner->runCalls[1][0])->to_be($formatter);
            pecs\runner($oldRunner);
        });
    });
});
Example #22
0
            $response->headers['Content-Type'] = 'text/html';
            $response->headers['Set-Cookie'] = 'username=skeletor';
            $response->flush();
            $headers = pipes\headers();
            expect($headers[0])->to_be('Content-Type: text/html');
            expect($headers[1])->to_be('Set-Cookie: username=skeletor');
            expect(ob_get_clean())->to_be_empty();
        });
        it("should implode and echo \$body", function ($context) {
            extract($context);
            ob_start();
            $response->write("foo\n");
            $response->write("bar");
            $response->write("baz");
            $response->flush();
            expect(ob_get_clean())->to_be("foo\nbarbaz");
        });
    });
    describe("write()", function () {
        it("should append the string to \$body and increase \$length", function ($context) {
            extract($context);
            expect($response->body)->to_have_count(0);
            $response->write("foo");
            expect($response->body)->to_have_count(1);
            $response->write("bar");
            expect($response->body)->to_have_count(2);
            expect($response->body)->to_be(array('foo', 'bar'));
            expect($response->length)->to_be(6);
        });
    });
});
Example #23
0
            $matcher = new TypeMatcher('string');
            if (!$matcher->match('test')) {
                throw new \Exception('Does not return true');
            }
        });
        it('returns false if the value is not of the correct type', function () {
            $matcher = new TypeMatcher('integer');
            if ($matcher->match('test')) {
                throw new \Exception('Does not return false');
            }
        });
    });
    context('getFailureMessage', function () {
        it('lists the expected type and the type of the value', function () {
            $matcher = new TypeMatcher('integer');
            $matcher->match(false);
            $expected = 'Expected integer, got boolean';
            if ($expected !== $matcher->getFailureMessage()) {
                throw new \Exception('Did not return expected failure message');
            }
        });
        it('lists the expected and actual type with inversed logic', function () {
            $matcher = new TypeMatcher('integer');
            $matcher->match(0);
            $expected = 'Expected a type other than integer';
            if ($expected !== $matcher->getFailureMessage(true)) {
                throw new \Exception('Did not return expected failure message');
            }
        });
    });
});
        $sql = 'select * from (select `users`.*, max(case when `users`.`first_name` = ? then 15 else 0 end ' . '+ case when `users`.`first_name` like ? then 5 else 0 end) as relevance from `users` ' . 'where (`users`.`first_name` like ?) group by `users`.`id`) ' . 'as `users` where `relevance` >= 0.25 order by `relevance` desc';
        $bindings = ['jarek tkaczyk', 'jarek tkaczyk%', 'jarek tkaczyk%'];
        $query = $this->query->search('"jarek tkaczyk*"', ['first_name'], false);
        expect($query->toSql())->toBe($sql);
        expect($query->toBase()->getBindings())->toBe($bindings);
    });
    it('prefixes tables correctly', function () {
        $sql = 'select * from (select `PREFIX_users`.*, max(case when `PREFIX_users`.`first_name` = ? then 15 else 0 end) ' . 'as relevance from `PREFIX_users` where (`PREFIX_users`.`first_name` like ?) ' . 'group by `PREFIX_users`.`id`) as `PREFIX_users` where `relevance` >= 0.25 order by `relevance` desc';
        $bindings = ['jarek', 'jarek'];
        $query = $this->query;
        $query->getGrammar()->setTablePrefix('PREFIX_');
        $query = $query->search('jarek', ['first_name'], false);
        expect($query->toSql())->toBe($sql);
        expect($query->toBase()->getBindings())->toBe($bindings);
    });
    it('supports single character wildcards', function () {
        $sql = 'select * from (select `users`.*, max(case when `users`.`last_name` = ? then 150 else 0 end) ' . 'as relevance from `users` where (`users`.`last_name` like ?) ' . 'group by `users`.`id`) as `users` where `relevance` >= 2.5 order by `relevance` desc';
        $bindings = ['jaros_aw', 'jaros_aw'];
        $query = $this->query->search(' jaros?aw ', ['last_name' => 10], false);
        expect($query->toSql())->toBe($sql);
        expect($query->toBase()->getBindings())->toBe($bindings);
    });
    it('supports custom weight and wildcard', function () {
        (new Searchable(new Parser(10, '%')))->boot();
        $sql = 'select * from (select `users`.*, max(case when `users`.`last_name` = ? then 150 else 0 end ' . '+ case when `users`.`last_name` like ? then 50 else 0 end ' . '+ case when `users`.`last_name` like ? then 10 else 0 end) ' . 'as relevance from `users` where (`users`.`last_name` like ?) ' . 'group by `users`.`id`) as `users` where `relevance` >= 2.5 order by `relevance` desc';
        $bindings = ['jarek', 'jarek%', '%jarek%', '%jarek%'];
        $query = $this->query->search('%jarek%', ['last_name'], false);
        expect($query->toSql())->toBe($sql);
        expect($query->toBase()->getBindings())->toBe($bindings);
    });
});
Example #25
0
                $runner = new Runner($suite, $configuration, $this->eventEmitter);
                $result = new TestResult($this->eventEmitter);
                $runner->run($result);
                assert($result->getTestCount() === 3, "spec count should be 3");
            });
        });
        $behavesLikeErrorEmitter = function () {
            $this->suite->addTest(new Test("my spec", function () {
                trigger_error("This is a user notice", E_USER_NOTICE);
            }));
            $error = [];
            $this->eventEmitter->on('error', function ($errno, $errstr, $errfile, $errline) use(&$error) {
                $error = array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline);
            });
            $this->runner->run(new TestResult(new EventEmitter()));
            assert($error['errno'] == E_USER_NOTICE, "error event should have passed error constant");
            assert($error['errstr'] == "This is a user notice");
        };
        it("should emit an error event with error information", $behavesLikeErrorEmitter);
        it("should restore a previous error handler", function () use($behavesLikeErrorEmitter) {
            $handler = function ($errno, $errstr, $errfile, $errline) {
                //such errors handled. wow!
            };
            set_error_handler($handler);
            call_user_func(Closure::bind($behavesLikeErrorEmitter, $this, $this));
            $old = set_error_handler(function ($n, $s, $f, $l) {
            });
            assert($handler === $old, "runner should have restored previous handler");
        });
    });
});
Example #26
0
<?php

namespace Kahlan\Spec\Suite\Jit\Patcher;

use Kahlan\Jit\Parser;
use Kahlan\Jit\Patcher\Rebase;
describe("Rebase", function () {
    beforeEach(function () {
        $this->path = 'spec/Fixture/Jit/Patcher/Rebase';
        $this->patcher = new Rebase();
    });
    describe("->process()", function () {
        it("patches class's methods", function () {
            $nodes = Parser::parse(file_get_contents($this->path . '/Rebase.php'));
            $expected = file_get_contents($this->path . '/RebaseProcessed.php');
            $actual = Parser::unparse($this->patcher->process($nodes, '/the/original/path/Rebase.php'));
            expect($actual)->toBe($expected);
        });
    });
    describe("->patchable()", function () {
        it("return `true`", function () {
            expect($this->patcher->patchable('SomeClass'))->toBe(true);
        });
    });
});
Example #27
0
            $injected = $rad;
        });
        $route->bind($this->container);
        $route->resolve();
        expect($injected)->to->be->instanceof('Rad\\DependencyImpl');
    });
    it('should be able to resolve dependencies of a class responder', function () {
        $route = new Route('slug', 'Rad\\Responder');
        $route->bind($this->container);
        $dep = $route->resolve();
        expect($dep)->to->be->an->instanceof('Rad\\DependencyImpl');
    });
    it('should be able to resolve dependencies registered as a factory', function () {
        $container = new Container();
        $container->bind('Rad\\DependencyInterface', function () {
            return new \Rad\DependencyImpl();
        });
        $route = new Route('slug', 'Rad\\Responder');
        $route->bind($container);
        $dep = $route->resolve();
        expect($dep)->to->be->an->instanceof('Rad\\DependencyImpl');
    });
    it('should be able to resolve a route if container not bound', function () {
        $executed = false;
        $route = new Route('slug', function (DependencyInterface $ignoreMe) use(&$executed) {
            $executed = true;
        });
        $route->resolve();
        expect($executed)->to->be->true;
    });
});
Example #28
0
 */
use Notes\Domain\Entity\User;
use Notes\Domain\ValueObject\StringLiteral;
use Notes\Domain\ValueObject\Uuid;
describe('Notes\\Domain\\Entity\\User', function () {
    describe('->__construct()', function () {
        it('should return a User object', function () {
            $actual = new User(new Uuid());
            expect($actual)->to->be->instanceof('\\Notes\\Domain\\Entity\\User');
        });
    });
    describe('->getId()', function () {
        it('should return the user\'s username', function () {
            $uuid = new Uuid();
            expect($uuid->isValidV4())->to->be->true();
            $user = new User($uuid);
            $actual = $user->getId();
            expect($actual)->to->be->instanceof('\\Notes\\Domain\\ValueObject\\Uuid');
            expect($actual->__toString())->equal($uuid->__toString());
        });
    });
    describe('->get/setUsername', function () {
        it('should get/set the correct the user\'s username', function () {
            $user = new User(new Uuid());
            $user->setUsername(new StringLiteral('Joe'));
            $actual = $user->getUsername();
            expect($actual)->to->be->instanceof('\\Notes\\Domain\\ValueObject\\StringLiteral');
            expect($actual->__toString())->equal('Joe');
        });
    });
});
Example #29
0
        });
        afterEach(function () {
            unlink($this->output);
        });
        it("writes the coverage to a file", function () {
            $path = 'spec' . DS . 'Fixture' . DS . 'Reporter' . DS . 'Coverage' . DS . 'ExtraEmptyLine.php';
            $collector = new Collector(['driver' => $this->driver, 'path' => $path]);
            $code = new ExtraEmptyLine();
            $collector->start();
            $code->shallNotPass();
            $collector->stop();
            $success = Coveralls::write(['collector' => $collector, 'file' => $this->output, 'service_name' => 'kahlan-ci', 'service_job_id' => '123', 'repo_token' => 'ABC']);
            expect($success)->toBe(585);
            $json = file_get_contents($this->output);
            $actual = json_decode($json, true);
            unset($actual['run_at']);
            expect($actual['service_name'])->toBe('kahlan-ci');
            expect($actual['service_job_id'])->toBe('123');
            expect($actual['repo_token'])->toBe('ABC');
            $coverage = $actual['source_files'][0];
            expect($coverage['name'])->toBe($path);
            expect($coverage['source'])->toBe(file_get_contents($path));
            expect($coverage['coverage'])->toHaveLength(16);
        });
        it("throws an exception no file is set", function () {
            expect(function () {
                Coveralls::write([]);
            })->toThrow(new RuntimeException("Missing file name"));
        });
    });
});
            beforeEach(function () {
                $this->template = new ArrayTemplate([]);
                $this->matcher->setTemplate($this->template);
            });
            it('should return the set template', function () {
                expect($this->matcher->getTemplate())->to->equal($this->template);
            });
        });
    });
    describe('->getArguments()', function () {
        it('should fetch callable arguments', function () {
            $args = [1, 2, 3];
            $this->matcher->setArguments($args);
            expect($this->matcher->getArguments())->to->equal($args);
        });
    });
    describe('->getExpectedMessage()', function () {
        it('should fetch expected message', function () {
            $expected = 'expected';
            $this->matcher->setExpectedMessage($expected);
            expect($this->matcher->getExpectedMessage())->to->equal($expected);
        });
    });
    describe('->getMessage()', function () {
        it('should fetch the actual message', function () {
            $expected = 'expected';
            $this->matcher->setMessage($expected);
            expect($this->matcher->getMessage())->to->equal($expected);
        });
    });
});