Skip to content

Commit

Permalink
Actually implement wrapInTransaction, through it will still throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed committed Sep 23, 2024
1 parent 27d28ec commit 2cf343c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/InMemoryEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Driver\MappingDriver,
};
use RuntimeException;
use Throwable;

use function class_exists;

Expand Down Expand Up @@ -305,6 +306,28 @@ public function beginTransaction(): void
throw new RuntimeException(__METHOD__ . ' not yet implemented');
}

/**
* @inheritDoc
*/
public function wrapInTransaction(callable $func): mixed

Check warning on line 312 in src/InMemoryEntityManager.php

View check run for this annotation

Codecov / codecov/patch

src/InMemoryEntityManager.php#L312

Added line #L312 was not covered by tests
{
$this->beginTransaction();

Check warning on line 314 in src/InMemoryEntityManager.php

View check run for this annotation

Codecov / codecov/patch

src/InMemoryEntityManager.php#L314

Added line #L314 was not covered by tests

try {
$return = $func($this);

Check warning on line 317 in src/InMemoryEntityManager.php

View check run for this annotation

Codecov / codecov/patch

src/InMemoryEntityManager.php#L317

Added line #L317 was not covered by tests

$this->flush();
$this->commit();

Check warning on line 320 in src/InMemoryEntityManager.php

View check run for this annotation

Codecov / codecov/patch

src/InMemoryEntityManager.php#L319-L320

Added lines #L319 - L320 were not covered by tests

return $return;
} catch (Throwable $e) {
$this->close();
$this->rollback();

Check warning on line 325 in src/InMemoryEntityManager.php

View check run for this annotation

Codecov / codecov/patch

src/InMemoryEntityManager.php#L322-L325

Added lines #L322 - L325 were not covered by tests

throw $e;

Check warning on line 327 in src/InMemoryEntityManager.php

View check run for this annotation

Codecov / codecov/patch

src/InMemoryEntityManager.php#L327

Added line #L327 was not covered by tests
}
}

/**
* Commits a transaction on the underlying database connection.
*/
Expand Down Expand Up @@ -480,9 +503,4 @@ private static function getDefaultMappingDriver(): MappingDriver
}
return self::$defaultMappingDriver;
}

public function wrapInTransaction(callable $func): mixed
{
throw new RuntimeException(__METHOD__ . ' not yet implemented');
}
}

0 comments on commit 2cf343c

Please sign in to comment.