PHP Class VersionPress\Tests\Utils\CommitAsserter

Can be used from any type of tests (Selenium, WP-CLI, ...).
显示文件 Open project: versionpress/versionpress

Public Methods

Method Description
__construct ( GitRepository $gitRepository, DbSchemaInfo $dbSchema, ActionsInfoProvider $actionsInfoProvider, string[] $pathPlaceholders = [] ) Create CommitAsserter to start tracking the git repo for future asserts. Should generally be called after a test setup (if there is any) and before all the actual work. Asserts follow after it.
assertBulkAction ( string $expectedAction, integer $expectedCountOfGroupedActions ) Asserts that commit is a bulk action. Asserts the action and number of grouped change info objects.
assertCleanWorkingDirectory ( )
assertCommitAction ( string $expectedAction, integer $whichCommit, boolean $regardlessOfPriority = false ) Asserts that the recorded commit if of certain type, e.g. "post/edit". By default inspects the most recent commit; if this asserter captured more commits $whichCommit specifies which commit to assert against.
assertCommitPath ( string $type, string $path, integer $whichCommit ) Asserts that commit affected some path. Paths support wildcards and two placeholders:
assertCommitPaths ( $changes, integer $whichCommit ) Calls {@link assertCommitPath} for every item of given array.
assertCommitTag ( $tagKey, $tagValue )
assertCommitsAreEquivalent ( integer $whichCommit, integer $referenceCommit ) Asserts that two commits are "equivalent". Equivalent means that they both captured the same action over the same entity and that the captured VP tags are the same set (values may differ).
assertCountOfAffectedFiles ( integer $count, integer $whichCommit ) Asserts that commit affected exact number of files (no matter the type).
assertCountOfUntrackedFiles ( $count )
assertNumCommits ( integer $numExpectedCommits ) Asserts that the number of commits made since the constructor matches the given number.
ignoreCommits ( string | string[] $action ) Ignores commits of given action(s)
reset ( )

Protected Methods

Method Description
getChangeInfo ( Commit $commit ) : ChangeInfoEnvelope | UntrackedChangeInfo

Private Methods

Method Description
expandPath ( $path, $whichCommit ) : mixed
getCommit ( integer $whichCommit ) : Commit
getNonIgnoredCommits ( ) : Commit[] Use this to fetch all the commits since $startCommit that are not ignored.
getRevRange ( integer $whichCommit ) : string Converts $whichCommit (int) to a Git rev range

Method Details

__construct() public method

Create CommitAsserter to start tracking the git repo for future asserts. Should generally be called after a test setup (if there is any) and before all the actual work. Asserts follow after it.
public __construct ( GitRepository $gitRepository, DbSchemaInfo $dbSchema, ActionsInfoProvider $actionsInfoProvider, string[] $pathPlaceholders = [] )
$gitRepository VersionPress\Git\GitRepository
$dbSchema VersionPress\Database\DbSchemaInfo
$actionsInfoProvider VersionPress\Actions\ActionsInfoProvider
$pathPlaceholders string[]

assertBulkAction() public method

Asserts that commit is a bulk action. Asserts the action and number of grouped change info objects.
public assertBulkAction ( string $expectedAction, integer $expectedCountOfGroupedActions )
$expectedAction string Expected action, e.g., "post/edit" or "plugin/activate".
$expectedCountOfGroupedActions integer

assertCleanWorkingDirectory() public method

assertCommitAction() public method

Asserts that the recorded commit if of certain type, e.g. "post/edit". By default inspects the most recent commit; if this asserter captured more commits $whichCommit specifies which commit to assert against.
public assertCommitAction ( string $expectedAction, integer $whichCommit, boolean $regardlessOfPriority = false )
$expectedAction string Expected action, e.g., "post/edit" or "wordpress/update".
$whichCommit integer See $whichCommitParameter documentation. "HEAD" by default.
$regardlessOfPriority boolean By default, commit action must be the "main" one in the envelope (with the highest priority). If this param is set to true the whole envelope is searched for the given action.

assertCommitPath() public method

- %vpdb% expands to "wp-content/vpdb" - %VPID% expands to the VPID of the committed entity - %VPID(TAG_NAME)% expands to VPID stored in given TAG_NAME Placeholders are case sensitive.
public assertCommitPath ( string $type, string $path, integer $whichCommit )
$type string Standard git "M" (modified), "A" (added), "D" (deleted) etc. or array of actions for more possibilities.
$path string Path relative to repo root. Supports wildcards, e.g. "wp-content/uploads/*", and placeholders, e.g., "%vpdb%/posts/%VPID%.ini"
$whichCommit integer See $whichCommitParameter documentation. "HEAD" by default.

assertCommitPaths() public method

The first item in the nested array equals the type of change, the second one is the changed path.
public assertCommitPaths ( $changes, integer $whichCommit )
$changes
$whichCommit integer See $whichCommitParameter documentation. "HEAD" by default.

assertCommitTag() public method

public assertCommitTag ( $tagKey, $tagValue )

assertCommitsAreEquivalent() public method

When called without parameters, compares HEAD and the next most recent commit.
public assertCommitsAreEquivalent ( integer $whichCommit, integer $referenceCommit )
$whichCommit integer See $whichCommitParameter documentation. "HEAD" by default.
$referenceCommit integer See $whichCommitParameter documentation. "HEAD^" by default.

assertCountOfAffectedFiles() public method

Asserts that commit affected exact number of files (no matter the type).
public assertCountOfAffectedFiles ( integer $count, integer $whichCommit )
$count integer Expected count of affected files.
$whichCommit integer See $whichCommitParameter documentation. "HEAD" by default.

assertCountOfUntrackedFiles() public method

public assertCountOfUntrackedFiles ( $count )

assertNumCommits() public method

Asserts that the number of commits made since the constructor matches the given number.
public assertNumCommits ( integer $numExpectedCommits )
$numExpectedCommits integer

getChangeInfo() protected method

protected getChangeInfo ( Commit $commit ) : ChangeInfoEnvelope | UntrackedChangeInfo
$commit VersionPress\Git\Commit
return VersionPress\ChangeInfos\ChangeInfoEnvelope | VersionPress\ChangeInfos\UntrackedChangeInfo

ignoreCommits() public method

This is useful in tests where different number of commits might be created in different circumstances. For example, file upload will create two commits on first attempted upload ('post/create' and 'usermeta/edit') while it will only generate a single commit ('post/create') for repeated runs. In such case, if we only care about the 'post/create' action, 'usermeta/edit' can be set as ignored using this method.
public ignoreCommits ( string | string[] $action )
$action string | string[] An action like "usermeta/edit", or an array of them

reset() public method

public reset ( )