it('uses valid case insensitive operator in postgres', function () {
     $connection = Stub::create(['extends' => Connection::class, 'methods' => ['__construct']]);
     $grammar = new Illuminate\Database\Query\Grammars\PostgresGrammar();
     $processor = new Illuminate\Database\Query\Processors\PostgresProcessor();
     $sql = 'select * from (select "users".*, max(case when "users"."last_name" = ? then 150 else 0 end ' . '+ case when "users"."last_name" ilike ? then 50 else 0 end ' . '+ case when "users"."last_name" ilike ? then 10 else 0 end) ' . 'as relevance from "users" where ("users"."last_name" ilike ?) ' . 'group by "users"."id") as "users" where "relevance" >= 2.5 order by "relevance" desc';
     $bindings = ['jarek', 'jarek%', '%jarek%', '%jarek%'];
     $query = (new Builder($connection, $grammar, $processor))->from('users')->search(' jarek ', ['last_name' => 10]);
     expect($query->toSql())->toBe($sql);
     expect($query->toBase()->getBindings())->toBe($bindings);
 });
 it('supports length aware pagination', function () {
     $sql = 'select count(*) as aggregate 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';
     $bindings = ['jarek', 'jarek%', '%jarek%', '%jarek%'];
     $query = $this->query->search(' jarek ', ['last_name' => 10]);
     Stub::on($query->getConnection())->method('select', []);
     expect($query->getConnection())->toReceive('select')->with($sql, $bindings, Arg::toBeA('boolean'));
     $query->getCountForPagination();
 });
 it('moves order clauses after the relevance ordering', function () {
     $sql = 'select * from (select `users`.*, max(case when `users`.`name` = ? then 15 else 0 end) as relevance ' . 'from `users` where (`users`.`name` like ?) group by `users`.`id`) as `users` ' . 'where `relevance` >= 1 order by `relevance` desc, `first_name` asc';
     $bindings = ['jarek', 'jarek'];
     $query = $this->query->orderBy('first_name')->search('jarek', ['name'], false, 1);
     expect($query->toSql())->toBe($sql);
     expect($query->toBase()->getBindings())->toBe($bindings);
 });
 it('doesn\'t split quoted string and treats it as a single keyword to search for', function () {
     $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);
Пример #2
0
     it("expects called method with missing params to not be called", function () {
         $foo = new Foo();
         expect($foo)->not->toReceive('message')->with('My Message');
         $foo->message();
     });
 });
 context("when using with() and matchers", function () {
     it("expects params match the toContain argument matcher", function () {
         $foo = new Foo();
         expect($foo)->toReceive('message')->with(Arg::toContain('My Message'));
         $foo->message(['My Message', 'My Other Message']);
     });
     it("expects params match the argument matchers", function () {
         $foo = new Foo();
         expect($foo)->toReceive('message')->with(Arg::toBeA('boolean'));
         expect($foo)->toReceiveNext('message')->with(Arg::toBeA('string'));
         $foo->message(true);
         $foo->message('Hello World');
     });
     it("expects params to not match the toContain argument matcher", function () {
         $foo = new Foo();
         expect($foo)->not->toReceive('message')->with(Arg::toContain('Message'));
         $foo->message(['My Message', 'My Other Message']);
     });
 });
 context("when using classname", function () {
     it("expects called method to be called", function () {
         $foo = new Foo();
         expect('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->toReceive('message');
         $foo->message();
     });
Пример #3
0
     it("doesn't stubs on unmatched parameter", function () {
         $foo = new Foo();
         Stub::on($foo)->method('message')->with('Hello World!')->andReturn('Good Bye!');
         expect($foo->message('Hello!'))->not->toBe('Good Bye!');
     });
 });
 context("using the with() parameter and the argument matchers", function () {
     it("stubs on matched parameter", function () {
         $foo = new Foo();
         Stub::on($foo)->method('message')->with(Arg::toBeA('string'))->andReturn('Good Bye!');
         expect($foo->message('Hello World!'))->toBe('Good Bye!');
         expect($foo->message('Hello'))->toBe('Good Bye!');
     });
     it("doesn't stubs on unmatched parameter", function () {
         $foo = new Foo();
         Stub::on($foo)->method('message')->with(Arg::toBeA('string'))->andReturn('Good Bye!');
         expect($foo->message(false))->not->toBe('Good Bye!');
         expect($foo->message(['Hello World!']))->not->toBe('Good Bye!');
     });
 });
 context("with multiple return values", function () {
     it("stubs a method", function () {
         $foo = new Foo();
         Stub::on($foo)->method('message')->andReturn('Good Evening World!', 'Good Bye World!');
         expect($foo->message())->toBe('Good Evening World!');
         expect($foo->message())->toBe('Good Bye World!');
         expect($foo->message())->toBe('Good Bye World!');
     });
 });
 context("with ->methods()", function () {
     it("stubs methods using return values as an array", function () {
Пример #4
0
     it("doesn't stubs on unmatched arguments", function () {
         $foo = new Foo();
         allow($foo)->toReceive('message')->with('Hello World!')->andReturn('Good Bye!');
         expect($foo->message('Hello!'))->not->toBe('Good Bye!');
     });
 });
 context("using the with() parameter and the argument matchers", function () {
     it("stubs on matched arguments", function () {
         $foo = new Foo();
         allow($foo)->toReceive('message')->with(Arg::toBeA('string'))->andReturn('Good Bye!');
         expect($foo->message('Hello World!'))->toBe('Good Bye!');
         expect($foo->message('Hello'))->toBe('Good Bye!');
     });
     it("doesn't stubs on unmatched arguments", function () {
         $foo = new Foo();
         allow($foo)->toReceive('message')->with(Arg::toBeA('string'))->andReturn('Good Bye!');
         expect($foo->message(false))->not->toBe('Good Bye!');
         expect($foo->message(['Hello World!']))->not->toBe('Good Bye!');
     });
 });
 context("with multiple return values", function () {
     it("stubs a method", function () {
         $foo = new Foo();
         allow($foo)->toReceive('message')->andReturn('Good Evening World!', 'Good Bye World!');
         expect($foo->message())->toBe('Good Evening World!');
         expect($foo->message())->toBe('Good Bye World!');
         expect($foo->message())->toBe('Good Bye World!');
     });
 });
 context("with chain of methods", function () {
     it("expects stubbed chain to be stubbed", function () {