Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Mar 8, 2024
1 parent b995c8c commit d0ae740
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 299 deletions.
22 changes: 12 additions & 10 deletions tests/EloquentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Staudenmeir\LaravelCte\Tests;

use DateTime;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Expression;
use Staudenmeir\LaravelCte\Tests\Models\Post;
use Staudenmeir\LaravelCte\Tests\Models\User;
Expand All @@ -12,12 +11,12 @@ class EloquentTest extends TestCase
{
public function testWithExpression()
{
$users = User::withExpression('ids', 'select 1 union all select 2', ['id'])
->whereIn('id', function (Builder $query) {
$query->from('ids');
})->orderBy('id')->get();
$users = User::withExpression('u', User::where('id', '>', 1))
->from('u')
->orderBy('id')
->get();

$this->assertEquals([1, 2], $users->pluck('id')->all());
$this->assertEquals([2, 3], $users->pluck('id')->all());
}

public function testWithRecursiveExpression()
Expand Down Expand Up @@ -79,8 +78,13 @@ public function testOuterUnion()

public function testInsertUsing()
{
Post::withExpression('u', User::select('id')->where('id', '>', 1))
->insertUsing(['user_id'], User::from('u'));
$query = User::selectRaw('(select max(id) from posts) + id as id')
->addSelect('id as post_id')
->selectRaw('1 as views')
->where('id', '>', 1);

Post::withExpression('u', $query)
->insertUsing(['id', 'user_id', 'views'], User::from('u'));

$this->assertEquals([1, 2, 2, 3], Post::orderBy('user_id')->pluck('user_id')->all());
}
Expand Down Expand Up @@ -117,8 +121,6 @@ public function testUpdateWithJoin()

public function testUpdateWithLimit()
{
// SingleStore support update with limit only when it is constrained to a single partition
// https://docs.singlestore.com/cloud/reference/sql-reference/data-manipulation-language-dml/update/#update-using-limit
if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) {
$this->markTestSkipped();
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
class Post extends Model
{
use QueriesExpressions;

public $incrementing = false;
}
2 changes: 2 additions & 0 deletions tests/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
class User extends Model
{
use QueriesExpressions;

public $incrementing = false;
}
Loading

0 comments on commit d0ae740

Please sign in to comment.