classRowConstraints
final class RowConstraints
Refuses a row the table would not have accepted.
Nothing is inserted, so nothing checks these but this. A statement whose rows the database would have rejected has to be rejected here too, or the shadow ends up describing a state the database could never have been in.
A key with a null in it is left alone: SQL says such a key collides with nothing, not even with another row carrying the same nulls.
Type Aliases§
Row = import from TableDefinitionRowValue = import from TableDefinitionMethods§
public function __construct(
private TableDefinition|null $definition,
private string $tableName,
private string $sql,
)Parameters
$definition | TableDefinition|null | What the table declares, or null when nothing has described it |
$tableName | string | Table being written to, for the refusal |
$sql | string | Statement being simulated, for the refusal |
Test cases 12
RowConstraintsTest::testAgreeOnIsFalseWhereTheRowAlreadyThereCarriesNothingcoversRowConstraintsTest::testAgreeOnReportsTwoRowsCarryingTheSameValuesTherecoversRowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsARowNotCollideWithItselfcoversRowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsTwoNullsThroughBecauseNeitherCollidescoversRowConstraintsTest::testAssertNoDuplicateUniqueKeyRefusesARowCollidingWithOneAlreadyTherecoversRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedLetsAColumnTheRowNeverWroteThroughcoversRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedLetsEverythingThroughForATableNothingDescribescoversRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedRefusesANullInSuchAColumncoversRowConstraintsTest::testCarriesNullInIsFalseWhereEveryColumnCarriesSomethingcoversRowConstraintsTest::testCarriesNullInReportsAColumnTheRowLeftNullcoversRowConstraintsTest::testCarriesNullInReportsAColumnTheRowNeverWrotecoversRowConstraintsTest::testKeyValuesReadsWhatTheRowCarriesUnderTheColumnNamescovers
public function assertNoNullWhereNoneIsAllowed(Row $row): voidRefuses a row that leaves null in a column the table will not take one in.
A column the row does not carry at all is not a null: the database would put its default there.
Parameters
$row | Row | Row that would be written |
Throws
NotNullViolationException When a column that cannot be null is written as nullTest cases 3
RowConstraintsTest::testAssertNoNullWhereNoneIsAllowedLetsAColumnTheRowNeverWroteThroughcovers and callsRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedLetsEverythingThroughForATableNothingDescribescovers and callsRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedRefusesANullInSuchAColumncovers and calls
Called from 2
Calls 2
- function-call
array_key_existsline 55 - new NotNullViolationException line 56
public function assertNoDuplicateUniqueKey(
Row $row,
array<int, Row> $existingRows,
list<string> $identityColumns = [],
): voidRefuses a row that would collide with one already there on a unique key.
A row being changed does not collide with itself, so the row already there that is this row is left out. Which columns say so is passed in, because an insert has no such row and an update does.
Parameters
Throws
DuplicateKeyException When the row collides on one of the table's unique keysTest cases 3
RowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsARowNotCollideWithItselfcovers and callsRowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsTwoNullsThroughBecauseNeitherCollidescovers and callsRowConstraintsTest::testAssertNoDuplicateUniqueKeyRefusesARowCollidingWithOneAlreadyTherecovers and calls
Called from 2
Calls 4
- method-call RowConstraints::carriesNullIn() line 81
- method-call RowConstraints::agreeOn() line 86
- new DuplicateKeyException line 90
- method-call RowConstraints::keyValues() line 94
public function carriesNullIn(Row $row, list<string> $columns): boolReports whether a row leaves any of the named columns unwritten or null.
Parameters
$row | Row | Row to read |
$columns | list<string> | Columns of one key |
Returns
bool True when the key cannot collide with anythingTest cases 6
RowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsARowNotCollideWithItselfcoversRowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsTwoNullsThroughBecauseNeitherCollidescoversRowConstraintsTest::testAssertNoDuplicateUniqueKeyRefusesARowCollidingWithOneAlreadyTherecoversRowConstraintsTest::testCarriesNullInIsFalseWhereEveryColumnCarriesSomethingcovers and callsRowConstraintsTest::testCarriesNullInReportsAColumnTheRowLeftNullcovers and callsRowConstraintsTest::testCarriesNullInReportsAColumnTheRowNeverWrotecovers and calls
Called from 1
Calls 1
- function-call
array_key_existsline 112
Reports whether two rows carry the same values in the named columns.
A row that does not carry one of them agrees with nothing on it.
Parameters
Returns
bool True when both carry every column identicallyTest cases 4
RowConstraintsTest::testAgreeOnIsFalseWhereTheRowAlreadyThereCarriesNothingcovers and callsRowConstraintsTest::testAgreeOnReportsTwoRowsCarryingTheSameValuesTherecovers and callsRowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsARowNotCollideWithItselfcoversRowConstraintsTest::testAssertNoDuplicateUniqueKeyRefusesARowCollidingWithOneAlreadyTherecovers
Called from 2
Private surface 3§
Implementation details, listed for orientation only.
private TableDefinition|null $definitionprivate string $tableNameprivate string $sqlTest cases 22§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 12
RowConstraintsTest::testAgreeOnIsFalseWhereTheRowAlreadyThereCarriesNothingcovers and callsRowConstraintsTest::testAgreeOnReportsTwoRowsCarryingTheSameValuesTherecovers and callsRowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsARowNotCollideWithItselfcovers and callsRowConstraintsTest::testAssertNoDuplicateUniqueKeyLetsTwoNullsThroughBecauseNeitherCollidescovers and callsRowConstraintsTest::testAssertNoDuplicateUniqueKeyRefusesARowCollidingWithOneAlreadyTherecovers and callsRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedLetsAColumnTheRowNeverWroteThroughcovers and callsRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedLetsEverythingThroughForATableNothingDescribescovers and callsRowConstraintsTest::testAssertNoNullWhereNoneIsAllowedRefusesANullInSuchAColumncovers and callsRowConstraintsTest::testCarriesNullInIsFalseWhereEveryColumnCarriesSomethingcovers and callsRowConstraintsTest::testCarriesNullInReportsAColumnTheRowLeftNullcovers and callsRowConstraintsTest::testCarriesNullInReportsAColumnTheRowNeverWrotecovers and callsRowConstraintsTest::testKeyValuesReadsWhatTheRowCarriesUnderTheColumnNamescovers and calls
Other tests reaching this symbol 10
RewritePlanTestcallsSessionTestcallsMutationImpactTestcallsInsertMutationTestcallsUpdateMutationTestcallsShadowMutationTestcallsReferentialIntegrityEnforcerTestcallsShadowApplicationTestcallsTableTransitionsTestcallsStatementSimulatorTestcalls
Relations§
Instantiated in 2
Method calls 4
- method-call ZtdQuery\Shadow\Mutation\Row\InsertMutation::apply() packages/ztd-query-core/src/Shadow/Mutation/Row/InsertMutation.php:109
- method-call ZtdQuery\Shadow\Mutation\Row\InsertMutation::apply() packages/ztd-query-core/src/Shadow/Mutation/Row/InsertMutation.php:129
- method-call ZtdQuery\Shadow\Mutation\Row\UpdateMutation::apply() packages/ztd-query-core/src/Shadow/Mutation/Row/UpdateMutation.php:95
- method-call ZtdQuery\Shadow\Mutation\Row\UpdateMutation::apply() packages/ztd-query-core/src/Shadow/Mutation/Row/UpdateMutation.php:96