classShadowApplication
final class ShadowApplication
Writes one simulated statement into the shadow, all of it or none of it.
A statement that is refused part-way through must leave the shadow as it was, or every later statement is simulated against a state the database would never have been in, so the shadow is taken back to the snapshot before the refusal is passed on.
What comes out through here is a driver-shaped failure. A caller went through an adapter that looks like PDO or mysqli, and a simulation-specific exception surfacing there would be a type it has no reason to know about.
Methods§
public function __construct(
private ShadowStore $shadowStore,
private ReferentialIntegrityEnforcer $referentialIntegrity,
private TableDefinitionRegistry $registry,
private SqlRewriter $rewriter,
)Parameters
$shadowStore | ShadowStore | Shadow the statement is written into |
$referentialIntegrity | ReferentialIntegrityEnforcer | Carries the consequences outward |
$registry | TableDefinitionRegistry | Answers what a table declares |
$rewriter | SqlRewriter | Rewriter whose own state moves on with a committed insert |
Test cases 7
ShadowApplicationTest::testApplyAnswersWhatTheStatementCameTocoversShadowApplicationTest::testApplyLeavesTheShadowAsItWasWhenTheStatementIsRefusedcoversShadowApplicationTest::testApplyWritesTheRowsAMutationDescribesIntoTheShadowcoversShadowApplicationTest::testLastInsertIdOfAnswersTheIdentityTheTableSaysIsNumberedcoversShadowApplicationTest::testLastInsertIdOfFallsBackToASingleColumnKeycoversShadowApplicationTest::testLastInsertIdOfIsNothingForAStatementThatInsertedNothingcoversShadowApplicationTest::testLastInsertIdOfIsNothingWhereNoColumnIsNumberedcovers
public function apply(
ShadowMutation $mutation,
ResultSet $resultSet,
string $sql,
): MutationImpactWrites a mutation into the shadow and answers what it came to.
Parameters
$mutation | ShadowMutation | Mutation to write |
$resultSet | ResultSet | What the rewritten statement read back |
$sql | string | Statement being simulated, for the refusal |
Returns
MutationImpact What the statement came toThrows
DatabaseException When the shadow refuses the statementTest cases 7
ShadowApplicationTest::testApplyAnswersWhatTheStatementCameTocovers and callsShadowApplicationTest::testApplyLeavesTheShadowAsItWasWhenTheStatementIsRefusedcovers and callsShadowApplicationTest::testApplyWritesTheRowsAMutationDescribesIntoTheShadowcovers and callsShadowApplicationTest::testLastInsertIdOfAnswersTheIdentityTheTableSaysIsNumberedcovers and callsShadowApplicationTest::testLastInsertIdOfFallsBackToASingleColumnKeycovers and callsShadowApplicationTest::testLastInsertIdOfIsNothingForAStatementThatInsertedNothingcovers and callsShadowApplicationTest::testLastInsertIdOfIsNothingWhereNoColumnIsNumberedcovers and calls
Called from 1
Calls 11
- method-call ShadowStore::get() line 58
- method-call ShadowMutation::tableName() line 58
- method-call ShadowStore::snapshot() line 59
- method-call ShadowMutation::applyResultSet() line 62
- method-call ShadowMutation::apply() line 64
- method-call ReferentialIntegrityEnforcer::synchronize() line 66
- method-call ShadowStore::restore() line 74
- new DatabaseException line 76
- new MutationImpact line 79
- method-call MutationImpact::isInsertLike() line 85
- method-call SqlRewriter::commitRewriteState() line 86
public function lastInsertIdOf(ShadowMutation $mutation, MutationImpact $impact): string|nullAnswers the identity a driver would report for a simulated insert.
A table says which column a database numbers; where it says nothing and the key is one column, that column is what a database would have numbered. Only the last row counts, which is what lastInsertId() means.
Parameters
$mutation | ShadowMutation | Mutation that was written |
$impact | MutationImpact | What it came to |
Returns
string|null The identity, or null when nothing was inserted or nothing was numberedTest cases 4
ShadowApplicationTest::testLastInsertIdOfAnswersTheIdentityTheTableSaysIsNumberedcovers and callsShadowApplicationTest::testLastInsertIdOfFallsBackToASingleColumnKeycovers and callsShadowApplicationTest::testLastInsertIdOfIsNothingForAStatementThatInsertedNothingcovers and callsShadowApplicationTest::testLastInsertIdOfIsNothingWhereNoColumnIsNumberedcovers and calls
Called from 1
Calls 8
- method-call MutationImpact::isInsertLike() line 106
- method-call TableDefinitionRegistry::get() line 110
- method-call ShadowMutation::tableName() line 110
- function-call
array_keysline 111 - function-call
countline 112 - method-call MutationImpact::returningRows() line 116
- function-call
is_intline 122 - function-call
is_stringline 122
Private surface 4§
Implementation details, listed for orientation only.
private ShadowStore $shadowStoreprivate ReferentialIntegrityEnforcer $referentialIntegrityprivate TableDefinitionRegistry $registryprivate SqlRewriter $rewriterTest cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
ShadowApplicationTest::testApplyAnswersWhatTheStatementCameTocovers and callsShadowApplicationTest::testApplyLeavesTheShadowAsItWasWhenTheStatementIsRefusedcovers and callsShadowApplicationTest::testApplyWritesTheRowsAMutationDescribesIntoTheShadowcovers and callsShadowApplicationTest::testLastInsertIdOfAnswersTheIdentityTheTableSaysIsNumberedcovers and callsShadowApplicationTest::testLastInsertIdOfFallsBackToASingleColumnKeycovers and callsShadowApplicationTest::testLastInsertIdOfIsNothingForAStatementThatInsertedNothingcovers and callsShadowApplicationTest::testLastInsertIdOfIsNothingWhereNoColumnIsNumberedcovers and calls
Other tests reaching this symbol 2
SessionTestcallsStatementSimulatorTestcalls