Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/DI/ContainerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function array_key_exists, class_exists, interface_exists, is_array, is_string, is_subclass_of, uniqid, count;

/**
* @phpstan-type ServiceDefinition class-string|array{factory?:class-string, factory_method?:callable, parameters?:array<string, mixed>, wiring?: class-string<object>, auto_wiring?: bool}
* @implements ArrayAccess<string, object|class-string<object>|array{name: string, factory?: class-string<object>, auto_wiring?: bool, parameters?: array<string, mixed>, factory_method?: callable(mixed ...$parameters):object|null, instantiable: bool, factory_method?: callable(mixed ...$parameters):object|null}>
*/
abstract class ContainerBase implements ArrayAccess, Countable
Expand Down Expand Up @@ -57,7 +58,7 @@ public function setConfig(array $config): void
foreach ($config as $name => $service) if (is_string($service) || is_array($service))
{
/**
* @var class-string<object>|array{factory?: class-string<object>, parameters?: array<string, mixed>, wiring?: class-string<object>, auto_wiring?: bool, factory_method?: callable(mixed ...$parameters):object|null} $service
* @var ServiceDefinition $service
*/
$this[is_string($name) ? $name : uniqid('class-')] = $service;
}
Expand Down Expand Up @@ -285,8 +286,8 @@ public function offsetGet($offset): object


/**
* @param array-key $offset
* @param class-string<object>|array{factory?: class-string<object>, parameters?: array<string, mixed>, wiring?: class-string<object>, auto_wiring?: bool, factory_method?: callable(mixed ...$parameters):object|null} $value
* @param array-key $offset The service id
* @param ServiceDefinition $value The service definition.
* @throws AutoWiringException|InvalidStateException
*/
public function offsetSet($offset, $value): void
Expand Down
7 changes: 6 additions & 1 deletion src/Event/Repository/AsynchronousDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ public function load(int $limit): Collection

$this->db->execute('START TRANSACTION');

/**
* @var literal-string $limit
*/
$limit = strval($limit);

$records = $this->db->execute(
$this->db->prepare("SELECT * FROM `{$this->db->table('bulkgate_module')}` WHERE `scope` = 'asynchronous' AND `order` = 0 LIMIT %s FOR UPDATE", $limit)
"SELECT * FROM `{$this->db->table('bulkgate_module')}` WHERE `scope` = 'asynchronous' AND `order` = 0 LIMIT $limit FOR UPDATE"
);

if ($records !== null)
Expand Down
6 changes: 2 additions & 4 deletions tests/Event/Repository/AsynchronousDatabaseTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class AsynchronousDatabaseTest extends TestCase

$db->shouldReceive('table')->with('bulkgate_module')->times(3)->andReturn('bulkgate_module');
$db->shouldReceive('execute')->with('START TRANSACTION')->once()->ordered();
$db->shouldReceive('prepare')->with("SELECT * FROM `bulkgate_module` WHERE `scope` = 'asynchronous' AND `order` = 0 LIMIT %s FOR UPDATE", 2)->once()->ordered()->andReturn('SQL1');
$db->shouldReceive('execute')->with('SQL1')->once()->ordered()->andReturn(new ResultCollection([
$db->shouldReceive('execute')->with("SELECT * FROM `bulkgate_module` WHERE `scope` = 'asynchronous' AND `order` = 0 LIMIT 2 FOR UPDATE")->once()->ordered()->andReturn(new ResultCollection([
['key' => 'task1', 'value' => '{"category": "test", "endpoint": "endpoint1", "variables": {"key": "value"}}', 'datetime' => '456', 'order' => '0'],
['key' => 'task2', 'value' => '{"category": "test", "endpoint": "endpoint2", "variables": {"key2": "value2"}}', 'datetime' => 456, 'order' => 0],
]));
Expand Down Expand Up @@ -50,8 +49,7 @@ class AsynchronousDatabaseTest extends TestCase

$db->shouldReceive('table')->once()->andReturn('bulkgate_module');
$db->shouldReceive('execute')->with('START TRANSACTION')->once()->ordered();
$db->shouldReceive('prepare')->with("SELECT * FROM `bulkgate_module` WHERE `scope` = 'asynchronous' AND `order` = 0 LIMIT %s FOR UPDATE", 2)->once()->ordered()->andReturn('SQL1');
$db->shouldReceive('execute')->with('SQL1')->once()->ordered()->andReturnNull();
$db->shouldReceive('execute')->with("SELECT * FROM `bulkgate_module` WHERE `scope` = 'asynchronous' AND `order` = 0 LIMIT 2 FOR UPDATE")->once()->ordered()->andReturnNull();
$db->shouldReceive('execute')->with('ROLLBACK')->once()->ordered();

$asynchronousDatabase = new AsynchronousDatabase($db);
Expand Down