Skip to content

Commit

Permalink
UpgradeSnapshots - Call methods using object/instance notation
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Jul 21, 2022
1 parent 9a5357a commit fd7030b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/UpgradeSnapshots.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

class UpgradeSnapshots {

/**
* Get a default instance (based on the colocated list of snapshot files).
*
* @return \Civi\UpgradeTest\UpgradeSnapshots
*/
public static function instance(): UpgradeSnapshots {
static $instance;
$instance = $instance ?: new UpgradeSnapshots(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'databases');
return $instance;
}

/**
* Get the base-path of the snapshot data.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/FindFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getExamples(): array {
* @dataProvider getExamples
*/
public function testExamples($pattern, array $expectFileNames): void {
$actualFilePaths = UpgradeSnapshots::find($pattern);
$actualFilePaths = UpgradeSnapshots::instance()->find($pattern);
foreach ($actualFilePaths as $actualFile) {
$this->assertTrue(file_exists($actualFile), "Identified file [$actualFile] should exist");
}
Expand All @@ -29,8 +29,8 @@ public function testExamples($pattern, array $expectFileNames): void {
}

public function testMaxCount() {
$big = UpgradeSnapshots::find('@4.0..4.5');
$little = UpgradeSnapshots::find('@4.0..4.5:3');
$big = UpgradeSnapshots::instance()->find('@4.0..4.5');
$little = UpgradeSnapshots::instance()->find('@4.0..4.5:3');
$this->assertEquals(3, count($little));
$this->assertTrue(count($big) > count($little));
$this->assertEquals($little, array_intersect($little, $big), 'All items in $little are also in $big');
Expand Down
2 changes: 1 addition & 1 deletion tests/ParseFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testMisc() {
}

protected function assertFilterExpr($expected, $filterExpr) {
$parsed = UpgradeSnapshots::parseFilterExpr($filterExpr);
$parsed = UpgradeSnapshots::instance()->parseFilterExpr($filterExpr);
$this->assertEquals($expected, $parsed, "Parsing \"$filterExpr\": ");
}

Expand Down
6 changes: 3 additions & 3 deletions util/pickFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function main($args) {
}

$files = array();
$maxCount = 0;
$upgradeSnapshots = UpgradeSnapshots::instance();
while (!empty($args)) {
$arg = array_shift($args);

Expand All @@ -44,15 +44,15 @@ function main($args) {
$files[] = $arg;
}
elseif ($arg[0] === '@' || strpos($arg, '*')) {
$files = array_merge($files, UpgradeSnapshots::find($arg));
$files = array_merge($files, $upgradeSnapshots->find($arg));
}
else {
help("Unrecognized argument or missing file: $arg\n");
exit(3);
}
}

$files = UpgradeSnapshots::sortFilesByVer(array_unique($files));
$files = $upgradeSnapshots->sortFilesByVer(array_unique($files));
foreach ($files as $file) {
echo "$file\n";
}
Expand Down

0 comments on commit fd7030b

Please sign in to comment.