Skip to content

Commit

Permalink
Fixed tests that failed because newer Laravel tried
Browse files Browse the repository at this point in the history
to replace bindings for pretend (laravel/framework@4e43ca0)
  • Loading branch information
AdalbertMemSQL committed Dec 12, 2023
1 parent de5f662 commit 1d5f60a
Showing 1 changed file with 48 additions and 12 deletions.
60 changes: 48 additions & 12 deletions tests/Hybrid/Json/JsonUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SingleStore\Laravel\Tests\Hybrid\Json;

use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB;
use SingleStore\Laravel\Tests\BaseTest;
use SingleStore\Laravel\Tests\Hybrid\HybridTestHelpers;
Expand Down Expand Up @@ -49,16 +50,29 @@ public function set_boolean_execution()
/** @test */
public function set_string_syntax()
{
if (! $this->runHybridIntegrations()) {
return;
}

[$logs] = DB::pretend(function ($database) {
$database->table('test')->update([
'data->value1' => 'foo',
]);
});

$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', ?)",
$logs['query']
);
if (version_compare(Application::VERSION, '10.30.0', '>=')) {
// Laravel version >= 10.30.0
$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', '\\\"foo\\\"')",
$logs['query']
);
} else {
// Laravel version < 10.30.0
$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', ?)",
$logs['query']
);
}

$this->assertSame('"foo"', $logs['bindings'][0]);
}
Expand Down Expand Up @@ -93,10 +107,19 @@ public function set_double_syntax()
]);
});

$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', ?)",
$logs['query']
);
if (version_compare(Application::VERSION, '10.30.0', '>=')) {
// Laravel version >= 10.30.0
$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', 1.3)",
$logs['query']
);
} else {
// Laravel version < 10.30.0
$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', ?)",
$logs['query']
);
}

$this->assertSame(1.3, $logs['bindings'][0]);
}
Expand Down Expand Up @@ -125,16 +148,29 @@ public function set_double_execution()
/** @test */
public function set_json_syntax()
{
if (! $this->runHybridIntegrations()) {
return;
}

[$logs] = DB::pretend(function ($database) {
$database->table('test')->update([
'data->value1' => ['foo' => 'bar'],
]);
});

$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', ?)",
$logs['query']
);
if (version_compare(Application::VERSION, '10.30.0', '>=')) {
// Laravel version >= 10.30.0
$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', '{\\\"foo\\\":\\\"bar\\\"}')",
$logs['query']
);
} else {
// Laravel version < 10.30.0
$this->assertEquals(
"update `test` set data = JSON_SET_JSON(data, 'value1', ?)",
$logs['query']
);
}

$this->assertSame('{"foo":"bar"}', $logs['bindings'][0]);
}
Expand Down

0 comments on commit 1d5f60a

Please sign in to comment.