classForeignKeyIntegrity
final class ForeignKeyIntegrity
Refuses a shadow in which some child references a parent that is not there.
This is the check that runs once the cascades have finished, so that a statement whose consequences left the shadow inconsistent is refused rather than read back. A key with a null in it references nothing and is left alone, which is what SQL says a partly-null key means.
Methods§
public function __construct(
private TableDefinitionRegistry $registry,
private ForeignKeyEnds $ends,
private ParentKeyLookup $parents = new \ZtdQuery\Shadow\ParentKeyLookup(),
private RowMatch $rows = new \ZtdQuery\Shadow\Row\RowMatch(),
)Parameters
$registry | TableDefinitionRegistry | Answers what a table declares |
$ends | ForeignKeyEnds | Answers which parent columns a key points at |
$parents | ParentKeyLookup | Reports whether a referenced row is there |
$rows | RowMatch | Finds a row among rows |
Test cases 5
ForeignKeyIntegrityTest::testAssertHoldsChecksNothingThroughAKeyWhoseEndsDisagreecoversForeignKeyIntegrityTest::testAssertHoldsLeavesAKeyWithANullInItAlonecoversForeignKeyIntegrityTest::testAssertHoldsLeavesARowThatDoesNotCarryTheKeyColumnsAlonecoversForeignKeyIntegrityTest::testAssertHoldsPassesAShadowInWhichEveryChildFindsItsParentcoversForeignKeyIntegrityTest::testAssertHoldsRefusesAShadowInWhichAChildReferencesNothingcovers
Calls 2
- new ParentKeyLookup line 30
- new RowMatch line 31
public function assertHolds(ShadowStore $store, string $sql): voidRefuses the shadow where a declared constraint no longer holds.
Parameters
$store | ShadowStore | Shadow to check |
$sql | string | Statement being simulated, for the refusal |
Throws
ForeignKeyViolationException When a child references a row that is not thereTest cases 5
ForeignKeyIntegrityTest::testAssertHoldsChecksNothingThroughAKeyWhoseEndsDisagreecovers and callsForeignKeyIntegrityTest::testAssertHoldsLeavesAKeyWithANullInItAlonecovers and callsForeignKeyIntegrityTest::testAssertHoldsLeavesARowThatDoesNotCarryTheKeyColumnsAlonecovers and callsForeignKeyIntegrityTest::testAssertHoldsPassesAShadowInWhichEveryChildFindsItsParentcovers and callsForeignKeyIntegrityTest::testAssertHoldsRefusesAShadowInWhichAChildReferencesNothingcovers and calls
Called from 1
Calls 8
- method-call TableDefinitionRegistry::getAll() line 45
- method-call ForeignKeyEnds::areBalanced() line 47
- method-call ForeignKeyEnds::referencedColumns() line 50
- method-call ShadowStore::get() line 52
- method-call RowMatch::valuesOf() line 53
- function-call
in_arrayline 54 - method-call ParentKeyLookup::exists() line 57
- static-call ForeignKeyViolationException::of() line 58
Private surface 4§
Implementation details, listed for orientation only.
private TableDefinitionRegistry $registryprivate ForeignKeyEnds $endsprivate ParentKeyLookup $parents = new \ZtdQuery\Shadow\ParentKeyLookup()private RowMatch $rows = new \ZtdQuery\Shadow\Row\RowMatch()Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
ForeignKeyIntegrityTest::testAssertHoldsChecksNothingThroughAKeyWhoseEndsDisagreecovers and callsForeignKeyIntegrityTest::testAssertHoldsLeavesAKeyWithANullInItAlonecovers and callsForeignKeyIntegrityTest::testAssertHoldsLeavesARowThatDoesNotCarryTheKeyColumnsAlonecovers and callsForeignKeyIntegrityTest::testAssertHoldsPassesAShadowInWhichEveryChildFindsItsParentcovers and callsForeignKeyIntegrityTest::testAssertHoldsRefusesAShadowInWhichAChildReferencesNothingcovers and calls
Other tests reaching this symbol 4
SessionTestcallsReferentialIntegrityEnforcerTestcallsShadowApplicationTestcallsStatementSimulatorTestcalls